2023-05-20 09:15:38 +02:00
|
|
|
#include "gfx_1.h"
|
|
|
|
#include "datetimeHandler.h"
|
|
|
|
#include "cpu.h"
|
|
|
|
#include "Adafruit_GFX.h"
|
|
|
|
#include <Adafruit_ILI9341.h>
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
static uint8_t s_time_tab[6] = { '0', '0', ':', '0', '0', 0 };
|
2023-05-20 09:15:38 +02:00
|
|
|
static uint8_t s_localHum = 0, s_localTemp = 0, s_cpuTemp = 255;
|
|
|
|
static int16_t s_cpu_usage = 255;
|
|
|
|
static uint32_t s_ram_free = 255, s_ram_max = 255;
|
2023-05-20 15:14:22 +02:00
|
|
|
static String s_os = "Unknown", s_kernel = "Unknown", s_uptime = "Unknown";
|
2023-05-20 09:15:38 +02:00
|
|
|
|
|
|
|
|
|
|
|
// 5px size
|
|
|
|
static void gfx_update_toolbar();
|
|
|
|
static void gfx_update_cpu();
|
|
|
|
static void gfx_update_mem();
|
2023-05-20 15:14:22 +02:00
|
|
|
static void gfx_update_sys_info();
|
2023-05-20 09:15:38 +02:00
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
static void writeArray(const char *buf) {
|
|
|
|
uint8_t c = 0;
|
|
|
|
while (buf[c] != 0)
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.write(buf[c++]);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
void gfx1_udpate() {
|
2023-05-20 09:15:38 +02:00
|
|
|
gfx_update_toolbar();
|
|
|
|
gfx_update_cpu();
|
|
|
|
gfx_update_mem();
|
2023-05-20 15:14:22 +02:00
|
|
|
gfx_update_sys_info();
|
2023-05-20 09:15:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#define LINE_Y_REL 29
|
|
|
|
#define TEXT_Y_REL 9
|
|
|
|
#define FIRST_TEXT_Y_REL 40
|
|
|
|
#define TEXT_ESPACE_Y 35
|
|
|
|
#define TEXT_ESPACE_SHORT_Y 25
|
|
|
|
|
|
|
|
char buf[20];
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
void gfx1_layout() {
|
|
|
|
uint8_t c = 0;
|
|
|
|
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.fillScreen(ILI9341_BLACK);
|
|
|
|
tft.drawLine(10, 18, 310, 18, ILI9341_YELLOW);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setTextColor(ILI9341_YELLOW, ILI9341_BLACK);
|
|
|
|
|
|
|
|
// Temp
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.setCursor(35, 0);
|
|
|
|
tft.setTextSize(1);
|
|
|
|
tft.write('o');
|
|
|
|
tft.setTextSize(2);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setCursor(35 + 8, 2);
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.write('C');
|
2023-05-20 15:14:22 +02:00
|
|
|
|
|
|
|
// Humidity
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.setCursor(300, 2);
|
|
|
|
tft.write('%');
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
// CPU
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.setTextSize(2);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.drawRoundRect(5, 25, 150, 90, 10, ILI9341_RED);
|
|
|
|
tft.drawLine(5, 25 + LINE_Y_REL, 154, 25 + LINE_Y_REL, ILI9341_RED);
|
|
|
|
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
|
|
|
|
tft.setCursor(60, 25 + TEXT_Y_REL);
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "CPU");
|
|
|
|
writeArray(buf);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setCursor(15, 25 + FIRST_TEXT_Y_REL);
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "Usage:");
|
|
|
|
writeArray(buf);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setCursor(15, 25 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y);
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "Temp:");
|
|
|
|
writeArray(buf);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setCursor(15, 25 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y * 2);
|
2023-05-20 09:15:38 +02:00
|
|
|
|
|
|
|
// memory
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.drawRoundRect(165, 25, 150, 90, 10, ILI9341_GREEN);
|
|
|
|
tft.drawLine(165, 25 + LINE_Y_REL, 314, 25 + LINE_Y_REL, ILI9341_GREEN);
|
|
|
|
tft.setTextColor(ILI9341_GREEN, ILI9341_BLACK);
|
|
|
|
tft.setCursor(205, 25 + TEXT_Y_REL);
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "MEMORY");
|
|
|
|
writeArray(buf);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setCursor(175, 25 + FIRST_TEXT_Y_REL);
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "Max:");
|
|
|
|
writeArray(buf);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setCursor(175, 25 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y);
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "Free:");
|
|
|
|
writeArray(buf);
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
// sysinfo
|
|
|
|
tft.setTextSize(2);
|
|
|
|
tft.drawRoundRect(5, 125, 310, 110, 10, ILI9341_CYAN);
|
|
|
|
tft.drawLine(5, 125 + LINE_Y_REL, 314, 125 + LINE_Y_REL, ILI9341_CYAN);
|
|
|
|
tft.setTextColor(ILI9341_CYAN, ILI9341_BLACK);
|
|
|
|
tft.setCursor(55, 125 + TEXT_Y_REL);
|
|
|
|
sprintf(buf, "System Information");
|
|
|
|
writeArray(buf);
|
|
|
|
tft.setCursor(15, 125 + FIRST_TEXT_Y_REL);
|
|
|
|
sprintf(buf, "OS:");
|
|
|
|
writeArray(buf);
|
|
|
|
tft.setCursor(15, 125 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y);
|
|
|
|
sprintf(buf, "Kernel:");
|
|
|
|
writeArray(buf);
|
|
|
|
tft.setCursor(15, 125 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y * 2);
|
|
|
|
sprintf(buf, "Uptime:");
|
|
|
|
writeArray(buf);
|
|
|
|
|
2023-05-20 09:15:38 +02:00
|
|
|
gfx1_udpate();
|
|
|
|
}
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
void get_formated_space(int32_t valueMb) {
|
2023-05-20 09:15:38 +02:00
|
|
|
int8_t unity = 0;
|
2023-05-20 15:14:22 +02:00
|
|
|
if (valueMb > 999) {
|
2023-05-20 09:15:38 +02:00
|
|
|
valueMb = valueMb / 1024;
|
2023-05-20 15:14:22 +02:00
|
|
|
unity = 1; // GB
|
2023-05-20 09:15:38 +02:00
|
|
|
}
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
if (valueMb > 9999) {
|
2023-05-20 09:15:38 +02:00
|
|
|
valueMb = valueMb / 1024;
|
2023-05-20 15:14:22 +02:00
|
|
|
unity = 2; // TB
|
2023-05-20 09:15:38 +02:00
|
|
|
}
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
if (unity == 0)
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "%4d MB", valueMb);
|
2023-05-20 15:14:22 +02:00
|
|
|
else if (unity == 1)
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "%4d GB", valueMb);
|
|
|
|
else
|
|
|
|
sprintf(buf, "%4d TB", valueMb);
|
|
|
|
}
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
static void gfx_update_mem() {
|
|
|
|
tft.setTextColor(ILI9341_GREEN, ILI9341_BLACK);
|
|
|
|
if (s_ram_max != ramMax) {
|
|
|
|
tft.setCursor(175 + 50, 25 + FIRST_TEXT_Y_REL);
|
2023-05-20 09:15:38 +02:00
|
|
|
get_formated_space(ramMax);
|
|
|
|
writeArray(buf);
|
2023-05-20 15:14:22 +02:00
|
|
|
s_ram_max = ramMax;
|
2023-05-20 09:15:38 +02:00
|
|
|
}
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
if (s_ram_free != ramFree) {
|
|
|
|
tft.setCursor(175 + 50, 25 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y);
|
2023-05-20 09:15:38 +02:00
|
|
|
get_formated_space(ramFree);
|
|
|
|
writeArray(buf);
|
|
|
|
s_ram_free = ramFree;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
static void gfx_update_cpu() {
|
|
|
|
tft.setTextColor(ILI9341_RED, ILI9341_BLACK);
|
|
|
|
if (cpuUsageGlobal != s_cpu_usage) {
|
|
|
|
tft.setCursor(15 + 75, 25 + FIRST_TEXT_Y_REL);
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "%3d %%", cpuUsageGlobal);
|
|
|
|
writeArray(buf);
|
|
|
|
s_cpu_usage = cpuUsageGlobal;
|
|
|
|
}
|
2023-05-20 15:14:22 +02:00
|
|
|
if (s_cpuTemp != cpuTempGlobal) {
|
|
|
|
tft.setCursor(15 + 75, 25 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y);
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "%3d ", cpuTempGlobal);
|
|
|
|
writeArray(buf);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setCursor(15 + 115, 25 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y - 2);
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.setTextSize(1);
|
|
|
|
tft.write('o');
|
|
|
|
tft.setTextSize(2);
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setCursor(15 + 115 + 8, 25 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y);
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.write('C');
|
|
|
|
s_cpuTemp = cpuTempGlobal;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-20 15:14:22 +02:00
|
|
|
static void gfx_update_sys_info() {
|
|
|
|
tft.setTextColor(ILI9341_CYAN, ILI9341_BLACK);
|
|
|
|
|
|
|
|
tft.setCursor(15 + 50, 125 + FIRST_TEXT_Y_REL);
|
|
|
|
sprintf(buf, "%s", OS);
|
|
|
|
writeArray(buf);
|
|
|
|
s_os = OS;
|
|
|
|
|
|
|
|
tft.setCursor(15 + 95, 125 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y);
|
|
|
|
sprintf(buf, "%s ", KernelVer);
|
|
|
|
writeArray(buf);
|
|
|
|
tft.setCursor(15 + 115, 125 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y - 2);
|
|
|
|
s_kernel = KernelVer;
|
|
|
|
|
|
|
|
tft.setCursor(15 + 95, 125 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y * 2);
|
|
|
|
sprintf(buf, "%s ", Uptime);
|
|
|
|
writeArray(buf);
|
|
|
|
tft.setCursor(15 + 115, 125 + FIRST_TEXT_Y_REL + TEXT_ESPACE_SHORT_Y * 2 - 2);
|
|
|
|
s_uptime = Uptime;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void gfx_update_toolbar() {
|
|
|
|
uint8_t c = 0;
|
2023-05-20 09:15:38 +02:00
|
|
|
char buf[5];
|
2023-05-20 15:14:22 +02:00
|
|
|
tft.setTextColor(ILI9341_YELLOW, ILI9341_BLACK);
|
|
|
|
|
|
|
|
if (s_time_tab[4] != time_tab[4] || s_time_tab[3] != time_tab[3]
|
|
|
|
|| s_time_tab[1] != time_tab[1] || s_time_tab[0] != time_tab[0]) {
|
|
|
|
tft.setTextSize(2);
|
|
|
|
tft.setCursor(135, 2);
|
|
|
|
|
|
|
|
while (c < 5) {
|
|
|
|
uint8_t car = time_tab[c];
|
|
|
|
s_time_tab[c] = car;
|
|
|
|
tft.write(car);
|
|
|
|
c++;
|
|
|
|
}
|
2023-05-20 09:15:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
//temp
|
2023-05-20 15:14:22 +02:00
|
|
|
if (s_localTemp != localTemp) {
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.setCursor(10, 2);
|
2023-05-20 15:14:22 +02:00
|
|
|
if (localTemp != 255)
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "%2d", localTemp);
|
|
|
|
else
|
|
|
|
sprintf(buf, "--");
|
|
|
|
writeArray(buf);
|
|
|
|
s_localTemp = localTemp;
|
|
|
|
}
|
2023-05-20 15:14:22 +02:00
|
|
|
|
2023-05-20 09:15:38 +02:00
|
|
|
// humidity
|
2023-05-20 15:14:22 +02:00
|
|
|
if (s_localHum != localHum) {
|
2023-05-20 09:15:38 +02:00
|
|
|
tft.setCursor(275, 2);
|
2023-05-20 15:14:22 +02:00
|
|
|
if (localHum != 255)
|
2023-05-20 09:15:38 +02:00
|
|
|
sprintf(buf, "%2d", localHum);
|
|
|
|
else
|
|
|
|
sprintf(buf, "--");
|
|
|
|
writeArray(buf);
|
|
|
|
s_localHum = localHum;
|
|
|
|
}
|
|
|
|
}
|