func createStopListener(ch chan int) { var prevStateStop int = 0 var StateStop int = 0 for { time.Sleep(time.Millisecond * 10) StateStop = int(C.elev_get_stop_signal()) if StateStop != prevStateStop { prevStateStop = StateStop if StateStop == 1 { ch <- STOP } } } }
// StopButtonListener should be spawned as a goroutine, and will trigger on press func StopButtonListener(ch chan<- bool) { var stopButtonState bool for { mutex.Lock() newState := C.elev_get_stop_signal() != 0 mutex.Unlock() if newState != stopButtonState { stopButtonState = newState if newState { log.Debug("Stop button pressed") } else { log.Debug("Stop button released") } ch <- newState } } }
func Elev_get_stop_signal() int { return int(C.elev_get_stop_signal()) }
func Elevator_get_stop_signal() bool { return (int(C.elev_get_stop_signal()) != 0) }
func GetStopSignal() int { return int(C.elev_get_stop_signal()) }