Hintergrundbeleuchtung geht nach 3 Minuten aus und mit dem ersten Tastendruck wieder an

This commit is contained in:
Carsten Keller 2024-06-10 20:19:37 +02:00
parent 8b070887e9
commit 30531b4c0b
Signed by: carsten
GPG Key ID: DF06343A3A9B8868
6 changed files with 52 additions and 11 deletions

View File

@ -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)

View File

@ -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);
};

View File

@ -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;
}
}
}

View File

@ -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);

View File

@ -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;

View File

@ -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);