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