mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 08:39:43 +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"`
|
||||
LowTemp float64 `yaml:"lowtemp"`
|
||||
HeatGPIO int32 `yaml:"heatgpio"`
|
||||
HeatPullup bool `yaml:"heatpullup"`
|
||||
HeatInvert bool `yaml:"heatinvert"`
|
||||
HeatMinutes float64 `yaml:"heatminutes"`
|
||||
CoolGPIO int32 `yaml:"coolgpio"`
|
||||
CoolPullup bool `yaml:"coolpullup"`
|
||||
CoolInvert bool `yaml:"coolinvert"`
|
||||
CoolMinutes float64 `yaml:"coolminutes"`
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -13,10 +13,10 @@ func Test_LoadConfig(t *testing.T) {
|
|||
HighTemp: 8,
|
||||
LowTemp: 4,
|
||||
HeatGPIO: 5,
|
||||
HeatPullup: true,
|
||||
HeatInvert: true,
|
||||
HeatMinutes: 5,
|
||||
CoolGPIO: 17,
|
||||
CoolPullup: false,
|
||||
CoolInvert: false,
|
||||
CoolMinutes: 10}
|
||||
|
||||
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.
|
||||
// If pullup is true, the pin will be pulled up when turned on, and pulled down when turned off.
|
||||
func SetPinState(pin rpio.Pin, on bool, pullup bool) {
|
||||
// If invert is false, the pin will be high turned on, and low when turned off.
|
||||
func SetPinState(pin rpio.Pin, on bool, invert bool) {
|
||||
switch {
|
||||
case on && pullup:
|
||||
pin.PullUp()
|
||||
case on && !pullup:
|
||||
pin.PullDown()
|
||||
case !on && !pullup:
|
||||
pin.PullUp()
|
||||
case on && !invert:
|
||||
pin.High()
|
||||
case on && invert:
|
||||
pin.Low()
|
||||
case !on && invert:
|
||||
pin.High()
|
||||
default:
|
||||
pin.PullDown()
|
||||
pin.Low()
|
||||
}
|
||||
}
|
||||
|
||||
// GetPinState will return true if the pin is on.
|
||||
// If pullup is true, the pin will be on when pulled up.
|
||||
func GetPinState(pin rpio.Pin, pullup bool) bool {
|
||||
// If invert is false, the pin will be on when high.
|
||||
func GetPinState(pin rpio.Pin, invert bool) bool {
|
||||
switch pin.Read() {
|
||||
case rpio.High:
|
||||
return pullup
|
||||
return !invert
|
||||
default:
|
||||
return !pullup
|
||||
return invert
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -82,26 +82,34 @@ func RunThermostat(sensor Sensor) {
|
|||
switch {
|
||||
case t > sensor.HighTemp && t < sensor.HighTemp:
|
||||
log.Panic("Invalid state! Temperature is too high AND too low!")
|
||||
case t > sensor.HighTemp && GetPinState(hpin, sensor.HeatPullup):
|
||||
SetPinState(hpin, false, sensor.HeatPullup)
|
||||
case t > sensor.HighTemp && GetPinState(hpin, sensor.HeatInvert):
|
||||
SetPinState(hpin, false, sensor.HeatInvert)
|
||||
log.Printf("%s Turned off heat", sensor.Alias)
|
||||
s.Changed = time.Now()
|
||||
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:
|
||||
break
|
||||
case t < sensor.LowTemp && GetPinState(cpin, sensor.CoolPullup):
|
||||
SetPinState(cpin, false, sensor.CoolPullup)
|
||||
case t < sensor.LowTemp && GetPinState(cpin, sensor.CoolInvert):
|
||||
SetPinState(cpin, false, sensor.CoolInvert)
|
||||
log.Printf("%s Turned off cool", sensor.Alias)
|
||||
s.Changed = time.Now()
|
||||
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:
|
||||
break
|
||||
default: // Turn off both switches
|
||||
SetPinState(cpin, false, sensor.CoolPullup)
|
||||
SetPinState(hpin, false, sensor.HeatPullup)
|
||||
SetPinState(cpin, false, sensor.CoolInvert)
|
||||
SetPinState(hpin, false, sensor.HeatInvert)
|
||||
}
|
||||
|
||||
s.Temp = t
|
||||
s.Cooling = GetPinState(cpin, sensor.CoolPullup)
|
||||
s.Heating = GetPinState(hpin, sensor.HeatPullup)
|
||||
log.Printf("Temp: %.2f, Cooling: %t, Heating: %t, Changed: %s", s.Temp, s.Cooling, s.Heating, s.Changed)
|
||||
//s.Cooling = GetPinState(cpin, sensor.CoolInvert)
|
||||
//s.Heating = GetPinState(hpin, sensor.HeatInvert)
|
||||
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
|
||||
lowtemp: 4
|
||||
heatgpio: 5
|
||||
heatpullup: true
|
||||
heatinvert: true
|
||||
heatminutes: 5
|
||||
coolgpio: 17
|
||||
coolpullup: false
|
||||
coolinvert: false
|
||||
coolminutes: 10
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue