mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 16:49:42 +00:00
Commit current stuff, though it doesn't work
This commit is contained in:
parent
18fb4bad6d
commit
6363f53257
4 changed files with 38 additions and 30 deletions
|
|
@ -13,10 +13,10 @@ type Sensor struct {
|
||||||
HighTemp float64 `yaml:"hightemp"`
|
HighTemp float64 `yaml:"hightemp"`
|
||||||
LowTemp float64 `yaml:"lowtemp"`
|
LowTemp float64 `yaml:"lowtemp"`
|
||||||
HeatGPIO int32 `yaml:"heatgpio"`
|
HeatGPIO int32 `yaml:"heatgpio"`
|
||||||
HeatPullup bool `yaml:"heatpullup"`
|
HeatInvert bool `yaml:"heatinvert"`
|
||||||
HeatMinutes float64 `yaml:"heatminutes"`
|
HeatMinutes float64 `yaml:"heatminutes"`
|
||||||
CoolGPIO int32 `yaml:"coolgpio"`
|
CoolGPIO int32 `yaml:"coolgpio"`
|
||||||
CoolPullup bool `yaml:"coolpullup"`
|
CoolInvert bool `yaml:"coolinvert"`
|
||||||
CoolMinutes float64 `yaml:"coolminutes"`
|
CoolMinutes float64 `yaml:"coolminutes"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -13,10 +13,10 @@ func Test_LoadConfig(t *testing.T) {
|
||||||
HighTemp: 8,
|
HighTemp: 8,
|
||||||
LowTemp: 4,
|
LowTemp: 4,
|
||||||
HeatGPIO: 5,
|
HeatGPIO: 5,
|
||||||
HeatPullup: true,
|
HeatInvert: true,
|
||||||
HeatMinutes: 5,
|
HeatMinutes: 5,
|
||||||
CoolGPIO: 17,
|
CoolGPIO: 17,
|
||||||
CoolPullup: false,
|
CoolInvert: false,
|
||||||
CoolMinutes: 10}
|
CoolMinutes: 10}
|
||||||
|
|
||||||
testConfig := Config{Sensors: []Sensor{testSensor}}
|
testConfig := Config{Sensors: []Sensor{testSensor}}
|
||||||
|
|
|
||||||
56
run.go
56
run.go
|
|
@ -35,28 +35,28 @@ func ReadTemperature(id string) (float64, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetPinState is used to turn a pin on or off.
|
// SetPinState is used to turn a pin on or off.
|
||||||
// If pullup is true, the pin will be pulled up when turned on, and pulled down when turned off.
|
// If invert is false, the pin will be high turned on, and low when turned off.
|
||||||
func SetPinState(pin rpio.Pin, on bool, pullup bool) {
|
func SetPinState(pin rpio.Pin, on bool, invert bool) {
|
||||||
switch {
|
switch {
|
||||||
case on && pullup:
|
case on && !invert:
|
||||||
pin.PullUp()
|
pin.High()
|
||||||
case on && !pullup:
|
case on && invert:
|
||||||
pin.PullDown()
|
pin.Low()
|
||||||
case !on && !pullup:
|
case !on && invert:
|
||||||
pin.PullUp()
|
pin.High()
|
||||||
default:
|
default:
|
||||||
pin.PullDown()
|
pin.Low()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetPinState will return true if the pin is on.
|
// GetPinState will return true if the pin is on.
|
||||||
// If pullup is true, the pin will be on when pulled up.
|
// If invert is false, the pin will be on when high.
|
||||||
func GetPinState(pin rpio.Pin, pullup bool) bool {
|
func GetPinState(pin rpio.Pin, invert bool) bool {
|
||||||
switch pin.Read() {
|
switch pin.Read() {
|
||||||
case rpio.High:
|
case rpio.High:
|
||||||
return pullup
|
return !invert
|
||||||
default:
|
default:
|
||||||
return !pullup
|
return invert
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -82,26 +82,34 @@ func RunThermostat(sensor Sensor) {
|
||||||
switch {
|
switch {
|
||||||
case t > sensor.HighTemp && t < sensor.HighTemp:
|
case t > sensor.HighTemp && t < sensor.HighTemp:
|
||||||
log.Panic("Invalid state! Temperature is too high AND too low!")
|
log.Panic("Invalid state! Temperature is too high AND too low!")
|
||||||
case t > sensor.HighTemp && GetPinState(hpin, sensor.HeatPullup):
|
case t > sensor.HighTemp && GetPinState(hpin, sensor.HeatInvert):
|
||||||
SetPinState(hpin, false, sensor.HeatPullup)
|
SetPinState(hpin, false, sensor.HeatInvert)
|
||||||
|
log.Printf("%s Turned off heat", sensor.Alias)
|
||||||
|
s.Changed = time.Now()
|
||||||
case t > sensor.HighTemp && min > sensor.CoolMinutes:
|
case t > sensor.HighTemp && min > sensor.CoolMinutes:
|
||||||
SetPinState(cpin, true, sensor.CoolPullup)
|
SetPinState(cpin, true, sensor.CoolInvert)
|
||||||
|
log.Printf("%s Turned on cool", sensor.Alias)
|
||||||
|
s.Changed = time.Now()
|
||||||
case t > sensor.HighTemp:
|
case t > sensor.HighTemp:
|
||||||
break
|
break
|
||||||
case t < sensor.LowTemp && GetPinState(cpin, sensor.CoolPullup):
|
case t < sensor.LowTemp && GetPinState(cpin, sensor.CoolInvert):
|
||||||
SetPinState(cpin, false, sensor.CoolPullup)
|
SetPinState(cpin, false, sensor.CoolInvert)
|
||||||
|
log.Printf("%s Turned off cool", sensor.Alias)
|
||||||
|
s.Changed = time.Now()
|
||||||
case t < sensor.LowTemp && min > sensor.HeatMinutes:
|
case t < sensor.LowTemp && min > sensor.HeatMinutes:
|
||||||
SetPinState(hpin, true, sensor.HeatPullup)
|
SetPinState(hpin, true, sensor.HeatInvert)
|
||||||
|
log.Printf("%s Turned on heat", sensor.Alias)
|
||||||
|
s.Changed = time.Now()
|
||||||
case t < sensor.LowTemp:
|
case t < sensor.LowTemp:
|
||||||
break
|
break
|
||||||
default: // Turn off both switches
|
default: // Turn off both switches
|
||||||
SetPinState(cpin, false, sensor.CoolPullup)
|
SetPinState(cpin, false, sensor.CoolInvert)
|
||||||
SetPinState(hpin, false, sensor.HeatPullup)
|
SetPinState(hpin, false, sensor.HeatInvert)
|
||||||
}
|
}
|
||||||
|
|
||||||
s.Temp = t
|
s.Temp = t
|
||||||
s.Cooling = GetPinState(cpin, sensor.CoolPullup)
|
//s.Cooling = GetPinState(cpin, sensor.CoolInvert)
|
||||||
s.Heating = GetPinState(hpin, sensor.HeatPullup)
|
//s.Heating = GetPinState(hpin, sensor.HeatInvert)
|
||||||
log.Printf("Temp: %.2f, Cooling: %t, Heating: %t, Changed: %s", s.Temp, s.Cooling, s.Heating, s.Changed)
|
log.Printf("%s Temp: %.2f, Cooling: %t, Heating: %t, Duration: %.1f", sensor.Alias, s.Temp, s.Cooling, s.Heating, min)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,8 +4,8 @@ sensors:
|
||||||
hightemp: 8
|
hightemp: 8
|
||||||
lowtemp: 4
|
lowtemp: 4
|
||||||
heatgpio: 5
|
heatgpio: 5
|
||||||
heatpullup: true
|
heatinvert: true
|
||||||
heatminutes: 5
|
heatminutes: 5
|
||||||
coolgpio: 17
|
coolgpio: 17
|
||||||
coolpullup: false
|
coolinvert: false
|
||||||
coolminutes: 10
|
coolminutes: 10
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue