Exemple #1
0
func (elev *ElevatorState) goToStateMoving(direction Direction_t) {
	if DEBUG_FSM {
		fmt.Printf("fsm: Starting to move in dir = %d against destination = %d\n\n\n", direction, elev.destination)
	}
	switch direction {
	case DIR_UP:
		driver.RunUp()
		elev.motorErrorTimer.Reset(time.Second * MOTOR_ERROR_SEC)
	case DIR_DOWN:
		driver.RunDown()
		elev.motorErrorTimer.Reset(time.Second * MOTOR_ERROR_SEC)
	default:
		if DEBUG_FSM {
			fmt.Printf("fsm: unknown direction")
		}
		return
	}
	elev.setDir(direction)
	elev.setState(STATE_MOVING)

}
Exemple #2
0
func NewElevator() *ElevatorState {
	var elev ElevatorState
	elev.setDestination(NO_DESTINATION)
	elev.OrderDone = make(chan int, 1)
	floorEvent := eventmgr.CheckFloorSignal()
	driver.RunDown()
	elev.motorErrorTimer = time.AfterFunc(time.Second*MOTOR_ERROR_SEC, motorError)
	elev.NewFloorReached(<-floorEvent)
	driver.RunStop()
	elev.motorErrorTimer.Stop()

	elev.goToStateIdle()

	go func() {
		for {
			newFloor := <-floorEvent
			elev.NewFloorReached(newFloor)
		}
	}()
	fmt.Printf("fsm: init done at floor %d, NewElevator returned\n\n", elev.Floor())

	return &elev
}