214 lines
7.2 KiB
C
214 lines
7.2 KiB
C
#ifndef ICONS_H
|
|
#define ICONS_H
|
|
|
|
#include <Arduino.h>
|
|
#include <TFT_eSPI.h>
|
|
|
|
// ==================== کدهای آیکونهای Unicode ====================
|
|
#define ICON_SUN 0x2600 // ☀️
|
|
#define ICON_THERMO 0x1F321 // 🌡️
|
|
#define ICON_DROP 0x1F4A7 // 💧
|
|
#define ICON_WARNING 0x26A0 // ⚠️
|
|
#define ICON_BATTERY 0x1F50B // 🔋
|
|
#define ICON_SIGNAL 0x1F4F6 // 📶
|
|
#define ICON_POWER 0x1F50C // 🔌
|
|
#define ICON_WIFI 0x1F4F6 // 📶
|
|
#define ICON_CLOCK 0x1F552 // 🕒
|
|
#define ICON_HOME 0x1F3E0 // 🏠
|
|
#define ICON_COG 0x2699 // ⚙️
|
|
#define ICON_DEGREE 0x00B0 // °
|
|
|
|
// ==================== توابع رسم آیکونهای گرافیکی ====================
|
|
|
|
// تابع رسم آیکون خورشید (دایرهای شکل)
|
|
inline void drawSunIcon(TFT_eSPI& tft, int x, int y, int radius, uint16_t color) {
|
|
// دایره مرکزی
|
|
tft.fillCircle(x, y, radius, color);
|
|
tft.drawCircle(x, y, radius, TFT_WHITE);
|
|
|
|
// پرتوهای خورشید
|
|
for (int i = 0; i < 8; i++) {
|
|
float angle = i * 45 * 3.14159 / 180;
|
|
int x1 = x + (radius * cos(angle));
|
|
int y1 = y + (radius * sin(angle));
|
|
int x2 = x + (radius * 1.5 * cos(angle));
|
|
int y2 = y + (radius * 1.5 * sin(angle));
|
|
tft.drawLine(x1, y1, x2, y2, color);
|
|
}
|
|
}
|
|
|
|
// تابع رسم آیکون دماسنج (برای LCD دایرهای)
|
|
inline void drawThermometerIcon(TFT_eSPI& tft, int x, int y, int height, uint16_t color, float tempPercent) {
|
|
// بدنه دماسنج
|
|
tft.drawRoundRect(x - 3, y, 6, height, 3, color);
|
|
|
|
// حباب پایین
|
|
tft.fillCircle(x, y + height + 5, 8, color);
|
|
tft.drawCircle(x, y + height + 5, 8, TFT_WHITE);
|
|
|
|
// سطح جیوه
|
|
int mercuryHeight = (tempPercent * height) / 100;
|
|
tft.fillRect(x - 2, y + (height - mercuryHeight), 4, mercuryHeight, TFT_RED);
|
|
}
|
|
|
|
// تابع رسم آیکون قطره (رطوبت)
|
|
inline void drawDropIcon(TFT_eSPI& tft, int x, int y, int size, uint16_t color, float fillPercent) {
|
|
// بدنه قطره
|
|
int dropHeight = size;
|
|
int dropWidth = size / 2;
|
|
|
|
// قسمت دایرهای بالایی
|
|
tft.fillCircle(x, y + dropWidth/2, dropWidth/2, color);
|
|
tft.drawCircle(x, y + dropWidth/2, dropWidth/2, TFT_WHITE);
|
|
|
|
// قسمت مثلثی پایینی
|
|
tft.fillTriangle(x - dropWidth/2, y + dropWidth/2,
|
|
x + dropWidth/2, y + dropWidth/2,
|
|
x, y + dropHeight, color);
|
|
|
|
tft.drawTriangle(x - dropWidth/2, y + dropWidth/2,
|
|
x + dropWidth/2, y + dropWidth/2,
|
|
x, y + dropHeight, TFT_WHITE);
|
|
|
|
// سطح آب داخل قطره
|
|
if (fillPercent > 0) {
|
|
int waterHeight = (fillPercent * dropHeight) / 100;
|
|
int waterY = y + dropHeight - waterHeight;
|
|
|
|
// قسمت دایرهای آب
|
|
if (waterY < y + dropWidth/2) {
|
|
int waterRadius = dropWidth/2;
|
|
int waterLevel = (y + dropWidth/2) - waterY;
|
|
tft.fillCircle(x, y + dropWidth/2, waterRadius - waterLevel, TFT_BLUE);
|
|
}
|
|
|
|
// قسمت مثلثی آب
|
|
tft.fillTriangle(x - dropWidth/2, y + dropHeight - waterHeight,
|
|
x + dropWidth/2, y + dropHeight - waterHeight,
|
|
x, y + dropHeight, TFT_BLUE);
|
|
}
|
|
}
|
|
|
|
// تابع رسم آیکون گاز (هشدار)
|
|
inline void drawGasIcon(TFT_eSPI& tft, int x, int y, int size, uint16_t color, bool warning) {
|
|
// مثلث هشدار
|
|
tft.fillTriangle(x, y,
|
|
x - size/2, y + size,
|
|
x + size/2, y + size,
|
|
warning ? TFT_RED : color);
|
|
|
|
tft.drawTriangle(x, y,
|
|
x - size/2, y + size,
|
|
x + size/2, y + size,
|
|
TFT_WHITE);
|
|
|
|
// علامت تعجب
|
|
tft.fillRect(x - 1, y + size/3, 2, size/3, TFT_WHITE);
|
|
tft.fillCircle(x, y + size*2/3, 2, TFT_WHITE);
|
|
|
|
// امواج گاز (دایرههای متحدالمرکز)
|
|
if (warning) {
|
|
for (int i = 1; i <= 3; i++) {
|
|
tft.drawCircle(x, y + size + 5, i * 4, TFT_YELLOW);
|
|
}
|
|
}
|
|
}
|
|
|
|
// تابع رسم آیکون باتری (برای LCD دایرهای)
|
|
inline void drawBatteryIcon(TFT_eSPI& tft, int x, int y, int width, int height, int percent, bool charging) {
|
|
// بدنه باتری
|
|
tft.drawRoundRect(x, y, width, height, 2, TFT_WHITE);
|
|
|
|
// قطب مثبت
|
|
tft.fillRoundRect(x + width, y + height/3, 2, height/3, 1, TFT_WHITE);
|
|
|
|
// سطح شارژ
|
|
int fillWidth = (percent * (width - 4)) / 100;
|
|
|
|
// رنگ باتری بر اساس درصد
|
|
uint16_t fillColor;
|
|
if (percent > 70) fillColor = TFT_GREEN;
|
|
else if (percent > 30) fillColor = TFT_YELLOW;
|
|
else fillColor = TFT_RED;
|
|
|
|
tft.fillRoundRect(x + 2, y + 2, fillWidth, height - 4, 1, fillColor);
|
|
|
|
// آیکون شارژ (صاعقه)
|
|
if (charging && percent < 95) {
|
|
tft.fillTriangle(x + width/2, y + 3,
|
|
x + width/2 - 3, y + height - 3,
|
|
x + width/2 + 3, y + height - 3, TFT_CYAN);
|
|
}
|
|
|
|
// نمایش درصد در وسط باتری (اگر جای کافی باشد)
|
|
if (width > 30) {
|
|
tft.setTextColor(TFT_WHITE, fillColor);
|
|
tft.setTextSize(1);
|
|
tft.setTextDatum(MC_DATUM);
|
|
tft.drawNumber(percent, x + width/2, y + height/2 + 1);
|
|
tft.setTextDatum(TL_DATUM); // بازگشت به حالت پیشفرض
|
|
}
|
|
}
|
|
|
|
// تابع رسم نوار سیگنال (دایرهای)
|
|
inline void drawSignalBars(TFT_eSPI& tft, int x, int y, int radius, int strength) {
|
|
// 4 میله سیگنال به شکل دایرهای
|
|
int bars = (strength * 4) / 31;
|
|
if (bars > 4) bars = 4;
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
int barRadius = radius - (i * 5);
|
|
if (barRadius > 0) {
|
|
if (i < bars) {
|
|
uint16_t barColor;
|
|
if (strength > 20) barColor = TFT_GREEN;
|
|
else if (strength > 10) barColor = TFT_YELLOW;
|
|
else barColor = TFT_RED;
|
|
|
|
// رسم قوس برای هر میله
|
|
int startAngle = 180 + (i * 15);
|
|
int endAngle = 180 - (i * 15);
|
|
tft.drawArc(x, y, barRadius, barRadius - 2, startAngle, endAngle, barColor, barColor);
|
|
} else {
|
|
//tft.drawArc(x, y, barRadius, barRadius - 2, 150, 210, TFT_DARKGREY, TFT_DARKGREY);
|
|
}
|
|
}
|
|
}
|
|
|
|
// نقطه مرکزی
|
|
tft.fillCircle(x, y, 2, TFT_WHITE);
|
|
}
|
|
|
|
// تابع رسم آیکون برق شهری
|
|
inline void drawPowerIcon(TFT_eSPI& tft, int x, int y, int size, uint16_t color) {
|
|
// دایره بیرونی
|
|
tft.drawCircle(x, y, size/2, color);
|
|
|
|
// علامت پاور (دایره با خط)
|
|
tft.drawLine(x, y - size/4, x, y + size/4, color);
|
|
tft.fillTriangle(x, y - size/4,
|
|
x - size/6, y,
|
|
x + size/6, y, color);
|
|
}
|
|
|
|
// تابع رسم آیکون وایفای (دایرهای)
|
|
inline void drawWifiIcon(TFT_eSPI& tft, int x, int y, int radius, uint16_t color, bool connected) {
|
|
if (!connected) {
|
|
tft.drawLine(x - radius/2, y - radius/2, x + radius/2, y + radius/2, TFT_RED);
|
|
tft.drawLine(x + radius/2, y - radius/2, x - radius/2, y + radius/2, TFT_RED);
|
|
return;
|
|
}
|
|
|
|
// حلقههای وایفای
|
|
for (int i = 1; i <= 3; i++) {
|
|
int r = radius - (i * 4);
|
|
if (r > 0) {
|
|
tft.drawCircle(x, y, r, color);
|
|
}
|
|
}
|
|
|
|
// نقطه مرکزی
|
|
tft.fillCircle(x, y, 2, color);
|
|
}
|
|
|
|
#endif // ICONS_H
|