Exemple #1
0
func detectAndSendExternalButtonCall(newExternalOrderChan chan datatypes.ExternalOrder, n_floors int) {
	var order datatypes.ExternalOrder
	order.New_order = true
	order.Executed_order = false

	for button := driver.BUTTON_OUTSIDE_UP; button <= driver.BUTTON_OUTSIDE_DOWN; button++ {
		for floor := 0; floor < n_floors; floor++ {
			if driver.Elevator_is_button_pushed(button, floor) {
				order.Floor = floor
				if button == driver.BUTTON_OUTSIDE_UP {
					order.Direction = int(datatypes.UP)
				} else {
					order.Direction = int(datatypes.DOWN)
				}
				if (order.Floor != external_button_control_variable.Floor) && (order.Direction != external_button_control_variable.Direction) {
					newExternalOrderChan <- order
					external_button_control_variable = order
					external_button_control_variable.Timestamp = time.Now().Unix()

				} else if (time.Now().Unix() - external_button_control_variable.Timestamp) > 2 {
					external_button_control_variable.Timestamp = time.Now().Unix()
					newExternalOrderChan <- order
				}
				return
			}
		}
	}
}
Exemple #2
0
func detectAndSendInternalButtonCall(newInternalOrderChan chan datatypes.InternalOrder, n_floors int) {
	var order datatypes.InternalOrder
	for floor := 0; floor < n_floors; floor++ {
		if driver.Elevator_is_button_pushed(driver.BUTTON_INSIDE_COMMAND, floor) {
			order.Floor = floor
			newInternalOrderChan <- order
		}
	}
}