refactor: flatten hash updates

This commit is contained in:
2025-12-22 21:18:23 +02:00
parent 2f4005a7ba
commit 9bf71b347f
9 changed files with 82 additions and 90 deletions

View File

@@ -57,6 +57,7 @@ func (w *WiegandHW) IsDoorOpen() (bool, error) {
defer w.lock.RUnlock()
return w.isDoorOpen()
}
func (w *WiegandHW) isDoorOpen() (bool, error) {
i, err := w.solenoidLine.Value()
if err != nil {
@@ -90,19 +91,18 @@ func (w *WiegandHW) GetCardUid() (uint64, error) {
func (w *WiegandHW) wiegandAEvent(evt gpiod.LineEvent) {
w.bitTimeoutTimer.Reset(w.bitTimeout)
w.bits[w.bitNr] = true
//fmt.Printf("1")
// fmt.Printf("1")
w.bitNr += 1
}
func (w *WiegandHW) wiegandBEvent(evt gpiod.LineEvent) {
w.bitTimeoutTimer.Reset(w.bitTimeout)
w.bits[w.bitNr] = false
//fmt.Printf("0")
// fmt.Printf("0")
w.bitNr += 1
}
func WiegandSetup(a int, b int, bitTimeout time.Duration, solenoid int) *WiegandHW {
log.Printf("Wiegand GPIO-s: A:%d B:%d Solenoid:%d", a, b, solenoid)
var wiegand WiegandHW
wiegand.bitTimeout = bitTimeout
@@ -141,9 +141,9 @@ func (w *WiegandHW) WiegandClose() {
w.solenoidLine.Close()
}
func printCardId(card uint64) {
for i := 0; i < 7; i++ {
fmt.Printf("%02x", (card>>(8*i))&0xff)
}
fmt.Printf("\n")
}
// func printCardId(card uint64) {
// for i := 0; i < 7; i++ {
// fmt.Printf("%02x", (card>>(8*i))&0xff)
// }
// fmt.Printf("\n")
// }