Skip to content

Commit

Permalink
Changed display turn off and turn on sequence/methods to fix a proble…
Browse files Browse the repository at this point in the history
…m with clocks without a power off functionality for the LCDs - changed init and reinit sequence in the TFT class to reduce/avoid "flickering" - changed showDigit in TFT class, now only "draws" something, if the TFTs are in state "enable" (#105)
  • Loading branch information
Martinius79 authored Nov 25, 2024
1 parent 1aa6b5b commit ec968ef
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 56 deletions.
58 changes: 29 additions & 29 deletions EleksTubeHAX_pio/src/TFTs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
56 changes: 29 additions & 27 deletions EleksTubeHAX_pio/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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()
Expand Down

0 comments on commit ec968ef

Please sign in to comment.