Add configuration options to disable heater/cooler

This commit is contained in:
Søren Rasmussen 2022-07-24 08:17:04 +02:00
parent 5b3f7708c0
commit d873538b70
3 changed files with 16 additions and 9 deletions

View file

@ -3,12 +3,13 @@ package main
import ( import (
"log" "log"
"git.joco.dk/sng/fermentord/internal/configuration"
"git.joco.dk/sng/fermentord/internal/controllers" "git.joco.dk/sng/fermentord/internal/controllers"
"git.joco.dk/sng/fermentord/internal/hw" "git.joco.dk/sng/fermentord/internal/hw"
"git.joco.dk/sng/fermentord/internal/metrics" "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 { switch state {
case controllers.ChamberStateIdle: case controllers.ChamberStateIdle:
log.Printf("Setting chamber state idle") log.Printf("Setting chamber state idle")
@ -20,12 +21,16 @@ func gpioSetState(state controllers.ChamberState, gpio *hw.Gpio) {
log.Printf("Setting chamber state cooling") log.Printf("Setting chamber state cooling")
metrics.State.Set(metrics.MetricStateCooling) metrics.State.Set(metrics.MetricStateCooling)
gpio.StopHeater() gpio.StopHeater()
if config.CoolerEnabled {
gpio.StartCooler() gpio.StartCooler()
}
case controllers.ChamberStateHeating: case controllers.ChamberStateHeating:
log.Printf("Setting chamber state heating") log.Printf("Setting chamber state heating")
metrics.State.Set(metrics.MetricStateHeating) metrics.State.Set(metrics.MetricStateHeating)
gpio.StopCooler() gpio.StopCooler()
if config.HeaterEnabled {
gpio.StartHeater() gpio.StartHeater()
} }
}
} }

View file

@ -111,7 +111,7 @@ func mainLoop(ctx context.Context, wg *sync.WaitGroup, js nats.JetStream, config
} }
case state := <-ctrl.C: case state := <-ctrl.C:
gpioSetState(state, gpio) gpioSetState(state, gpio, config)
ingest.AddState(state) ingest.AddState(state)
display.SetState(state) display.SetState(state)

View file

@ -34,7 +34,8 @@ type Configuration struct {
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"`
HeaterDutyCycle time.Duration `mapstructure:"heater_duty_cycle"` HeaterEnabled bool `mapstructure:"heater_enabled"`
CoolerEnabled bool `mapstructure:"cooler_enabled"`
Limits struct { Limits struct {
MinChamberTemperature float64 `mapstructure:"min_chamber_temp"` MinChamberTemperature float64 `mapstructure:"min_chamber_temp"`
@ -56,7 +57,8 @@ func LoadConfiguration() *Configuration {
hub := sentry.CurrentHub().Clone() hub := sentry.CurrentHub().Clone()
defer hub.Flush(10 * time.Second) 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("http.port", 8000)
viper.SetDefault("nats.stream", "DWJONDAHL") viper.SetDefault("nats.stream", "DWJONDAHL")
viper.SetDefault("nats.subject.event", "DWJONDAHL.ingest.fermentor.ingest_event") viper.SetDefault("nats.subject.event", "DWJONDAHL.ingest.fermentor.ingest_event")