コード例 #1
0
func main() {
	driver.IOInit()
	time.Sleep(time.Second * 1)
	hardware.ResetLights()
	hardware.SetMotorDirection(0)
	time.Sleep(time.Second * 1)
}
コード例 #2
0
func Init(buttonChannel chan<- ButtonEvent, lightChannel <-chan LightEvent, motorChannel <-chan int, floorChannel chan<- FloorEvent, pollingDelay time.Duration) error {
	if initialized {
		return fmt.Errorf("Hardware is already initialized.")
	}
	initSuccess := driver.IOInit()
	if initSuccess != nil {
		return fmt.Errorf("Unable to initialize hardware.")
	}
	resetLights()

	setMotorDirection(typedef.DIR_STOP)
	// If initialized between floors, move down to nearest floor.
	if checkFloor() == -1 {
		fmt.Printf("HARDWARE:\t Starting between floors, going down.\n")
		setMotorDirection(typedef.DIR_DOWN)
		for {
			if floor := checkFloor(); floor != -1 {
				fmt.Printf("HARDWARE:\t INIT -> Arrived at floor: %d\n", floor)
				setMotorDirection(typedef.DIR_STOP)
				floorChannel <- FloorEvent{CurrentDirection: typedef.DIR_STOP, Floor: floor}
				break
			} else {
				time.Sleep(pollingDelay)
			}
		}
	}

	// Start goroutines to handle hardware events.
	go controlLights(lightChannel)
	go controlMotor(motorChannel)
	go readButtons(buttonChannel, pollingDelay)
	go readFloorSensors(floorChannel, pollingDelay)
	return nil
	// TODO -> Acceptance test!!!
}