77 lines
2.5 KiB
Go
77 lines
2.5 KiB
Go
//go:build gopher_badge
|
|
// +build gopher_badge
|
|
|
|
package main
|
|
|
|
import (
|
|
_ "embed"
|
|
"image/color"
|
|
"time"
|
|
|
|
"tinygo.org/x/tinyfont"
|
|
"tinygo.org/x/tinyfont/freesans"
|
|
|
|
qrcode "github.com/skip2/go-qrcode"
|
|
)
|
|
|
|
const QR_modeInfo_SIZE = 180
|
|
|
|
func Info() {
|
|
|
|
qr, err := qrcode.New("https://gopherbadge.com/", qrcode.Medium)
|
|
if err != nil {
|
|
println(err, 123)
|
|
}
|
|
|
|
qrbytes := qr.Bitmap()
|
|
size := int16(len(qrbytes))
|
|
|
|
factor := int16(QR_modeInfo_SIZE / len(qrbytes))
|
|
|
|
bx := (QR_modeInfo_SIZE - size*factor) / 2
|
|
by := (QR_modeInfo_SIZE - 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++ {
|
|
if qrbytes[y][x] {
|
|
display.FillRectangle(bx+x*factor, by+y*factor, factor, factor, colorBlack)
|
|
} else {
|
|
display.FillRectangle(bx+x*factor, by+y*factor, factor, factor, colorWhite)
|
|
}
|
|
}
|
|
}
|
|
|
|
w32, _ := tinyfont.LineWidth(&freesans.Bold18pt7b, "SCAN")
|
|
tinyfont.WriteLine(&display, &freesans.Bold18pt7b, QR_modeInfo_SIZE+((displayWidth-QR_modeInfo_SIZE)-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)
|
|
|
|
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)
|
|
|
|
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)
|
|
|
|
quit := false
|
|
for {
|
|
time.Sleep(100 * time.Millisecond)
|
|
getInput()
|
|
for b := 0; b < 9; b++ {
|
|
if !buttonsOldState[b] && buttonsState[b] {
|
|
quit = true
|
|
break
|
|
}
|
|
}
|
|
if quit {
|
|
break
|
|
}
|
|
}
|
|
|
|
}
|