Ejemplo n.º 1
0
func OnNewRequest(OutgoingMsg chan<- def.Message, hwCh def.HardwareChan) {
	switch Elevator.Behaviour {
	case doorOpen:
		if queue.ShouldStop(Elevator.Floor, Elevator.Dir) {
			hwCh.DoorTimerReset <- true
			queue.RemoveLocalRequestsAt(Elevator.Floor, OutgoingMsg)
		}
	case moving:
		//Do nothing
	case idle:
		Elevator.Dir = queue.ChooseDirection(Elevator.Floor, Elevator.Dir)
		if Elevator.Dir == def.DirStop {
			hwCh.DoorLamp <- true
			hwCh.DoorTimerReset <- true
			queue.RemoveLocalRequestsAt(Elevator.Floor, OutgoingMsg)
			Elevator.Behaviour = doorOpen
		} else {
			hwCh.MotorDir <- Elevator.Dir
			Elevator.Behaviour = moving
		}
	}
}
Ejemplo n.º 2
0
func OnFloorArrival(hwCh def.HardwareChan, OutgoingMsg chan<- def.Message, newFloor int) {
	Elevator.Floor = newFloor
	hwCh.FloorLamp <- Elevator.Floor
	switch Elevator.Behaviour {
	case moving:
		if queue.ShouldStop(newFloor, Elevator.Dir) {
			hwCh.MotorDir <- def.DirStop
			hwCh.DoorLamp <- true
			hwCh.DoorTimerReset <- true
			queue.RemoveLocalRequestsAt(Elevator.Floor, OutgoingMsg)
			Elevator.Behaviour = doorOpen
		}
	}
}