diff --git a/cmd/fermentord/gpio.go b/cmd/fermentord/gpio.go index 94e7b10..0d88e91 100644 --- a/cmd/fermentord/gpio.go +++ b/cmd/fermentord/gpio.go @@ -3,12 +3,13 @@ package main import ( "log" + "git.joco.dk/sng/fermentord/internal/configuration" "git.joco.dk/sng/fermentord/internal/controllers" "git.joco.dk/sng/fermentord/internal/hw" "git.joco.dk/sng/fermentord/internal/metrics" ) -func gpioSetState(state controllers.ChamberState, gpio *hw.Gpio) { +func gpioSetState(state controllers.ChamberState, gpio *hw.Gpio, config *configuration.Configuration) { switch state { case controllers.ChamberStateIdle: log.Printf("Setting chamber state idle") @@ -20,12 +21,16 @@ func gpioSetState(state controllers.ChamberState, gpio *hw.Gpio) { log.Printf("Setting chamber state cooling") metrics.State.Set(metrics.MetricStateCooling) gpio.StopHeater() - gpio.StartCooler() + if config.CoolerEnabled { + gpio.StartCooler() + } case controllers.ChamberStateHeating: log.Printf("Setting chamber state heating") metrics.State.Set(metrics.MetricStateHeating) gpio.StopCooler() - gpio.StartHeater() + if config.HeaterEnabled { + gpio.StartHeater() + } } } diff --git a/cmd/fermentord/loop.go b/cmd/fermentord/loop.go index 2ee1397..d874f80 100644 --- a/cmd/fermentord/loop.go +++ b/cmd/fermentord/loop.go @@ -111,7 +111,7 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config } case state := <-ctrl.C: - gpioSetState(state, gpio) + gpioSetState(state, gpio, config) ingest.AddState(state) display.SetState(state) diff --git a/internal/configuration/config.go b/internal/configuration/config.go index 22981dd..20e9b83 100644 --- a/internal/configuration/config.go +++ b/internal/configuration/config.go @@ -31,10 +31,11 @@ type Configuration struct { Weight float64 `mapstructure:"weight"` } `mapstructure:"sensors"` - FermentationTemperature float64 `mapstructure:"fermentation_temp"` - DeltaTemperatureCool float64 `mapstructure:"delta_temp_cool"` - DeltaTemperatureHeat float64 `mapstructure:"delta_temp_heat"` - HeaterDutyCycle time.Duration `mapstructure:"heater_duty_cycle"` + FermentationTemperature float64 `mapstructure:"fermentation_temp"` + DeltaTemperatureCool float64 `mapstructure:"delta_temp_cool"` + DeltaTemperatureHeat float64 `mapstructure:"delta_temp_heat"` + HeaterEnabled bool `mapstructure:"heater_enabled"` + CoolerEnabled bool `mapstructure:"cooler_enabled"` Limits struct { MinChamberTemperature float64 `mapstructure:"min_chamber_temp"` @@ -56,7 +57,8 @@ func LoadConfiguration() *Configuration { hub := sentry.CurrentHub().Clone() defer hub.Flush(10 * time.Second) - viper.SetDefault("heater_duty_cycle", 1*time.Second) + viper.SetDefault("cooler_enabled", true) + viper.SetDefault("heater_enabled", true) viper.SetDefault("http.port", 8000) viper.SetDefault("nats.stream", "DWJONDAHL") viper.SetDefault("nats.subject.event", "DWJONDAHL.ingest.fermentor.ingest_event")