Check DS18B20 bulk read status before reading
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
b3c1e2c520
commit
017ac159de
1 changed files with 28 additions and 26 deletions
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue