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);
|
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);
|
||||||
|
@ -25,7 +25,6 @@ protected:
|
|||||||
typedef enum {
|
typedef enum {
|
||||||
evButtonPressed = 10,
|
evButtonPressed = 10,
|
||||||
evButtonReleased,
|
evButtonReleased,
|
||||||
evTimeout,
|
|
||||||
evReturn
|
evReturn
|
||||||
} event;
|
} event;
|
||||||
|
|
||||||
|
@ -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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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);
|
||||||
|
Reference in New Issue
Block a user