This commit is contained in:
Daniel Esteban 2026-04-15 22:50:12 +02:00
parent b5e08452b6
commit e77882114e
9 changed files with 129 additions and 122 deletions

View file

@ -107,32 +107,32 @@ func myNameIs(name string) {
// top band
display.FillRectangle(cornerRadius, 0, displayWidth-2*cornerRadius-1, cornerRadius, colorRed)
display.FillRectangle(0, cornerRadius, displayWidth, int16(TopBandHeight), colorRed)
display.FillRectangle(0, cornerRadius, displayWidth, int16(topBandHeight), colorRed)
// bottom band
display.FillRectangle(cornerRadius, displayHeight-cornerRadius-1, displayWidth-2*cornerRadius-1, cornerRadius+1, colorRed)
display.FillRectangle(0, displayHeight-int16(BottomBandHeight)-cornerRadius-1, displayWidth, int16(BottomBandHeight), colorRed)
display.FillRectangle(0, displayHeight-int16(bottomBandHeight)-cornerRadius-1, displayWidth, int16(bottomBandHeight), colorRed)
// top text
if displayWidth >= 320 {
// gopherbadge: HELLO + my name is
w32, _ := tinyfont.LineWidth(&freesans.Bold18pt7b, "HELLO")
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, (displayWidth-int16(w32))/2, int16(HelloY), "HELLO", colorWhite)
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, (displayWidth-int16(w32))/2, int16(helloY), "HELLO", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Oblique9pt7b, "my name is")
tinyfont.WriteLine(&display, &freesans.Oblique9pt7b, (displayWidth-int16(w32))/2, int16(MyNameIsY), "my name is", colorWhite)
tinyfont.WriteLine(&display, &freesans.Oblique9pt7b, (displayWidth-int16(w32))/2, int16(myNameIsY), "my name is", colorWhite)
} else {
// pybadge: my NAME is
w32, _ := tinyfont.LineWidth(&freesans.Regular12pt7b, "my NAME is")
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, (displayWidth-int16(w32))/2, int16(MyNameIsY), "my NAME is", colorWhite)
tinyfont.WriteLine(&display, &freesans.Regular12pt7b, (displayWidth-int16(w32))/2, int16(myNameIsY), "my NAME is", colorWhite)
}
writeLine(name, colorBlack, displayWidth/2, 6*displayHeight/10, displayWidth, true)
// gophers
if displayWidth >= 320 {
tinyfont.WriteLineColors(&display, &gophers.Regular58pt, displayWidth-int16(GophersX), int16(GophersY), "BE", []color.RGBA{getRainbowRGB(100), getRainbowRGB(200)})
tinyfont.WriteLineColors(&display, &gophers.Regular58pt, displayWidth-int16(gophersX), int16(gophersY), "BE", []color.RGBA{getRainbowRGB(100), getRainbowRGB(200)})
} else {
tinyfont.WriteLineColors(&display, &gophers.Regular32pt, displayWidth-int16(GophersX), int16(GophersY), "BE", []color.RGBA{getRainbowRGB(100), getRainbowRGB(200)})
tinyfont.WriteLineColors(&display, &gophers.Regular32pt, displayWidth-int16(gophersX), int16(gophersY), "BE", []color.RGBA{getRainbowRGB(100), getRainbowRGB(200)})
}
}

View file

@ -1,5 +1,5 @@
//go:build !gopher_badge && !pybadge
// +build !gopher_badge,!pybadge
//go:build !gopher_badge && !pybadge && !nicenano
// +build !gopher_badge,!pybadge,!nicenano
package main
@ -7,20 +7,20 @@ package main
// This file is not compiled when using a specific target
const (
hardware_name = "DEFAULT"
displayWidth = 320
displayHeight = 240
)
const (
CornerRadius = 10
TopBandHeight = 54
BottomBandHeight = 20
HelloY = 34
MyNameIsY = 54
GophersY = 208
GophersX = 84
menuItemSpace = 20
menuCircleR = 6
cornerRadius = 10
topBandHeight = 54
bottomBandHeight = 20
helloY = 34
myNameIsY = 54
gophersY = 208
gophersX = 84
menuItemSpace = 20
menuCircleR = 6
)

