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

View File

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

View File

@ -17,12 +17,12 @@
#endif #endif
#include "DigitalIoPin.h" #include "DigitalIoPin.h"
#include "I2C.h"
#include "LiquidCrystal.h" #include "LiquidCrystal.h"
#include "PressureWrapper.h"
#include "StateHandler.h" #include "StateHandler.h"
#include "SwitchController.h" #include "SwitchController.h"
#include "Timer.h" #include "Timer.h"
#include "PressureWrapper.h"
#include "I2C.h"
#include <cr_section_macros.h> #include <cr_section_macros.h>
@ -60,15 +60,14 @@ main (void)
lcd.print ("Test"); lcd.print ("Test");
/* FAN object */ /* FAN object */
ModbusMaster fan(1); ModbusMaster fan (1);
fan.begin(9600); fan.begin (9600);
ModbusRegister A01(&fan, 0); ModbusRegister A01 (&fan, 0);
// ModbusRegister DI1(&fan, 4, false); // ModbusRegister DI1(&fan, 4, false);
PressureWrapper sens; PressureWrapper sens;
StateHandler ventMachine (&lcd, &A01, &sens, &glob_time);
StateHandler ventMachine (&lcd, &A01, &sens);
/** Common pins */ /** Common pins */
DigitalIoPin b_up (0, 7, true, true, true); // A5 DigitalIoPin b_up (0, 7, true, true, true); // A5
SwitchController sw_up (&b_up, &glob_time, &ventMachine, BUTTON_CONTROL_UP); 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, SwitchController sw_toggle (&b_toggle, &glob_time, &ventMachine,
BUTTON_CONTROL_TOG_MODE); BUTTON_CONTROL_TOG_MODE);
int pressure = 0, pressure_time = 0; int pressure = 0, pressure_time = 0;
while (1) while (1)
{ {