func motorError() { driver.RunStop() fmt.Printf("\n\n================== ERROR, ELEVATOR MOTOR NOT WORKING PROPERLY ==========\n\n") if floor := driver.GetFloorSignal(); floor != -1 { fmt.Printf("Elevator at floor %d, door opened\n", floor) } fmt.Printf("took %d seconds to reach new floor when running, try fixing the problem and restart\n", MOTOR_ERROR_SEC) fmt.Printf("Program exiting now!\n") fmt.Printf("\n===============================================================================\n\n\n") os.Exit(1) }
func CheckFloorSignal() <-chan int { event := make(chan int) lastFloorState := -1 fmt.Println("eventmgr: CheckFloorSignal started\n") go func() { for { newFloorState := driver.GetFloorSignal() if newFloorState != lastFloorState { lastFloorState = newFloorState if newFloorState != -1 { if DEBUG_CHANNELS { fmt.Println("eventMgr: newFloorState %d ", newFloorState) } event <- newFloorState } } time.Sleep(time.Millisecond * 20) } }() return event }