79 lines
2.9 KiB
Go
79 lines
2.9 KiB
Go
package configuration
|
|
|
|
import (
|
|
"github.com/gofrs/uuid"
|
|
"github.com/spf13/viper"
|
|
)
|
|
|
|
type Configuration struct {
|
|
Brew struct {
|
|
UUID uuid.UUID `mapstructure:"uuid"`
|
|
} `mapstructure:"brew"`
|
|
|
|
NATS struct {
|
|
Servers []string `mapstructure:"servers"`
|
|
Username string `mapstructure:"username"`
|
|
Password string `mapstructure:"password"`
|
|
Stream string `mapstructure:"stream"`
|
|
Subject struct {
|
|
Event string `mapstructure:"event"`
|
|
State string `mapstructure:"state"`
|
|
Temp string `mapstructure:"temp"`
|
|
Tilt string `mapstructure:"tilt"`
|
|
} `mapstructure:"subject"`
|
|
} `mapstructure:"nats"`
|
|
|
|
HTTP struct {
|
|
Port int16 `mapstructure:"port"`
|
|
} `mapstructure:"http"`
|
|
|
|
Sensors struct {
|
|
Wort string `mapstructure:"wort"`
|
|
Chamber string `mapstructure:"chamber"`
|
|
Ambient string `mapstructure:"ambient"`
|
|
Weight float64 `mapstructure:"weight"`
|
|
} `mapstructure:"sensors"`
|
|
|
|
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"`
|
|
MaxChamberTemperature float64 `mapstructure:"max_chamber_temp"`
|
|
MinCoolerRuntimeSecs float64 `mapstructure:"min_cooler_runtime_secs"`
|
|
MaxCoolerRuntimeSecs float64 `mapstructure:"max_cooler_runtime_secs"`
|
|
MinCoolerCooldownSecs float64 `mapstructure:"min_cooler_cooldown_secs"`
|
|
HeaterGraceTimeSecs float64 `mapstructure:"heater_grace_time_secs"`
|
|
} `mapstructure:"limits"`
|
|
|
|
PID struct {
|
|
Kp float64 `mapstructure:"kp"` // 2.0
|
|
Ki float64 `mapstructure:"ki"` // 0.0001
|
|
Kd float64 `mapstructure:"kd"` // 2.0
|
|
} `mapstructure:"pid"`
|
|
}
|
|
|
|
func setDefaults() {
|
|
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")
|
|
viper.SetDefault("nats.subject.state", "DWJONDAHL.ingest.fermentor.ingest_state")
|
|
viper.SetDefault("nats.subject.temp", "DWJONDAHL.ingest.fermentor.ingest_temperature_reading")
|
|
viper.SetDefault("nats.subject.tilt", "DWJONDAHL.ingest.fermentor.ingest_tilt_reading")
|
|
viper.SetDefault("nats.url", "nats.service.consul")
|
|
viper.SetDefault("pid.kd", 2.0)
|
|
viper.SetDefault("pid.ki", 0.0001)
|
|
viper.SetDefault("pid.kp", 2.0)
|
|
viper.SetDefault("limits.heater_grace_time_secs", 1800)
|
|
viper.SetDefault("limits.max_chamber_temp", 40)
|
|
viper.SetDefault("limits.max_cooler_runtime_secs", 86400)
|
|
viper.SetDefault("limits.min_chamber_temp", 5)
|
|
viper.SetDefault("limits.min_cooler_cooldown_secs", 300)
|
|
viper.SetDefault("limits.min_cooler_runtime_secs", 300)
|
|
viper.SetDefault("sensors.weight", 0.8)
|
|
}
|