Skip to content

Commit

Permalink
allow to set the dimming per the sleep state
Browse files Browse the repository at this point in the history
  • Loading branch information
perexg committed Nov 29, 2023
1 parent e092b72 commit 12bd214
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 1 deletion.
2 changes: 1 addition & 1 deletion data/en.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"en":{"language":"English","home":{"title":"Main Menu","btn":"Main Menu","nav":"Home"},"save":"Save Settings","user":"Username","pass":"Password","hasp":{"title":"HASP Design","btn":"HASP Design","theme":"UI Theme","color1":"Primary color","color2":"Secondary color","pages":"Start Layout","font":"Default Font","startpage":"Startup Page","startdim":"Startup Dim"},"screenshot":{"title":"Screenshot","btn":"Screenshot","nav":"Screenshot","prev":"Prev Page","next":"Next Page","refresh":"Refresh"},"info":{"title":"Information","btn":"Information","nav":"Information"},"config":{"title":"Configuration","btn":"Configuration","nav":"Settings"},"ota":{"title":"Firmware Update","btn":"Firmware Update","nav":"Firmware","submit":"Update Firmware","file":"Firmware File","url":"Firmware URL","redirect":"Follow Redirects","never":"Never","strict":"Strict","always":"Always"},"editor":{"title":"File Editor","btn":"File Editor","nav":"File Editor"},"reset":{"title":"Factory Reset","btn":"Factory Reset","warning":"Warning","message":"This process will reset all settings to the default values. The internal flash will be erased and the device is restarted. You may need to connect to the WiFi AP displayed on the panel to reconfigure the device before accessing it again.","fileloss":"ALL FILES WILL BE LOST!"},"reboot":{"title":"Rebooting...","btn":"Restart","nav":"Reboot","message":"The device is rebooting."},"about":{"credits":"Based on the previous work of the following open source developers:","copyright":"Copyright ","rights":"All rights reserved.","clause1":"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:","clause2":"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.","clause3":"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","mit":"MIT License","bsd":"BSD License","freebsd":"FreeBSD License","apache2":"Apache2 License"},"wifi":{"title":"Wifi Settings","btn":"Wifi Settings","ssid":"SSID"},"mqtt":{"title":"MQTT Settings","btn":"MQTT Settings","name":"Hostname","group":"Groupname","host":"Broker","port":"Port","node_t":"Node Topic","group_t":"Group Topic","broadcast_t":"Broadcast Topic","hass_t":"HA LWT Topic"},"http":{"title":"HTTP Settings","btn":"HTTP Settings"},"ftp":{"title":"FTP Settings","btn":"FTP Settings","port":"FTP Port","pasv":"Passive Port"},"gui":{"title":"Display Settings","btn":"Display Settings","antiburn":"Antiburn","calibrate":"Calibrate"},"gpio":"GPIO Settings","debug":{"title":"Debug Settings","btn":"Debug Settings","baud":"Baudrate","tele":"Tele Period","ansi":"Use ANSI codes","host":"Syslog Server","port":"Syslog Port","ietf":"IETF (RFC 5424)","bsd":"BSD (RFC 3164)","log":"Facility"},"time":{"title":"Time Settings","btn":"Time Settings","region":"Region","zone":"Timezone","tz":"Timezone","ntp":"NTP Servers"},"region":{"etc":"Etcetera ","continents":"Continents ","af":"Africa ","as":"Asia ","au":"Australia ","aq":"Antarctica ","eu":"Europe ","na":"North America ","sa":"South America ","islands":"Islands ","at":"Atlantic Ocean ","in":"Indian Ocean ","pa":"Pacific Ocean "}}}
{"en":{"language":"English","home":{"title":"Main Menu","btn":"Main Menu","nav":"Home"},"save":"Save Settings","user":"Username","pass":"Password","hasp":{"title":"HASP Design","btn":"HASP Design","theme":"UI Theme","color1":"Primary color","color2":"Secondary color","pages":"Start Layout","font":"Default Font","startpage":"Startup Page","startdim":"Startup Dim","dimidleoff":"Idle Off Dim","dimidleshort":"Short Idle Dim","dimidlelong":"Long Idle Dim"},"screenshot":{"title":"Screenshot","btn":"Screenshot","nav":"Screenshot","prev":"Prev Page","next":"Next Page","refresh":"Refresh"},"info":{"title":"Information","btn":"Information","nav":"Information"},"config":{"title":"Configuration","btn":"Configuration","nav":"Settings"},"ota":{"title":"Firmware Update","btn":"Firmware Update","nav":"Firmware","submit":"Update Firmware","file":"Firmware File","url":"Firmware URL","redirect":"Follow Redirects","never":"Never","strict":"Strict","always":"Always"},"editor":{"title":"File Editor","btn":"File Editor","nav":"File Editor"},"reset":{"title":"Factory Reset","btn":"Factory Reset","warning":"Warning","message":"This process will reset all settings to the default values. The internal flash will be erased and the device is restarted. You may need to connect to the WiFi AP displayed on the panel to reconfigure the device before accessing it again.","fileloss":"ALL FILES WILL BE LOST!"},"reboot":{"title":"Rebooting...","btn":"Restart","nav":"Reboot","message":"The device is rebooting."},"about":{"credits":"Based on the previous work of the following open source developers:","copyright":"Copyright ","rights":"All rights reserved.","clause1":"Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files(the \"Software\"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and / or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:","clause2":"The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.","clause3":"THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.","mit":"MIT License","bsd":"BSD License","freebsd":"FreeBSD License","apache2":"Apache2 License"},"wifi":{"title":"Wifi Settings","btn":"Wifi Settings","ssid":"SSID"},"mqtt":{"title":"MQTT Settings","btn":"MQTT Settings","name":"Hostname","group":"Groupname","host":"Broker","port":"Port","node_t":"Node Topic","group_t":"Group Topic","broadcast_t":"Broadcast Topic","hass_t":"HA LWT Topic"},"http":{"title":"HTTP Settings","btn":"HTTP Settings"},"ftp":{"title":"FTP Settings","btn":"FTP Settings","port":"FTP Port","pasv":"Passive Port"},"gui":{"title":"Display Settings","btn":"Display Settings","antiburn":"Antiburn","calibrate":"Calibrate"},"gpio":"GPIO Settings","debug":{"title":"Debug Settings","btn":"Debug Settings","baud":"Baudrate","tele":"Tele Period","ansi":"Use ANSI codes","host":"Syslog Server","port":"Syslog Port","ietf":"IETF (RFC 5424)","bsd":"BSD (RFC 3164)","log":"Facility"},"time":{"title":"Time Settings","btn":"Time Settings","region":"Region","zone":"Timezone","tz":"Timezone","ntp":"NTP Servers"},"region":{"etc":"Etcetera ","continents":"Continents ","af":"Africa ","as":"Asia ","au":"Australia ","aq":"Antarctica ","eu":"Europe ","na":"North America ","sa":"South America ","islands":"Islands ","at":"Atlantic Ocean ","in":"Indian Ocean ","pa":"Pacific Ocean "}}}
21 changes: 21 additions & 0 deletions src/hasp/hasp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,9 @@ static uint16_t sleepTimeLong = 120; // 1 second resolution
static uint32_t sleepTimeOffset = 0; // 1 second resolution

