state-handler: replace while loop to tick

This commit is contained in:
Vasily Davydov 2022-10-21 21:01:42 +03:00
parent 6cfaca32c8
commit 486cd3acb7
3 changed files with 14 additions and 16 deletions

View File

@ -24,6 +24,7 @@
#include "ModbusMaster.h"
#include "ModbusRegister.h"
#include "PressureWrapper.h"
#include "Timer.h"
/** Buttons enumeration
*
@ -77,7 +78,7 @@ class StateHandler
{
public:
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01,
PressureWrapper *pressure);
PressureWrapper *pressure, Timer *global);
virtual ~StateHandler ();
/** Get currently set pressure
@ -131,6 +132,7 @@ private:
LiquidCrystal *_lcd;
ModbusRegister *A01;
PressureWrapper *pressure;
Timer *state_timer;
/* CO2 sensor object */
GMP252 co2;

View File

@ -9,11 +9,12 @@
#define PID 0
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01,
PressureWrapper *pressure)
PressureWrapper *pressure, Timer *global)
{
this->_lcd = lcd;
this->A01 = A01;
this->pressure = pressure;
this->state_timer = global;
current = &StateHandler::stateInit;
(this->*current) (Event (Event::eEnter));
current_mode = MANUAL;
@ -222,10 +223,7 @@ StateHandler::save (int eventValue, size_t mode)
if (!eventValue)
{
/* Small delay for modbus communications with pressure sensor */
int i = 0;
while (i < 720)
i++;
i = 0;
state_timer->tickCounter (1);
eventValue = pressure->getPressure ();
}
int counterValue = value[mode].getCurrent ();

View File

@ -17,12 +17,12 @@
#endif
#include "DigitalIoPin.h"
#include "I2C.h"
#include "LiquidCrystal.h"
#include "PressureWrapper.h"
#include "StateHandler.h"
#include "SwitchController.h"
#include "Timer.h"
#include "PressureWrapper.h"
#include "I2C.h"
#include <cr_section_macros.h>
@ -67,8 +67,7 @@ main (void)
PressureWrapper sens;
StateHandler ventMachine (&lcd, &A01, &sens);
StateHandler ventMachine (&lcd, &A01, &sens, &glob_time);
/** Common pins */
DigitalIoPin b_up (0, 7, true, true, true); // A5
SwitchController sw_up (&b_up, &glob_time, &ventMachine, BUTTON_CONTROL_UP);
@ -81,7 +80,6 @@ main (void)
SwitchController sw_toggle (&b_toggle, &glob_time, &ventMachine,
BUTTON_CONTROL_TOG_MODE);
int pressure = 0, pressure_time = 0;
while (1)
{