-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
87 lines (78 loc) · 1.75 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
75
76
77
78
79
80
81
82
83
84
85
86
87
package main
import (
"image/color"
"time"
"github.com/misterikkit/tinytimer/apps/arcade"
"github.com/misterikkit/tinytimer/apps/colorpicker"
"github.com/misterikkit/tinytimer/apps/pong"
"github.com/misterikkit/tinytimer/apps/rainbow"
"github.com/misterikkit/tinytimer/apps/simon"
"github.com/misterikkit/tinytimer/apps/timer"
"github.com/misterikkit/tinytimer/easter"
"github.com/misterikkit/tinytimer/input"
)
const frameRate = 60
type App interface {
Update(time.Time)
Frame() []color.RGBA
}
func main() {
println("hello world")
ui := setup() // initialize hardware
mgr := input.NewManager(ui.BtnCancel, ui.Btn2Min, ui.Btn10Min)
eggs := easter.New(mgr)
var (
timer = timer.New(mgr)
rainbow = rainbow.New()
pong = pong.New(mgr)
picker = colorpicker.New(mgr)
simon = simon.New(mgr)
arcade = arcade.New(mgr)
)
app := App(timer)
for {
mgr.Poll() // Invokes appropriate handlers.
switch eggs.Get() {
case easter.Eggsit:
if isTimer(app) {
ui.Sleepish()
}
timer.Reset()
app = timer
case easter.Rainbow:
if isTimer(app) {
app = rainbow
}
case easter.Pong:
if isTimer(app) {
pong.Reset()
app = pong
}
case easter.ColorPicker:
if isTimer(app) {
picker.Reset()
app = picker
}
case easter.Simon:
if isTimer(app) {
simon.Reset()
app = simon
}
case easter.Arcade:
if isTimer(app) {
arcade.Reset(time.Now())
app = arcade
}
}
// Compute and display next frame for the current app.
app.Update(time.Now())
ui.DisplayLEDs(app.Frame())
// The effective frame rate is slightly less due to Update and DisplayLEDs,
// but nobody will notice.
time.Sleep(time.Second / frameRate)
}
}
func isTimer(a App) bool {
_, ok := a.(*timer.App)
return ok
}