uint8_t haspStartDim = HASP_START_DIM;
uint16_t haspDimIdleOff = HASP_DIM_IDLE_OFF;
uint16_t haspDimIdleShort = HASP_DIM_IDLE_SHORT;
uint16_t haspDimIdleLong = HASP_DIM_IDLE_LONG;
uint8_t haspStartPage = HASP_START_PAGE;
uint8_t haspThemeId = HASP_THEME_ID;
uint16_t haspThemeHue = 200;
Expand Down Expand Up @@ -149,15 +152,21 @@ void hasp_set_sleep_state(uint8_t state, uint8_t source)
switch(state) {
case HASP_SLEEP_LONG:
hasp_set_sleep_offset(sleepTimeShort + sleepTimeLong);
if (haspDimIdleLong < 256)
haspDevice.set_backlight_level(haspDimIdleLong);
dispatch_run_script(NULL, "L:/idle_long.cmd", source);
break;
case HASP_SLEEP_SHORT:
hasp_set_sleep_offset(sleepTimeShort);
if (haspDimIdleShort < 256)
haspDevice.set_backlight_level(haspDimIdleShort);
dispatch_run_script(NULL, "L:/idle_short.cmd", source);
break;
case HASP_SLEEP_OFF:
hasp_set_sleep_offset(0);
// hasp_set_wakeup_touch(false);
if (haspDimIdleOff < 256)
haspDevice.set_backlight_level(haspDimIdleOff);
dispatch_run_script(NULL, "L:/idle_off.cmd", source);
break;
default:
Expand Down Expand Up @@ -792,6 +801,15 @@ bool haspGetConfig(const JsonObject& settings)
if(haspStartDim != settings[FPSTR(FP_CONFIG_STARTDIM)].as<uint8_t>()) changed = true;
settings[FPSTR(FP_CONFIG_STARTDIM)] = haspStartDim;

if(haspDimIdleOff != settings[FPSTR(FP_CONFIG_DIM_IDLE_OFF)].as<uint16_t>()) changed = true;
settings[FPSTR(FP_CONFIG_DIM_IDLE_OFF)] = haspDimIdleOff;

if(haspDimIdleShort != settings[FPSTR(FP_CONFIG_DIM_IDLE_SHORT)].as<uint16_t>()) changed = true;
settings[FPSTR(FP_CONFIG_DIM_IDLE_SHORT)] = haspDimIdleShort;

if(haspDimIdleLong != settings[FPSTR(FP_CONFIG_DIM_IDLE_LONG)].as<uint16_t>()) changed = true;
settings[FPSTR(FP_CONFIG_DIM_IDLE_LONG)] = haspDimIdleLong;

if(haspThemeId != settings[FPSTR(FP_CONFIG_THEME)].as<uint8_t>()) changed = true;
settings[FPSTR(FP_CONFIG_THEME)] = haspThemeId;

Expand Down Expand Up @@ -831,6 +849,9 @@ bool haspSetConfig(const JsonObject& settings)

changed |= configSet(haspStartPage, settings[FPSTR(FP_CONFIG_STARTPAGE)], "haspStartPage");
changed |= configSet(haspStartDim, settings[FPSTR(FP_CONFIG_STARTDIM)], "haspStartDim");
changed |= configSet(haspDimIdleOff, settings[FPSTR(FP_CONFIG_DIM_IDLE_OFF)], "haspDimIdleOff");
changed |= configSet(haspDimIdleShort, settings[FPSTR(FP_CONFIG_DIM_IDLE_SHORT)], "haspDimIdleShort");
changed |= configSet(haspDimIdleLong, settings[FPSTR(FP_CONFIG_DIM_IDLE_LONG)], "haspDimIdleLong");

{ // Theme related settings
// Set from Hue first
Expand Down
12 changes: 12 additions & 0 deletions src/hasp/hasp.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,18 @@
#define HASP_START_DIM 255
#endif

#ifndef HASP_DIM_IDLE_OFF
#define HASP_DIM_IDLE_OFF 256
#endif

#ifndef HASP_DIM_IDLE_SHORT
#define HASP_DIM_IDLE_SHORT 256
#endif

#ifndef HASP_DIM_IDLE_LONG
#define HASP_DIM_IDLE_LONG 256
#endif

#ifndef HASP_START_PAGE
#define HASP_START_PAGE 1
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/hasp_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ void configGetConfig(JsonDocument& settings);
/* json keys used in the configfile */
const char FP_CONFIG_STARTPAGE[] PROGMEM = "startpage";
const char FP_CONFIG_STARTDIM[] PROGMEM = "startdim";
const char FP_CONFIG_DIM_IDLE_OFF[] PROGMEM = "dimidleoff";
const char FP_CONFIG_DIM_IDLE_SHORT[] PROGMEM = "dimidleshort";
const char FP_CONFIG_DIM_IDLE_LONG[] PROGMEM = "dimidlelong";
const char FP_CONFIG_THEME[] PROGMEM = "theme";
const char FP_CONFIG_HUE[] PROGMEM = "hue";
const char FP_CONFIG_ZIFONT[] PROGMEM = "font";
Expand Down
12 changes: 12 additions & 0 deletions src/sys/svc/hasp_http.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2242,6 +2242,18 @@ static void webHandleHaspConfig()
<div class="row">
<div class="col-25"><label for="startdim" v-t="'hasp.startdim'"></label></div>
<div class="col-75"><input v-model="config.hasp.startdim" id="startdim" type="number" min="0" max="255"></div>
</div>
<div class="row">
<div class="col-25"><label for="dimidleoff" v-t="'hasp.dimidleoff'"></label></div>
<div class="col-75"><input v-model="config.hasp.dimidleoff" id="dimidleoff" type="number" min="0" max="256"></div>
</div>
<div class="row">
<div class="col-25"><label for="dimidleshort" v-t="'hasp.dimidleshort'"></label></div>
<div class="col-75"><input v-model="config.hasp.dimidleshort" id="dimidleshort" type="number" min="0" max="256"></div>
</div>
<div class="row">
<div class="col-25"><label for="dimidlelong" v-t="'hasp.dimidlelong'"></label></div>
<div class="col-75"><input v-model="config.hasp.dimidlelong" id="dimidlelong" type="number" min="0" max="256"></div>
</div>)";
html[min(i++, len)] = R"(<button type="submit" v-t="'save'"></button></form></div>)";
html[min(i++, len)] = R"(<a v-t="'home.btn'" href="/"></a>)";
Expand Down
12 changes: 12 additions & 0 deletions src/sys/svc/hasp_http_async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1997,6 +1997,18 @@ void webHandleHaspConfig(AsyncWebServerRequest* request)
F("'></p><p><b>Startup Brightness</b> <i><small>(required)</small></i><input id='startpage' required "
"name='startdim' type='number' min='0' max='255' value='");
httpMessage += settings[FPSTR(FP_CONFIG_STARTDIM)].as<String>();
httpMessage +=
F("'></p><p><b>Idle Off Brightness</b> <i><small>(required, 256=do not use)</small></i><input id='startpage' required "
"name='dimidleoff' type='number' min='0' max='256' value='");
httpMessage += settings[FPSTR(FP_CONFIG_DIM_IDLE_OFF)].as<String>();
httpMessage +=
F("'></p><p><b>Short Idle Brightness</b> <i><small>(required, 256=do not use)</small></i><input id='startpage' required "
"name='dimidleshort' type='number' min='0' max='256' value='");
httpMessage += settings[FPSTR(FP_CONFIG_DIM_IDLE_SHORT)].as<String>();
httpMessage +=
F("'></p><p><b>Long Idle Brightness</b> <i><small>(required, 256=do not use)</small></i><input id='startpage' required "
"name='dimidlelong' type='number' min='0' max='256' value='");
httpMessage += settings[FPSTR(FP_CONFIG_DIM_IDLE_LONG)].as<String>();
httpMessage += F("'></p>");

httpMessage +=
Expand Down

0 comments on commit 12bd214

Please sign in to comment.