new code
This commit is contained in:
320
Display.h
Normal file
320
Display.h
Normal file
@@ -0,0 +1,320 @@
|
||||
#ifndef DISPLAY_H
|
||||
#define DISPLAY_H
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Adafruit_SSD1306.h>
|
||||
#include <Fonts/FreeSans9pt7b.h>
|
||||
#include <Fonts/FreeSansBold12pt7b.h>
|
||||
#include <Fonts/FreeSansBold18pt7b.h>
|
||||
#include "Config.h"
|
||||
|
||||
// -------------------- متغیرهای خارجی --------------------
|
||||
extern Adafruit_SSD1306 display;
|
||||
extern DeviceConfig config;
|
||||
extern SensorData currentData;
|
||||
extern bool sht31Connected;
|
||||
extern bool lightSensorConnected;
|
||||
extern bool coSensorConnected;
|
||||
extern bool calibrationComplete;
|
||||
extern bool awaitingSMS2;
|
||||
extern int signalStrength;
|
||||
extern String lastMessage;
|
||||
extern int displayMode;
|
||||
extern unsigned long lastDisplayChange;
|
||||
extern unsigned long lastNetworkStatusUpdate;
|
||||
|
||||
// Forward declaration
|
||||
void updateNetworkStatus();
|
||||
|
||||
// -------------------- توابع نمایشگر --------------------
|
||||
inline void displayAllParameters() {
|
||||
display.clearDisplay();
|
||||
//display.setTextColor(SSD1306_WHITE);
|
||||
|
||||
// عنوان با فونت زیبا
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(8, 12);
|
||||
display.print("All Parameters");
|
||||
|
||||
// خط جداکننده
|
||||
display.drawLine(0, 15, 128, 15, SSD1306_WHITE);
|
||||
|
||||
// ارتفاع 12-14
|
||||
// دما
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(1, 30);
|
||||
display.print("T:");//16 پیکسل
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(18, 30);
|
||||
display.print(currentData.temperature, 1);//34 پیکسل
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
//display.setCursor(55, 30);
|
||||
//display.print("-");//3 پیکسل
|
||||
|
||||
// رطوبت
|
||||
display.setCursor(65, 30);
|
||||
display.print("H:");//16 پیکسل
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(83, 30);
|
||||
display.print(currentData.humidity, 0);//34 پیکسل
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(110, 31);
|
||||
display.print("%");
|
||||
|
||||
// نور
|
||||
display.setCursor(1, 55);
|
||||
display.print("L:");//15 پیکسل
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(20, 55);
|
||||
display.print((int)currentData.lightLux);//40 پیکسل
|
||||
|
||||
//گاز
|
||||
display.setCursor(70, 55);
|
||||
display.print("G:");//15 پیکسل
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(88, 55);
|
||||
display.print((int)currentData.coPPM);//40 پیکسل
|
||||
|
||||
// برگشت به فونت پیشفرض
|
||||
display.setFont();
|
||||
display.display();
|
||||
}
|
||||
|
||||
inline void displayTemperature() {
|
||||
display.clearDisplay();
|
||||
|
||||
// عنوان
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(18, 14);
|
||||
display.print("Temperature");
|
||||
|
||||
// خط جداکننده
|
||||
display.drawLine(0, 18, 128, 18, SSD1306_WHITE);
|
||||
|
||||
// مقدار دما - عدد بزرگ و نرم
|
||||
display.setFont(&FreeSansBold18pt7b);
|
||||
display.setCursor(10, 50);
|
||||
display.print(currentData.temperature, 1);
|
||||
|
||||
// واحد
|
||||
display.setFont(&FreeSansBold12pt7b);
|
||||
display.setCursor(90, 45);
|
||||
display.print("C");
|
||||
|
||||
// علامت درجه
|
||||
display.drawCircle(85, 30, 3, SSD1306_WHITE);
|
||||
|
||||
// وضعیت سنسور
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(50, 63);
|
||||
if (!sht31Connected) {
|
||||
display.print("ERR");
|
||||
}
|
||||
|
||||
display.setFont();
|
||||
display.display();
|
||||
}
|
||||
|
||||
inline void displayHumidity() {
|
||||
display.clearDisplay();
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
|
||||
// عنوان
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(30, 14);
|
||||
display.print("Humidity");
|
||||
|
||||
// خط جداکننده
|
||||
display.drawLine(0, 18, 128, 18, SSD1306_WHITE);
|
||||
|
||||
// مقدار رطوبت - عدد بزرگ و نرم
|
||||
display.setFont(&FreeSansBold18pt7b);
|
||||
display.setCursor(25, 50);
|
||||
display.print(currentData.humidity, 0);
|
||||
|
||||
// واحد درصد
|
||||
display.setFont(&FreeSansBold12pt7b);
|
||||
display.setCursor(75, 48);
|
||||
display.print("%");
|
||||
|
||||
// وضعیت سنسور
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(50, 63);
|
||||
if (!sht31Connected) {
|
||||
display.print("ERR");
|
||||
}
|
||||
|
||||
display.setFont();
|
||||
display.display();
|
||||
}
|
||||
|
||||
inline void displayCO() {
|
||||
display.clearDisplay();
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
|
||||
// عنوان
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(35, 14);
|
||||
display.print("CO Gas");
|
||||
|
||||
// خط جداکننده
|
||||
display.drawLine(0, 18, 128, 18, SSD1306_WHITE);
|
||||
|
||||
// مقدار CO (منفی = در حال کالیبره) - عدد بزرگ و نرم
|
||||
display.setFont(&FreeSansBold18pt7b);
|
||||
display.setCursor(8, 50);
|
||||
display.print(currentData.coPPM, 0);
|
||||
|
||||
// واحد
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(70, 48);
|
||||
display.print("ppm");
|
||||
|
||||
// وضعیت سنسور و کالیبراسیون
|
||||
display.setCursor(5, 63);
|
||||
if (!calibrationComplete) {
|
||||
display.print("Calibrating...");
|
||||
} else if (!coSensorConnected) {
|
||||
display.print("Sensor ERR");
|
||||
}
|
||||
|
||||
display.setFont();
|
||||
display.display();
|
||||
}
|
||||
|
||||
inline void displayLight() {
|
||||
display.clearDisplay();
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
|
||||
// عنوان
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(40, 14);
|
||||
display.print("Light");
|
||||
|
||||
// خط جداکننده
|
||||
display.drawLine(0, 18, 128, 18, SSD1306_WHITE);
|
||||
|
||||
// مقدار نور - عدد بزرگ و نرم
|
||||
display.setFont(&FreeSansBold18pt7b);
|
||||
display.setCursor(8, 50);
|
||||
display.print((int)currentData.lightLux);
|
||||
|
||||
// واحد
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(75, 48);
|
||||
display.print("lux");
|
||||
|
||||
// وضعیت سنسور
|
||||
display.setCursor(50, 63);
|
||||
if (!lightSensorConnected) {
|
||||
display.print("ERR");
|
||||
}
|
||||
|
||||
display.setFont();
|
||||
display.display();
|
||||
}
|
||||
|
||||
inline void displaySIMStatus() {
|
||||
display.clearDisplay();
|
||||
display.setTextColor(SSD1306_WHITE);
|
||||
|
||||
// عنوان
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(25, 14);
|
||||
display.print("SIM Status");
|
||||
|
||||
// خط جداکننده
|
||||
display.drawLine(0, 18, 128, 18, SSD1306_WHITE);
|
||||
|
||||
// بقیه اطلاعات با فونت پیشفرض برای جا شدن بیشتر
|
||||
display.setFont();
|
||||
|
||||
if (!config.verified) {
|
||||
// وضعیت تنظیم نشده
|
||||
display.setTextSize(1);
|
||||
display.setCursor(20, 28);
|
||||
if (!awaitingSMS2) {
|
||||
display.print("Waiting SMS1");
|
||||
display.setCursor(15, 42);
|
||||
display.print("for activation");
|
||||
} else {
|
||||
display.print("Waiting SMS2");
|
||||
display.setCursor(15, 42);
|
||||
display.print("for config");
|
||||
}
|
||||
} else {
|
||||
// وضعیت تنظیم شده
|
||||
display.setTextSize(1);
|
||||
display.setCursor(5, 22);
|
||||
display.print("ID:");
|
||||
display.setCursor(25, 22);
|
||||
display.print(config.deviceId);
|
||||
|
||||
display.setCursor(5, 32);
|
||||
display.print("SIM:");
|
||||
display.setCursor(30, 32);
|
||||
display.print(simTypeToString(config.simType));
|
||||
|
||||
display.setCursor(5, 42);
|
||||
display.print("Upload:");
|
||||
display.setCursor(50, 42);
|
||||
display.print(config.uploadInterval);
|
||||
display.print("m");
|
||||
|
||||
// سیگنال با نشانگر گرافیکی
|
||||
display.setCursor(80, 42);
|
||||
display.print("Sig:");
|
||||
display.setCursor(105, 42);
|
||||
display.print(signalStrength);
|
||||
}
|
||||
|
||||
// آخرین پیام
|
||||
display.setFont(&FreeSans9pt7b);
|
||||
display.setCursor(5, 62);
|
||||
if (lastMessage.length() > 14) {
|
||||
display.print(lastMessage.substring(0, 14));
|
||||
} else {
|
||||
display.print(lastMessage);
|
||||
}
|
||||
|
||||
display.setFont();
|
||||
display.display();
|
||||
}
|
||||
|
||||
inline void updateDisplay() {
|
||||
// تغییر صفحه هر 3 ثانیه
|
||||
if (millis() - lastDisplayChange > 3000) {
|
||||
displayMode = (displayMode + 1) % 6; // 6 صفحه داریم
|
||||
lastDisplayChange = millis();
|
||||
}
|
||||
|
||||
// بهروزرسانی وضعیت شبکه هر 30 ثانیه
|
||||
if (millis() - lastNetworkStatusUpdate > 30000) {
|
||||
updateNetworkStatus();
|
||||
lastNetworkStatusUpdate = millis();
|
||||
}
|
||||
switch(displayMode) {
|
||||
case 0:
|
||||
displayAllParameters();
|
||||
break;
|
||||
case 1:
|
||||
displayTemperature();
|
||||
break;
|
||||
case 2:
|
||||
displayHumidity();
|
||||
break;
|
||||
case 3:
|
||||
displayCO();
|
||||
break;
|
||||
case 4:
|
||||
displayLight();
|
||||
break;
|
||||
case 5:
|
||||
displaySIMStatus();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif // DISPLAY_H
|
||||
|
||||
Reference in New Issue
Block a user