diff --git a/src/mdw/button/ButtonStateSm.cpp b/src/mdw/button/ButtonStateSm.cpp index 20a5564..4b00377 100644 --- a/src/mdw/button/ButtonStateSm.cpp +++ b/src/mdw/button/ButtonStateSm.cpp @@ -19,9 +19,8 @@ ButtonStateSm::ButtonStateSm() stWaitButtonPressed.addTransition(event::evButtonPressed, &stButtonPressed); - // TODO bug if setTimeout is used before addTransition !!! - stButtonPressed.addTransition(event::evButtonReleased, &stButtonShortPressed); stButtonPressed.setTimeout(1000, &stButtonLongPressed); + stButtonPressed.addTransition(event::evButtonReleased, &stButtonShortPressed); stButtonPressed.registerOnExit((XFState::callback)&ButtonStateSm::genNullTransition); stButtonShortPressed.registerOnEntry((XFState::callback)&ButtonStateSm::notifyShortPress); diff --git a/src/mdw/button/ButtonStateSm.h b/src/mdw/button/ButtonStateSm.h index 3b8111a..0acf1d5 100644 --- a/src/mdw/button/ButtonStateSm.h +++ b/src/mdw/button/ButtonStateSm.h @@ -25,7 +25,6 @@ protected: typedef enum { evButtonPressed = 10, evButtonReleased, - evTimeout, evReturn } event; diff --git a/src/xf/core/XFState.cpp b/src/xf/core/XFState.cpp index ed88adb..ca3aab3 100644 --- a/src/xf/core/XFState.cpp +++ b/src/xf/core/XFState.cpp @@ -32,6 +32,12 @@ void XFState::addTransition(XFEvent::XFEventType type, const int evid, const int transitions_.push_back(t); } +XFEventStatus XFState::changeState(XFState* state) { + pBehavior->curentXFState_ = state; + pBehavior->changeXFState = true; + return XFEventStatus::Consumed; +} + XFEventStatus XFState::onState(const XFEvent* ev) { if(cbState_ != nullptr) { @@ -43,23 +49,28 @@ XFEventStatus XFState::onState(const XFEvent* ev) { for(transition t : transitions_) { - if(t.evType == XFEvent::XFEventType::Initial){ - pBehavior->curentXFState_ = t.nextState; - pBehavior->changeXFState = true; - return XFEventStatus::Consumed; + switch(ev->getEventType()) { + + case XFEvent::XFEventType::Initial: + if(t.evType == XFEvent::XFEventType::Initial) { + return changeState(t.nextState); + } + break; + + case XFEvent::XFEventType::Timeout: + if(t.evType == XFEvent::XFEventType::Timeout) { + return changeState(t.nextState); + } + break; + + case XFEvent::XFEventType::Event: + if(t.evid == ev->getId()) { + return changeState(t.nextState); + } + break; + } - if(t.evType == XFEvent::XFEventType::Timeout) { - pBehavior->curentXFState_ = t.nextState; - pBehavior->changeXFState = true; - return XFEventStatus::Consumed; - } - - if(t.evid == ev->getId()) { - pBehavior->curentXFState_ = t.nextState; - pBehavior->changeXFState = true; - return XFEventStatus::Consumed; - } } diff --git a/src/xf/include/xf/XFState.h b/src/xf/include/xf/XFState.h index 2b1b815..e27844e 100644 --- a/src/xf/include/xf/XFState.h +++ b/src/xf/include/xf/XFState.h @@ -82,6 +82,7 @@ public: protected: void addTransition(XFEvent::XFEventType type, const int evid, const int time, XFState* state); + XFEventStatus changeState(XFState* state); XFEventStatus onState(const XFEvent* ev); void onEntry(const XFEvent* ev); void onExit(const XFEvent* ev);