From e142662cc872471c0f9e1d92908ea65e4065c1c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B8ren=20Rasmussen?= Date: Sat, 15 Jun 2024 16:26:28 +0200 Subject: [PATCH] Enable I2C display --- cmd/fermentord/loop.go | 11 +++++----- internal/configuration/fermentord.go | 4 ++++ internal/configuration/fermentord.toml | 3 +++ internal/lcd/hd44780.go | 29 +++++++++++++------------- 4 files changed, 27 insertions(+), 20 deletions(-) diff --git a/cmd/fermentord/loop.go b/cmd/fermentord/loop.go index e289475..d05a081 100644 --- a/cmd/fermentord/loop.go +++ b/cmd/fermentord/loop.go @@ -24,8 +24,10 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) { hub := sentry.CurrentHub().Clone() defer hub.Flush(10 * time.Second) + config := configuration.Global() + // Display - display, err := lcd.NewLCD() + display, err := lcd.NewLCD(config.I2C.Bus) if err != nil { hub.CaptureException(err) log.Fatal(err) @@ -33,7 +35,6 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) { defer display.Close() // Controller - config := configuration.Global() ctrl := controllers.NewChamberController(config) chConfigChange := make(chan configuration.Configuration, 1) @@ -76,7 +77,7 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) { case reading := <-temperature.Reading: ctrl.SetTemperature(reading) ingest.AddReading(reading) - //display.SetTemperature(reading) + display.SetTemperature(reading) case <-temperature.RequestReset: log.Print("Powering down one wire bus for 20 seconds") @@ -85,7 +86,7 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) { ingest.AddEvent("ONEWIRE_RESET") case <-oneWirePowerUpChannel: - log.Print("Powering up one wire bus") + log.Print("Powering up OneWire bus") gpio.StartOneWirePower() case ev := <-gpio.C: @@ -110,7 +111,7 @@ 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) + display.SetState(state) case c := <-chConfigChange: config = c diff --git a/internal/configuration/fermentord.go b/internal/configuration/fermentord.go index f203d44..e2ed642 100644 --- a/internal/configuration/fermentord.go +++ b/internal/configuration/fermentord.go @@ -29,6 +29,10 @@ type Configuration struct { Weight float64 `mapstructure:"weight"` } `mapstructure:"sensors"` + I2C struct { + Bus int `mapstructure:"bus"` + } `mapstructure:"i2c"` + FermentationTemperature float64 `mapstructure:"fermentation_temp"` DeltaTemperatureCool float64 `mapstructure:"delta_temp_cool"` DeltaTemperatureHeat float64 `mapstructure:"delta_temp_heat"` diff --git a/internal/configuration/fermentord.toml b/internal/configuration/fermentord.toml index f2361e7..1439073 100644 --- a/internal/configuration/fermentord.toml +++ b/internal/configuration/fermentord.toml @@ -26,6 +26,9 @@ chamber = "" ambient = "" weight = 0.8 +[i2c] +bus = 0 + [limits] min_chamber_temp = 0.0 max_chamber_temp = 25 diff --git a/internal/lcd/hd44780.go b/internal/lcd/hd44780.go index 4a516b9..ac376ec 100644 --- a/internal/lcd/hd44780.go +++ b/internal/lcd/hd44780.go @@ -28,7 +28,7 @@ type LCD struct { hub *sentry.Hub } -func NewLCD() (*LCD, error) { +func NewLCD(bus int) (*LCD, error) { var err error p := &LCD{ @@ -39,7 +39,7 @@ func NewLCD() (*LCD, error) { hub: sentry.CurrentHub().Clone(), } - p.bus, err = i2c.NewI2C(0x27, 0) + p.bus, err = i2c.NewI2C(0x27, bus) if err != nil { return nil, err } @@ -50,25 +50,24 @@ func NewLCD() (*LCD, error) { return nil, err } - err = p.lcd.BacklightOff() + err = p.lcd.BacklightOn() if err != nil { p.bus.Close() return nil, err } - /* - err = p.lcd.ShowMessage("Fermentor", device.SHOW_LINE_1) - if err != nil { - p.bus.Close() - return nil, err - } + err = p.lcd.ShowMessage("Fermentor", device.SHOW_LINE_1) + if err != nil { + p.bus.Close() + return nil, err + } + + err = p.lcd.ShowMessage("Initializing", device.SHOW_LINE_2|device.SHOW_BLANK_PADDING) + if err != nil { + p.bus.Close() + return nil, err + } - err = p.lcd.ShowMessage("Initializing", device.SHOW_LINE_2|device.SHOW_BLANK_PADDING) - if err != nil { - p.bus.Close() - return nil, err - } - */ return p, nil }