diff --git a/src/app/buttoneventslogger.cpp b/src/app/buttoneventslogger.cpp index 98a0312..0ec8c3f 100644 --- a/src/app/buttoneventslogger.cpp +++ b/src/app/buttoneventslogger.cpp @@ -9,8 +9,13 @@ #include "trace/trace.h" #include "ButtonEvent.h" -ButtonEventsLogger::ButtonEventsLogger() { - curentState_ = state::initial; +ButtonEventsLogger::ButtonEventsLogger() + : stWait(this) { + + stInitial.addInitialTransition(&stWait); + stWait.addTransition(event::evButtonShortPressed, &stWait); + stWait.addTransition(event::evButtonLongPressed, &stWait); + stWait.registerOnEntry((XFState::callbackEv)&ButtonEventsLogger::logOnTrace); } void ButtonEventsLogger::onButtonShortPressed(ButtonIndex buttonIndex) { @@ -21,62 +26,13 @@ void ButtonEventsLogger::onButtonLongPressed(ButtonIndex buttonIndex) { GEN(ButtonEvent(event::evButtonLongPressed, this, buttonIndex)); } -XFEventStatus ButtonEventsLogger::processEvent() { - eEventStatus eventStatus = XFEventStatus::NotConsumed; - - ButtonEvent* ev = (ButtonEvent*)getCurrentEvent(); - XFEvent::XFEventType evType = ev->getEventType(); - int evid = ev->getId(); - - oldState_ = curentState_; - changeXFState = false; - - - - switch (curentState_) { //on state - case state::initial: - if(evType == XFEvent::Initial) { - curentState_ = state::waitButtonPressed; - changeXFState = true; - eventStatus = XFEventStatus::Consumed; - } - break; - - case state::waitButtonPressed: - if(evid == event::evButtonShortPressed){ - Trace::out("ButtonEventLogger: Button %d short pressed", ev->getButtonId()); - curentState_ = state::waitButtonPressed; - changeXFState = true; - eventStatus = XFEventStatus::Consumed; - } - if(evid == event::evButtonLongPressed){ - Trace::out("ButtonEventLogger: Button %d long pressed", ev->getButtonId()); - curentState_ = state::waitButtonPressed; - changeXFState = true; - eventStatus = XFEventStatus::Consumed; - } - break; +void ButtonEventsLogger::logOnTrace(const XFEvent* ev) { + ButtonEvent* buttonEvent = (ButtonEvent*)ev; + int evid = buttonEvent->getId(); + if(evid == event::evButtonShortPressed){ + Trace::out("ButtonEventLogger: Button %d short pressed", buttonEvent->getButtonId()); } - - if(changeXFState) { - switch (oldState_) { // onExit - case state::initial: - break; - - case state::waitButtonPressed: - break; - } - - switch (curentState_) { // onEntry - case state::initial: - break; - - case state::waitButtonPressed: - break; - - } - changeXFState = false; + if(evid == event::evButtonLongPressed){ + Trace::out("ButtonEventLogger: Button %d long pressed", buttonEvent->getButtonId()); } - return eventStatus; } - diff --git a/src/app/buttoneventslogger.h b/src/app/buttoneventslogger.h index 73e99e8..3f533a3 100644 --- a/src/app/buttoneventslogger.h +++ b/src/app/buttoneventslogger.h @@ -21,20 +21,14 @@ public: protected: - XFEventStatus processEvent() override; + void logOnTrace(const XFEvent* ev); typedef enum { - evButtonShortPressed = 1, + evButtonShortPressed = 10, evButtonLongPressed } event; - typedef enum { - initial, - waitButtonPressed - } state; - - state curentState_; - state oldState_; + XFState stWait; }; diff --git a/src/mdw/button/ButtonEventsHandler.cpp b/src/mdw/button/ButtonEventsHandler.cpp index b6a88c3..6bdede2 100644 --- a/src/mdw/button/ButtonEventsHandler.cpp +++ b/src/mdw/button/ButtonEventsHandler.cpp @@ -16,12 +16,12 @@ ButtonEventsHandler::ButtonEventsHandler() observer_[i] = nullptr; } - stInitial.setNextState(&stRun); + stInitial.addInitialTransition(&stRun); stRun.registerOnEntry((XFState::callback)&ButtonEventsHandler::startButtonSM); } -void ButtonEventsHandler::startButtonSM(const XFEvent* ev) { +void ButtonEventsHandler::startButtonSM() { buttonStateSm_[0].startBehavior(); buttonStateSm_[1].startBehavior(); buttonStateSm_[2].startBehavior(); diff --git a/src/mdw/button/ButtonEventsHandler.h b/src/mdw/button/ButtonEventsHandler.h index db58690..00ee768 100644 --- a/src/mdw/button/ButtonEventsHandler.h +++ b/src/mdw/button/ButtonEventsHandler.h @@ -31,7 +31,7 @@ public: protected: ButtonEventsHandler(); - void startButtonSM(const XFEvent* ev); + void startButtonSM(); XFState stRun; diff --git a/src/mdw/button/ButtonStateSm.cpp b/src/mdw/button/ButtonStateSm.cpp index e190eb7..20a5564 100644 --- a/src/mdw/button/ButtonStateSm.cpp +++ b/src/mdw/button/ButtonStateSm.cpp @@ -8,10 +8,27 @@ #include