Merge pull request #14 from vas-dav/state-machine
State machine: add pressure member
This commit is contained in:
commit
b49115143c
@ -8,11 +8,13 @@
|
|||||||
#ifndef EVENT_H_
|
#ifndef EVENT_H_
|
||||||
#define EVENT_H_
|
#define EVENT_H_
|
||||||
|
|
||||||
class Event {
|
class Event
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~Event (){};
|
virtual ~Event (){};
|
||||||
|
|
||||||
enum eventType {
|
enum eventType
|
||||||
|
{
|
||||||
/** Start of the event */
|
/** Start of the event */
|
||||||
eEnter,
|
eEnter,
|
||||||
/** End of the event*/
|
/** End of the event*/
|
||||||
@ -23,10 +25,11 @@ class Event {
|
|||||||
/** Time event */
|
/** Time event */
|
||||||
eTick
|
eTick
|
||||||
};
|
};
|
||||||
Event(eventType e = eTick, uint8_t b = 0, int t = 0)
|
Event (eventType e = eTick, uint8_t b = 0) : type (e), button (b){};
|
||||||
: type(e), button(b), temp(t){};
|
Event (eventType e = eTick, int16_t pres = 0) : type (e), pressure (pres){};
|
||||||
eventType type;
|
eventType type;
|
||||||
uint8_t button;
|
uint8_t button;
|
||||||
|
int16_t pressure;
|
||||||
int temp;
|
int temp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -79,6 +79,10 @@ public:
|
|||||||
unsigned int getSetSpeed ();
|
unsigned int getSetSpeed ();
|
||||||
|
|
||||||
/** Display values on LCD depending on current mode
|
/** 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 value1 value to be displayed on LCD line 0
|
||||||
* @param value2 value to be displayed on LCD line 1
|
* @param value2 value to be displayed on LCD line 1
|
||||||
@ -86,6 +90,7 @@ public:
|
|||||||
void displaySet (unsigned int value1, unsigned int value2);
|
void displaySet (unsigned int value1, unsigned int value2);
|
||||||
|
|
||||||
/** Handle the given event of the current state
|
/** Handle the given event of the current state
|
||||||
|
*
|
||||||
* @param event event to be handled in the current state
|
* @param event event to be handled in the current state
|
||||||
*/
|
*/
|
||||||
void HandleState (const Event &event);
|
void HandleState (const Event &event);
|
||||||
|
|||||||
@ -28,25 +28,11 @@ StateHandler::displaySet (unsigned int value1, unsigned int value2)
|
|||||||
|
|
||||||
if (current_mode == MANUAL)
|
if (current_mode == MANUAL)
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* MANUAL MODE:
|
|
||||||
* ----------------
|
|
||||||
* SPEED: 20%
|
|
||||||
* PRESSURE: XXPa
|
|
||||||
* ----------------
|
|
||||||
*/
|
|
||||||
snprintf (line_up, 16, "SPEED: %02d%", value1);
|
snprintf (line_up, 16, "SPEED: %02d%", value1);
|
||||||
snprintf (line_down, 16, "PRESSURE: %02dPa", value2);
|
snprintf (line_down, 16, "PRESSURE: %02dPa", value2);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/*
|
|
||||||
* AUTO MODE:
|
|
||||||
* ----------------
|
|
||||||
* P. SET: 35Pa
|
|
||||||
* P. CURR: XXPa
|
|
||||||
* ----------------
|
|
||||||
*/
|
|
||||||
snprintf (line_up, 16, "P. SET: %02dPa", value1);
|
snprintf (line_up, 16, "P. SET: %02dPa", value1);
|
||||||
snprintf (line_down, 16, "P. CURR: %02dPa", value2);
|
snprintf (line_down, 16, "P. CURR: %02dPa", value2);
|
||||||
}
|
}
|
||||||
@ -124,6 +110,7 @@ StateHandler::stateManual (const Event &event)
|
|||||||
handleControlButtons (event.button);
|
handleControlButtons (event.button);
|
||||||
break;
|
break;
|
||||||
case Event::eTick:
|
case Event::eTick:
|
||||||
|
displaySet (getSetSpeed (), event.pressure);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -142,6 +129,7 @@ StateHandler::stateAuto (const Event &event)
|
|||||||
handleControlButtons (event.button);
|
handleControlButtons (event.button);
|
||||||
break;
|
break;
|
||||||
case Event::eTick:
|
case Event::eTick:
|
||||||
|
displaySet (getSetPressure (), event.pressure);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,6 +48,8 @@ main (void)
|
|||||||
|
|
||||||
StateHandler ventMachine;
|
StateHandler ventMachine;
|
||||||
|
|
||||||
|
int16_t pressure = 1;
|
||||||
|
|
||||||
while (1)
|
while (1)
|
||||||
{
|
{
|
||||||
if (b_up.read ())
|
if (b_up.read ())
|
||||||
@ -77,7 +79,7 @@ main (void)
|
|||||||
* TODO:
|
* TODO:
|
||||||
* - Update current pressure to eTick
|
* - Update current pressure to eTick
|
||||||
*/
|
*/
|
||||||
ventMachine.HandleState (Event (Event::eTick));
|
ventMachine.HandleState (Event (Event::eTick, pressure));
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user