state-handler: #6 add state controller functions
- HandleState to set an event of the state - SetState to update current state to new
This commit is contained in:
parent
f95c15e13c
commit
69d767a73e
@ -15,10 +15,10 @@
|
||||
#ifndef STATE_HANDLER_H_
|
||||
#define STATE_HANDLER_H_
|
||||
|
||||
#include "DigitalIoPin.h"
|
||||
#include "LiquidCrystal.h"
|
||||
#include "Counter.h"
|
||||
#include "DigitalIoPin.h"
|
||||
#include "Event.h"
|
||||
#include "LiquidCrystal.h"
|
||||
|
||||
/** Buttons enumeration
|
||||
*
|
||||
@ -28,7 +28,8 @@
|
||||
* of the particular button.
|
||||
* */
|
||||
|
||||
enum _buttons {
|
||||
enum _buttons
|
||||
{
|
||||
/** Raises the bar up */
|
||||
BUTTON_CONTROL_UP,
|
||||
/** Raises the bar down */
|
||||
@ -42,14 +43,16 @@ enum _buttons {
|
||||
BUTTON_CONTROL_TOG_ACTIVE
|
||||
};
|
||||
|
||||
enum _bars {
|
||||
enum _bars
|
||||
{
|
||||
/** 0-100 % */
|
||||
FAN_SPEED,
|
||||
/** 0-120 Pa */
|
||||
PRESSURE
|
||||
};
|
||||
|
||||
enum _mode {
|
||||
enum _mode
|
||||
{
|
||||
MANUAL,
|
||||
AUTO
|
||||
};
|
||||
@ -57,8 +60,8 @@ enum _mode {
|
||||
class StateHandler;
|
||||
typedef void (StateHandler::*state_pointer) (const Event &);
|
||||
|
||||
|
||||
class StateHandler {
|
||||
class StateHandler
|
||||
{
|
||||
public:
|
||||
StateHandler (LiquidCrystal *lcd);
|
||||
virtual ~StateHandler ();
|
||||
@ -86,6 +89,7 @@ public:
|
||||
* @param event event to be handled in the current state
|
||||
*/
|
||||
void HandleState (const Event &event);
|
||||
|
||||
private:
|
||||
state_pointer current;
|
||||
/** Set a new curremt state
|
||||
@ -95,7 +99,6 @@ private:
|
||||
bool current_mode;
|
||||
Counter set[2] = { { 0, 100 }, { 0, 120 } };
|
||||
LiquidCrystal *_lcd;
|
||||
|
||||
};
|
||||
|
||||
#endif /* STATE_HANDLER_H_ */
|
||||
|
||||
@ -61,3 +61,14 @@ StateHandler::SetState (state_pointer newstate)
|
||||
current = newstate;
|
||||
(this->*current) (Event (Event::eEnter));
|
||||
}
|
||||
|
||||
void StateHandler::HandleState(const Event &event){
|
||||
(this->*current)(event);
|
||||
}
|
||||
|
||||
void StateHandler::SetState(state_pointer newstate){
|
||||
(this->*current)(Event(Event::eExit));
|
||||
current = newstate;
|
||||
(this->*current)(Event(Event::eEnter));
|
||||
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user