From 91e94aa0e894be8b9cf2734c72ae9357c92cea10 Mon Sep 17 00:00:00 2001 From: leptun Date: Fri, 18 Oct 2019 10:32:41 +0300 Subject: [PATCH] Adjustable timeout --- Firmware/backlight.cpp | 7 +++++-- Firmware/backlight.h | 1 + Firmware/eeprom.h | 3 ++- Firmware/ultralcd.cpp | 9 +++++---- 4 files changed, 13 insertions(+), 7 deletions(-) diff --git a/Firmware/backlight.cpp b/Firmware/backlight.cpp index 59f08b6f..5ceef595 100644 --- a/Firmware/backlight.cpp +++ b/Firmware/backlight.cpp @@ -15,7 +15,7 @@ bool backlightSupport = 0; //only if it's true will any of the settings be visib int16_t backlightLevel_HIGH = 0; int16_t backlightLevel_LOW = 0; uint8_t backlightMode = BACKLIGHT_MODE_BRIGHT; -unsigned long backlightTimer_period = 10000ul; +int16_t backlightTimer_period = 10; LongTimer backlightTimer; void backlight_save() //saves all backlight data to eeprom. @@ -23,6 +23,7 @@ void backlight_save() //saves all backlight data to eeprom. eeprom_update_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL_HIGH, (uint8_t)backlightLevel_HIGH); eeprom_update_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL_LOW, (uint8_t)backlightLevel_LOW); eeprom_update_byte((uint8_t *)EEPROM_BACKLIGHT_MODE, backlightMode); + eeprom_update_word((uint16_t *)EEPROM_BACKLIGHT_TIMEOUT, backlightTimer_period); } void backlightTimer_reset() //used for resetting the timer and waking the display. Triggered on events such as knob click, rotate and on full screen notifications. @@ -37,7 +38,7 @@ void backlight_update() if (backlightMode == BACKLIGHT_MODE_AUTO) { - if (backlightTimer.expired(backlightTimer_period)) analogWrite(LCD_BL_PIN, backlightLevel_LOW); + if (backlightTimer.expired((uint32_t)backlightTimer_period * 1000ul)) analogWrite(LCD_BL_PIN, backlightLevel_LOW); else if (backlightTimer.running()) analogWrite(LCD_BL_PIN, backlightLevel_HIGH); else {/*do nothing*/;} //display is dimmed. } @@ -61,10 +62,12 @@ void backlight_init() backlightMode = BACKLIGHT_MODE_AUTO; backlightLevel_HIGH = 130; backlightLevel_LOW = 50; + backlightTimer_period = 10; //in seconds backlight_save(); } backlightLevel_HIGH = eeprom_read_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL_HIGH); backlightLevel_LOW = eeprom_read_byte((uint8_t *)EEPROM_BACKLIGHT_LEVEL_LOW); + backlightTimer_period = eeprom_read_word((uint16_t *)EEPROM_BACKLIGHT_TIMEOUT); SET_OUTPUT(LCD_BL_PIN); backlightTimer_reset(); diff --git a/Firmware/backlight.h b/Firmware/backlight.h index f3e2ee60..fc18dd5e 100644 --- a/Firmware/backlight.h +++ b/Firmware/backlight.h @@ -15,6 +15,7 @@ extern int16_t backlightLevel_HIGH; extern int16_t backlightLevel_LOW; extern uint8_t backlightMode; extern bool backlightSupport; +extern int16_t backlightTimer_period; extern void backlight_update(); extern void backlight_init(); diff --git a/Firmware/eeprom.h b/Firmware/eeprom.h index f47a2333..b869ac1c 100644 --- a/Firmware/eeprom.h +++ b/Firmware/eeprom.h @@ -204,9 +204,10 @@ static Sheets * const EEPROM_Sheets_base = (Sheets*)(EEPROM_SHEETS_BASE); #define EEPROM_BACKLIGHT_LEVEL_HIGH (EEPROM_SHEETS_BASE-1) // uint8 #define EEPROM_BACKLIGHT_LEVEL_LOW (EEPROM_BACKLIGHT_LEVEL_HIGH-1) // uint8 #define EEPROM_BACKLIGHT_MODE (EEPROM_BACKLIGHT_LEVEL_LOW-1) // uint8 +#define EEPROM_BACKLIGHT_TIMEOUT (EEPROM_BACKLIGHT_MODE-2) // uint16 //This is supposed to point to last item to allow EEPROM overrun check. Please update when adding new items. -#define EEPROM_LAST_ITEM EEPROM_BACKLIGHT_MODE +#define EEPROM_LAST_ITEM EEPROM_BACKLIGHT_TIMEOUT // !!!!! // !!!!! this is end of EEPROM section ... all updates MUST BE inserted before this mark !!!!! // !!!!! diff --git a/Firmware/ultralcd.cpp b/Firmware/ultralcd.cpp index f4a60f7d..305ba7cb 100755 --- a/Firmware/ultralcd.cpp +++ b/Firmware/ultralcd.cpp @@ -7187,14 +7187,15 @@ static void lcd_backlight_menu() ); MENU_ITEM_BACK_P(_T(MSG_BACK)); - MENU_ITEM_EDIT_int3_P(_i("Level Bright"), &backlightLevel_HIGH, 0, 255); - MENU_ITEM_EDIT_int3_P(_i("Level Dimmed"), &backlightLevel_LOW, 0, 255); + MENU_ITEM_EDIT_int3_P(_i("Level Bright"), &backlightLevel_HIGH, backlightLevel_LOW, 255); + MENU_ITEM_EDIT_int3_P(_i("Level Dimmed"), &backlightLevel_LOW, 0, backlightLevel_HIGH); switch (backlightMode) { - case BACKLIGHT_MODE_BRIGHT: MENU_ITEM_FUNCTION_P(_i("Mode [Always on]"), backlight_mode_toggle); break; - case BACKLIGHT_MODE_DIM: MENU_ITEM_FUNCTION_P(_i("Mode [Always off]"), backlight_mode_toggle); break; + case BACKLIGHT_MODE_BRIGHT: MENU_ITEM_FUNCTION_P(_i("Mode [Bright]"), backlight_mode_toggle); break; + case BACKLIGHT_MODE_DIM: MENU_ITEM_FUNCTION_P(_i("Mode [Dim]"), backlight_mode_toggle); break; default: MENU_ITEM_FUNCTION_P(_i("Mode [Auto]"), backlight_mode_toggle); break; } + MENU_ITEM_EDIT_int3_P(_i("Timeout"), &backlightTimer_period, 1, 999); MENU_END(); }