state-handler: replace while loop to tick
This commit is contained in:
parent
6cfaca32c8
commit
486cd3acb7
@ -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;
|
||||
|
||||
|
||||
@ -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 ();
|
||||
|
||||
@ -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>
|
||||
|
||||
@ -60,15 +60,14 @@ main (void)
|
||||
lcd.print ("Test");
|
||||
|
||||
/* FAN object */
|
||||
ModbusMaster fan(1);
|
||||
fan.begin(9600);
|
||||
ModbusRegister A01(&fan, 0);
|
||||
// ModbusRegister DI1(&fan, 4, false);
|
||||
ModbusMaster fan (1);
|
||||
fan.begin (9600);
|
||||
ModbusRegister A01 (&fan, 0);
|
||||
// ModbusRegister DI1(&fan, 4, false);
|
||||
|
||||
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)
|
||||
{
|
||||
@ -100,7 +98,7 @@ main (void)
|
||||
}
|
||||
++pressure_time;
|
||||
#endif
|
||||
ventMachine.HandleState (Event (Event::eTick, pressure));
|
||||
ventMachine.HandleState (Event (Event::eTick, pressure));
|
||||
glob_time.tickCounter (1);
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user