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

43 lines
723 B
Go

package main
import (
"log"
"sync"
"github.com/alexflint/go-arg"
"github.com/stianeikeland/go-rpio"
)
func main() {
var args struct {
Action string `arg:"required,positional" help:"run"`
ConfigFile string `arg:"-c,required" help:"path to config file"`
}
p := arg.MustParse(&args)
if args.Action != "run" {
p.Fail("ACTION must be run")
}
config, err := LoadConfig(args.ConfigFile)
if err != nil {
log.Fatal(err)
}
// Prep for GPIO access
err = rpio.Open()
if err != nil {
log.Fatal(err)
}
// Launch the thermostat go routines
var wg sync.WaitGroup
for _, sensor := range config.Sensors {
wg.Add(1)
go RunThermostat(sensor)
}
wg.Wait()
// Close the GPIO access
rpio.Close()
}