fuckit: clean slate
This commit is contained in:
27
esp-vent-main/inc/StateHandler/Counter.h
Normal file
27
esp-vent-main/inc/StateHandler/Counter.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Counter.h
|
||||
*
|
||||
* Created on: Sep 1, 2022
|
||||
* Author: tylen
|
||||
*/
|
||||
|
||||
#ifndef COUNTER_H_
|
||||
#define COUNTER_H_
|
||||
|
||||
class Counter
|
||||
{
|
||||
|
||||
public:
|
||||
Counter (unsigned int i, unsigned int up);
|
||||
void inc ();
|
||||
void dec ();
|
||||
unsigned int getCurrent ();
|
||||
void setInit (unsigned int i);
|
||||
~Counter () = default;
|
||||
|
||||
private:
|
||||
unsigned int init;
|
||||
unsigned int up_lim;
|
||||
unsigned int down_lim;
|
||||
};
|
||||
#endif /* COUNTER_H_ */
|
||||
33
esp-vent-main/inc/StateHandler/Event.h
Normal file
33
esp-vent-main/inc/StateHandler/Event.h
Normal file
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* Event.h
|
||||
*
|
||||
* Created on: Oct 5, 2022
|
||||
* Author: tylen
|
||||
*/
|
||||
|
||||
#ifndef EVENT_H_
|
||||
#define EVENT_H_
|
||||
|
||||
class Event
|
||||
{
|
||||
public:
|
||||
virtual ~Event (){};
|
||||
|
||||
enum eventType
|
||||
{
|
||||
/** Start of the event */
|
||||
eEnter,
|
||||
/** End of the event*/
|
||||
eExit,
|
||||
/** Button toggle event type (has values:
|
||||
* temperature or button) */
|
||||
eKey,
|
||||
/** Time event */
|
||||
eTick
|
||||
};
|
||||
Event (eventType e = eTick, int val = 0) : type (e), value (val){};
|
||||
eventType type;
|
||||
int value;
|
||||
};
|
||||
|
||||
#endif /* EVENT_H_ */
|
||||
195
esp-vent-main/inc/StateHandler/StateHandler.h
Normal file
195
esp-vent-main/inc/StateHandler/StateHandler.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* StateHandler.h
|
||||
*
|
||||
* Created on: Sep 21, 2022
|
||||
* Author: tylen
|
||||
*
|
||||
* Purpose of this class is to store and pass
|
||||
* the events of the current mode to further process.
|
||||
*
|
||||
* Current goal is to make it to operate on interrupts
|
||||
* caused by button presses.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef STATE_HANDLER_H_
|
||||
#define STATE_HANDLER_H_
|
||||
|
||||
#include "Counter.h"
|
||||
#include "DigitalIoPin.h"
|
||||
#include "Event.h"
|
||||
#include "GMP252.h"
|
||||
#include "HMP60.h"
|
||||
#include "LiquidCrystal.h"
|
||||
#include "Modbus/ModbusMaster.h"
|
||||
#include "Modbus/ModbusRegister.h"
|
||||
#include "PressureWrapper.h"
|
||||
#include "Timer.h"
|
||||
|
||||
/** Buttons enumeration
|
||||
*
|
||||
* Current switch state is being passed
|
||||
* from main to StateHandler through
|
||||
* a keyEvent. Enumeration determines the state
|
||||
* of the particular button.
|
||||
* */
|
||||
|
||||
enum _buttons
|
||||
{
|
||||
/** Raises the bar up */
|
||||
BUTTON_CONTROL_UP,
|
||||
/** Raises the bar down */
|
||||
BUTTON_CONTROL_DOWN,
|
||||
/** Toggles the mode between auto and
|
||||
* manual, which changes the state */
|
||||
BUTTON_CONTROL_TOG_MODE,
|
||||
/** Optional button to toggle the
|
||||
* activation of the current setting.
|
||||
* Not compulsory to be used. */
|
||||
BUTTON_CONTROL_TOG_ACTIVE
|
||||
};
|
||||
|
||||
enum _bars
|
||||
{
|
||||
/** 0-100 % */
|
||||
FAN_SPEED,
|
||||
/** 0-120 Pa */
|
||||
PRESSURE
|
||||
};
|
||||
|
||||
enum _mode
|
||||
{
|
||||
MANUAL,
|
||||
AUTO
|
||||
};
|
||||
|
||||
enum _sensors
|
||||
{
|
||||
PRESSUREDAT,
|
||||
TEMPERATURE,
|
||||
HUMIDITY,
|
||||
CO2
|
||||
};
|
||||
|
||||
class StateHandler;
|
||||
typedef void (StateHandler::*state_pointer) (const Event &);
|
||||
|
||||
class StateHandler
|
||||
{
|
||||
public:
|
||||
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01,
|
||||
PressureWrapper *pressure, Timer *global);
|
||||
virtual ~StateHandler ();
|
||||
|
||||
/** Get currently set pressure
|
||||
*
|
||||
* @return pressure in range of 0-120
|
||||
*/
|
||||
unsigned int getSetPressure ();
|
||||
|
||||
/** Get currently set FanSpeed
|
||||
*
|
||||
* @return speed in range of 0-100
|
||||
*/
|
||||
unsigned int getSetSpeed ();
|
||||
|
||||
/** Display values on LCD depending on current mode
|
||||
*
|
||||
* MANUAL MODE: SPEED: XX% PRESSURE: XXPa
|
||||
*
|
||||
* AUTO MODE: P. SET: XXPa P. CURR: XXPa
|
||||
*
|
||||
* @param value1 value to be displayed on LCD line 0
|
||||
* @param value2 value to be displayed on LCD line 1
|
||||
*/
|
||||
void displaySet (unsigned int value1, unsigned int value2);
|
||||
|
||||
/** Handle the given event of the current state
|
||||
*
|
||||
* @param event event to be handled in the current state
|
||||
*/
|
||||
void HandleState (const Event &event);
|
||||
|
||||
private:
|
||||
state_pointer current;
|
||||
/** Set a new curremt state
|
||||
* @param newstate new state to be set to current
|
||||
*/
|
||||
void SetState (state_pointer newstate);
|
||||
bool current_mode;
|
||||
Counter value[2] = { { 0, 100 }, { 0, 120 } };
|
||||
/* motor of fan starts at value 90. probably because of some
|
||||
* weigh of fan, so voltage within range of 0-89 is not
|
||||
* sufficient to start motor.
|
||||
* TODO: Value 89 should be scaled to 0 at some point */
|
||||
Counter fan_speed = { 20, 1000 };
|
||||
/*integral controller for PID. should be global, since it
|
||||
* accumulates error signals encountered since startup*/
|
||||
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;
|
||||
Timer *state_timer;
|
||||
/* CO2 sensor object */
|
||||
GMP252 co2;
|
||||
|
||||
/* Humidity and temperature sensor object */
|
||||
HMP60 humidity;
|
||||
|
||||
/** Initialization state
|
||||
*
|
||||
* @param event event of the state
|
||||
*/
|
||||
void stateInit (const Event &event);
|
||||
|
||||
/** Manual state
|
||||
*
|
||||
* - set current speed
|
||||
* - print current pressure
|
||||
*
|
||||
* @param event event of the state
|
||||
*/
|
||||
void stateManual (const Event &event);
|
||||
|
||||
/** Automated state
|
||||
*
|
||||
* - print current pressure
|
||||
* - print set pressure
|
||||
* - inc/dec fan speed
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
void stateAuto (const Event &event);
|
||||
|
||||
/** Sensors state
|
||||
*
|
||||
* - print current sensrs readings
|
||||
*
|
||||
* @param event
|
||||
*/
|
||||
void stateSensors (const Event &event);
|
||||
|
||||
/** Handle button presses
|
||||
*
|
||||
* @param button current button
|
||||
*/
|
||||
void handleControlButtons (uint8_t button);
|
||||
|
||||
/** Save values to class' varibales
|
||||
*
|
||||
* @param eventValue value coming from an event
|
||||
* @param counterValue value of the inner Counter
|
||||
* @param mode current mode
|
||||
*/
|
||||
void save (int eventValue, size_t mode);
|
||||
|
||||
/** Calculates pid for fan control value
|
||||
*
|
||||
*/
|
||||
void pid ();
|
||||
};
|
||||
|
||||
#endif /* STATE_HANDLER_H_ */
|
||||
Reference in New Issue
Block a user