View file

@ -13,6 +13,7 @@ import (
)
const (
hardware_name = "GOPHERBADGE"
displayWidth = 320
displayHeight = 240
)
@ -21,12 +22,12 @@ const (
const (
// myNameIs layout
cornerRadius = 10
TopBandHeight = 54
BottomBandHeight = 20
HelloY = 34
MyNameIsY = 54
GophersY = 208
GophersX = 84
topBandHeight = 54
bottomBandHeight = 20
helloY = 34
myNameIsY = 54
gophersY = 208
gophersX = 84
// menu layout
menuItemSpace = 20
@ -76,8 +77,7 @@ func initHardware() {
SDA: machine.I2C0_SDA_PIN,
})
accel = lis3dh.New(machine.I2C0)
accel.Address = lis3dh.Address0
accel.Configure()
accel.Configure(lis3dh.Config{Address: lis3dh.Address0})
display = st7789.New(machine.SPI0,
machine.TFT_RST, // TFT_RESET

View file

@ -13,6 +13,7 @@ import (
)
const (
hardware_name = "GOBADGE"
displayWidth = 160
displayHeight = 128
)
@ -21,18 +22,18 @@ const (
const (
// myNameIs layout
cornerRadius = 8
TopBandHeight = 26
BottomBandHeight = 8
HelloY = 24 // not used, uses "my NAME is" instead
MyNameIsY = 24
GophersY = 110
GophersX = 48
topBandHeight = 26
bottomBandHeight = 8
helloY = 24 // not used, uses "my NAME is" instead
myNameIsY = 24
gophersY = 110
gophersX = 48
// menu layout
menuItemSpace = 10
menuCircleR = 4
numLEDs = 5
numLEDs = 5
buttonBack = buttonSelect
)

11
go.mod
View file

@ -5,11 +5,14 @@ go 1.22.1
require (
github.com/acifani/vita v1.4.1
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
golang.org/x/image v0.7.0
tinygo.org/x/drivers v0.32.0
tinygo.org/x/drivers v0.34.0
tinygo.org/x/tinydraw v0.4.0
tinygo.org/x/tinyfont v0.6.0
tinygo.org/x/tinyterm v0.5.0
)
require github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
require (
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/tinygo-org/pio v0.3.0 // indirect
)
replace tinygo.org/x/drivers => /home/conejo/go/src/tinygo.org/x/drivers

39
go.sum
View file

@ -4,44 +4,9 @@ github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 h1:El6M4kTTCOh6aBiKaU
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510/go.mod h1:pupxD2MaaD3pAXIBCelhxNneeOaAeabZDe5s4K6zSpQ=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/image v0.7.0 h1:gzS29xtG1J5ybQlv0PuyfE3nmc6R4qB73m6LUUmvFuw=
golang.org/x/image v0.7.0/go.mod h1:nd/q4ef1AKKYl/4kft7g+6UyGbdiqWqTP1ZAbRoV7Rg=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCbuttonUpdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
tinygo.org/x/drivers v0.32.0 h1:qz7MRR1ZBIUhWC6kc4XuVNPr2+mUT8m7QJwA+Jji4IU=
tinygo.org/x/drivers v0.32.0/go.mod h1:ZdErNrApSABdVXjA1RejD67R8SNRI6RKVfYgQDZtKtk=
github.com/tinygo-org/pio v0.3.0 h1:opEnOtw58KGB4RJD3/n/Rd0/djYGX3DeJiXLI6y/yDI=
github.com/tinygo-org/pio v0.3.0/go.mod h1:wf6c6lKZp+pQOzKKcpzchmRuhiMc27ABRuo7KVnaMFU=
tinygo.org/x/tinydraw v0.4.0 h1:U9V0mHz8/jPShKjlh199vCfq1ARFyUOD1b+FfqIwV8c=
tinygo.org/x/tinydraw v0.4.0/go.mod h1:WCV/EMljTv8w04iAxjv+fRD6/4ffx0afATYeJlN90Yo=
tinygo.org/x/tinyfont v0.6.0 h1:GibXDSFz6xrWnEDkDRo6vsbOyRw0MVj/eza3zNHMSHs=
tinygo.org/x/tinyfont v0.6.0/go.mod h1:onflMSkpWl7r7j4MIqhPEVV39pn7yL4N3MOePl3G+G8=
tinygo.org/x/tinyterm v0.5.0 h1:HusDSiTM290KzYM4+2X+ZfNM6Ll1yu13LpvIszlQE9M=
tinygo.org/x/tinyterm v0.5.0/go.mod h1:mTNhIZ3bNXjLmtyTreqh0tUJNdTTXyPZ7i0z8vpZgaI=

44
info.go
View file

@ -1,10 +1,9 @@
//go:build gopher_badge
// +build gopher_badge
//go:build gopher_badge || nicenano
// +build gopher_badge nicenano
package main
import (
_ "embed"
"image/color"
"time"
@ -14,9 +13,11 @@ import (
qrcode "github.com/skip2/go-qrcode"
)
const QR_modeInfo_SIZE = 180
func Info() {
qrSize := int16(180)
if displayHeight < 200 {
qrSize = displayHeight - 5
}
qr, err := qrcode.New("https://gopherbadge.com/", qrcode.Medium)
if err != nil {
@ -26,10 +27,10 @@ func Info() {
qrbytes := qr.Bitmap()
size := int16(len(qrbytes))
factor := int16(QR_modeInfo_SIZE / len(qrbytes))
factor := qrSize / size
bx := (QR_modeInfo_SIZE - size*factor) / 2
by := (QR_modeInfo_SIZE - size*factor) / 2
bx := (qrSize - size*factor) / 2
by := (qrSize - size*factor) / 2
display.FillScreen(color.RGBA{109, 0, 140, 255})
for y := int16(0); y < size; y++ {
for x := int16(0); x < size; x++ {
@ -42,22 +43,24 @@ func Info() {
}
w32, _ := tinyfont.LineWidth(&freesans.Bold18pt7b, "SCAN")
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-int16(w32))/2, 45, "SCAN", colorWhite)
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 45, "SCAN", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold18pt7b, "ME")
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-int16(w32))/2, 80, "ME", colorWhite)
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 80, "ME", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "Press any")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-int16(w32))/2, 120, "Press any", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "button")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-int16(w32))/2, 140, "button", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "to continue")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-int16(w32))/2, 160, "to continue", colorWhite)
if displayHeight >= 200 {
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "Press any")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 120, "Press any", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "button")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 140, "button", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "to continue")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 160, "to continue", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "Visit https://gopherbadge.com/")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, QR_modeInfo_SIZE+25, "Visit https://gopherbadge.com/", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "for more information")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, QR_modeInfo_SIZE+45, "for more information", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "Visit https://gopherbadge.com/")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, qrSize+25, "Visit https://gopherbadge.com/", colorWhite)
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "for more information")
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, qrSize+45, "for more information", colorWhite)
}
quit := false
for {
@ -73,5 +76,4 @@ func Info() {
break
}
}
}

