Example #1
0
func receiveOrder(commChannel chan ElevatorOrder) {
	var prevOrderMatrix [driver.N_FLOORS][driver.N_BUTTONS]int
	for i := 0; i < driver.N_FLOORS; i++ {
		for j := 0; j < driver.N_BUTTONS; j++ {
			prevOrderMatrix[i][j] = 0
		}
	}
	var currentOrderMatrix [driver.N_FLOORS][driver.N_BUTTONS]int
	var tempOrder ElevatorOrder
	for {
		time.Sleep(time.Millisecond * 10)
		for i := 0; i < driver.N_FLOORS; i++ {
			for j := 0; j < driver.N_BUTTONS; j++ {
				currentOrderMatrix[i][j] = driver.Elev_get_button_signal(driver.Elev_button_type_t(j), i)
			}
		}
		for i := 0; i < driver.N_FLOORS; i++ {
			for j := 0; j < driver.N_BUTTONS; j++ {
				if (currentOrderMatrix[i][j] == 1) && (prevOrderMatrix[i][j] == 0) {
					tempOrder.OrderType = driver.Elev_button_type_t(j)
					tempOrder.Floor = i
					commChannel <- tempOrder
				}
			}
		}
		prevOrderMatrix = currentOrderMatrix
	}
}
Example #2
0
func getButtons() <-chan def.ButtonPress {
	c := make(chan def.ButtonPress, 10)
	go func() {
		var buttonState [def.N_FLOORS][def.N_BUTTONS]bool
		for {
			for f := 0; f < def.N_FLOORS; f++ {
				for b := 0; b < def.N_BUTTONS; b++ {
					if driver.Elev_get_button_signal(b, f) {
						if !buttonState[f][b] {
							c <- def.ButtonPress{Button: b, Floor: f, Value: true}
						}
						buttonState[f][b] = true
					} else {
						buttonState[f][b] = false
					}
				}
			}
			time.Sleep(time.Millisecond)

		}
	}()
	return c
}