wip
This commit is contained in:
parent
b5e08452b6
commit
e77882114e
9 changed files with 129 additions and 122 deletions
14
badge.go
14
badge.go
|
|
@ -107,32 +107,32 @@ func myNameIs(name string) {
|
||||||
|
|
||||||
// top band
|
// top band
|
||||||
display.FillRectangle(cornerRadius, 0, displayWidth-2*cornerRadius-1, cornerRadius, colorRed)
|
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
|
// bottom band
|
||||||
display.FillRectangle(cornerRadius, displayHeight-cornerRadius-1, displayWidth-2*cornerRadius-1, cornerRadius+1, colorRed)
|
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
|
// top text
|
||||||
if displayWidth >= 320 {
|
if displayWidth >= 320 {
|
||||||
// gopherbadge: HELLO + my name is
|
// gopherbadge: HELLO + my name is
|
||||||
w32, _ := tinyfont.LineWidth(&freesans.Bold18pt7b, "HELLO")
|
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")
|
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 {
|
} else {
|
||||||
// pybadge: my NAME is
|
// pybadge: my NAME is
|
||||||
w32, _ := tinyfont.LineWidth(&freesans.Regular12pt7b, "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)
|
writeLine(name, colorBlack, displayWidth/2, 6*displayHeight/10, displayWidth, true)
|
||||||
|
|
||||||
// gophers
|
// gophers
|
||||||
if displayWidth >= 320 {
|
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 {
|
} 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)})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
//go:build !gopher_badge && !pybadge
|
//go:build !gopher_badge && !pybadge && !nicenano
|
||||||
// +build !gopher_badge,!pybadge
|
// +build !gopher_badge,!pybadge,!nicenano
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
|
|
@ -7,20 +7,20 @@ package main
|
||||||
// This file is not compiled when using a specific target
|
// This file is not compiled when using a specific target
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
hardware_name = "DEFAULT"
|
||||||
displayWidth = 320
|
displayWidth = 320
|
||||||
displayHeight = 240
|
displayHeight = 240
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
CornerRadius = 10
|
cornerRadius = 10
|
||||||
TopBandHeight = 54
|
topBandHeight = 54
|
||||||
BottomBandHeight = 20
|
bottomBandHeight = 20
|
||||||
HelloY = 34
|
helloY = 34
|
||||||
MyNameIsY = 54
|
myNameIsY = 54
|
||||||
GophersY = 208
|
gophersY = 208
|
||||||
GophersX = 84
|
gophersX = 84
|
||||||
|
|
||||||
menuItemSpace = 20
|
|
||||||
menuCircleR = 6
|
|
||||||
|
|
||||||
|
menuItemSpace = 20
|
||||||
|
menuCircleR = 6
|
||||||
)
|
)
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
hardware_name = "GOPHERBADGE"
|
||||||
displayWidth = 320
|
displayWidth = 320
|
||||||
displayHeight = 240
|
displayHeight = 240
|
||||||
)
|
)
|
||||||
|
|
@ -21,12 +22,12 @@ const (
|
||||||
const (
|
const (
|
||||||
// myNameIs layout
|
// myNameIs layout
|
||||||
cornerRadius = 10
|
cornerRadius = 10
|
||||||
TopBandHeight = 54
|
topBandHeight = 54
|
||||||
BottomBandHeight = 20
|
bottomBandHeight = 20
|
||||||
HelloY = 34
|
helloY = 34
|
||||||
MyNameIsY = 54
|
myNameIsY = 54
|
||||||
GophersY = 208
|
gophersY = 208
|
||||||
GophersX = 84
|
gophersX = 84
|
||||||
|
|
||||||
// menu layout
|
// menu layout
|
||||||
menuItemSpace = 20
|
menuItemSpace = 20
|
||||||
|
|
@ -76,8 +77,7 @@ func initHardware() {
|
||||||
SDA: machine.I2C0_SDA_PIN,
|
SDA: machine.I2C0_SDA_PIN,
|
||||||
})
|
})
|
||||||
accel = lis3dh.New(machine.I2C0)
|
accel = lis3dh.New(machine.I2C0)
|
||||||
accel.Address = lis3dh.Address0
|
accel.Configure(lis3dh.Config{Address: lis3dh.Address0})
|
||||||
accel.Configure()
|
|
||||||
|
|
||||||
display = st7789.New(machine.SPI0,
|
display = st7789.New(machine.SPI0,
|
||||||
machine.TFT_RST, // TFT_RESET
|
machine.TFT_RST, // TFT_RESET
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
hardware_name = "GOBADGE"
|
||||||
displayWidth = 160
|
displayWidth = 160
|
||||||
displayHeight = 128
|
displayHeight = 128
|
||||||
)
|
)
|
||||||
|
|
@ -21,18 +22,18 @@ const (
|
||||||
const (
|
const (
|
||||||
// myNameIs layout
|
// myNameIs layout
|
||||||
cornerRadius = 8
|
cornerRadius = 8
|
||||||
TopBandHeight = 26
|
topBandHeight = 26
|
||||||
BottomBandHeight = 8
|
bottomBandHeight = 8
|
||||||
HelloY = 24 // not used, uses "my NAME is" instead
|
helloY = 24 // not used, uses "my NAME is" instead
|
||||||
MyNameIsY = 24
|
myNameIsY = 24
|
||||||
GophersY = 110
|
gophersY = 110
|
||||||
GophersX = 48
|
gophersX = 48
|
||||||
|
|
||||||
// menu layout
|
// menu layout
|
||||||
menuItemSpace = 10
|
menuItemSpace = 10
|
||||||
menuCircleR = 4
|
menuCircleR = 4
|
||||||
|
|
||||||
numLEDs = 5
|
numLEDs = 5
|
||||||
|
|
||||||
buttonBack = buttonSelect
|
buttonBack = buttonSelect
|
||||||
)
|
)
|
||||||
|
|
|
||||||
11
go.mod
11
go.mod
|
|
@ -5,11 +5,14 @@ go 1.22.1
|
||||||
require (
|
require (
|
||||||
github.com/acifani/vita v1.4.1
|
github.com/acifani/vita v1.4.1
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
|
||||||
golang.org/x/image v0.7.0
|
tinygo.org/x/drivers v0.34.0
|
||||||
tinygo.org/x/drivers v0.32.0
|
|
||||||
tinygo.org/x/tinydraw v0.4.0
|
tinygo.org/x/tinydraw v0.4.0
|
||||||
tinygo.org/x/tinyfont v0.6.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
39
go.sum
|
|
@ -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/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 h1:MRM5ITcdelLK2j1vwZ3Je0FKVCfqOLp5zO6trqMLYs0=
|
||||||
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e/go.mod h1:XV66xRDqSt+GTGFMVlhk3ULuV0y9ZmzeVGR4mloJI3M=
|
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=
|
github.com/tinygo-org/pio v0.3.0 h1:opEnOtw58KGB4RJD3/n/Rd0/djYGX3DeJiXLI6y/yDI=
|
||||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
github.com/tinygo-org/pio v0.3.0/go.mod h1:wf6c6lKZp+pQOzKKcpzchmRuhiMc27ABRuo7KVnaMFU=
|
||||||
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=
|
|
||||||
tinygo.org/x/tinydraw v0.4.0 h1:U9V0mHz8/jPShKjlh199vCfq1ARFyUOD1b+FfqIwV8c=
|
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/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 h1:GibXDSFz6xrWnEDkDRo6vsbOyRw0MVj/eza3zNHMSHs=
|
||||||
tinygo.org/x/tinyfont v0.6.0/go.mod h1:onflMSkpWl7r7j4MIqhPEVV39pn7yL4N3MOePl3G+G8=
|
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
44
info.go
|
|
@ -1,10 +1,9 @@
|
||||||
//go:build gopher_badge
|
//go:build gopher_badge || nicenano
|
||||||
// +build gopher_badge
|
// +build gopher_badge nicenano
|
||||||
|
|
||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
_ "embed"
|
|
||||||
"image/color"
|
"image/color"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -14,9 +13,11 @@ import (
|
||||||
qrcode "github.com/skip2/go-qrcode"
|
qrcode "github.com/skip2/go-qrcode"
|
||||||
)
|
)
|
||||||
|
|
||||||
const QR_modeInfo_SIZE = 180
|
|
||||||
|
|
||||||
func Info() {
|
func Info() {
|
||||||
|
qrSize := int16(180)
|
||||||
|
if displayHeight < 200 {
|
||||||
|
qrSize = displayHeight - 5
|
||||||
|
}
|
||||||
|
|
||||||
qr, err := qrcode.New("https://gopherbadge.com/", qrcode.Medium)
|
qr, err := qrcode.New("https://gopherbadge.com/", qrcode.Medium)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -26,10 +27,10 @@ func Info() {
|
||||||
qrbytes := qr.Bitmap()
|
qrbytes := qr.Bitmap()
|
||||||
size := int16(len(qrbytes))
|
size := int16(len(qrbytes))
|
||||||
|
|
||||||
factor := int16(QR_modeInfo_SIZE / len(qrbytes))
|
factor := qrSize / size
|
||||||
|
|
||||||
bx := (QR_modeInfo_SIZE - size*factor) / 2
|
bx := (qrSize - size*factor) / 2
|
||||||
by := (QR_modeInfo_SIZE - size*factor) / 2
|
by := (qrSize - size*factor) / 2
|
||||||
display.FillScreen(color.RGBA{109, 0, 140, 255})
|
display.FillScreen(color.RGBA{109, 0, 140, 255})
|
||||||
for y := int16(0); y < size; y++ {
|
for y := int16(0); y < size; y++ {
|
||||||
for x := int16(0); x < size; x++ {
|
for x := int16(0); x < size; x++ {
|
||||||
|
|
@ -42,22 +43,24 @@ func Info() {
|
||||||
}
|
}
|
||||||
|
|
||||||
w32, _ := tinyfont.LineWidth(&freesans.Bold18pt7b, "SCAN")
|
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")
|
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")
|
if displayHeight >= 200 {
|
||||||
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-int16(w32))/2, 120, "Press any", colorWhite)
|
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "Press any")
|
||||||
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "button")
|
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 120, "Press any", colorWhite)
|
||||||
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-int16(w32))/2, 140, "button", colorWhite)
|
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "button")
|
||||||
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "to continue")
|
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, qrSize+((displayWidth-qrSize)-int16(w32))/2, 140, "button", colorWhite)
|
||||||
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-int16(w32))/2, 160, "to continue", 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/")
|
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)
|
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, qrSize+25, "Visit https://gopherbadge.com/", colorWhite)
|
||||||
w32, _ = tinyfont.LineWidth(&freesans.Bold9pt7b, "for more information")
|
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)
|
tinyfont.WriteLine(&display, &freesans.Bold9pt7b, (displayWidth-int16(w32))/2, qrSize+45, "for more information", colorWhite)
|
||||||
|
}
|
||||||
|
|
||||||
quit := false
|
quit := false
|
||||||
for {
|
for {
|
||||||
|
|
@ -73,5 +76,4 @@ func Info() {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
main.go
5
main.go
|
|
@ -79,7 +79,7 @@ func main() {
|
||||||
buttonsState = make([]bool, 9)
|
buttonsState = make([]bool, 9)
|
||||||
buttonsOldState = make([]bool, 9)
|
buttonsOldState = make([]bool, 9)
|
||||||
defaultFont = &freemono.Regular12pt7b
|
defaultFont = &freemono.Regular12pt7b
|
||||||
if displayWidth <= 180 {
|
if displayWidth <= 180 || (displayWidth == 240 && displayHeight == 135) {
|
||||||
defaultFont = &proggy.TinySZ8pt7b
|
defaultFont = &proggy.TinySZ8pt7b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -87,6 +87,9 @@ func main() {
|
||||||
display.FillScreen(colorBlack)
|
display.FillScreen(colorBlack)
|
||||||
setCustomData()
|
setCustomData()
|
||||||
|
|
||||||
|
for {
|
||||||
|
scroll("ABC", "XYZ", "123")
|
||||||
|
}
|
||||||
Info()
|
Info()
|
||||||
|
|
||||||
for {
|
for {
|
||||||
|
|
|
||||||
83
menu.go
83
menu.go
|
|
@ -8,6 +8,13 @@ import (
|
||||||
"tinygo.org/x/tinyfont"
|
"tinygo.org/x/tinyfont"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
maxOpts int16
|
||||||
|
offset int16
|
||||||
|
menuX, menuY int16
|
||||||
|
numOpts int16
|
||||||
|
)
|
||||||
|
|
||||||
func runMenuOption(selected int16) {
|
func runMenuOption(selected int16) {
|
||||||
switch menuOptions[selected] {
|
switch menuOptions[selected] {
|
||||||
case modeBadge:
|
case modeBadge:
|
||||||
|
|
@ -39,49 +46,75 @@ func menu() int16 {
|
||||||
display.FillScreen(bgColor)
|
display.FillScreen(bgColor)
|
||||||
|
|
||||||
selected := int16(0)
|
selected := int16(0)
|
||||||
numOpts := int16(len(menuOptions))
|
numOpts = int16(len(menuOptions))
|
||||||
|
|
||||||
menuX := int16(0)
|
menuX = int16(0)
|
||||||
for i := int16(0); i < numOpts; i++ {
|
for i := int16(0); i < numOpts; i++ {
|
||||||
w32, _ := tinyfont.LineWidth(defaultFont, options[menuOptions[i]])
|
w32, _ := tinyfont.LineWidth(defaultFont, options[menuOptions[i]])
|
||||||
if int16(w32) > menuX && w32 <= displayWidth {
|
if int16(w32) > menuX && w32 <= displayWidth {
|
||||||
menuX = int16(w32)
|
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
|
maxOpts = int16((displayHeight - 15) / menuItemSpace)
|
||||||
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY, menuCircleR-2, color.RGBA{200, 200, 0, 255})
|
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 {
|
for {
|
||||||
getInput()
|
getInput()
|
||||||
if !buttonsOldState[buttonUp] && buttonsState[buttonUp] && selected > 0 {
|
if !buttonsOldState[buttonUp] && buttonsState[buttonUp] {
|
||||||
selected--
|
selected--
|
||||||
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY+menuItemSpace*selected, menuCircleR-2, color.RGBA{200, 200, 0, 255})
|
if selected < 0 {
|
||||||
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY+menuItemSpace*(selected+1), menuCircleR-2, bgColor)
|
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++
|
selected++
|
||||||
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY+menuItemSpace*selected, menuCircleR-2, color.RGBA{200, 200, 0, 255})
|
if selected >= maxOpts {
|
||||||
tinydraw.FilledCircle(&display, menuX-2*menuCircleR, menuY+menuItemSpace*(selected-1), menuCircleR-2, bgColor)
|
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] {
|
if !buttonsOldState[buttonA] && buttonsState[buttonA] {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
time.Sleep(50 * time.Millisecond)
|
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})
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue