StateHandler: new state - stateSensors which pools data from sensors and displays it
This commit is contained in:
parent
ab184498e1
commit
45ae1d0e3e
@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* PressureWrapper.h
|
||||||
|
*
|
||||||
|
* Created on: 5 Oct 2022
|
||||||
|
* Author: evgenymeshcheryakov
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef PRESSUREWRAPPER_H_
|
||||||
|
#define PRESSUREWRAPPER_H_
|
||||||
|
|
||||||
|
#include "I2C.h"
|
||||||
|
#include <cstdio>
|
||||||
|
|
||||||
|
#define ADDRESS 0x40
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief structure to hold a raw data from
|
||||||
|
* the pressure sensor
|
||||||
|
*/
|
||||||
|
|
||||||
|
typedef struct _PRESSURE{
|
||||||
|
uint8_t rBuffer[2];
|
||||||
|
uint8_t crc;
|
||||||
|
}PRESSURE_DATA;
|
||||||
|
|
||||||
|
class PressureWrapper
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
PressureWrapper ();
|
||||||
|
/*
|
||||||
|
* @return pressure in Pascal
|
||||||
|
*/
|
||||||
|
int getPressure ();
|
||||||
|
|
||||||
|
virtual ~PressureWrapper ();
|
||||||
|
|
||||||
|
private:
|
||||||
|
I2C *i2c;
|
||||||
|
PRESSURE_DATA data = {{0, 0}, 0};
|
||||||
|
/*
|
||||||
|
* @return struct with pressure data in
|
||||||
|
* rBuffer and CRC check in crc
|
||||||
|
*/
|
||||||
|
bool getRawPressure ();
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif /* PRESSUREWRAPPER_H_ */
|
||||||
@ -23,6 +23,7 @@
|
|||||||
#include "ModbusRegister.h"
|
#include "ModbusRegister.h"
|
||||||
#include "GMP252.h"
|
#include "GMP252.h"
|
||||||
#include "HMP60.h"
|
#include "HMP60.h"
|
||||||
|
#include "PressureWrapper.h"
|
||||||
|
|
||||||
/** Buttons enumeration
|
/** Buttons enumeration
|
||||||
*
|
*
|
||||||
@ -61,13 +62,21 @@ enum _mode
|
|||||||
AUTO
|
AUTO
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum _sensors
|
||||||
|
{
|
||||||
|
PRESSUREDAT,
|
||||||
|
TEMPERATURE,
|
||||||
|
HUMIDITY,
|
||||||
|
CO2
|
||||||
|
};
|
||||||
|
|
||||||
class StateHandler;
|
class StateHandler;
|
||||||
typedef void (StateHandler::*state_pointer) (const Event &);
|
typedef void (StateHandler::*state_pointer) (const Event &);
|
||||||
|
|
||||||
class StateHandler
|
class StateHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01);
|
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01, PressureWrapper *pressure);
|
||||||
virtual ~StateHandler ();
|
virtual ~StateHandler ();
|
||||||
|
|
||||||
/** Get currently set pressure
|
/** Get currently set pressure
|
||||||
@ -117,9 +126,10 @@ private:
|
|||||||
int integral = 0;
|
int integral = 0;
|
||||||
int saved_set_value[2] = { 0, 0 };
|
int saved_set_value[2] = { 0, 0 };
|
||||||
int saved_curr_value[2] = { 0, 0 };
|
int saved_curr_value[2] = { 0, 0 };
|
||||||
|
int sensors_data[4] = {0};
|
||||||
LiquidCrystal *_lcd;
|
LiquidCrystal *_lcd;
|
||||||
ModbusRegister *A01;
|
ModbusRegister *A01;
|
||||||
|
PressureWrapper * pressure;
|
||||||
/* CO2 sensor object */
|
/* CO2 sensor object */
|
||||||
GMP252 co2;
|
GMP252 co2;
|
||||||
|
|
||||||
@ -151,7 +161,15 @@ private:
|
|||||||
*/
|
*/
|
||||||
void stateAuto (const Event &event);
|
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
|
* @param button current button
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -7,10 +7,11 @@
|
|||||||
|
|
||||||
#include <StateHandler.h>
|
#include <StateHandler.h>
|
||||||
|
|
||||||
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01)
|
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01, PressureWrapper *pressure)
|
||||||
{
|
{
|
||||||
this->_lcd = lcd;
|
this->_lcd = lcd;
|
||||||
this->A01 = A01;
|
this->A01 = A01;
|
||||||
|
this->pressure = pressure;
|
||||||
current = &StateHandler::stateInit;
|
current = &StateHandler::stateInit;
|
||||||
(this->*current) (Event (Event::eEnter));
|
(this->*current) (Event (Event::eEnter));
|
||||||
current_mode = MANUAL;
|
current_mode = MANUAL;
|
||||||
@ -77,6 +78,7 @@ StateHandler::stateInit (const Event &event)
|
|||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case Event::eEnter:
|
case Event::eEnter:
|
||||||
|
SetState(&StateHandler::stateSensors);
|
||||||
break;
|
break;
|
||||||
case Event::eExit:
|
case Event::eExit:
|
||||||
_lcd->clear ();
|
_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
|
void
|
||||||
StateHandler::handleControlButtons (uint8_t button)
|
StateHandler::handleControlButtons (uint8_t button)
|
||||||
|
|||||||
@ -65,8 +65,10 @@ main (void)
|
|||||||
ModbusRegister A01(&fan, 0);
|
ModbusRegister A01(&fan, 0);
|
||||||
// ModbusRegister DI1(&fan, 4, false);
|
// ModbusRegister DI1(&fan, 4, false);
|
||||||
|
|
||||||
|
PressureWrapper sens;
|
||||||
|
|
||||||
StateHandler ventMachine (&lcd, &A01);
|
|
||||||
|
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);
|
||||||
@ -79,7 +81,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);
|
||||||
|
|
||||||
PressureWrapper sens;
|
|
||||||
int pressure = 0, pressure_time = 0;
|
int pressure = 0, pressure_time = 0;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user