-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (61 loc) · 1.59 KB
/
main.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"os"
"github.com/KonradChlupka/berglen-led/engine"
"github.com/KonradChlupka/berglen-led/server"
ws281x "github.com/rpi-ws281x/rpi-ws281x-go"
"github.com/urfave/cli/v2"
)
const (
defaultBrightness = 255
numLEDs = 240
flagBrightness = "brightness"
)
func main() {
app := &cli.App{
Name: "Berglen LED",
Usage: "Shine bright like an east london flat",
Flags: []cli.Flag{
&cli.IntFlag{
Name: flagBrightness,
Aliases: []string{"b"},
Usage: "Brightness [0-255]",
},
},
Action: func(ctx *cli.Context) error {
brightness := ctx.Int(flagBrightness)
if brightness < 0 || brightness > 255 {
return fmt.Errorf("brightness requires a value of 0>=b<=255, not %d", brightness)
}
if !ctx.IsSet(flagBrightness) {
brightness = defaultBrightness
}
// Setup light strip connection.
opt := ws281x.DefaultOptions
opt.Channels[0].Brightness = brightness
opt.Channels[0].LedCount = numLEDs
ws, err := ws281x.MakeWS2811(&opt)
if err != nil {
return fmt.Errorf("failed to initiate the dumbass LEDs: %w", err)
}
leds := engine.NewLightstrip(ws)
err = leds.Init()
if err != nil {
return fmt.Errorf("failed to initiate the light strip: %w", err)
}
defer leds.Close()
rainbowProgram, err := leds.RainbowRGB()
if err != nil {
return fmt.Errorf("failed to create rainbow program: %w", err)
}
server := server.NewServer(leds, server.WithProgram(rainbowProgram))
return server.Serve()
},
}
app.EnableBashCompletion = true
err := app.Run(os.Args)
if err != nil {
panic(err)
}
}