Skip to content

Commit

Permalink
Merge pull request #582 from perexg/topic/idle-scripts
Browse files Browse the repository at this point in the history
sleep state - run idle scripts and allow to control the backlight
  • Loading branch information
fvanroie authored Nov 29, 2023
2 parents b7283c9 + e092b72 commit 894370b
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 14 deletions.
14 changes: 7 additions & 7 deletions src/hasp/hasp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,17 @@ HASP_ATTRIBUTE_FAST_MEM void hasp_update_sleep_state()
if(sleepTimeLong > 0 && idle >= (sleepTimeShort + sleepTimeLong)) {
if(hasp_sleep_state != HASP_SLEEP_LONG) {
gui_hide_pointer(true);
hasp_sleep_state = HASP_SLEEP_LONG;
dispatch_idle_state(HASP_SLEEP_LONG);
hasp_set_sleep_state(HASP_SLEEP_LONG, TAG_MAIN);
}
} else if(sleepTimeShort > 0 && idle >= sleepTimeShort) {
if(hasp_sleep_state != HASP_SLEEP_SHORT) {
gui_hide_pointer(true);
hasp_sleep_state = HASP_SLEEP_SHORT;
dispatch_idle_state(HASP_SLEEP_SHORT);
hasp_set_sleep_state(HASP_SLEEP_SHORT, TAG_MAIN);
}
} else {
if(hasp_sleep_state != HASP_SLEEP_OFF) {
gui_hide_pointer(false);
hasp_sleep_state = HASP_SLEEP_OFF;
dispatch_idle_state(HASP_SLEEP_OFF);
hasp_set_sleep_state(HASP_SLEEP_OFF, TAG_MAIN);
}
}
}
Expand All @@ -147,18 +144,21 @@ uint8_t hasp_get_sleep_state()
return hasp_sleep_state;
}

void hasp_set_sleep_state(uint8_t state)
void hasp_set_sleep_state(uint8_t state, uint8_t source)
{
switch(state) {
case HASP_SLEEP_LONG:
hasp_set_sleep_offset(sleepTimeShort + sleepTimeLong);
dispatch_run_script(NULL, "L:/idle_long.cmd", source);
break;
case HASP_SLEEP_SHORT:
hasp_set_sleep_offset(sleepTimeShort);
dispatch_run_script(NULL, "L:/idle_short.cmd", source);
break;
case HASP_SLEEP_OFF:
hasp_set_sleep_offset(0);
// hasp_set_wakeup_touch(false);
dispatch_run_script(NULL, "L:/idle_off.cmd", source);
break;
default:
return;
Expand Down
2 changes: 1 addition & 1 deletion src/hasp/hasp.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ lv_font_t* hasp_get_font(uint8_t fontid);
HASP_ATTRIBUTE_FAST_MEM void hasp_update_sleep_state();
void hasp_get_sleep_payload(uint8_t state, char* payload);
uint8_t hasp_get_sleep_state();
void hasp_set_sleep_state(uint8_t state);
void hasp_set_sleep_state(uint8_t state, uint8_t source);
void hasp_get_sleep_time(uint16_t& short_time, uint16_t& long_time);
void hasp_set_sleep_time(uint16_t short_time, uint16_t long_time);
void hasp_set_sleep_offset(uint32_t offset);
Expand Down
9 changes: 3 additions & 6 deletions src/hasp/hasp_dispatch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1356,14 +1356,11 @@ void dispatch_idle(const char*, const char* payload, uint8_t source)
if(payload && strlen(payload)) {
uint8_t state = HASP_SLEEP_LAST;
if(!strcmp_P(payload, "off")) {
hasp_set_sleep_state(HASP_SLEEP_OFF);
dispatch_run_script(NULL, "L:/idle_off.cmd", source);
hasp_set_sleep_state(HASP_SLEEP_OFF, source);
} else if(!strcmp_P(payload, "short")) {
hasp_set_sleep_state(HASP_SLEEP_SHORT);
dispatch_run_script(NULL, "L:/idle_short.cmd", source);
hasp_set_sleep_state(HASP_SLEEP_SHORT, source);
} else if(!strcmp_P(payload, "long")) {
hasp_set_sleep_state(HASP_SLEEP_LONG);
dispatch_run_script(NULL, "L:/idle_long.cmd", source);
hasp_set_sleep_state(HASP_SLEEP_LONG, source);
} else {
LOG_WARNING(TAG_MSGR, F("Invalid idle value %s"), payload);
return;
Expand Down

0 comments on commit 894370b

Please sign in to comment.