Handle LCD errors gracefully
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
Søren Rasmussen 2024-06-15 19:30:52 +02:00
parent a055514612
commit cbc1f161c1

View file

@ -27,12 +27,15 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
config := configuration.Global()
// Display
var hasDisplay bool
display, err := lcd.NewLCD(config.I2C.Bus)
if err != nil {
hub.CaptureException(err)
log.Fatal(err)
log.Printf("Error initializing LCD: %v", err)
} else {
hasDisplay = true
defer display.Close()
}
defer display.Close()
// Controller
ctrl := controllers.NewChamberController(config)
@ -60,8 +63,12 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
}
defer gpio.Close()
wg.Add(5)
go display.Run(ctx, wg)
if hasDisplay {
wg.Add(1)
go display.Run(ctx, wg)
}
wg.Add(4)
go ctrl.Run(ctx, wg)
go ingest.Run(ctx, wg)
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:
ctrl.SetTemperature(reading)
ingest.AddReading(reading)
display.SetTemperature(reading)
if hasDisplay {
display.SetTemperature(reading)
}
case <-temperature.RequestReset:
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:
gpioSetState(state, gpio, config)
ingest.AddState(state)
display.SetState(state)
if hasDisplay {
display.SetState(state)
}
case c := <-chConfigChange:
config = c