Check DS18B20 bulk read status before reading
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Søren Rasmussen 2022-07-26 21:28:13 +02:00
parent b3c1e2c520
commit 017ac159de

View file

@ -78,18 +78,29 @@ func PollSensors(ctx context.Context, wg *sync.WaitGroup, readingInterval time.D
work_loop:
select {
case <-ticker.C:
start := time.Now()
if accErrTrigger > 60 {
log.Fatal("Thermal bulk read failed 60 times in a row -- terminating")
poll_bus:
state, err := pollBusState()
if err != nil {
accErrTrigger++
hub.CaptureException(err)
log.Print(err)
break
}
switch state {
case BulkReadBusy:
time.Sleep(busPollDelay)
goto poll_bus
case BulkReadIdle:
start := time.Now()
// Trigger a bulk read to start conversion on all sensors.
if err := triggerBulkRead(); err != nil {
accErrTrigger++
hub.CaptureException(err)
log.Print(err)
break
break work_loop
}
accErrTrigger = 0
@ -101,25 +112,16 @@ func PollSensors(ctx context.Context, wg *sync.WaitGroup, readingInterval time.D
time.Sleep(deltaSleep)
}
// Poll bus state
poll_bus:
state, err := pollBusState()
if err != nil {
accErrTrigger++
hub.CaptureException(err)
log.Print(err)
break work_loop
}
switch state {
case BulkReadBusy:
time.Sleep(busPollDelay)
goto poll_bus
case BulkReadIdle, BulkReadReady:
case BulkReadReady:
readSensors(hub)
}
if accErrTrigger > 60 {
log.Fatal("Thermal bulk read failed 60 times in a row -- terminating")
}
case c := <-ConfigUpdate:
configure(c)