Exemple #1
0
func EventOrderReceived() {
	for {
		button := <-ch_order_received
		var target string
		if button.Button_type == config.BUTTON_COMMAND {
			target = config.Laddr
		} else {
			target = queue.GetOptimalElev(button)
		}
		queue.AddOrder(button, target, ch_order_received)

		if target == config.Laddr {
			if config.Local_elev.Door_open {
				if queue.ShouldStopOnFloor(config.Local_elev.Last_floor) {
					ch_door_open <- true
					time.Sleep(time.Millisecond)
					queue.DeleteOrder(config.Local_elev.Last_floor, ch_outgoing, true)
				}
			} else if config.Local_elev.Is_idle {
				if queue.ShouldStopOnFloor(config.Local_elev.Last_floor) {
					ch_door_open <- true
					time.Sleep(time.Millisecond)
					queue.DeleteOrder(config.Local_elev.Last_floor, ch_outgoing, true)
				} else {
					dir := ChooseNewDirection()
					config.Local_elev.Is_idle = false
					config.Local_elev.Direction = dir
					hardware.SetMotorDirection(dir)
				}
			}
		}
	}
}
Exemple #2
0
func EventReachedFloor(floor int) {
	config.Local_elev.Last_floor = floor
	hardware.SetFloorIndicator(floor)
	if queue.ShouldStopOnFloor(floor) {
		config.Local_elev.Is_idle = true
		hardware.SetMotorDirection(config.DIR_STOP)
		queue.DeleteOrder(floor, ch_outgoing, true)
		ch_door_open <- true
	}
}