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()
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

View file

@ -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"`

View file

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

View file

@ -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
}