Beispiel #1
0
// Turn off motor if program is terminated by user
func safeKill() {
	var c = make(chan os.Signal)
	signal.Notify(c, os.Interrupt)
	<-c
	hw.SetMotorDir(def.DirStop)
	log.Fatal(def.Col0, "User terminated program.", def.ColN)
}
Beispiel #2
0
func EventHandler(eventCh def.EventChan, msgCh def.MessageChan, hwCh def.HardwareChan) {

	go eventBtnPressed(hwCh.BtnPressed)
	go eventCabAtFloor(eventCh.FloorReached)

	for {
		select {
		case btnPress := <-hwCh.BtnPressed:
			handleBtnPress(btnPress, msgCh.Outgoing)
		case incomingMsg := <-msgCh.Incoming:
			go handleMessage(incomingMsg, msgCh)
		case btnLightUpdate := <-q.LightUpdate:
			log.Println(def.ColW, "Light update", def.ColN)
			hw.SetBtnLamp(btnLightUpdate)
		case requestTimeout := <-q.RequestTimeoutChan:
			q.ReassignRequest(requestTimeout.Floor, requestTimeout.Button, msgCh.Outgoing)
		case motorDir := <-hwCh.MotorDir:
			hw.SetMotorDir(motorDir)
		case floorLamp := <-hwCh.FloorLamp:
			hw.SetFloorLamp(floorLamp)
		case doorLamp := <-hwCh.DoorLamp:
			hw.SetDoorLamp(doorLamp)
		case <-q.NewRequest:
			log.Println(def.ColW, "Event: New Request", def.ColN)
			fsm.OnNewRequest(msgCh.Outgoing, hwCh)
		case currFloor := <-eventCh.FloorReached:
			fsm.OnFloorArrival(hwCh, msgCh.Outgoing, currFloor)
		case <-eventCh.DoorTimeout:
			fsm.OnDoorTimeout(hwCh)
		}
		time.Sleep(10 * time.Millisecond)
	}
}