コード例 #1
0
//Called by Init
//Polls and sets the GPIO
func driverLoop(lightCh <-chan driver.Light, buttonCh chan<- driver.Button, floorSensorCh chan<- uint, motorDirectionCh <-chan driver.MotorDirection, quitCh <-chan bool) {
	for {
		select {
		case <-quitCh:
			driver.ClearAll()
			return
		default:
			driver.ReadButtons(buttonCh)
			driver.ReadFloorSensors(floorSensorCh)
			driver.RunMotor(motorDirectionCh)
			driver.SetLight(lightCh)
			time.Sleep(5 * time.Millisecond)
		}
	}
}
コード例 #2
0
//Called by control.RunLift
//Initializes the driver, runs polling from driver to channels and executes orders from channel
func Init(orderedFloorCh <-chan uint, lightCh chan driver.Light, statusCh chan driver.LiftStatus, buttonCh chan<- driver.Button, motorStopCh chan<- bool, quitCh <-chan bool) bool {
	if !driver.Init() {
		log.Fatal("could not initialize driver")
		return false
	}
	// clear all lights and stop motor
	driver.ClearAll()
	log.Println("cleared all lights and stopped motor.")
	var floorSensorCh = make(chan uint, 5)
	var doorTimerCh = make(chan bool, 2)
	var motorDirectionCh = make(chan driver.MotorDirection, 5)
	go driverLoop(lightCh, buttonCh, floorSensorCh, motorDirectionCh, quitCh)
	go executeOrder(orderedFloorCh, lightCh, statusCh, floorSensorCh, doorTimerCh, motorDirectionCh, motorStopCh, quitCh)
	log.Println("fsmElev initialized")
	return true
}