diff --git a/EleksTubeHAX_pio/src/TFTs.cpp b/EleksTubeHAX_pio/src/TFTs.cpp index cdd856b..3497d4e 100644 --- a/EleksTubeHAX_pio/src/TFTs.cpp +++ b/EleksTubeHAX_pio/src/TFTs.cpp @@ -5,17 +5,14 @@ void TFTs::begin() { - // Start with all displays selected. chip_select.begin(); - chip_select.setAll(); - - // Turn power on to displays. - pinMode(TFT_ENABLE_PIN, OUTPUT); - enableAllDisplays(); - InvalidateImageInBuffer(); + chip_select.setAll(); // Start with all displays selected - // Initialize the super class. - init(); + pinMode(TFT_ENABLE_PIN, OUTPUT); // Set pin for turning display power on and off. + InvalidateImageInBuffer(); // Signal, that the image in the buffer is invalid and needs to be reloaded and refilled + init(); // Initialize the super class. + fillScreen(TFT_BLACK); // to avoid/reduce flickering patterns on the screens + enableAllDisplays(); // Signal, that the displays are enabled now // Set SPIFFS ready if (!SPIFFS.begin()) @@ -33,14 +30,13 @@ void TFTs::reinit() { // Start with all displays selected. chip_select.begin(); - chip_select.setAll(); - - // Turn power on to displays. - pinMode(TFT_ENABLE_PIN, OUTPUT); - enableAllDisplays(); + chip_select.setAll(); // Start again with all displays selected. - // Initialize the super class. - init(); + pinMode(TFT_ENABLE_PIN, OUTPUT); // Set pin for turning display power on and off. + InvalidateImageInBuffer(); // Signal, that the image in the buffer is invalid and needs to be reloaded and refilled + init(); // Initialize the super class (again). + fillScreen(TFT_BLACK); // to avoid/reduce flickering patterns on the screens + enableAllDisplays(); // Signal, that the displays are enabled now } void TFTs::clear() @@ -142,22 +138,26 @@ void TFTs::setDigit(uint8_t digit, uint8_t value, show_t show) void TFTs::showDigit(uint8_t digit) { - chip_select.setDigit(digit); + if (enabled) + { // only do this, if the displays are enabled + chip_select.setDigit(digit); - if (digits[digit] == blanked) - { - fillScreen(TFT_BLACK); - } - else - { - uint8_t file_index = current_graphic * 10 + digits[digit]; - DrawImage(file_index); + if (digits[digit] == blanked) + { // Blank Zero + fillScreen(TFT_BLACK); + } + else + { + uint8_t file_index = current_graphic * 10 + digits[digit]; + DrawImage(file_index); - uint8_t NextNumber = digits[SECONDS_ONES] + 1; - if (NextNumber > 9) - NextNumber = 0; // pre-load only seconds, because they are drawn first - NextFileRequired = current_graphic * 10 + NextNumber; + uint8_t NextNumber = digits[SECONDS_ONES] + 1; + if (NextNumber > 9) + NextNumber = 0; // pre-load only seconds, because they are drawn first + NextFileRequired = current_graphic * 10 + NextNumber; + } } + // else { } //display is disabled, do nothing } void TFTs::LoadNextImage() diff --git a/EleksTubeHAX_pio/src/main.cpp b/EleksTubeHAX_pio/src/main.cpp index 1835139..b0505d5 100644 --- a/EleksTubeHAX_pio/src/main.cpp +++ b/EleksTubeHAX_pio/src/main.cpp @@ -221,18 +221,18 @@ void loop() MqttCommandPowerReceived = false; if (MqttCommandPower) { -#ifndef HARDWARE_SI_HAI_CLOCK - if (!tfts.isEnabled()) - { - tfts.reinit(); // reinit (original EleksTube HW: after a few hours in OFF state the displays do not wake up properly) - updateClockDisplay(TFTs::force); - } +#ifdef HARDWARE_Elekstube_CLOCK // original EleksTube hardware and direct clones need a reinit to wake up the displays properly + tfts.reinit(); +#else + tfts.enableAllDisplays(); // for all other clocks, just enable the displays #endif - tfts.enableAllDisplays(); + updateClockDisplay(TFTs::force); // redraw all the clock digits -> needed because the displays was blanked before turning off backlights.PowerOn(); } else { + tfts.chip_select.setAll(); + tfts.fillScreen(TFT_BLACK); // blank the screens before turning off -> needed for all clocks without a real "power switch curcuit" to "simulate" the off-switched displays tfts.disableAllDisplays(); backlights.PowerOff(); } @@ -243,17 +243,17 @@ void loop() MqttCommandMainPowerReceived = false; if (MqttCommandMainPower) { -#ifndef HARDWARE_SI_HAI_CLOCK - if (!tfts.isEnabled()) - { - tfts.reinit(); // reinit (original EleksTube HW: after a few hours in OFF state the displays do not wake up properly) - updateClockDisplay(TFTs::force); - } +#ifdef HARDWARE_Elekstube_CLOCK // original EleksTube hardware and direct clones need a reinit to wake up the displays properly + tfts.reinit(); +#else + tfts.enableAllDisplays(); // for all other clocks, just enable the displays #endif - tfts.enableAllDisplays(); + updateClockDisplay(TFTs::force); // redraw all the clock digits -> needed because the displays was blanked before turning off } else { + tfts.chip_select.setAll(); + tfts.fillScreen(TFT_BLACK); // blank the screens before turning off -> needed for all clocks without a real "power switch curcuit" to "simulate" the off-switched displays tfts.disableAllDisplays(); } } @@ -442,22 +442,24 @@ void loop() // Power button: If in menu, exit menu. Else turn off displays and backlight. if (buttons.power.isDownEdge() && (menu.getState() == Menu::idle)) - { - tfts.chip_select.setAll(); - tfts.fillScreen(TFT_BLACK); - - tfts.toggleAllDisplays(); + { // Power button was pressed: if in the menu, exit menu, else turn off displays and backlight. if (tfts.isEnabled()) - { -#ifndef HARDWARE_SI_HAI_CLOCK - tfts.reinit(); // reinit (original EleksTube HW: after a few hours in OFF state the displays do not wake up properly) -#endif + { // check if tft state is enabled -> switch OFF the LCDs and LED backlights tfts.chip_select.setAll(); - tfts.fillScreen(TFT_BLACK); - - updateClockDisplay(TFTs::force); + tfts.fillScreen(TFT_BLACK); // blank the screens before turning off -> needed for all clocks without a real "power switch curcuit" + tfts.disableAllDisplays(); + backlights.PowerOff(); + } + else + { // tft state is disabled -> turn ON the displays and backlights +#ifdef HARDWARE_Elekstube_CLOCK // original EleksTube hardware and direct clones need a reinit to wake up the displays properly + tfts.reinit(); +#else + tfts.enableAllDisplays(); // for all other clocks, just enable the displays +#endif + updateClockDisplay(TFTs::force); // redraw all the clock digits -> needed because the displays was blanked before turning off + backlights.PowerOn(); } - backlights.togglePower(); } menu.loop(buttons); // Must be called after buttons.loop()