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 8858c71087
2 changed files with 8 additions and 1 deletions

View file

@ -30,7 +30,7 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
display, err := lcd.NewLCD(config.I2C.Bus)
if err != nil {
hub.CaptureException(err)
log.Fatal(err)
log.Printf("Error initializing LCD: %v", err)
}
defer display.Close()

View file

@ -26,6 +26,7 @@ type LCD struct {
chSetpoint chan float64
lastUpdate time.Time
hub *sentry.Hub
isOpen bool
}
func NewLCD(bus int) (*LCD, error) {
@ -68,6 +69,8 @@ func NewLCD(bus int) (*LCD, error) {
return nil, err
}
p.isOpen = true
return p, nil
}
@ -175,6 +178,10 @@ func (p *LCD) Run(ctx context.Context, wg *sync.WaitGroup) {
}
func (p *LCD) update() error {
if !p.isOpen {
return nil
}
if time.Since(p.lastUpdate) < 3*time.Second {
return nil
}