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,37 +78,13 @@ 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()
if accErrTrigger > 60 {
log.Fatal("Thermal bulk read failed 60 times in a row -- terminating")
}
// Trigger a bulk read to start conversion on all sensors.
if err := triggerBulkRead(); err != nil {
accErrTrigger++
hub.CaptureException(err)
log.Print(err)
break
}
accErrTrigger = 0
// Ensure that we wait for sensors to convert data.
deltaSleep := sensorConversionTime - time.Since(start)
if deltaSleep > 0 {
// Wait for sensors to convert data.
time.Sleep(deltaSleep)
}
// Poll bus state
poll_bus: poll_bus:
state, err := pollBusState() state, err := pollBusState()
if err != nil { if err != nil {
accErrTrigger++ accErrTrigger++
hub.CaptureException(err) hub.CaptureException(err)
log.Print(err) log.Print(err)
break work_loop break
} }
switch state { switch state {
@ -116,10 +92,36 @@ func PollSensors(ctx context.Context, wg *sync.WaitGroup, readingInterval time.D
time.Sleep(busPollDelay) time.Sleep(busPollDelay)
goto poll_bus goto poll_bus
case BulkReadIdle, BulkReadReady: 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 work_loop
}
accErrTrigger = 0
// Ensure that we wait for sensors to convert data.
deltaSleep := sensorConversionTime - time.Since(start)
if deltaSleep > 0 {
// Wait for sensors to convert data.
time.Sleep(deltaSleep)
}
goto poll_bus
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)