forked from conejoninja/badger2040
-
Notifications
You must be signed in to change notification settings - Fork 9
/
menu.go
70 lines (59 loc) · 1.73 KB
/
menu.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
package main
import (
"time"
"tinygo.org/x/drivers/pixel"
"tinygo.org/x/tinydraw"
"tinygo.org/x/tinyfont"
"tinygo.org/x/tinyfont/proggy"
)
func menu() int16 {
options := []string{
"Badge",
"GopherCon Schedule",
"GopherCon Adventure",
"Demo",
}
display.ClearBuffer()
showRect(0, 0, WIDTH, 16, black)
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 6, 12, "MENU - GOPHERCON.COM.AU", white)
selected := int16(0)
numOpts := int16(len(options))
for i := int16(0); i < numOpts; i++ {
tinydraw.Circle(&display, 20, 38+12*i, 3, black)
tinyfont.WriteLine(&display, &proggy.TinySZ8pt7b, 28, 40+12*i, options[i], black)
}
tinydraw.FilledCircle(&display, 20, 38, 4, black)
img := pixel.NewImageFromBytes[pixel.Monochrome](112, 96, []byte(logochip))
if err := display.DrawBitmap(168, 24, img); err != nil {
println(err)
}
display.Display()
display.WaitUntilIdle()
released := true
for {
if released && btnUp.Get() && selected > 0 {
selected--
tinydraw.FilledCircle(&display, 20, 38+12*selected, 4, black)
tinydraw.FilledCircle(&display, 20, 38+12*(selected+1), 4, white)
tinydraw.Circle(&display, 20, 38+12*(selected+1), 3, black)
display.Display()
}
if released && btnDown.Get() && selected < (numOpts-1) {
selected++
tinydraw.FilledCircle(&display, 20, 38+12*selected, 4, black)
tinydraw.FilledCircle(&display, 20, 38+12*(selected-1), 4, white)
tinydraw.Circle(&display, 20, 38+12*(selected-1), 3, black)
display.Display()
}
if released && (btnA.Get() || btnB.Get() || btnC.Get()) {
break
}
if !btnA.Get() && !btnB.Get() && !btnC.Get() && !btnUp.Get() && !btnDown.Get() {
released = true
} else {
released = false
}
time.Sleep(200 * time.Millisecond)
}
return selected
}