From 30531b4c0b2cf73c53a7fc1c0f6b971e48dab1f8 Mon Sep 17 00:00:00 2001 From: Carsten Keller Date: Mon, 10 Jun 2024 20:19:37 +0200 Subject: [PATCH] Hintergrundbeleuchtung geht nach 3 Minuten aus und mit dem ersten Tastendruck wieder an --- Source/Button.cpp | 7 ++++++- Source/Button.hpp | 2 +- Source/Menu.cpp | 45 ++++++++++++++++++++++++++++++++++++--------- Source/Menu.hpp | 2 ++ Source/Timer.cpp | 6 ++++++ Source/Timer.hpp | 1 + 6 files changed, 52 insertions(+), 11 deletions(-) diff --git a/Source/Button.cpp b/Source/Button.cpp index 6aff510..b33029c 100644 --- a/Source/Button.cpp +++ b/Source/Button.cpp @@ -27,18 +27,23 @@ namespace ElektronischeLast this->debounceTimer = systick; } - void Button::cyclic(void) + bool Button::cyclic(void) { + bool changed = false; + if((systick - this->debounceTimer) > this->debounce) { bool state = LL_GPIO_IsInputPinSet(this->port, this->pin); this->stateLast = this->state; if(state != this->state) { + changed = true; this->debounceTimer = systick; this->state = state; } } + + return changed; } bool Button::isPressed(void) diff --git a/Source/Button.hpp b/Source/Button.hpp index 7d4976b..0d67f97 100644 --- a/Source/Button.hpp +++ b/Source/Button.hpp @@ -23,7 +23,7 @@ namespace ElektronischeLast uint32_t debounceTimer; public: void init(GPIO_TypeDef* port, uint16_t pin); - void cyclic(void); + bool cyclic(void); bool isPressed(void); bool isReleased(void); }; diff --git a/Source/Menu.cpp b/Source/Menu.cpp index 7dbb6e2..cc8c267 100644 --- a/Source/Menu.cpp +++ b/Source/Menu.cpp @@ -17,7 +17,8 @@ namespace ElektronischeLast { - static Timer timer = Timer(); + static Timer timer_MainScreen = Timer(); + static Timer timer_Backlight = Timer(); static Button ok = Button(); static Button up = Button(); static Button down = Button(); @@ -28,7 +29,8 @@ namespace ElektronischeLast void Menu::init() { - timer.start(500U); + timer_MainScreen.start(500U); + timer_Backlight.start(3UL * 60UL * 1000UL); ok.init(GPIOA, LL_GPIO_PIN_7); up.init(GPIOA, LL_GPIO_PIN_9); down.init(GPIOA, LL_GPIO_PIN_8); @@ -76,9 +78,27 @@ namespace ElektronischeLast void Menu::run() { - ok.cyclic(); - up.cyclic(); - down.cyclic(); + if(ok.cyclic()) + { + timer_Backlight.restart(); + lcd.set_backlight(true); + } + if(up.cyclic()) + { + timer_Backlight.restart(); + lcd.set_backlight(true); + } + if(down.cyclic()) + { + timer_Backlight.restart(); + lcd.set_backlight(true); + } + + if(timer_Backlight.elapsed()) + { + lcd.set_backlight(false); + this->menu_locked = true; + } switch(menu_level) { @@ -110,11 +130,11 @@ namespace ElektronischeLast void Menu::menu_main(void) { - if(timer.elapsed()) + if(timer_MainScreen.elapsed()) { if(lcd.ready_for_data()) { - timer.start(500U); + timer_MainScreen.start(500U); char data[17U]; @@ -143,8 +163,15 @@ namespace ElektronischeLast if(ok.isReleased()) { - this->menu_level = MenuLevel_ISoll; - this->configurations = 0UL; + if(this->menu_locked) + { + this->menu_locked = false; + } + else + { + this->menu_level = MenuLevel_ISoll; + this->configurations = 0UL; + } } } diff --git a/Source/Menu.hpp b/Source/Menu.hpp index c7758de..14a992c 100644 --- a/Source/Menu.hpp +++ b/Source/Menu.hpp @@ -38,6 +38,8 @@ namespace ElektronischeLast uint8_t configurations = 0U; + bool menu_locked = false; + void menu_main(void); void menu_call(void); void menu_icall_init(void); diff --git a/Source/Timer.cpp b/Source/Timer.cpp index 073716d..58f9527 100644 --- a/Source/Timer.cpp +++ b/Source/Timer.cpp @@ -22,6 +22,12 @@ namespace ElektronischeLast this->isRunning = true; } + void Timer::restart(void) + { + this->timer_start = systick; + this->isRunning = true; + } + void Timer::stop(void) { this->isRunning = false; diff --git a/Source/Timer.hpp b/Source/Timer.hpp index b0254be..6386116 100644 --- a/Source/Timer.hpp +++ b/Source/Timer.hpp @@ -21,6 +21,7 @@ namespace ElektronischeLast public: Timer(); void start(uint32_t durationMs); + void restart(void); void stop(void); bool elapsed(void); void tick(void);