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
8858c71087
2 changed files with 8 additions and 1 deletions
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue