diff --git a/cmd/fermentord/loop.go b/cmd/fermentord/loop.go index a7155ec..64609bf 100644 --- a/cmd/fermentord/loop.go +++ b/cmd/fermentord/loop.go @@ -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() diff --git a/internal/lcd/hd44780.go b/internal/lcd/hd44780.go index b426cae..1b5e05b 100644 --- a/internal/lcd/hd44780.go +++ b/internal/lcd/hd44780.go @@ -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 }