void StateSwitch::updateState() { if(newState_ != currentState_) { oldState_ = currentState_; currentState_ = newState_; } switch(currentState_) { case STATE_IDLE: handleIdle(); break; case STATE_WANDER: handleWander(); break; case STATE_FOLLOW: handleFollow(); break; case STATE_OFFENSIVE: handleOffensive(); break; case STATE_DEFENSIVE: handleDefensive(); break; case STATE_FLEEING: handleFleeing(); break; case STATE_DEATH: handleDeath(); break; } }
void EventHandler::analyze(PupilsFrame& frame){ frames.addData(frame); switch(state){ case RED_ALERT: handleRedAlert(); break; case WAITING_FOR_LEFT_TURN: handleWaitingForLeftTurn(); break; case WAITING_FOR_RIGHT_TURN: handleWaitingForRightTurn(); break; case TURNED_LEFT: handleTurnedLeft(); break; case TURNED_RIGHT: handleTurnedRight(); break; case WINK_LEFT: handleWinkLeft(); break; case WINK_RIGHT: handleWinkRight(); break; case DEACTIVATE: handleDeactivate(); break; case IDLE: handleIdle(); break; default: handleActive(); } frames.getFrameAt(0).state = state; }
void ServerInstance::run() { while(true) { PacketBase pb; if(N->recv(pb) == 0) { continue; } if(pb.type == TYPE_SERVER) { continue; } switch(state) { case Idle: handleIdle(pb); break; case Write: handleWrite(pb); break; case CommitReady: handleCommitReady(pb); break; default: throw FSException("Unknown server state"); } } }
struct StateClass handleRed(enum Event event) { if (event == STANDBY) { handleStandby(); return states[RED_YELLOW]; } else if (event == IDLE) { handleIdle(); return states[YELLOW_BLINKING]; } }
/** * \see trafficlight.h */ void runTrafficLight() { /* initial state */ enum Event event = NO_EVENT; enum State state = RED; toggleLight(RED_LIGHT, ON); timer(RED_TIME, STANDBY); /* state machine loop */ while (1) { event = checkEvent(); // check if an event has been triggered switch (event) { case STANDBY: if (state == RED) { state = RED_YELLOW; handleStandby(); } break; case GO: if (state == RED_YELLOW) { state = GREEN; handleGo(); } break; case PREPARE_TO_STOP: if (state == GREEN) { state = GREEN_BLINKING; handlePrepareToStop(); } break; case REPEAT: if (state == GREEN_BLINKING) { handleRepeatGreen(); } else if (state == YELLOW_BLINKING) { handleRepeatYellow(); } break; case STOP: if (state == GREEN_BLINKING) { state = YELLOW; handleStop(); } break; case WAIT: if (state == YELLOW) { state = RED; handleWait(); } break; case IDLE: if (state == RED) { state = YELLOW_BLINKING; handleIdle(); } case RESET: if (state == YELLOW_BLINKING) { state = RED; handleReset(); } break; } } }