StateHandler: new state - stateSensors which pools data from sensors and displays it
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include "ModbusRegister.h"
|
||||
#include "GMP252.h"
|
||||
#include "HMP60.h"
|
||||
#include "PressureWrapper.h"
|
||||
|
||||
/** Buttons enumeration
|
||||
*
|
||||
@@ -61,13 +62,21 @@ enum _mode
|
||||
AUTO
|
||||
};
|
||||
|
||||
enum _sensors
|
||||
{
|
||||
PRESSUREDAT,
|
||||
TEMPERATURE,
|
||||
HUMIDITY,
|
||||
CO2
|
||||
};
|
||||
|
||||
class StateHandler;
|
||||
typedef void (StateHandler::*state_pointer) (const Event &);
|
||||
|
||||
class StateHandler
|
||||
{
|
||||
public:
|
||||
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01);
|
||||
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01, PressureWrapper *pressure);
|
||||
virtual ~StateHandler ();
|
||||
|
||||
/** Get currently set pressure
|
||||
@@ -117,9 +126,10 @@ private:
|
||||
int integral = 0;
|
||||
int saved_set_value[2] = { 0, 0 };
|
||||
int saved_curr_value[2] = { 0, 0 };
|
||||
int sensors_data[4] = {0};
|
||||
LiquidCrystal *_lcd;
|
||||
ModbusRegister *A01;
|
||||
|
||||
PressureWrapper * pressure;
|
||||
/* CO2 sensor object */
|
||||
GMP252 co2;
|
||||
|
||||
@@ -151,7 +161,15 @@ private:
|
||||
*/
|
||||
void stateAuto (const Event &event);
|
||||
|
||||
/** Hnadle button presses
|
||||
/** Sensors state
|
||||
*
|
||||
* - print current sensrs readings
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
void stateSensors (const Event &event);
|
||||
|
||||
/** Handle button presses
|
||||
*
|
||||
* @param button current button
|
||||
*/
|
||||
|
||||
@@ -7,10 +7,11 @@
|
||||
|
||||
#include <StateHandler.h>
|
||||
|
||||
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01)
|
||||
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01, PressureWrapper *pressure)
|
||||
{
|
||||
this->_lcd = lcd;
|
||||
this->A01 = A01;
|
||||
this->pressure = pressure;
|
||||
current = &StateHandler::stateInit;
|
||||
(this->*current) (Event (Event::eEnter));
|
||||
current_mode = MANUAL;
|
||||
@@ -77,6 +78,7 @@ StateHandler::stateInit (const Event &event)
|
||||
switch (event.type)
|
||||
{
|
||||
case Event::eEnter:
|
||||
SetState(&StateHandler::stateSensors);
|
||||
break;
|
||||
case Event::eExit:
|
||||
_lcd->clear ();
|
||||
@@ -152,6 +154,37 @@ StateHandler::stateAuto (const Event &event)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StateHandler::stateSensors (const Event &event)
|
||||
{
|
||||
switch (event.type)
|
||||
{
|
||||
case Event::eEnter:
|
||||
break;
|
||||
case Event::eExit:
|
||||
break;
|
||||
case Event::eKey:
|
||||
break;
|
||||
case Event::eTick:
|
||||
sensors_data[PRESSUREDAT] = pressure->getPressure();
|
||||
sensors_data[TEMPERATURE] = humidity.readT();
|
||||
sensors_data[HUMIDITY] = humidity.readRH();
|
||||
sensors_data[CO2] = co2.read();
|
||||
char line_up[16] = { 0 };
|
||||
char line_down[16] = { 0 };
|
||||
|
||||
snprintf (line_up, 16, "PRE:%02dPa TEM:%02dC", sensors_data[PRESSUREDAT],sensors_data[TEMPERATURE]);
|
||||
snprintf (line_down, 16, "HUM:%02d CO2:%02d", sensors_data[HUMIDITY], sensors_data[CO2]);
|
||||
|
||||
_lcd->clear ();
|
||||
_lcd->setCursor (0, 0);
|
||||
_lcd->print (line_up);
|
||||
_lcd->setCursor (0, 1);
|
||||
_lcd->print (line_down);
|
||||
SetState (&StateHandler::stateManual);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
StateHandler::handleControlButtons (uint8_t button)
|
||||
|
||||
Reference in New Issue
Block a user