1
0
Fork 0
mirror of https://github.com/shouptech/tempgopher.git synced 2026-02-03 16:49:42 +00:00

Skeleton for web frontend

This commit is contained in:
Emma 2018-09-30 09:00:20 -06:00
parent 3e302c20f9
commit a86c3dc3b9
3 changed files with 38 additions and 1 deletions

10
main.go
View file

@ -36,6 +36,9 @@ func main() {
// run is tracking whether or not the thermostats should run // run is tracking whether or not the thermostats should run
run := true run := true
// done is used to signal the web frontend to stop
done := make(chan bool)
sig := make(chan os.Signal) sig := make(chan os.Signal)
signal.Notify(sig, os.Interrupt, syscall.SIGTERM) signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
signal.Notify(sig, os.Interrupt, syscall.SIGINT) signal.Notify(sig, os.Interrupt, syscall.SIGINT)
@ -43,6 +46,7 @@ func main() {
go func() { go func() {
<-sig <-sig
run = false run = false
done <- true
}() }()
sc := make(chan State) sc := make(chan State)
@ -53,6 +57,12 @@ func main() {
wg.Add(1) wg.Add(1)
go RunThermostat(sensor, sc, &run, &wg) go RunThermostat(sensor, sc, &run, &wg)
} }
// Launch the web frontend
wg.Add(1)
RunWeb(sc, done, &wg)
// Wait for all threads to stop
wg.Wait() wg.Wait()
// Close the GPIO access // Close the GPIO access

8
run.go
View file

@ -107,7 +107,13 @@ func RunThermostat(sensor Sensor, sc chan<- State, run *bool, wg *sync.WaitGroup
s.Temp = t s.Temp = t
log.Printf("%s Temp: %.2f, Cooling: %t, Heating: %t, Duration: %.1f", sensor.Alias, s.Temp, s.Cooling, s.Heating, min) log.Printf("%s Temp: %.2f, Cooling: %t, Heating: %t, Duration: %.1f", sensor.Alias, s.Temp, s.Cooling, s.Heating, min)
sc <- s
select {
case sc <- s:
break
default:
break
}
} }
PinSwitch(cpin, false, sensor.CoolInvert) PinSwitch(cpin, false, sensor.CoolInvert)

21
web.go Normal file
View file

@ -0,0 +1,21 @@
package main
import (
"sync"
)
// RunWeb launches a web server
func RunWeb(sc <-chan State, done <-chan bool, wg *sync.WaitGroup) {
states := make(map[string]State)
go func() {
for {
s := <-sc
states[s.ID] = s
}
}()
<-done
wg.Done()
}