Quality of life improvements
This commit is contained in:
		
							
								
								
									
										15
									
								
								godoor.go
									
									
									
									
									
								
							
							
						
						
									
										15
									
								
								godoor.go
									
									
									
									
									
								
							| @@ -115,7 +115,14 @@ func setup() { | |||||||
|  |  | ||||||
| 	go func() { | 	go func() { | ||||||
| 		for { | 		for { | ||||||
| 			waitEvents() | 			err := waitEvents() | ||||||
|  | 			if err != nil { | ||||||
|  | 				log.Printf("LongPoll for events failed: %v", err) | ||||||
|  | 				log.Println("Will try to LongPoll again in 120 seconds") | ||||||
|  | 				time.Sleep(120 * time.Second) | ||||||
|  | 				go reloadTokens() | ||||||
|  | 			} | ||||||
|  | 			time.Sleep(1 * time.Second) | ||||||
| 		} | 		} | ||||||
| 	}() | 	}() | ||||||
|  |  | ||||||
| @@ -299,8 +306,6 @@ func waitEvents() error { | |||||||
| 					log.Println("There was an error opening and closing the Door") | 					log.Println("There was an error opening and closing the Door") | ||||||
| 				} | 				} | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			go reloadTokens() |  | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 	} | 	} | ||||||
| @@ -319,7 +324,9 @@ func reloadTokens() error { | |||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		return err | 		return err | ||||||
| 	} | 	} | ||||||
|  | 	if resp.StatusCode != 200 { | ||||||
| 		log.Printf("%v\n", resp) | 		log.Printf("%v\n", resp) | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	var cl cardList | 	var cl cardList | ||||||
|  |  | ||||||
| @@ -338,7 +345,7 @@ func reloadTokens() error { | |||||||
| 	validUids = make(ValidUids) | 	validUids = make(ValidUids) | ||||||
| 	var totalCardCount int = 0 | 	var totalCardCount int = 0 | ||||||
| 	for i, val := range cl.AllowedUids { | 	for i, val := range cl.AllowedUids { | ||||||
| 		log.Printf("%d: %+v\n", i, val.Token.UidHash) | 		//log.Printf("%d: %+v\n", i, val.Token.UidHash) | ||||||
| 		validUids[val.Token.UidHash] = true | 		validUids[val.Token.UidHash] = true | ||||||
| 		totalCardCount = i | 		totalCardCount = i | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -90,14 +90,14 @@ func (w *WiegandHW) GetCardUid() (uint64, error) { | |||||||
| func (w *WiegandHW) wiegandAEvent(evt gpiod.LineEvent) { | func (w *WiegandHW) wiegandAEvent(evt gpiod.LineEvent) { | ||||||
| 	w.bitTimeoutTimer.Reset(w.bitTimeout) | 	w.bitTimeoutTimer.Reset(w.bitTimeout) | ||||||
| 	w.bits[w.bitNr] = true | 	w.bits[w.bitNr] = true | ||||||
| 	fmt.Printf("1") | 	//fmt.Printf("1") | ||||||
| 	w.bitNr += 1 | 	w.bitNr += 1 | ||||||
| } | } | ||||||
|  |  | ||||||
| func (w *WiegandHW) wiegandBEvent(evt gpiod.LineEvent) { | func (w *WiegandHW) wiegandBEvent(evt gpiod.LineEvent) { | ||||||
| 	w.bitTimeoutTimer.Reset(w.bitTimeout) | 	w.bitTimeoutTimer.Reset(w.bitTimeout) | ||||||
| 	w.bits[w.bitNr] = false | 	w.bits[w.bitNr] = false | ||||||
| 	fmt.Printf("0") | 	//fmt.Printf("0") | ||||||
| 	w.bitNr += 1 | 	w.bitNr += 1 | ||||||
| } | } | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user