Handle LCD errors gracefully
Some checks reported errors
continuous-integration/drone/push Build encountered an error
Some checks reported errors
continuous-integration/drone/push Build encountered an error
This commit is contained in:
parent
a055514612
commit
cbc1f161c1
1 changed files with 17 additions and 6 deletions
|
@ -27,12 +27,15 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
|
||||||
config := configuration.Global()
|
config := configuration.Global()
|
||||||
|
|
||||||
// Display
|
// Display
|
||||||
|
var hasDisplay bool
|
||||||
display, err := lcd.NewLCD(config.I2C.Bus)
|
display, err := lcd.NewLCD(config.I2C.Bus)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
hub.CaptureException(err)
|
hub.CaptureException(err)
|
||||||
log.Fatal(err)
|
log.Printf("Error initializing LCD: %v", err)
|
||||||
|
} else {
|
||||||
|
hasDisplay = true
|
||||||
|
defer display.Close()
|
||||||
}
|
}
|
||||||
defer display.Close()
|
|
||||||
|
|
||||||
// Controller
|
// Controller
|
||||||
ctrl := controllers.NewChamberController(config)
|
ctrl := controllers.NewChamberController(config)
|
||||||
|
@ -60,8 +63,12 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
|
||||||
}
|
}
|
||||||
defer gpio.Close()
|
defer gpio.Close()
|
||||||
|
|
||||||
wg.Add(5)
|
if hasDisplay {
|
||||||
go display.Run(ctx, wg)
|
wg.Add(1)
|
||||||
|
go display.Run(ctx, wg)
|
||||||
|
}
|
||||||
|
|
||||||
|
wg.Add(4)
|
||||||
go ctrl.Run(ctx, wg)
|
go ctrl.Run(ctx, wg)
|
||||||
go ingest.Run(ctx, wg)
|
go ingest.Run(ctx, wg)
|
||||||
go temperature.PollSensors(ctx, wg, 1*time.Second, config.Sensors.Weight)
|
go temperature.PollSensors(ctx, wg, 1*time.Second, config.Sensors.Weight)
|
||||||
|
@ -77,7 +84,9 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
|
||||||
case reading := <-temperature.Reading:
|
case reading := <-temperature.Reading:
|
||||||
ctrl.SetTemperature(reading)
|
ctrl.SetTemperature(reading)
|
||||||
ingest.AddReading(reading)
|
ingest.AddReading(reading)
|
||||||
display.SetTemperature(reading)
|
if hasDisplay {
|
||||||
|
display.SetTemperature(reading)
|
||||||
|
}
|
||||||
|
|
||||||
case <-temperature.RequestReset:
|
case <-temperature.RequestReset:
|
||||||
log.Print("Powering down one wire bus for 20 seconds")
|
log.Print("Powering down one wire bus for 20 seconds")
|
||||||
|
@ -111,7 +120,9 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
|
||||||
case state := <-ctrl.C:
|
case state := <-ctrl.C:
|
||||||
gpioSetState(state, gpio, config)
|
gpioSetState(state, gpio, config)
|
||||||
ingest.AddState(state)
|
ingest.AddState(state)
|
||||||
display.SetState(state)
|
if hasDisplay {
|
||||||
|
display.SetState(state)
|
||||||
|
}
|
||||||
|
|
||||||
case c := <-chConfigChange:
|
case c := <-chConfigChange:
|
||||||
config = c
|
config = c
|
||||||
|
|
Loading…
Reference in a new issue