1
0
Fork 0
mirror of https://github.com/shouptech/tempgopher.git synced 2026-02-03 08:39:43 +00:00

Backend for selectively disabling heating/cooling

This commit is contained in:
Emma 2018-10-19 14:41:44 -06:00
parent 64ca5a3bfd
commit 0bd6c9bf73
3 changed files with 79 additions and 50 deletions

21
cli.go
View file

@ -8,7 +8,6 @@ import (
"strings" "strings"
"github.com/howeyc/gopass" "github.com/howeyc/gopass"
"github.com/yryz/ds18b20" "github.com/yryz/ds18b20"
) )
@ -101,6 +100,14 @@ func PromptForConfiguration() Config {
panic("Alias cannot be blank") panic("Alias cannot be blank")
} }
fmt.Print("Disable cooling? [false]: ")
s.CoolDisable, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
}
if !s.CoolDisable {
fmt.Print("High temperature: ") fmt.Print("High temperature: ")
s.HighTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64) s.HighTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil { if err != nil {
@ -125,6 +132,15 @@ func PromptForConfiguration() Config {
if err != nil { if err != nil {
panic(err) panic(err)
} }
}
fmt.Print("Disable heating? [false]: ")
s.HeatDisable, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
}
if !s.HeatDisable {
fmt.Print("Low temperature: ") fmt.Print("Low temperature: ")
s.LowTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64) s.LowTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
@ -139,7 +155,7 @@ func PromptForConfiguration() Config {
} }
fmt.Print("Heating GPIO: ") fmt.Print("Heating GPIO: ")
resp, err = strconv.ParseInt(ReadInput(reader, ""), 10, 32) resp, err := strconv.ParseInt(ReadInput(reader, ""), 10, 32)
s.HeatGPIO = int32(resp) s.HeatGPIO = int32(resp)
if err != nil { if err != nil {
panic(err) panic(err)
@ -150,6 +166,7 @@ func PromptForConfiguration() Config {
if err != nil { if err != nil {
panic(err) panic(err)
} }
}
fmt.Print("Enable verbose logging [false]: ") fmt.Print("Enable verbose logging [false]: ")
s.Verbose, err = strconv.ParseBool(ReadInput(reader, "false")) s.Verbose, err = strconv.ParseBool(ReadInput(reader, "false"))

View file

@ -27,9 +27,11 @@ type Sensor struct {
Alias string `json:"alias" yaml:"alias"` Alias string `json:"alias" yaml:"alias"`
HighTemp float64 `json:"hightemp" yaml:"hightemp"` HighTemp float64 `json:"hightemp" yaml:"hightemp"`
LowTemp float64 `json:"lowtemp" yaml:"lowtemp"` LowTemp float64 `json:"lowtemp" yaml:"lowtemp"`
HeatDisable bool `json:"heatdisable" yaml:"heatdisable"`
HeatGPIO int32 `json:"heatgpio" yaml:"heatgpio"` HeatGPIO int32 `json:"heatgpio" yaml:"heatgpio"`
HeatInvert bool `json:"heatinvert" yaml:"heatinvert"` HeatInvert bool `json:"heatinvert" yaml:"heatinvert"`
HeatMinutes float64 `json:"heatminutes" yaml:"heatminutes"` HeatMinutes float64 `json:"heatminutes" yaml:"heatminutes"`
CoolDisable bool `json:"cooldisable" yaml:"cooldisable"`
CoolGPIO int32 `json:"coolgpio" yaml:"coolgpio"` CoolGPIO int32 `json:"coolgpio" yaml:"coolgpio"`
CoolInvert bool `json:"coolinvert" yaml:"coolinvert"` CoolInvert bool `json:"coolinvert" yaml:"coolinvert"`
CoolMinutes float64 `json:"coolminutes" yaml:"coolminutes"` CoolMinutes float64 `json:"coolminutes" yaml:"coolminutes"`

View file

@ -70,11 +70,18 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
state.When = time.Now() state.When = time.Now()
var cpin rpio.Pin
var hpin rpio.Pin
// Initialize the pins // Initialize the pins
cpin := rpio.Pin(sensor.CoolGPIO) if !sensor.CoolDisable {
cpin = rpio.Pin(sensor.CoolGPIO)
cpin.Output() cpin.Output()
hpin := rpio.Pin(sensor.HeatGPIO) }
if !sensor.HeatDisable {
hpin = rpio.Pin(sensor.HeatGPIO)
hpin.Output() hpin.Output()
}
// Calculate duration // Calculate duration
duration := time.Since(state.Changed).Minutes() duration := time.Since(state.Changed).Minutes()
@ -83,14 +90,14 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
case temp > sensor.HighTemp && temp < sensor.LowTemp: case temp > sensor.HighTemp && temp < sensor.LowTemp:
log.Println("Invalid state! Temperature is too high AND too low!") log.Println("Invalid state! Temperature is too high AND too low!")
// Temperature too high, start cooling // Temperature too high, start cooling
case temp > sensor.HighTemp: case temp > sensor.HighTemp && !sensor.CoolDisable:
PinSwitch(cpin, true, sensor.CoolInvert) PinSwitch(cpin, true, sensor.CoolInvert)
state.Cooling = true state.Cooling = true
PinSwitch(hpin, false, sensor.HeatInvert) // Ensure the heater is off PinSwitch(hpin, false, sensor.HeatInvert) // Ensure the heater is off
state.Heating = false state.Heating = false
state.Changed = future state.Changed = future
// Temperature too low, start heating // Temperature too low, start heating
case temp < sensor.LowTemp: case temp < sensor.LowTemp && !sensor.HeatDisable:
PinSwitch(hpin, true, sensor.HeatInvert) PinSwitch(hpin, true, sensor.HeatInvert)
state.Heating = true state.Heating = true
PinSwitch(cpin, false, sensor.CoolInvert) // Ensure the chiller is off PinSwitch(cpin, false, sensor.CoolInvert) // Ensure the chiller is off
@ -126,14 +133,17 @@ func ProcessSensor(sensor Sensor, state State) (State, error) {
// TurnOffSensor turns off all switches for an individual sensor // TurnOffSensor turns off all switches for an individual sensor
func TurnOffSensor(sensor Sensor) { func TurnOffSensor(sensor Sensor) {
if !sensor.CoolDisable {
cpin := rpio.Pin(sensor.CoolGPIO) cpin := rpio.Pin(sensor.CoolGPIO)
cpin.Output() cpin.Output()
PinSwitch(cpin, false, sensor.CoolInvert) PinSwitch(cpin, false, sensor.CoolInvert)
}
if !sensor.HeatDisable {
hpin := rpio.Pin(sensor.HeatGPIO) hpin := rpio.Pin(sensor.HeatGPIO)
hpin.Output() hpin.Output()
PinSwitch(hpin, false, sensor.HeatInvert) PinSwitch(hpin, false, sensor.HeatInvert)
} }
}
// TurnOffSensors turns off all sensors defined in the config // TurnOffSensors turns off all sensors defined in the config
func TurnOffSensors(config Config) { func TurnOffSensors(config Config) {