fan: include fan into state-handler
This commit is contained in:
parent
e4634a14e8
commit
fe75d4e992
@ -6,17 +6,20 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Modbus/ModbusRegister.h"
|
#include "Modbus/ModbusRegister.h"
|
||||||
|
#include <assert.h>
|
||||||
|
|
||||||
#ifndef FAN_H_
|
#ifndef FAN_H_
|
||||||
#define FAN_H_
|
#define FAN_H_
|
||||||
|
|
||||||
class Fan {
|
class Fan
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
Fan(ModbusRegister * A01);
|
Fan (ModbusRegister *A01);
|
||||||
virtual ~Fan();
|
virtual ~Fan ();
|
||||||
|
void spin (int speed);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ModbusRegister * _A01;
|
ModbusRegister *_A01;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* FAN_H_ */
|
#endif /* FAN_H_ */
|
||||||
|
|||||||
@ -16,11 +16,10 @@
|
|||||||
#include "Counter.h"
|
#include "Counter.h"
|
||||||
#include "DigitalIoPin.h"
|
#include "DigitalIoPin.h"
|
||||||
#include "Event.h"
|
#include "Event.h"
|
||||||
|
#include "Fan.h"
|
||||||
#include "GMP252.h"
|
#include "GMP252.h"
|
||||||
#include "HMP60.h"
|
#include "HMP60.h"
|
||||||
#include "LiquidCrystal.h"
|
#include "LiquidCrystal.h"
|
||||||
#include "Modbus/ModbusMaster.h"
|
|
||||||
#include "Modbus/ModbusRegister.h"
|
|
||||||
#include "PressureWrapper.h"
|
#include "PressureWrapper.h"
|
||||||
#include "Timer.h"
|
#include "Timer.h"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
@ -78,8 +77,8 @@ typedef void (StateHandler::*state_pointer) (const Event &);
|
|||||||
class StateHandler
|
class StateHandler
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01,
|
StateHandler (LiquidCrystal *lcd, Fan *propeller, PressureWrapper *pressure,
|
||||||
PressureWrapper *pressure, Timer *global);
|
Timer *global);
|
||||||
virtual ~StateHandler ();
|
virtual ~StateHandler ();
|
||||||
|
|
||||||
/** Get currently set pressure
|
/** Get currently set pressure
|
||||||
@ -135,7 +134,7 @@ private:
|
|||||||
int saved_curr_value[2] = { 0, 0 };
|
int saved_curr_value[2] = { 0, 0 };
|
||||||
int sensors_data[4] = { 0 };
|
int sensors_data[4] = { 0 };
|
||||||
LiquidCrystal *_lcd;
|
LiquidCrystal *_lcd;
|
||||||
ModbusRegister *_A01;
|
Fan *_propeller;
|
||||||
PressureWrapper *_pressure;
|
PressureWrapper *_pressure;
|
||||||
bool pressure_status;
|
bool pressure_status;
|
||||||
Timer *state_timer;
|
Timer *state_timer;
|
||||||
|
|||||||
@ -7,12 +7,19 @@
|
|||||||
|
|
||||||
#include "Fan.h"
|
#include "Fan.h"
|
||||||
|
|
||||||
Fan::Fan(ModbusRegister * A01) {
|
Fan::Fan (ModbusRegister *A01) { this->_A01 = A01; }
|
||||||
// TODO Auto-generated constructor stub
|
|
||||||
|
|
||||||
|
Fan::~Fan ()
|
||||||
|
{
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
}
|
}
|
||||||
|
|
||||||
Fan::~Fan() {
|
void
|
||||||
// TODO Auto-generated destructor stub
|
Fan::spin (int speed)
|
||||||
|
{
|
||||||
|
assert ((this->_A01));
|
||||||
|
if (speed >= 0 && speed <= 1000)
|
||||||
|
{
|
||||||
|
this->_A01->write (speed);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -7,11 +7,11 @@
|
|||||||
|
|
||||||
#include "StateHandler/StateHandler.h"
|
#include "StateHandler/StateHandler.h"
|
||||||
|
|
||||||
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *_A01,
|
StateHandler::StateHandler (LiquidCrystal *lcd, Fan *propeller,
|
||||||
PressureWrapper *pressure, Timer *global)
|
PressureWrapper *pressure, Timer *global)
|
||||||
{
|
{
|
||||||
this->_lcd = lcd;
|
this->_lcd = lcd;
|
||||||
this->_A01 = _A01;
|
this->_propeller = propeller;
|
||||||
this->_pressure = pressure;
|
this->_pressure = pressure;
|
||||||
this->state_timer = global;
|
this->state_timer = global;
|
||||||
current = &StateHandler::stateInit;
|
current = &StateHandler::stateInit;
|
||||||
@ -120,7 +120,7 @@ StateHandler::stateManual (const Event &event)
|
|||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case Event::eEnter:
|
case Event::eEnter:
|
||||||
this->_A01->write (fan_speed.getCurrent ());
|
this->_propeller->spin (fan_speed.getCurrent ());
|
||||||
break;
|
break;
|
||||||
case Event::eExit:
|
case Event::eExit:
|
||||||
break;
|
break;
|
||||||
@ -139,7 +139,7 @@ StateHandler::stateAuto (const Event &event)
|
|||||||
switch (event.type)
|
switch (event.type)
|
||||||
{
|
{
|
||||||
case Event::eEnter:
|
case Event::eEnter:
|
||||||
this->_A01->write (fan_speed.getCurrent ());
|
this->_propeller->spin (fan_speed.getCurrent ());
|
||||||
break;
|
break;
|
||||||
case Event::eExit:
|
case Event::eExit:
|
||||||
break;
|
break;
|
||||||
@ -149,7 +149,7 @@ StateHandler::stateAuto (const Event &event)
|
|||||||
case Event::eTick:
|
case Event::eTick:
|
||||||
handleTickValue (event.value);
|
handleTickValue (event.value);
|
||||||
pid ();
|
pid ();
|
||||||
this->_A01->write (fan_speed.getCurrent ());
|
this->_propeller->spin (fan_speed.getCurrent ());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "DigitalIoPin.h"
|
#include "DigitalIoPin.h"
|
||||||
|
#include "Fan.h"
|
||||||
#include "LiquidCrystal.h"
|
#include "LiquidCrystal.h"
|
||||||
#include "PressureWrapper.h"
|
#include "PressureWrapper.h"
|
||||||
#include "StateHandler/StateHandler.h"
|
#include "StateHandler/StateHandler.h"
|
||||||
@ -62,13 +63,12 @@ main (void)
|
|||||||
/* FAN object */
|
/* FAN object */
|
||||||
ModbusMaster fan (1);
|
ModbusMaster fan (1);
|
||||||
fan.begin (9600);
|
fan.begin (9600);
|
||||||
ModbusRegister A01 (&fan, 0);
|
Fan propeller (new ModbusRegister (&fan, 0));
|
||||||
// ModbusRegister DI1(&fan, 4, false);
|
|
||||||
|
|
||||||
PressureWrapper sens;
|
PressureWrapper sens;
|
||||||
glob_time.Sleep (1000);
|
glob_time.Sleep (1000);
|
||||||
|
|
||||||
StateHandler ventMachine (&lcd, &A01, &sens, &glob_time);
|
StateHandler ventMachine (&lcd, &propeller, &sens, &glob_time);
|
||||||
/** 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, &ventMachine, BUTTON_CONTROL_UP);
|
SwitchController sw_up (&b_up, &ventMachine, BUTTON_CONTROL_UP);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user