StateHandler: add functionality to control fan speed in Manual mode. Main: Modbus object + pressure display

This commit is contained in:
Evgenii Meshcheriakov 2022-10-18 15:21:34 +03:00
parent 67bc1589dd
commit 4a414ea70f
3 changed files with 25 additions and 6 deletions

View File

@ -19,6 +19,8 @@
#include "DigitalIoPin.h" #include "DigitalIoPin.h"
#include "Event.h" #include "Event.h"
#include "LiquidCrystal.h" #include "LiquidCrystal.h"
#include "ModbusMaster.h"
#include "ModbusRegister.h"
/** Buttons enumeration /** Buttons enumeration
* *
@ -63,7 +65,7 @@ typedef void (StateHandler::*state_pointer) (const Event &);
class StateHandler class StateHandler
{ {
public: public:
StateHandler (LiquidCrystal *lcd); StateHandler (LiquidCrystal *lcd, ModbusRegister *A01);
virtual ~StateHandler (); virtual ~StateHandler ();
/** Get currently set pressure /** Get currently set pressure
@ -106,6 +108,7 @@ private:
int saved_set_value[2] = { 0, 0 }; int saved_set_value[2] = { 0, 0 };
int saved_curr_value[2] = { 0, 0 }; int saved_curr_value[2] = { 0, 0 };
LiquidCrystal *_lcd; LiquidCrystal *_lcd;
ModbusRegister *A01;
/** Initialization state /** Initialization state
* *

View File

@ -7,9 +7,10 @@
#include <StateHandler.h> #include <StateHandler.h>
StateHandler::StateHandler (LiquidCrystal *lcd) StateHandler::StateHandler (LiquidCrystal *lcd, ModbusRegister *A01)
{ {
this->_lcd = lcd; this->_lcd = lcd;
this->A01 = A01;
current = &StateHandler::stateInit; current = &StateHandler::stateInit;
(this->*current) (Event (Event::eEnter)); (this->*current) (Event (Event::eEnter));
current_mode = MANUAL; current_mode = MANUAL;
@ -143,9 +144,13 @@ StateHandler::handleControlButtons (uint8_t button)
{ {
case BUTTON_CONTROL_DOWN: case BUTTON_CONTROL_DOWN:
this->value[(current_mode) ? AUTO : MANUAL].dec (); this->value[(current_mode) ? AUTO : MANUAL].dec ();
if(current_mode == MANUAL)
this->A01->write(value[(current_mode) ? AUTO : MANUAL].getCurrent() * 10);
break; break;
case BUTTON_CONTROL_UP: case BUTTON_CONTROL_UP:
this->value[(current_mode) ? AUTO : MANUAL].inc (); this->value[(current_mode) ? AUTO : MANUAL].inc ();
if(current_mode == MANUAL)
this->A01->write(value[(current_mode) ? AUTO : MANUAL].getCurrent() * 10);
break; break;
case BUTTON_CONTROL_TOG_MODE: case BUTTON_CONTROL_TOG_MODE:
current_mode = !current_mode; current_mode = !current_mode;

View File

@ -55,11 +55,17 @@ main (void)
DigitalIoPin d6 (1, 3, false, true, false); DigitalIoPin d6 (1, 3, false, true, false);
DigitalIoPin d7 (0, 0, false, true, false); DigitalIoPin d7 (0, 0, false, true, false);
LiquidCrystal lcd (&rs, &en, &d4, &d5, &d6, &d7); LiquidCrystal lcd (&rs, &en, &d4, &d5, &d6, &d7);
StateHandler ventMachine (&lcd);
// //
lcd.setCursor (0, 0); lcd.setCursor (0, 0);
lcd.print ("Test"); 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 */ /** 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, &glob_time, &ventMachine, BUTTON_CONTROL_UP); SwitchController sw_up (&b_up, &glob_time, &ventMachine, BUTTON_CONTROL_UP);
@ -73,9 +79,9 @@ main (void)
BUTTON_CONTROL_TOG_MODE); BUTTON_CONTROL_TOG_MODE);
PressureWrapper sens();
PressureWrapper sens;
int pressure = 0, pressure_time = 0;
while (1) while (1)
{ {
@ -87,8 +93,13 @@ main (void)
* TODO: * TODO:
* - Update current pressure to eTick * - 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); glob_time.tickCounter (1);
++pressure_time;
} }
return 0; return 0;