Skip to content

Commit

Permalink
[P095] Implement splash without delay()
Browse files Browse the repository at this point in the history
  • Loading branch information
tonhuisman committed Jun 14, 2022
1 parent 9c056d1 commit e897a33
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/_P095_ILI9341.ino
Expand Up @@ -19,6 +19,7 @@

/**
* Changelog:
* 2022-06-14 tonhuisman: Improved Splash handling, non-blocking delay, default 3 seconds
* 2022-06-11 tonhuisman: Implement support for getting config values, see AdafruitGFX_Helper.h changelog for details. Code optimization
* 2022-05-17 tonhuisman: Add setting for Splash during plugin startup, default on, when compiled in
* 2022-01-09 tonhuisman: Add support for ILI9342 (M5Stack, 240x320), ILI9481, ILI9486 and ILI9488 (320x480) displays
Expand Down
35 changes: 30 additions & 5 deletions src/src/PluginStructs/P095_data_struct.cpp
Expand Up @@ -173,7 +173,11 @@ bool P095_data_struct::plugin_init(struct EventStruct *event) {
gfxHelper->printText(String(F("ESPEasy")).c_str(), 0, yPos, 3, ADAGFX_WHITE, ADAGFX_BLUE);
yPos += (3 * _fontheight);
gfxHelper->printText(String(F("ILI934x/ILI948x")).c_str(), 0, yPos, 2, ADAGFX_BLUE, ADAGFX_WHITE);
delay(100); // Splash
_splashState = true; // Splash
_splashCounter = P095_SPLASH_DURATION;
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_INFO, F("P095 Splash start"));
# endif // ifndef BUILD_NO_DEBUG
}
# endif // ifdef P095_SHOW_SPLASH
updateFontMetrics();
Expand Down Expand Up @@ -223,7 +227,7 @@ bool P095_data_struct::plugin_exit(struct EventStruct *event) {
* plugin_read: Re-draw the default content
***************************************************************************/
bool P095_data_struct::plugin_read(struct EventStruct *event) {
if (nullptr != tft) {
if ((nullptr != tft) && !_splashState) {
String strings[P095_Nlines];
LoadCustomTaskSettings(event->TaskIndex, strings, P095_Nlines, 0);

Expand Down Expand Up @@ -266,6 +270,27 @@ bool P095_data_struct::plugin_read(struct EventStruct *event) {
* plugin_ten_per_second: check button, if any, that wakes up the display
***************************************************************************/
bool P095_data_struct::plugin_ten_per_second(struct EventStruct *event) {
# ifdef P095_SHOW_SPLASH

if (_splashState) { // Decrement splash counter
_splashCounter--;
_splashState = _splashCounter != 0;

if (!_splashState) {
# ifndef BUILD_NO_DEBUG
addLog(LOG_LEVEL_INFO, F("P095 Splash finished."));
# endif // ifndef BUILD_NO_DEBUG

if (nullptr != tft) {
tft->fillScreen(_bgcolor); // fill screen with background color
}

// Schedule the surrogate initial PLUGIN_READ that has been suppressed by the splash
Scheduler.schedule_task_device_timer(event->TaskIndex, millis() + 10);
}
}
# endif // ifdef P095_SHOW_SPLASH

if ((P095_CONFIG_BUTTON_PIN != -1) && (getButtonState()) && (nullptr != tft)) {
displayOnOff(true);
markButtonStateProcessed();
Expand All @@ -277,7 +302,7 @@ bool P095_data_struct::plugin_ten_per_second(struct EventStruct *event) {
* plugin_once_a_second: Count down display timer, if any, and turn display off if countdown reached
***************************************************************************/
bool P095_data_struct::plugin_once_a_second(struct EventStruct *event) {
if (_displayTimer > 0) {
if ((_displayTimer > 0) && !_splashState) {
_displayTimer--;

if ((nullptr != tft) && (_displayTimer == 0)) {
Expand All @@ -294,7 +319,7 @@ bool P095_data_struct::plugin_write(struct EventStruct *event, const String& str
bool success = false;
String cmd = parseString(string, 1);

if ((nullptr != tft) && cmd.equals(_commandTriggerCmd)) {
if ((nullptr != tft) && cmd.equals(_commandTriggerCmd) && !_splashState) {
String arg1 = parseString(string, 2);
success = true;

Expand Down Expand Up @@ -359,7 +384,7 @@ bool P095_data_struct::plugin_write(struct EventStruct *event, const String& str
}
}
else if (tft && (cmd.equals(_commandTrigger) ||
(gfxHelper && gfxHelper->isAdaGFXTrigger(cmd)))) {
(gfxHelper && gfxHelper->isAdaGFXTrigger(cmd))) && !_splashState) {
success = true;

if (!bitRead(P095_CONFIG_FLAGS, P095_CONFIG_FLAG_NO_WAKE)) { // Wake display?
Expand Down
6 changes: 6 additions & 0 deletions src/src/PluginStructs/P095_data_struct.h
Expand Up @@ -17,6 +17,7 @@
# ifndef LIMIT_BUILD_SIZE
# define P095_SHOW_SPLASH // Enable to show initial splash (text)
# endif // ifndef LIMIT_BUILD_SIZE
# define P095_SPLASH_DURATION (3000 / 100) // 3 seconds in 100 millisecond chunks

# define P095_CONFIG_VERSION PCONFIG(0) // Settings version
# define P095_CONFIG_ROTATION PCONFIG(1) // Rotation
Expand Down Expand Up @@ -169,6 +170,11 @@ struct P095_data_struct : public PluginTaskData_base {

int8_t _leftMarginCompensation = 0; // Not settable yet
int8_t _topMarginCompensation = 0;

bool _splashState = false; // Have this always available to avoid 'many' #ifdefs in the code
# ifdef P095_SHOW_SPLASH
uint8_t _splashCounter = P095_SPLASH_DURATION;
# endif // ifdef P095_SHOW_SPLASH
};


Expand Down

0 comments on commit e897a33

Please sign in to comment.