285 lines
No EOL
8.5 KiB
C++
285 lines
No EOL
8.5 KiB
C++
#include "display_ui.h"
|
|
#include <Wire.h>
|
|
#include <U8g2lib.h>
|
|
|
|
// Bitmaps & Animation-Dateien aus Lopaka
|
|
//#include "Clock.h"
|
|
//#include "Clock.h"
|
|
//#include "fire_flames.h"
|
|
|
|
uint32_t lastDispTime = 0;
|
|
|
|
// Statische Bitmap aus Lopaka
|
|
static const unsigned char image_paint_27_bits[] U8X8_PROGMEM = {
|
|
0x00,0x04,0x00,0x00,0x00,0x00,0x00,0x04,0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x80,
|
|
0x00,0x00,0x00,0x00,0x00,0x80,0x00,0x00,0x00,0x00,0x00,0x00,
|
|
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x00,0x00,0x00,
|
|
0x00,0x00,0x01,0x00
|
|
};
|
|
|
|
static const unsigned char image_checked_bits[] U8X8_PROGMEM = {0x00,0x00,0x40,0x21,0x13,0x0e,0x04,0x00};
|
|
static const unsigned char image_crossed_bits[] U8X8_PROGMEM = {0x00,0x21,0x12,0x0c,0x1e,0x33,0x00,0x00};
|
|
|
|
|
|
// Animations-Zähler
|
|
//static uint8_t fire_flames_frame = 0;
|
|
//static uint8_t Clock_frame = 0;
|
|
|
|
// U8g2-Display-Objekt
|
|
static U8G2_SSD1306_128X64_NONAME_F_HW_I2C u8g2(U8G2_R0, /* reset=*/ U8X8_PIN_NONE);
|
|
|
|
void initDisplay() {
|
|
Wire.begin(I2C_SDA, I2C_SCL); // SDA, SCL für XIAO ESP32-C6
|
|
Wire.setClock(400000); // 400 kHz Fast Mode
|
|
u8g2.begin();
|
|
}
|
|
|
|
// #############################################################
|
|
// ANIMATIONEN BERECHNEN & ZEICHNEN
|
|
// #############################################################
|
|
static void updateAnimations() {
|
|
//fire_flames_frame = (millis() / 77) % 8;
|
|
//Clock_frame = (millis() / 200) % 143;
|
|
}
|
|
|
|
static void drawAnimation_fire_flames() {
|
|
//u8g2.setDrawColor(1);
|
|
// u8g2.drawXBMP(80, 30, 21, 32, fire_flames_frames[fire_flames_frame]);
|
|
}
|
|
|
|
static void drawAnimation_Clock() {
|
|
//u8g2.setDrawColor(1);
|
|
// u8g2.drawXBMP(104, 40, 21, 21, Clock_frames[Clock_frame]);
|
|
}
|
|
|
|
// #############################################################
|
|
// HAUPTANZEIGE
|
|
// #############################################################
|
|
static void drawHomeScreen(int currentSpeed, int curH, int curM, bool timeValid, bool timerActive, SystemSettings settings, int curTemp) {
|
|
u8g2.setFontMode(1);
|
|
u8g2.setBitmapMode(1);
|
|
u8g2.setDrawColor(1); // 1 = Weiß (an)
|
|
|
|
// 1. Feste Beschriftungen
|
|
u8g2.setFont(u8g2_font_helvB08_tr);
|
|
u8g2.drawStr(5, 9, "Geschw");
|
|
u8g2.drawStr(5, 20, "Zeituhr");
|
|
u8g2.drawStr(5, 31, "Temp");
|
|
|
|
// 2. Dynamischer Wert: Geschwindigkeit
|
|
char speedBuf[10];
|
|
snprintf(speedBuf, sizeof(speedBuf), "%d", currentSpeed);
|
|
u8g2.drawStr(51, 8, speedBuf);
|
|
|
|
// 3. Dynamische Zeitschaltuhr: Start- und Endzeit
|
|
char startBuf[8];
|
|
char endBuf[8];
|
|
snprintf(startBuf, sizeof(startBuf), "%02d:%02d", settings.startHour, settings.startMin);
|
|
snprintf(endBuf, sizeof(endBuf), "%02d:%02d", settings.endHour, settings.endMin);
|
|
|
|
u8g2.drawStr(51, 19, startBuf);
|
|
u8g2.drawLine(79, 16, 83, 16); // Bindestrich zwischen Zeiten
|
|
u8g2.drawStr(89, 19, endBuf);
|
|
|
|
// 4. Dynamische Temperatur (Ist & Soll/Max)
|
|
char curTempBuf[10];
|
|
snprintf(curTempBuf, sizeof(curTempBuf), "%d", curTemp);
|
|
u8g2.drawStr(52, 30, curTempBuf);
|
|
u8g2.drawLine(67, 24, 67, 29); // Trennstrich
|
|
|
|
char maxTempBuf[8];
|
|
snprintf(maxTempBuf, sizeof(maxTempBuf), "%d", settings.maxTemp);
|
|
u8g2.drawStr(74, 30, maxTempBuf);
|
|
|
|
// 5. Große aktuelle Uhrzeit unten links
|
|
u8g2.setFont(u8g2_font_helvB08_tr);
|
|
char timeBuf[10];
|
|
if (timeValid) {
|
|
snprintf(timeBuf, sizeof(timeBuf), "%02d:%02d", curH, curM);
|
|
} else {
|
|
snprintf(timeBuf, sizeof(timeBuf), "--:--");
|
|
}
|
|
u8g2.drawStr(4, 60, timeBuf);
|
|
|
|
// 6. Lopaka Deko-Bitmap
|
|
u8g2.drawXBMP(32, 4, 16, 26, image_paint_27_bits);
|
|
|
|
// 7. Lopaka Animationen abspielen
|
|
//drawAnimation_fire_flames();
|
|
//drawAnimation_Clock();
|
|
}
|
|
|
|
// #############################################################
|
|
// Zeitschaltuhr
|
|
// #############################################################
|
|
static void drawTimerScreen(TimeEditStep timeEditStep, uint8_t settingIdx, const SystemSettings& settings){
|
|
u8g2.setFontMode(1);
|
|
u8g2.setBitmapMode(1);
|
|
// Von
|
|
u8g2.setFont(u8g2_font_6x12_tr);
|
|
u8g2.drawStr(31, 26, "Von:");
|
|
|
|
// Start Time
|
|
u8g2.setFont(u8g2_font_6x10_tr);
|
|
char startBuf[10];
|
|
snprintf(startBuf, sizeof(startBuf), "%02d:%02d", settings.startHour, settings.startMin);
|
|
u8g2.drawStr(66, 26, startBuf);
|
|
|
|
// string 23
|
|
u8g2.setFont(u8g2_font_6x12_tr);
|
|
u8g2.drawStr(31, 44, "Bis:");
|
|
|
|
// End Time
|
|
u8g2.setFont(u8g2_font_6x10_tr);
|
|
char endBuf[10];
|
|
snprintf(endBuf, sizeof(endBuf), "%02d:%02d", settings.endHour, settings.endMin);
|
|
u8g2.drawStr(66, 44, endBuf);
|
|
|
|
// Auswahlbox Zeichnen
|
|
switch (timeEditStep) {
|
|
case EDIT_START_HOUR:
|
|
u8g2.setDrawColor(2); // Invertierungs mode
|
|
u8g2.drawBox(66, 17, 11, 11);
|
|
u8g2.setDrawColor(1); // Wieder zurück auf normal
|
|
break;
|
|
case EDIT_START_MIN:
|
|
u8g2.setDrawColor(2); // Invertierungs mode
|
|
u8g2.drawBox((66+18), 17, 11, 11);
|
|
u8g2.setDrawColor(1); // Wieder zurück auf normal
|
|
break;
|
|
case EDIT_END_HOUR:
|
|
u8g2.setDrawColor(2); // Invertierungs mode
|
|
u8g2.drawBox(66, 35, 11, 11);
|
|
u8g2.setDrawColor(1); // Wieder zurück auf normal
|
|
break;
|
|
case EDIT_END_MIN:
|
|
u8g2.setDrawColor(2); // Invertierungs mode
|
|
u8g2.drawBox((66+18), 35, 11, 11);
|
|
u8g2.setDrawColor(1); // Wieder zurück auf normal
|
|
break;
|
|
default: break;
|
|
}
|
|
}
|
|
|
|
// #############################################################
|
|
// EINSTELLUNGSMENÜ
|
|
// #############################################################
|
|
static void drawSettingsScreen(uint8_t settingIdx, TimeEditStep timeEditStep, const SystemSettings& s) {
|
|
|
|
const uint8_t* textFont = u8g2_font_helvB08_tr;
|
|
const uint8_t* valFont = u8g2_font_helvB08_tr;
|
|
|
|
if(timeEditStep != EDIT_NONE){
|
|
drawTimerScreen(timeEditStep, settingIdx, s);
|
|
return;
|
|
}
|
|
|
|
u8g2.setFontMode(1);
|
|
u8g2.setBitmapMode(1);
|
|
u8g2.setDrawColor(1);
|
|
|
|
//######################
|
|
// Zeitschaltuhr Einstellungen
|
|
//######################
|
|
u8g2.setFont(textFont);
|
|
u8g2.drawStr(10, 10, "Zeituhr Einstellung");
|
|
|
|
//######################
|
|
// Zeitschaltuhr Status
|
|
//######################
|
|
u8g2.setFont(textFont);
|
|
u8g2.drawStr(10, 22, "Zeituhr:");
|
|
|
|
// Wenn Zeitschaltuhr Aktiviert
|
|
if(s.timerEnabled){
|
|
// Draw Check
|
|
u8g2.drawXBMP(78, 15, 7, 8, image_checked_bits);
|
|
}else{
|
|
// Draw X
|
|
u8g2.drawXBMP(78, 15, 6, 8, image_crossed_bits);
|
|
}
|
|
|
|
//######################
|
|
// Max Temp
|
|
//######################
|
|
u8g2.setFont(textFont);
|
|
u8g2.drawStr(10, 34, "Max Temp:");
|
|
char maxTempBuf[10];
|
|
snprintf(maxTempBuf, sizeof(maxTempBuf), "%d", s.maxTemp);
|
|
u8g2.setFont(valFont);
|
|
u8g2.drawStr(78, 34, maxTempBuf);
|
|
|
|
// Wenn Ausgewählt
|
|
if(s.editMaxTemp){
|
|
// Edit Fenster makieren
|
|
int w = u8g2.getStrWidth(maxTempBuf);
|
|
u8g2.drawFrame(75, 25, w + 6, 12);
|
|
}
|
|
|
|
//######################
|
|
// Beschleunigung
|
|
//######################
|
|
u8g2.setFont(textFont);
|
|
u8g2.drawStr(10, 46, "Beschleu:");
|
|
u8g2.setFont(valFont);
|
|
char accBuf[10];
|
|
snprintf(accBuf, sizeof(accBuf), "%d", s.accelRate);
|
|
u8g2.drawStr(78, 46, accBuf);
|
|
|
|
// Wenn Ausgewählt
|
|
if(s.editAcc){
|
|
// Edit Fenster makieren
|
|
int w = u8g2.getStrWidth(accBuf);
|
|
u8g2.drawFrame(75, 37, w + 6, 12);
|
|
}
|
|
|
|
//######################
|
|
// Save
|
|
//######################
|
|
u8g2.setFont(textFont);
|
|
u8g2.drawUTF8(10, 58, "Bestätigung");
|
|
|
|
// Wenn nichts bearbeitet wird...
|
|
if(!s.editAcc || !s.editMaxTemp){
|
|
// ... Auswahl rahmen anzeigen
|
|
int rowY = 0;
|
|
int rowH = 12;
|
|
|
|
switch (settingIdx) {
|
|
case 0: rowY = 1; break; // Zeituhr Einstellung
|
|
case 1: rowY = 13; break; // Zeituhr An/Aus
|
|
case 2: rowY = 25; break; // Max Temp
|
|
case 3: rowY = 37; break; // Beschleunigung
|
|
case 4: rowY = 49; break; // Bestätigung
|
|
default: break;
|
|
}
|
|
|
|
// Rahmen um die aktive Zeile (von X=2 bis fast zum rechten Rand)
|
|
u8g2.drawFrame(2, rowY, 124, rowH);
|
|
}
|
|
}
|
|
|
|
// #############################################################
|
|
// Main Funktion
|
|
// #############################################################
|
|
void updateDisplay(bool inSettings,
|
|
uint8_t settingIdx,
|
|
TimeEditStep editStep,
|
|
const SystemSettings& settings,
|
|
int currentSpeed,
|
|
int curH, int curM, bool timeValid, int curTemp) {
|
|
if (millis() - lastDispTime >= 50) {
|
|
lastDispTime = millis();
|
|
|
|
u8g2.clearBuffer();
|
|
|
|
if (inSettings) {
|
|
drawSettingsScreen(settingIdx, editStep, settings);
|
|
}else{
|
|
drawHomeScreen(currentSpeed, curH, curM, timeValid, settings.timerEnabled, settings, curTemp);
|
|
}
|
|
|
|
u8g2.sendBuffer();
|
|
}
|
|
} |