From 722ef421cb5d1d52cf31788f52c5a3da1af14b57 Mon Sep 17 00:00:00 2001 From: Jan Philipp Ecker Date: Sat, 2 Aug 2025 22:52:19 +0200 Subject: [PATCH] Reworks startup graphics and timings Reworks the graphics during the startup. Introduces a progress bar to visualize how much of the boot is completed. Also changes the the optics of the bambu, spoolman and wifi icons. They are now always displayed but they will be striked out if not working and they will start blinking. Also removes some unnessesary waits. --- src/api.cpp | 4 +-- src/bambu.cpp | 1 + src/config.cpp | 7 +----- src/config.h | 12 ++++++--- src/display.cpp | 65 +++++++++++++++++++++++++++++++++++++------------ src/display.h | 8 +++--- src/main.cpp | 6 +++++ src/nfc.cpp | 1 + src/scale.cpp | 2 +- src/website.cpp | 1 + src/wlan.cpp | 6 +---- 11 files changed, 75 insertions(+), 38 deletions(-) diff --git a/src/api.cpp b/src/api.cpp index e19fb9a..4020d67 100644 --- a/src/api.cpp +++ b/src/api.cpp @@ -551,9 +551,6 @@ bool checkSpoolmanInstance(const String& url) { if (httpCode > 0) { if (httpCode == HTTP_CODE_OK) { - oledShowMessage("Spoolman available"); - vTaskDelay(1000 / portTICK_PERIOD_MS); - String payload = http.getString(); JsonDocument doc; DeserializationError error = deserializeJson(doc, payload); @@ -617,6 +614,7 @@ String loadSpoolmanUrl() { } bool initSpoolman() { + oledShowProgressBar(3, 7, DISPLAY_BOOT_TEXT, "Spoolman init"); spoolmanUrl = loadSpoolmanUrl(); spoolmanUrl.trim(); if (spoolmanUrl == "") { diff --git a/src/bambu.cpp b/src/bambu.cpp index c738ec8..21fc6fa 100644 --- a/src/bambu.cpp +++ b/src/bambu.cpp @@ -627,6 +627,7 @@ bool setupMqtt() { if (bambuCredentials.ip != "" && bambuCredentials.accesscode != "" && bambuCredentials.serial != "") { + oledShowProgressBar(4, 7, DISPLAY_BOOT_TEXT, "Bambu init"); bambuDisabled = false; sslClient.setCACert(root_ca); sslClient.setInsecure(); diff --git a/src/config.cpp b/src/config.cpp index 644177e..359031a 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -26,16 +26,11 @@ const uint8_t TTP223_PIN = 25; // ***** Display -// Declaration for an SSD1306 display connected to I2C (SDA, SCL pins) -// On an ESP32: 21(SDA), 22(SCL) -const int8_t OLED_RESET = -1; // Reset pin # (or -1 if sharing Arduino reset pin) -const uint8_t SCREEN_ADDRESS = 0x3C; ///< See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 -const uint8_t SCREEN_WIDTH = 128; // OLED display width, in pixels -const uint8_t SCREEN_HEIGHT = 64; // OLED display height, in pixels const uint8_t OLED_TOP_START = 0; const uint8_t OLED_TOP_END = 16; const uint8_t OLED_DATA_START = 17; const uint8_t OLED_DATA_END = SCREEN_HEIGHT; + // ***** Display // ***** Webserver diff --git a/src/config.h b/src/config.h index ecccd51..88c57c0 100644 --- a/src/config.h +++ b/src/config.h @@ -25,6 +25,14 @@ #define BAMBU_USERNAME "bblp" +#define OLED_RESET -1 // Reset pin # (or -1 if sharing Arduino reset pin) +#define SCREEN_ADDRESS 0x3CU // See datasheet for Address; 0x3D for 128x64, 0x3C for 128x32 +#define SCREEN_WIDTH 128U +#define SCREEN_HEIGHT 64U +#define SCREEN_TOP_BAR_HEIGHT 16U +#define SCREEN_PROGRESS_BAR_HEIGHT 12U +#define DISPLAY_BOOT_TEXT "FilaMan" + extern const uint8_t PN532_IRQ; extern const uint8_t PN532_RESET; @@ -36,10 +44,6 @@ extern const uint16_t SCALE_LEVEL_WEIGHT; extern const uint8_t TTP223_PIN; -extern const int8_t OLED_RESET; -extern const uint8_t SCREEN_ADDRESS; -extern const uint8_t SCREEN_WIDTH; -extern const uint8_t SCREEN_HEIGHT; extern const uint8_t OLED_TOP_START; extern const uint8_t OLED_TOP_END; extern const uint8_t OLED_DATA_START; diff --git a/src/display.cpp b/src/display.cpp index dab0ccf..a15aa47 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -6,6 +6,7 @@ Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RESET); bool wifiOn = false; +bool iconToggle = false; void setupDisplay() { if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { @@ -15,14 +16,6 @@ void setupDisplay() { display.setTextColor(WHITE); display.clearDisplay(); display.display(); - - // Show initial display buffer contents on the screen -- - // the library initializes this with an Adafruit splash screen. - display.setTextColor(WHITE); - display.display(); - oledShowTopRow(); - oledShowMessage("FilaMan v" + String(VERSION)); - vTaskDelay(2000 / portTICK_PERIOD_MS); } void oledclearline() { @@ -45,14 +38,14 @@ void oledcleardata() { //display.display(); } -int oled_center_h(String text) { +int oled_center_h(const String &text) { int16_t x1, y1; uint16_t w, h; display.getTextBounds(text, 0, 0, &x1, &y1, &w, &h); return (SCREEN_WIDTH - w) / 2; } -int oled_center_v(String text) { +int oled_center_v(const String &text) { int16_t x1, y1; uint16_t w, h; display.getTextBounds(text, 0, OLED_DATA_START, &x1, &y1, &w, &h); @@ -60,7 +53,7 @@ int oled_center_v(String text) { return OLED_DATA_START + ((OLED_DATA_END - OLED_DATA_START - h) / 2); } -std::vector splitTextIntoLines(String text, uint8_t textSize) { +std::vector splitTextIntoLines(const String &text, uint8_t textSize) { std::vector lines; display.setTextSize(textSize); @@ -120,7 +113,7 @@ std::vector splitTextIntoLines(String text, uint8_t textSize) { return lines; } -void oledShowMultilineMessage(String message, uint8_t size) { +void oledShowMultilineMessage(const String &message, uint8_t size) { std::vector lines; int maxLines = 3; // Maximale Anzahl Zeilen für size 2 @@ -148,7 +141,7 @@ void oledShowMultilineMessage(String message, uint8_t size) { display.display(); } -void oledShowMessage(String message, uint8_t size) { +void oledShowMessage(const String &message, uint8_t size) { oledcleardata(); display.setTextSize(size); display.setTextWrap(false); @@ -171,22 +164,41 @@ void oledShowMessage(String message, uint8_t size) { void oledShowTopRow() { oledclearline(); + display.setTextSize(1); + display.setCursor(0, 4); + display.print("v"); + display.print(VERSION); + + iconToggle = !iconToggle; + if (bambu_connected == 1) { display.drawBitmap(50, 0, bitmap_bambu_on , 16, 16, WHITE); } else { - display.drawBitmap(50, 0, bitmap_off , 16, 16, WHITE); + if(iconToggle){ + display.drawBitmap(50, 0, bitmap_bambu_on , 16, 16, WHITE); + display.drawLine(50, 15, 66, 0, WHITE); + display.drawLine(51, 15, 67, 0, WHITE); + } } if (spoolmanApiState != API_INIT) { display.drawBitmap(80, 0, bitmap_spoolman_on , 16, 16, WHITE); } else { - display.drawBitmap(80, 0, bitmap_off , 16, 16, WHITE); + if(iconToggle){ + display.drawBitmap(80, 0, bitmap_spoolman_on , 16, 16, WHITE); + display.drawLine(80, 15, 96, 0, WHITE); + display.drawLine(81, 15, 97, 0, WHITE); + } } if (wifiOn == 1) { display.drawBitmap(107, 0, wifi_on , 16, 16, WHITE); } else { - display.drawBitmap(107, 0, wifi_off , 16, 16, WHITE); + if(iconToggle){ + display.drawBitmap(107, 0, wifi_on , 16, 16, WHITE); + display.drawLine(107, 15, 123, 0, WHITE); + display.drawLine(108, 15, 124, 0, WHITE); + } } display.display(); @@ -214,6 +226,27 @@ void oledShowIcon(const char* icon) { display.display(); } +void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char* largeText, const char* statusMessage){ + assert(step <= numSteps); + + // clear data and bar area + display.fillRect(0, OLED_DATA_START, SCREEN_WIDTH, SCREEN_HEIGHT-16, BLACK); + + + display.setTextWrap(false); + display.setTextSize(2); + display.setCursor(0, OLED_DATA_START+4); + display.print(largeText); + display.setTextSize(1); + display.setCursor(0, OLED_DATA_END-SCREEN_PROGRESS_BAR_HEIGHT-10); + display.print(statusMessage); + + const int barLength = ((SCREEN_WIDTH-2)*step)/numSteps; + display.drawRoundRect(0, SCREEN_HEIGHT-SCREEN_PROGRESS_BAR_HEIGHT, SCREEN_WIDTH, 12, 6, WHITE); + display.fillRoundRect(1, SCREEN_HEIGHT-SCREEN_PROGRESS_BAR_HEIGHT+1, barLength, 10, 6, WHITE); + display.display(); +} + void oledShowWeight(uint16_t weight) { // Display Gewicht oledcleardata(); diff --git a/src/display.h b/src/display.h index 173c48e..c4cdb08 100644 --- a/src/display.h +++ b/src/display.h @@ -13,11 +13,13 @@ extern bool wifiOn; void setupDisplay(); void oledclearline(); void oledcleardata(); -int oled_center_h(String text); -int oled_center_v(String text); +int oled_center_h(const String &text); +int oled_center_v(const String &text); + +void oledShowProgressBar(const uint8_t step, const uint8_t numSteps, const char* largeText, const char* statusMessage); void oledShowWeight(uint16_t weight); -void oledShowMessage(String message, uint8_t size = 2); +void oledShowMessage(const String &message, uint8_t size = 2); void oledShowTopRow(); void oledShowIcon(const char* icon); diff --git a/src/main.cpp b/src/main.cpp index 96fa2f0..eb590f2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -118,6 +118,12 @@ void loop() { checkWiFiConnection(); } + // Periodic display update + if (intervalElapsed(currentMillis, lastWifiCheckTime, 1000)) + { + oledShowTopRow(); + } + // Wenn Bambu auto set Spool aktiv if (bambuCredentials.autosend_enable && autoSetToBambuSpoolId > 0) { diff --git a/src/nfc.cpp b/src/nfc.cpp index e7aec4b..e223ef3 100644 --- a/src/nfc.cpp +++ b/src/nfc.cpp @@ -466,6 +466,7 @@ void scanRfidTask(void * parameter) { } void startNfc() { + oledShowProgressBar(5, 7, DISPLAY_BOOT_TEXT, "NFC init"); nfc.begin(); // Beginne Kommunikation mit RFID Leser delay(1000); unsigned long versiondata = nfc.getFirmwareVersion(); // Lese Versionsnummer der Firmware aus diff --git a/src/scale.cpp b/src/scale.cpp index 8172d9f..6856874 100644 --- a/src/scale.cpp +++ b/src/scale.cpp @@ -115,7 +115,7 @@ void start_scale(bool touchSensorConnected) { } } - oledShowMessage("Scale Tare Please remove all"); + oledShowProgressBar(6, 7, DISPLAY_BOOT_TEXT, "Tare scale"); for (uint16_t i = 0; i < 2000; i++) { yield(); vTaskDelay(pdMS_TO_TICKS(1)); diff --git a/src/website.cpp b/src/website.cpp index 6723a0c..d5d5f7e 100644 --- a/src/website.cpp +++ b/src/website.cpp @@ -189,6 +189,7 @@ void sendAmsData(AsyncWebSocketClient *client) { } void setupWebserver(AsyncWebServer &server) { + oledShowProgressBar(2, 7, DISPLAY_BOOT_TEXT, "Webserver init"); // Deaktiviere alle Debug-Ausgaben Serial.setDebugOutput(false); diff --git a/src/wlan.cpp b/src/wlan.cpp index cbbba38..8756d7b 100644 --- a/src/wlan.cpp +++ b/src/wlan.cpp @@ -61,8 +61,7 @@ void initWiFi() { wm.setWiFiAutoReconnect(true); wm.setConnectTimeout(10); - oledShowTopRow(); - oledShowMessage("WiFi Setup"); + oledShowProgressBar(0, 7, DISPLAY_BOOT_TEXT, "WiFi Setup"); //bool res = wm.autoConnect("FilaMan"); // anonymous ap if(!wm.autoConnect("FilaMan")) { @@ -80,9 +79,6 @@ void initWiFi() { Serial.println(WiFi.localIP()); oledShowTopRow(); - display.display(); - - vTaskDelay(500 / portTICK_PERIOD_MS); // mDNS startMDNS();