Merge pull request #14 from vas-dav/state-machine

State machine: add pressure member
This commit is contained in:
Evgenii Meshcheriakov 2022-10-14 17:03:38 +03:00 committed by GitHub
commit b49115143c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 19 additions and 21 deletions

View File

@ -8,11 +8,13 @@
#ifndef EVENT_H_
#define EVENT_H_
class Event {
class Event
{
public:
virtual ~Event (){};
enum eventType {
enum eventType
{
/** Start of the event */
eEnter,
/** End of the event*/
@ -23,10 +25,11 @@ class Event {
/** Time event */
eTick
};
Event(eventType e = eTick, uint8_t b = 0, int t = 0)
: type(e), button(b), temp(t){};
Event (eventType e = eTick, uint8_t b = 0) : type (e), button (b){};
Event (eventType e = eTick, int16_t pres = 0) : type (e), pressure (pres){};
eventType type;
uint8_t button;
int16_t pressure;
int temp;
};

View File

@ -79,6 +79,10 @@ public:
unsigned int getSetSpeed ();
/** Display values on LCD depending on current mode
*
* MANUAL MODE: SPEED: XX% PRESSURE: XXPa
*
* AUTO MODE: P. SET: XXPa P. CURR: XXPa
*
* @param value1 value to be displayed on LCD line 0
* @param value2 value to be displayed on LCD line 1
@ -86,6 +90,7 @@ public:
void displaySet (unsigned int value1, unsigned int value2);
/** Handle the given event of the current state
*
* @param event event to be handled in the current state
*/
void HandleState (const Event &event);

View File

@ -28,25 +28,11 @@ StateHandler::displaySet (unsigned int value1, unsigned int value2)
if (current_mode == MANUAL)
{
/*
* MANUAL MODE:
* ----------------
* SPEED: 20%
* PRESSURE: XXPa
* ----------------
*/
snprintf (line_up, 16, "SPEED: %02d%", value1);
snprintf (line_down, 16, "PRESSURE: %02dPa", value2);
}
else
{
/*
* AUTO MODE:
* ----------------
* P. SET: 35Pa
* P. CURR: XXPa
* ----------------
*/
snprintf (line_up, 16, "P. SET: %02dPa", value1);
snprintf (line_down, 16, "P. CURR: %02dPa", value2);
}
@ -124,6 +110,7 @@ StateHandler::stateManual (const Event &event)
handleControlButtons (event.button);
break;
case Event::eTick:
displaySet (getSetSpeed (), event.pressure);
break;
}
}
@ -142,6 +129,7 @@ StateHandler::stateAuto (const Event &event)
handleControlButtons (event.button);
break;
case Event::eTick:
displaySet (getSetPressure (), event.pressure);
break;
}
}

View File

@ -48,6 +48,8 @@ main (void)
StateHandler ventMachine;
int16_t pressure = 1;
while (1)
{
if (b_up.read ())
@ -77,7 +79,7 @@ main (void)
* TODO:
* - Update current pressure to eTick
*/
ventMachine.HandleState (Event (Event::eTick));
ventMachine.HandleState (Event (Event::eTick, pressure));
}
return 0;