View file

@ -79,7 +79,7 @@ func main() {
buttonsState = make([]bool, 9)
buttonsOldState = make([]bool, 9)
defaultFont = &freemono.Regular12pt7b
if displayWidth <= 180 {
if displayWidth <= 180 || (displayWidth == 240 && displayHeight == 135) {
defaultFont = &proggy.TinySZ8pt7b
}
@ -87,6 +87,9 @@ func main() {
display.FillScreen(colorBlack)
setCustomData()
for {
scroll("ABC", "XYZ", "123")
}
Info()
for {

83
menu.go
View file

@ -8,6 +8,13 @@ import (
"tinygo.org/x/tinyfont"
)
var (
maxOpts int16
offset int16
menuX, menuY int16
numOpts int16
)
func runMenuOption(selected int16) {
switch menuOptions[selected] {
case modeBadge:
@ -39,49 +46,75 @@ func menu() int16 {
display.FillScreen(bgColor)
selected := int16(0)
numOpts := int16(len(menuOptions))
numOpts = int16(len(menuOptions))
menuX := int16(0)
menuX = int16(0)
for i := int16(0); i < numOpts; i++ {
w32, _ := tinyfont.LineWidth(defaultFont, options[menuOptions[i]])
if int16(w32) > menuX && w32 <= displayWidth {
menuX = int16(w32)
}
}
menuX = (displayWidth - menuX) / 2
menuY := int16((displayHeight - ((numOpts - 1) * menuItemSpace)) / 2)
for i := int16(0); i < numOpts; i++ {
tinydraw.Circle(&display, menuX-2*menuCircleR, menuY-menuCircleR/2+menuItemSpace*i, int16(menuCircleR), color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX, menuY+menuItemSpace*i, options[menuOptions[i]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX, menuY+1+menuItemSpace*i, options[menuOptions[i]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX, menuY+2+menuItemSpace*i, options[menuOptions[i]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+1, menuY+2+menuItemSpace*i, options[menuOptions[i]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+2, menuY+2+menuItemSpace*i, options[menuOptions[i]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+2, menuY+1+menuItemSpace*i, options[menuOptions[i]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+2, menuY+menuItemSpace*i, options[menuOptions[i]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+1, menuY+menuItemSpace*i, options[menuOptions[i]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+1, menuY+1+menuItemSpace*i, options[menuOptions[i]], color.RGBA{250, 250, 0, 255})
}
menuY = menuY - menuCircleR/2
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY, menuCircleR-2, color.RGBA{200, 200, 0, 255})
maxOpts = int16((displayHeight - 15) / menuItemSpace)
if numOpts > maxOpts {
maxOpts = (displayHeight - 30) / menuItemSpace
} else {
maxOpts = numOpts
}
offset = 0
menuX = (displayWidth - menuX) / 2
menuY = int16((displayHeight - ((maxOpts - 1) * menuItemSpace)) / 2)
menuDrawOffset()
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY-(menuCircleR/2), menuCircleR-2, color.RGBA{200, 200, 0, 255})
for {
getInput()
if !buttonsOldState[buttonUp] && buttonsState[buttonUp] && selected > 0 {
if !buttonsOldState[buttonUp] && buttonsState[buttonUp] {
selected--
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY+menuItemSpace*selected, menuCircleR-2, color.RGBA{200, 200, 0, 255})
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY+menuItemSpace*(selected+1), menuCircleR-2, bgColor)
if selected < 0 {
offset = (numOpts + offset - maxOpts) % numOpts
selected = maxOpts - 1
menuDrawOffset()
}
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY-(menuCircleR/2)+menuItemSpace*selected, menuCircleR-2, color.RGBA{200, 200, 0, 255})
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY-(menuCircleR/2)+menuItemSpace*(selected+1), menuCircleR-2, bgColor)
}
if !buttonsOldState[buttonDown] && buttonsState[buttonDown] && selected < (numOpts-1) {
if !buttonsOldState[buttonDown] && buttonsState[buttonDown] {
selected++
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY+menuItemSpace*selected, menuCircleR-2, color.RGBA{200, 200, 0, 255})
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY+menuItemSpace*(selected-1), menuCircleR-2, bgColor)
if selected >= maxOpts {
offset = (offset + maxOpts) % numOpts
selected = 0
menuDrawOffset()
}
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY-(menuCircleR/2)+menuItemSpace*selected, menuCircleR-2, color.RGBA{200, 200, 0, 255})
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY-(menuCircleR/2)+menuItemSpace*(selected-1), menuCircleR-2, bgColor)
}
if !buttonsOldState[buttonA] && buttonsState[buttonA] {
break
}
time.Sleep(50 * time.Millisecond)
}
return selected
return (selected + offset) % numOpts
}
func menuDrawOffset() {
bgColor := color.RGBA{109, 0, 140, 255}
display.FillScreen(bgColor)
for i := int16(0); i < maxOpts; i++ {
tinydraw.Circle(&display, menuX-2*menuCircleR, menuY-menuCircleR/2+menuItemSpace*i, int16(menuCircleR), color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX, menuY+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX, menuY+1+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX, menuY+2+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+1, menuY+2+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+2, menuY+2+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+2, menuY+1+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+2, menuY+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+1, menuY+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{0, 0, 0, 255})
tinyfont.WriteLine(&display, defaultFont, menuX+1, menuY+1+menuItemSpace*i, options[menuOptions[(offset+i)%numOpts]], color.RGBA{250, 250, 0, 255})
}
}