sttae-handler: set timeout for sensor reading

This commit is contained in:
Vasily Davydov 2022-10-24 16:49:26 +03:00
parent 54b09fc46d
commit 59486a746a
2 changed files with 11 additions and 13 deletions

View File

@ -119,8 +119,12 @@ StateHandler::stateManual (const Event &event)
this->A01->write (value[MANUAL].getCurrent () * 10); this->A01->write (value[MANUAL].getCurrent () * 10);
break; break;
case Event::eTick: case Event::eTick:
SetState (&StateHandler::stateGetPressure); if (event.value > 500)
break; {
SetState (&StateHandler::stateGetPressure);
state_timer->resetCounter ();
break;
}
} }
} }

View File

@ -35,7 +35,7 @@ main (void)
#if defined(__USE_LPCOPEN) #if defined(__USE_LPCOPEN)
// Read clock settings and update SystemCoreClock variable // Read clock settings and update SystemCoreClock variable
SystemCoreClockUpdate (); SystemCoreClockUpdate ();
#if !defined(NO_BOARD_LIB) #if !defined(NO_BOARD_LIB)
// Set b_up_state and initialize all required blocks and // Set b_up_state and initialize all required blocks and
// functions related to the board hardware // functions related to the board hardware
@ -47,7 +47,7 @@ main (void)
/** Lcd & stateHandler */ /** Lcd & stateHandler */
Chip_RIT_Init (LPC_RITIMER); Chip_RIT_Init (LPC_RITIMER);
Timer glob_time; Timer glob_time;
Timer switch_time(false); Timer switch_time (false);
DigitalIoPin rs (0, 29, false, true, false); DigitalIoPin rs (0, 29, false, true, false);
DigitalIoPin en (0, 9, false, true, false); DigitalIoPin en (0, 9, false, true, false);
DigitalIoPin d4 (0, 10, false, true, false); DigitalIoPin d4 (0, 10, false, true, false);
@ -66,7 +66,7 @@ main (void)
// ModbusRegister DI1(&fan, 4, false); // ModbusRegister DI1(&fan, 4, false);
PressureWrapper sens; PressureWrapper sens;
glob_time.Sleep(1000); glob_time.Sleep (1000);
StateHandler ventMachine (&lcd, &A01, &sens, &glob_time); StateHandler ventMachine (&lcd, &A01, &sens, &glob_time);
/** Common pins */ /** Common pins */
@ -74,25 +74,19 @@ main (void)
SwitchController sw_up (&b_up, &ventMachine, BUTTON_CONTROL_UP); SwitchController sw_up (&b_up, &ventMachine, BUTTON_CONTROL_UP);
DigitalIoPin b_down (0, 6, true, true, true); // A4 DigitalIoPin b_down (0, 6, true, true, true); // A4
SwitchController sw_down (&b_down, &ventMachine, SwitchController sw_down (&b_down, &ventMachine, BUTTON_CONTROL_DOWN);
BUTTON_CONTROL_DOWN);
DigitalIoPin b_toggle (0, 5, true, true, true); // A3 DigitalIoPin b_toggle (0, 5, true, true, true); // A3
SwitchController sw_toggle (&b_toggle, &ventMachine, SwitchController sw_toggle (&b_toggle, &ventMachine,
BUTTON_CONTROL_TOG_MODE); BUTTON_CONTROL_TOG_MODE);
int pressure = 0;
while (1) while (1)
{ {
sw_up.listen (); sw_up.listen ();
sw_down.listen (); sw_down.listen ();
sw_toggle.listen (); sw_toggle.listen ();
if(glob_time.getCounter() > 3) { ventMachine.HandleState (Event (Event::eTick, glob_time.getCounter ()));
pressure = sens.getPressure();
glob_time.resetCounter();
}
ventMachine.HandleState (Event (Event::eTick, pressure));
glob_time.tickCounter (1); glob_time.tickCounter (1);
} }