fix miss order Timeout bug

This commit is contained in:
Rémi Heredero 2023-11-27 21:30:11 +01:00
parent dac64a2d64
commit 821df428e9
4 changed files with 28 additions and 18 deletions

View File

@ -19,9 +19,8 @@ ButtonStateSm::ButtonStateSm()
stWaitButtonPressed.addTransition(event::evButtonPressed, &stButtonPressed); stWaitButtonPressed.addTransition(event::evButtonPressed, &stButtonPressed);
// TODO bug if setTimeout is used before addTransition !!!
stButtonPressed.addTransition(event::evButtonReleased, &stButtonShortPressed);
stButtonPressed.setTimeout(1000, &stButtonLongPressed); stButtonPressed.setTimeout(1000, &stButtonLongPressed);
stButtonPressed.addTransition(event::evButtonReleased, &stButtonShortPressed);
stButtonPressed.registerOnExit((XFState::callback)&ButtonStateSm::genNullTransition); stButtonPressed.registerOnExit((XFState::callback)&ButtonStateSm::genNullTransition);
stButtonShortPressed.registerOnEntry((XFState::callback)&ButtonStateSm::notifyShortPress); stButtonShortPressed.registerOnEntry((XFState::callback)&ButtonStateSm::notifyShortPress);

View File

@ -25,7 +25,6 @@ protected:
typedef enum { typedef enum {
evButtonPressed = 10, evButtonPressed = 10,
evButtonReleased, evButtonReleased,
evTimeout,
evReturn evReturn
} event; } event;

View File

@ -32,6 +32,12 @@ void XFState::addTransition(XFEvent::XFEventType type, const int evid, const int
transitions_.push_back(t); transitions_.push_back(t);
} }
XFEventStatus XFState::changeState(XFState* state) {
pBehavior->curentXFState_ = state;
pBehavior->changeXFState = true;
return XFEventStatus::Consumed;
}
XFEventStatus XFState::onState(const XFEvent* ev) { XFEventStatus XFState::onState(const XFEvent* ev) {
if(cbState_ != nullptr) { if(cbState_ != nullptr) {
@ -43,23 +49,28 @@ XFEventStatus XFState::onState(const XFEvent* ev) {
for(transition t : transitions_) { for(transition t : transitions_) {
if(t.evType == XFEvent::XFEventType::Initial){ switch(ev->getEventType()) {
pBehavior->curentXFState_ = t.nextState;
pBehavior->changeXFState = true;
return XFEventStatus::Consumed;
}
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) { if(t.evType == XFEvent::XFEventType::Timeout) {
pBehavior->curentXFState_ = t.nextState; return changeState(t.nextState);
pBehavior->changeXFState = true; }
return XFEventStatus::Consumed; break;
case XFEvent::XFEventType::Event:
if(t.evid == ev->getId()) {
return changeState(t.nextState);
}
break;
} }
if(t.evid == ev->getId()) {
pBehavior->curentXFState_ = t.nextState;
pBehavior->changeXFState = true;
return XFEventStatus::Consumed;
}
} }

View File

@ -82,6 +82,7 @@ public:
protected: protected:
void addTransition(XFEvent::XFEventType type, const int evid, const int time, XFState* state); void addTransition(XFEvent::XFEventType type, const int evid, const int time, XFState* state);
XFEventStatus changeState(XFState* state);
XFEventStatus onState(const XFEvent* ev); XFEventStatus onState(const XFEvent* ev);
void onEntry(const XFEvent* ev); void onEntry(const XFEvent* ev);
void onExit(const XFEvent* ev); void onExit(const XFEvent* ev);