esp-vent-main: main cleanup and doc

- Delete unnused stuff in main
- Create common values header
- Minor fix
This commit is contained in:
Vasily Davydov
2022-10-26 23:10:20 +03:00
parent fe75d4e992
commit 4c3cd99e38
5 changed files with 95 additions and 89 deletions

View File

@@ -5,12 +5,12 @@
* Author: tylen
*/
#include "Modbus/ModbusRegister.h"
#include <assert.h>
#ifndef FAN_H_
#define FAN_H_
#include "Modbus/ModbusRegister.h"
#include <assert.h>
class Fan
{
public:

View File

@@ -22,6 +22,7 @@
#include "LiquidCrystal.h"
#include "PressureWrapper.h"
#include "Timer.h"
#include "common_control_values.h"
#include "nlohmann/json.hpp"
/** Buttons enumeration
@@ -30,8 +31,7 @@
* from main to StateHandler through
* a keyEvent. Enumeration determines the state
* of the particular button.
* */
*/
enum _buttons
{
/** Raises the bar up */
@@ -93,6 +93,39 @@ public:
*/
unsigned int getSetSpeed ();
/** 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;
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 = { 0, 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;
Fan *_propeller;
PressureWrapper *_pressure;
bool pressure_status;
Timer *state_timer;
/* CO2 sensor object */
GMP252 co2;
/* Humidity and temperature sensor object */
HMP60 humidity;
/** Display values on LCD depending on current mode
*
* MANUAL MODE: SPEED: XX% PRESSURE: XXPa
@@ -103,47 +136,10 @@ public:
*/
void displaySet (size_t mode);
/** 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 = { 0, 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;
Fan *_propeller;
PressureWrapper *_pressure;
bool pressure_status;
Timer *state_timer;
/* CO2 sensor object */
GMP252 co2;
/* Humidity and temperature sensor object */
HMP60 humidity;
/** Initialization state
*

View File

@@ -0,0 +1,20 @@
/*
* common_control_values.h
*
* Created on: Oct 26, 2022
* Author: tylen
*/
#ifndef COMMON_CONTROL_VALUES_H_
#define COMMON_CONTROL_VALUES_H_
enum _global_values
{
LCD_SIZE = 16,
TIMER_GLOBAL_TIMEOUT = 15000,
TIMER_SENSORS_TIMEOUT = 5000,
TIMER_PRESSURE_TIMEOUT = 500,
TIMER_ERROR_VALUE = -255,
};
#endif /* COMMON_CONTROL_VALUES_H_ */