fan: include fan into state-handler

This commit is contained in:
Vasily Davydov 2022-10-26 22:38:25 +03:00
parent e4634a14e8
commit fe75d4e992
5 changed files with 32 additions and 23 deletions

View File

@ -6,17 +6,20 @@
*/
#include "Modbus/ModbusRegister.h"
#include <assert.h>
#ifndef FAN_H_
#define FAN_H_
class Fan {
class Fan
{
public:
Fan(ModbusRegister * A01);
virtual ~Fan();
Fan (ModbusRegister *A01);
virtual ~Fan ();
void spin (int speed);
private:
ModbusRegister * _A01;
ModbusRegister *_A01;
};
#endif /* FAN_H_ */

View File

@ -16,11 +16,10 @@
#include "Counter.h"
#include "DigitalIoPin.h"
#include "Event.h"
#include "Fan.h"
#include "GMP252.h"
#include "HMP60.h"
#include "LiquidCrystal.h"
#include "Modbus/ModbusMaster.h"
#include "Modbus/ModbusRegister.h"
#include "PressureWrapper.h"
#include "Timer.h"
#include "nlohmann/json.hpp"
@ -78,8 +77,8 @@ typedef void (StateHandler::*state_pointer) (const Event &);
class StateHandler
{
public:
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01,
PressureWrapper *pressure, Timer *global);
StateHandler (LiquidCrystal *lcd, Fan *propeller, PressureWrapper *pressure,
Timer *global);
virtual ~StateHandler ();
/** Get currently set pressure
@ -135,7 +134,7 @@ private:
int saved_curr_value[2] = { 0, 0 };
int sensors_data[4] = { 0 };
LiquidCrystal *_lcd;
ModbusRegister *_A01;
Fan *_propeller;
PressureWrapper *_pressure;
bool pressure_status;
Timer *state_timer;

View File

@ -7,12 +7,19 @@
#include "Fan.h"
Fan::Fan(ModbusRegister * A01) {
// TODO Auto-generated constructor stub
Fan::Fan (ModbusRegister *A01) { this->_A01 = A01; }
Fan::~Fan ()
{
// TODO Auto-generated destructor stub
}
Fan::~Fan() {
// TODO Auto-generated destructor stub
}
void
Fan::spin (int speed)
{
assert ((this->_A01));
if (speed >= 0 && speed <= 1000)
{
this->_A01->write (speed);
}
}

View File

@ -7,11 +7,11 @@
#include "StateHandler/StateHandler.h"
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *_A01,
StateHandler::StateHandler (LiquidCrystal *lcd, Fan *propeller,
PressureWrapper *pressure, Timer *global)
{
this->_lcd = lcd;
this->_A01 = _A01;
this->_propeller = propeller;
this->_pressure = pressure;
this->state_timer = global;
current = &StateHandler::stateInit;
@ -120,7 +120,7 @@ StateHandler::stateManual (const Event &event)
switch (event.type)
{
case Event::eEnter:
this->_A01->write (fan_speed.getCurrent ());
this->_propeller->spin (fan_speed.getCurrent ());
break;
case Event::eExit:
break;
@ -139,7 +139,7 @@ StateHandler::stateAuto (const Event &event)
switch (event.type)
{
case Event::eEnter:
this->_A01->write (fan_speed.getCurrent ());
this->_propeller->spin (fan_speed.getCurrent ());
break;
case Event::eExit:
break;
@ -149,7 +149,7 @@ StateHandler::stateAuto (const Event &event)
case Event::eTick:
handleTickValue (event.value);
pid ();
this->_A01->write (fan_speed.getCurrent ());
this->_propeller->spin (fan_speed.getCurrent ());
break;
}
}

View File

@ -17,6 +17,7 @@
#endif
#include "DigitalIoPin.h"
#include "Fan.h"
#include "LiquidCrystal.h"
#include "PressureWrapper.h"
#include "StateHandler/StateHandler.h"
@ -62,13 +63,12 @@ main (void)
/* FAN object */
ModbusMaster fan (1);
fan.begin (9600);
ModbusRegister A01 (&fan, 0);
// ModbusRegister DI1(&fan, 4, false);
Fan propeller (new ModbusRegister (&fan, 0));
PressureWrapper sens;
glob_time.Sleep (1000);
StateHandler ventMachine (&lcd, &A01, &sens, &glob_time);
StateHandler ventMachine (&lcd, &propeller, &sens, &glob_time);
/** Common pins */
DigitalIoPin b_up (0, 7, true, true, true); // A5
SwitchController sw_up (&b_up, &ventMachine, BUTTON_CONTROL_UP);