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)
|
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)
|
||||||
}
|
}
|
||||||
defer display.Close()
|
defer display.Close()
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,7 @@ type LCD struct {
|
||||||
chSetpoint chan float64
|
chSetpoint chan float64
|
||||||
lastUpdate time.Time
|
lastUpdate time.Time
|
||||||
hub *sentry.Hub
|
hub *sentry.Hub
|
||||||
|
isOpen bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLCD(bus int) (*LCD, error) {
|
func NewLCD(bus int) (*LCD, error) {
|
||||||
|
@ -68,6 +69,8 @@ func NewLCD(bus int) (*LCD, error) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
p.isOpen = true
|
||||||
|
|
||||||
return p, nil
|
return p, nil
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -175,6 +178,10 @@ func (p *LCD) Run(ctx context.Context, wg *sync.WaitGroup) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *LCD) update() error {
|
func (p *LCD) update() error {
|
||||||
|
if !p.isOpen {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
if time.Since(p.lastUpdate) < 3*time.Second {
|
if time.Since(p.lastUpdate) < 3*time.Second {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue