From 59486a746a1940edead4f1a10a7f092625a09803 Mon Sep 17 00:00:00 2001 From: Vasily Davydov Date: Mon, 24 Oct 2022 16:49:26 +0300 Subject: [PATCH] sttae-handler: set timeout for sensor reading --- esp-vent-main/src/StateHandler/StateHandler.cpp | 8 ++++++-- esp-vent-main/src/esp-vent-main.cpp | 16 +++++----------- 2 files changed, 11 insertions(+), 13 deletions(-) diff --git a/esp-vent-main/src/StateHandler/StateHandler.cpp b/esp-vent-main/src/StateHandler/StateHandler.cpp index c4962d8..54e8caa 100644 --- a/esp-vent-main/src/StateHandler/StateHandler.cpp +++ b/esp-vent-main/src/StateHandler/StateHandler.cpp @@ -119,8 +119,12 @@ StateHandler::stateManual (const Event &event) this->A01->write (value[MANUAL].getCurrent () * 10); break; case Event::eTick: - SetState (&StateHandler::stateGetPressure); - break; + if (event.value > 500) + { + SetState (&StateHandler::stateGetPressure); + state_timer->resetCounter (); + break; + } } } diff --git a/esp-vent-main/src/esp-vent-main.cpp b/esp-vent-main/src/esp-vent-main.cpp index f595427..7eec552 100644 --- a/esp-vent-main/src/esp-vent-main.cpp +++ b/esp-vent-main/src/esp-vent-main.cpp @@ -35,7 +35,7 @@ main (void) #if defined(__USE_LPCOPEN) // Read clock settings and update SystemCoreClock variable - SystemCoreClockUpdate (); + SystemCoreClockUpdate (); #if !defined(NO_BOARD_LIB) // Set b_up_state and initialize all required blocks and // functions related to the board hardware @@ -47,7 +47,7 @@ main (void) /** Lcd & stateHandler */ Chip_RIT_Init (LPC_RITIMER); Timer glob_time; - Timer switch_time(false); + Timer switch_time (false); DigitalIoPin rs (0, 29, false, true, false); DigitalIoPin en (0, 9, false, true, false); DigitalIoPin d4 (0, 10, false, true, false); @@ -66,7 +66,7 @@ main (void) // ModbusRegister DI1(&fan, 4, false); PressureWrapper sens; - glob_time.Sleep(1000); + glob_time.Sleep (1000); StateHandler ventMachine (&lcd, &A01, &sens, &glob_time); /** Common pins */ @@ -74,25 +74,19 @@ main (void) SwitchController sw_up (&b_up, &ventMachine, BUTTON_CONTROL_UP); DigitalIoPin b_down (0, 6, true, true, true); // A4 - SwitchController sw_down (&b_down, &ventMachine, - BUTTON_CONTROL_DOWN); + SwitchController sw_down (&b_down, &ventMachine, BUTTON_CONTROL_DOWN); DigitalIoPin b_toggle (0, 5, true, true, true); // A3 SwitchController sw_toggle (&b_toggle, &ventMachine, BUTTON_CONTROL_TOG_MODE); - int pressure = 0; while (1) { sw_up.listen (); sw_down.listen (); sw_toggle.listen (); - if(glob_time.getCounter() > 3) { - pressure = sens.getPressure(); - glob_time.resetCounter(); - } - ventMachine.HandleState (Event (Event::eTick, pressure)); + ventMachine.HandleState (Event (Event::eTick, glob_time.getCounter ())); glob_time.tickCounter (1); }