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

91
cli.go
View file

@ -8,7 +8,6 @@ import (
"strings"
"github.com/howeyc/gopass"
"github.com/yryz/ds18b20"
)
@ -101,54 +100,72 @@ func PromptForConfiguration() Config {
panic("Alias cannot be blank")
}
fmt.Print("High temperature: ")
s.HighTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
fmt.Print("Disable cooling? [false]: ")
s.CoolDisable, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
}
fmt.Print("Cooling minutes: ")
s.CoolMinutes, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if !s.CoolDisable {
fmt.Print("High temperature: ")
s.HighTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil {
panic(err)
}
fmt.Print("Cooling minutes: ")
s.CoolMinutes, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil {
panic(err)
}
fmt.Print("Cooling GPIO: ")
resp, err := strconv.ParseInt(ReadInput(reader, ""), 10, 32)
s.CoolGPIO = int32(resp)
if err != nil {
panic(err)
}
fmt.Print("Invert cooling switch [false]: ")
s.CoolInvert, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
}
}
fmt.Print("Disable heating? [false]: ")
s.HeatDisable, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
}
fmt.Print("Cooling GPIO: ")
resp, err := strconv.ParseInt(ReadInput(reader, ""), 10, 32)
s.CoolGPIO = int32(resp)
if err != nil {
panic(err)
}
if !s.HeatDisable {
fmt.Print("Invert cooling switch [false]: ")
s.CoolInvert, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
}
fmt.Print("Low temperature: ")
s.LowTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil {
panic(err)
}
fmt.Print("Low temperature: ")
s.LowTemp, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil {
panic(err)
}
fmt.Print("Heating minutes: ")
s.HeatMinutes, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil {
panic(err)
}
fmt.Print("Heating minutes: ")
s.HeatMinutes, err = strconv.ParseFloat(ReadInput(reader, ""), 64)
if err != nil {
panic(err)
}
fmt.Print("Heating GPIO: ")
resp, err := strconv.ParseInt(ReadInput(reader, ""), 10, 32)
s.HeatGPIO = int32(resp)
if err != nil {
panic(err)
}
fmt.Print("Heating GPIO: ")
resp, err = strconv.ParseInt(ReadInput(reader, ""), 10, 32)
s.HeatGPIO = int32(resp)
if err != nil {
panic(err)
}
fmt.Print("Invert heating switch [false]: ")
s.HeatInvert, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
fmt.Print("Invert heating switch [false]: ")
s.HeatInvert, err = strconv.ParseBool(ReadInput(reader, "false"))
if err != nil {
panic(err)
}
}
fmt.Print("Enable verbose logging [false]: ")

View file

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

View file

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