fix miss order Timeout bug
This commit is contained in:
parent
dac64a2d64
commit
821df428e9
@ -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);
|
||||
|
@ -25,7 +25,6 @@ protected:
|
||||
typedef enum {
|
||||
evButtonPressed = 10,
|
||||
evButtonReleased,
|
||||
evTimeout,
|
||||
evReturn
|
||||
} event;
|
||||
|
||||
|
@ -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_) {
|
||||
|
||||
switch(ev->getEventType()) {
|
||||
|
||||
case XFEvent::XFEventType::Initial:
|
||||
if(t.evType == XFEvent::XFEventType::Initial) {
|
||||
pBehavior->curentXFState_ = t.nextState;
|
||||
pBehavior->changeXFState = true;
|
||||
return XFEventStatus::Consumed;
|
||||
return changeState(t.nextState);
|
||||
}
|
||||
break;
|
||||
|
||||
case XFEvent::XFEventType::Timeout:
|
||||
if(t.evType == XFEvent::XFEventType::Timeout) {
|
||||
pBehavior->curentXFState_ = t.nextState;
|
||||
pBehavior->changeXFState = true;
|
||||
return XFEventStatus::Consumed;
|
||||
return changeState(t.nextState);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -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);
|
||||
|
Reference in New Issue
Block a user