-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathledboard.go
48 lines (41 loc) · 1009 Bytes
/
ledboard.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"flag"
"github.com/ledboard/pkg/bus"
c "github.com/ledboard/pkg/controllers"
e "github.com/ledboard/pkg/errors"
)
const defaultConfig = "conf.json"
func main() {
debugFlag := flag.Bool("debug", false, "debug logging")
confFile := flag.String("conf", defaultConfig, "override default config file")
flag.Parse()
conf := c.NewConfig(*confFile, *debugFlag)
bus := bus.NewSerialBus(conf.LedBoard.Port, conf.LedBoard.Baud, conf.Log)
bus.Connect()
defer bus.Disconnect()
run(conf, bus)
}
func run(conf c.UserConfig, serialBus bus.SerialBus) {
//setup
stopCh := e.SetupCloseHandler()
activeChans := conf.MakeControllers(serialBus)
//loop
var btn uint8
readCh := serialBus.GetReadChannel()
for {
select {
case btn = <-readCh:
conf.Log.Debugf("Pushed:%v", btn)
ch, ok := activeChans[uint8(btn)]
if !ok {
conf.Log.Debugf("Error activating %v", btn)
continue
}
ch <- true
case <-stopCh:
conf.Log.Infof("\r- Sutting down")
return
}
}
}