Enable I2C display
Some checks reported errors
continuous-integration/drone/push Build encountered an error

This commit is contained in:
Søren Rasmussen 2024-06-15 16:26:28 +02:00
parent 9419a70c70
commit e142662cc8
4 changed files with 27 additions and 20 deletions

View file

@ -24,8 +24,10 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
hub := sentry.CurrentHub().Clone() hub := sentry.CurrentHub().Clone()
defer hub.Flush(10 * time.Second) defer hub.Flush(10 * time.Second)
config := configuration.Global()
// Display // Display
display, err := lcd.NewLCD() display, err := lcd.NewLCD(config.I2C.Bus)
if err != nil { if err != nil {
hub.CaptureException(err) hub.CaptureException(err)
log.Fatal(err) log.Fatal(err)
@ -33,7 +35,6 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
defer display.Close() defer display.Close()
// Controller // Controller
config := configuration.Global()
ctrl := controllers.NewChamberController(config) ctrl := controllers.NewChamberController(config)
chConfigChange := make(chan configuration.Configuration, 1) 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: case reading := <-temperature.Reading:
ctrl.SetTemperature(reading) ctrl.SetTemperature(reading)
ingest.AddReading(reading) ingest.AddReading(reading)
//display.SetTemperature(reading) display.SetTemperature(reading)
case <-temperature.RequestReset: case <-temperature.RequestReset:
log.Print("Powering down one wire bus for 20 seconds") 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") ingest.AddEvent("ONEWIRE_RESET")
case <-oneWirePowerUpChannel: case <-oneWirePowerUpChannel:
log.Print("Powering up one wire bus") log.Print("Powering up OneWire bus")
gpio.StartOneWirePower() gpio.StartOneWirePower()
case ev := <-gpio.C: case ev := <-gpio.C:
@ -110,7 +111,7 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream) {
case state := <-ctrl.C: case state := <-ctrl.C:
gpioSetState(state, gpio, config) gpioSetState(state, gpio, config)
ingest.AddState(state) ingest.AddState(state)
//display.SetState(state) display.SetState(state)
case c := <-chConfigChange: case c := <-chConfigChange:
config = c config = c

View file

@ -29,6 +29,10 @@ type Configuration struct {
Weight float64 `mapstructure:"weight"` Weight float64 `mapstructure:"weight"`
} `mapstructure:"sensors"` } `mapstructure:"sensors"`
I2C struct {
Bus int `mapstructure:"bus"`
} `mapstructure:"i2c"`
FermentationTemperature float64 `mapstructure:"fermentation_temp"` FermentationTemperature float64 `mapstructure:"fermentation_temp"`
DeltaTemperatureCool float64 `mapstructure:"delta_temp_cool"` DeltaTemperatureCool float64 `mapstructure:"delta_temp_cool"`
DeltaTemperatureHeat float64 `mapstructure:"delta_temp_heat"` DeltaTemperatureHeat float64 `mapstructure:"delta_temp_heat"`

View file

@ -26,6 +26,9 @@ chamber = ""
ambient = "" ambient = ""
weight = 0.8 weight = 0.8
[i2c]
bus = 0
[limits] [limits]
min_chamber_temp = 0.0 min_chamber_temp = 0.0
max_chamber_temp = 25 max_chamber_temp = 25

View file

@ -28,7 +28,7 @@ type LCD struct {
hub *sentry.Hub hub *sentry.Hub
} }
func NewLCD() (*LCD, error) { func NewLCD(bus int) (*LCD, error) {
var err error var err error
p := &LCD{ p := &LCD{
@ -39,7 +39,7 @@ func NewLCD() (*LCD, error) {
hub: sentry.CurrentHub().Clone(), hub: sentry.CurrentHub().Clone(),
} }
p.bus, err = i2c.NewI2C(0x27, 0) p.bus, err = i2c.NewI2C(0x27, bus)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -50,13 +50,12 @@ func NewLCD() (*LCD, error) {
return nil, err return nil, err
} }
err = p.lcd.BacklightOff() err = p.lcd.BacklightOn()
if err != nil { if err != nil {
p.bus.Close() p.bus.Close()
return nil, err return nil, err
} }
/*
err = p.lcd.ShowMessage("Fermentor", device.SHOW_LINE_1) err = p.lcd.ShowMessage("Fermentor", device.SHOW_LINE_1)
if err != nil { if err != nil {
p.bus.Close() p.bus.Close()
@ -68,7 +67,7 @@ func NewLCD() (*LCD, error) {
p.bus.Close() p.bus.Close()
return nil, err return nil, err
} }
*/
return p, nil return p, nil
} }