func indicateSyncFail(fe *frontend.Frontend) { if syncFailIndicatorRunning == true { return } syncFailIndicatorRunning = true for { if lastSyncState == true { syncFailIndicatorRunning = false return } fe.LED(2, 1000) fe.Beep(2) time.Sleep(2 * time.Second) } }
// Reads keypresses from the specified frontend, verifies entered pins using // the given pinstore and sends open/close commands to the specified hometec // channel. func ValidatePin(ps *pinstore.Pinstore, fe *frontend.Frontend, ht chan string) { var keypressBuffer bytes.Buffer for { keypress := <-fe.Keypresses b := []byte(keypress.Key) fe.LED(1, 50) fe.Beep(2) if b[0] != byte('#') { if keypressBuffer.Len() == 0 { fe.LcdSet("PIN: *") } else { fe.LcdPut("*") } keypressBuffer.WriteByte(b[0]) continue } pin := keypressBuffer.String() keypressBuffer.Reset() if pin == "666" { fmt.Printf("Got close pin, locking door\n") fe.LcdSet("Locking door...") fe.LED(3, 3000) fe.LED(2, 1) ht <- "close" continue } if len(pin) != 6 || !validPin.Match([]byte(pin)) { invalidPin(pin, fe) continue } // The pin is complete, let’s validate it. if handle, ok := ps.Pins[pin]; ok { fmt.Printf("%s unlocked the door\n", handle) fe.LcdSet("Unlocking door...") fe.LED(3, 3000) fe.LED(2, 1) ht <- "open" continue } fmt.Printf("No such PIN: %s\n", pin) invalidPin(pin, fe) } }