mirror of
https://github.com/shouptech/tempgopher.git
synced 2026-02-03 08:39:43 +00:00
Skeleton for web frontend
This commit is contained in:
parent
3e302c20f9
commit
a86c3dc3b9
3 changed files with 38 additions and 1 deletions
10
main.go
10
main.go
|
|
@ -36,6 +36,9 @@ func main() {
|
|||
// run is tracking whether or not the thermostats should run
|
||||
run := true
|
||||
|
||||
// done is used to signal the web frontend to stop
|
||||
done := make(chan bool)
|
||||
|
||||
sig := make(chan os.Signal)
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGTERM)
|
||||
signal.Notify(sig, os.Interrupt, syscall.SIGINT)
|
||||
|
|
@ -43,6 +46,7 @@ func main() {
|
|||
go func() {
|
||||
<-sig
|
||||
run = false
|
||||
done <- true
|
||||
}()
|
||||
|
||||
sc := make(chan State)
|
||||
|
|
@ -53,6 +57,12 @@ func main() {
|
|||
wg.Add(1)
|
||||
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()
|
||||
|
||||
// Close the GPIO access
|
||||
|
|
|
|||
8
run.go
8
run.go
|
|
@ -107,7 +107,13 @@ func RunThermostat(sensor Sensor, sc chan<- State, run *bool, wg *sync.WaitGroup
|
|||
|
||||
s.Temp = t
|
||||
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)
|
||||
|
|
|
|||
21
web.go
Normal file
21
web.go
Normal 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()
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue