コード例 #1
0
//Called by executeOrder
//Start the elevator ordered direction. Also starts the motorstop timer
func goToFloor(currentFloor uint, status *driver.LiftStatus, stopFloor *uint, motorDirectionCh chan<- driver.MotorDirection, statusCh chan<- driver.LiftStatus) {
	if !status.Door && !status.Running {
		if currentFloor < *stopFloor {
			motorDirectionCh <- driver.MD_up
			status.Direction = true
		} else {
			motorDirectionCh <- driver.MD_down
			status.Direction = false
		}
		motorStopTimerRunning = true
		timeGoToFloor = time.Now()
		status.Running = true
		statusCh <- *status
	}
}
コード例 #2
0
//Called by Init
func executeOrder(orderedFloorCh <-chan uint, lightCh chan<- driver.Light, statusCh chan<- driver.LiftStatus, floorSensorCh <-chan uint, doorTimerCh chan bool, motorDirectionCh chan<- driver.MotorDirection, motorStopCh chan<- bool, quitCh <-chan bool) {
	var (
		currentFloor uint
		stopFloor    uint
		status       driver.LiftStatus
	)
	status.Direction = true

	// not in state, go up until floor
	motorDirectionCh <- driver.MD_up
	for {
		currentFloor = <-floorSensorCh
		if currentFloor != 0 {
			log.Println("found floor")
			break
		}
	}
	motorDirectionCh <- driver.MD_stop
	status.Floor = currentFloor
	log.Println(currentFloor)
	status.Running = false
	status.Door = false
	statusCh <- status
	for {
		select {
		case <-quitCh:
			return
		case stopFloor = <-orderedFloorCh:
			//Got new stopFloor
		case <-doorTimerCh:
			lightCh <- driver.Light{0, driver.Door, false}
			status.Door = false
			statusCh <- status
		case currentFloor = <-floorSensorCh:
			updateStatus(currentFloor, &status, motorDirectionCh, statusCh)
		default:
			time.Sleep(5 * time.Millisecond)
			if stopFloor != 0 {
				stopAtFloor(currentFloor, &status, &stopFloor, motorDirectionCh, lightCh, statusCh, doorTimerCh, motorStopCh)
				goToFloor(currentFloor, &status, &stopFloor, motorDirectionCh, statusCh)
			}
		}
	}
}