StateHandler: add functionality to control fan speed in Manual mode. Main: Modbus object + pressure display
This commit is contained in:
parent
67bc1589dd
commit
4a414ea70f
@ -19,6 +19,8 @@
|
||||
#include "DigitalIoPin.h"
|
||||
#include "Event.h"
|
||||
#include "LiquidCrystal.h"
|
||||
#include "ModbusMaster.h"
|
||||
#include "ModbusRegister.h"
|
||||
|
||||
/** Buttons enumeration
|
||||
*
|
||||
@ -63,7 +65,7 @@ typedef void (StateHandler::*state_pointer) (const Event &);
|
||||
class StateHandler
|
||||
{
|
||||
public:
|
||||
StateHandler (LiquidCrystal *lcd);
|
||||
StateHandler (LiquidCrystal *lcd, ModbusRegister *A01);
|
||||
virtual ~StateHandler ();
|
||||
|
||||
/** Get currently set pressure
|
||||
@ -106,6 +108,7 @@ private:
|
||||
int saved_set_value[2] = { 0, 0 };
|
||||
int saved_curr_value[2] = { 0, 0 };
|
||||
LiquidCrystal *_lcd;
|
||||
ModbusRegister *A01;
|
||||
|
||||
/** Initialization state
|
||||
*
|
||||
|
||||
@ -7,9 +7,10 @@
|
||||
|
||||
#include <StateHandler.h>
|
||||
|
||||
StateHandler::StateHandler (LiquidCrystal *lcd)
|
||||
StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01)
|
||||
{
|
||||
this->_lcd = lcd;
|
||||
this->A01 = A01;
|
||||
current = &StateHandler::stateInit;
|
||||
(this->*current) (Event (Event::eEnter));
|
||||
current_mode = MANUAL;
|
||||
@ -143,9 +144,13 @@ StateHandler::handleControlButtons (uint8_t button)
|
||||
{
|
||||
case BUTTON_CONTROL_DOWN:
|
||||
this->value[(current_mode) ? AUTO : MANUAL].dec ();
|
||||
if(current_mode == MANUAL)
|
||||
this->A01->write(value[(current_mode) ? AUTO : MANUAL].getCurrent() * 10);
|
||||
break;
|
||||
case BUTTON_CONTROL_UP:
|
||||
this->value[(current_mode) ? AUTO : MANUAL].inc ();
|
||||
if(current_mode == MANUAL)
|
||||
this->A01->write(value[(current_mode) ? AUTO : MANUAL].getCurrent() * 10);
|
||||
break;
|
||||
case BUTTON_CONTROL_TOG_MODE:
|
||||
current_mode = !current_mode;
|
||||
|
||||
@ -55,11 +55,17 @@ main (void)
|
||||
DigitalIoPin d6 (1, 3, false, true, false);
|
||||
DigitalIoPin d7 (0, 0, false, true, false);
|
||||
LiquidCrystal lcd (&rs, &en, &d4, &d5, &d6, &d7);
|
||||
StateHandler ventMachine (&lcd);
|
||||
//
|
||||
lcd.setCursor (0, 0);
|
||||
lcd.print ("Test");
|
||||
|
||||
/* FAN object */
|
||||
ModbusMaster fan(1);
|
||||
fan.begin(9600);
|
||||
ModbusRegister A01(&fan, 0);
|
||||
ModbusRegister DI1(&fan, 4, false);
|
||||
|
||||
StateHandler ventMachine (&lcd, &A01);
|
||||
/** Common pins */
|
||||
DigitalIoPin b_up (0, 7, true, true, true); // A5
|
||||
SwitchController sw_up (&b_up, &glob_time, &ventMachine, BUTTON_CONTROL_UP);
|
||||
@ -73,9 +79,9 @@ main (void)
|
||||
BUTTON_CONTROL_TOG_MODE);
|
||||
|
||||
|
||||
PressureWrapper sens();
|
||||
|
||||
|
||||
PressureWrapper sens;
|
||||
int pressure = 0, pressure_time = 0;
|
||||
|
||||
while (1)
|
||||
{
|
||||
@ -87,8 +93,13 @@ main (void)
|
||||
* TODO:
|
||||
* - Update current pressure to eTick
|
||||
*/
|
||||
ventMachine.HandleState (Event (Event::eTick));
|
||||
if(pressure_time == 100) {
|
||||
pressure = sens.getPressure();
|
||||
pressure_time = 0;
|
||||
}
|
||||
ventMachine.HandleState (Event (Event::eTick, pressure));
|
||||
glob_time.tickCounter (1);
|
||||
++pressure_time;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user