func Run_Elevator(localStatusCh chan Elevator, sendBtnCallCh chan [2]int, receiveAllBtnCallsCh chan [Driver.NUMFLOORS][Driver.NUMBUTTONS - 1]bool, setLights_setExtBtnsCh chan [4][2]bool, errorCh chan int) {
	if Driver.ElevGetFloorSensorSignal() == -1 {
		fsm_onInitBetweenFloors()
	}
	fsm_elevatorUninitialized()
	fmt.Println("Elev ID: ", elevator.Elev_ID)

	running := true
	var prev_button [Driver.NUMFLOORS][Driver.NUMBUTTONS]int
	var prev_floor int
	prev_floor = Driver.ElevGetFloorSensorSignal()
	go Update_ExtBtnCallsInElevControl(setLights_setExtBtnsCh)
	go checkElevMoving(errorCh)
	update_status_count := 0
	update_lights_count := 0
	localStatusCh <- elevator
	for running {
		for f := 0; f < Driver.NUMFLOORS; f++ {
			for b := 0; b < Driver.NUMBUTTONS; b++ {
				v := Driver.ElevGetButtonSignal(b, f)
				if v&int(v) != prev_button[f][b] {
					if fsm_onRequestButtonPress(f, Button(b), sendBtnCallCh) { //Hvis true er det innvendig knappetrykk
						temp_Behaviour := elevator.Behaviour
						fsm_onNewActiveRequest(f, Button(b))
						if temp_Behaviour != elevator.Behaviour {
							localStatusCh <- elevator
						}
					} else {
						fsm_SendNewOrderToMaster(f, Button(b), sendBtnCallCh)
					}
				}
				prev_button[f][b] = v
			}
		}
		f := Driver.ElevGetFloorSensorSignal()
		if f != -1 {
			if f != prev_floor {
				fsm_onFloorArrival(f)
				localStatusCh <- elevator
			}
		}
		prev_floor = f
		if timer_timedOut() {
			fsm_onDoorTimeout()
			timer_stop()
			localStatusCh <- elevator
		}
		if update_status_count == 50 {
			localStatusCh <- elevator
			update_status_count = 0
		}
		if update_lights_count == 10 {
			setLights_setExtBtnsCh <- allExtBtns
			update_lights_count = 0
		}
		time.Sleep(25 * time.Millisecond)
		update_status_count += 1
		update_lights_count += 1
	}
}
Example #2
0
func RequestButtons() {
	for {
		var previousRequests = [driver.NUMFLOORS][3]bool{}

		for floor := 0; floor < driver.NUMFLOORS; floor++ {
			for btn := 0; btn < 3; btn++ {
				buttonPressed := driver.ElevGetButtonSignal(btn, floor)
				if buttonPressed && buttonPressed != previousRequests[floor][btn] {
					if btn != int(INSIDEBUTTON) {
						if driver.ElevGetFloorSensorSignal() == floor {
							FsmOnOrderReceived(floor, ButtonType(btn))
						} else {
							E.LocalRequests[floor][btn] = true
						}

					} else {
						E.MasterOrders[floor][btn] = true
						FsmOnOrderReceived(floor, ButtonType(btn))
					}
					//FsmOnOrderReceived(floor, ButtonType(btn)) //move to orderReceived
				}
				previousRequests[floor][btn] = buttonPressed
			}
		}

		time.Sleep(25 * time.Millisecond)
	}
}
Example #3
0
func ElevatorStoreOrders(receivedOrders [driver.NUMFLOORS][3]bool) {
	for floor := 0; floor < driver.NUMFLOORS; floor++ {
		for btn := 0; btn < 3; btn++ { //Had to add !buttonPushed, because it instantly set LocalRequests true again too fast
			if !driver.ElevGetButtonSignal(btn, floor) && receivedOrders[floor][btn] && receivedOrders[floor][btn] != elevatorOperation.E.MasterOrders[floor][btn] {
				elevatorOperation.E.MasterOrders[floor][btn] = true
				elevatorOperation.FsmOnOrderReceived(floor, elevatorOperation.ButtonType(btn))
			}
		}
	}
}