2026-04-14 17:21:59 +00:00
|
|
|
//go:build pybadge
|
|
|
|
|
// +build pybadge
|
|
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"machine"
|
|
|
|
|
|
|
|
|
|
"tinygo.org/x/drivers/lis3dh"
|
|
|
|
|
"tinygo.org/x/drivers/shifter"
|
|
|
|
|
"tinygo.org/x/drivers/st7735"
|
|
|
|
|
"tinygo.org/x/drivers/ws2812"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
const (
|
2026-04-15 20:50:12 +00:00
|
|
|
hardware_name = "GOBADGE"
|
2026-04-14 17:21:59 +00:00
|
|
|
displayWidth = 160
|
|
|
|
|
displayHeight = 128
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
// UI layout constants for pybadge/gobadge (160x128)
|
|
|
|
|
const (
|
|
|
|
|
// myNameIs layout
|
|
|
|
|
cornerRadius = 8
|
2026-04-15 20:50:12 +00:00
|
|
|
topBandHeight = 26
|
|
|
|
|
bottomBandHeight = 8
|
|
|
|
|
helloY = 24 // not used, uses "my NAME is" instead
|
|
|
|
|
myNameIsY = 24
|
|
|
|
|
gophersY = 110
|
|
|
|
|
gophersX = 48
|
2026-04-14 17:21:59 +00:00
|
|
|
|
|
|
|
|
// menu layout
|
|
|
|
|
menuItemSpace = 10
|
|
|
|
|
menuCircleR = 4
|
|
|
|
|
|
2026-04-15 20:50:12 +00:00
|
|
|
numLEDs = 5
|
2026-04-14 17:21:59 +00:00
|
|
|
|
|
|
|
|
buttonBack = buttonSelect
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var menuOptions = []int8{
|
|
|
|
|
modeBadge,
|
|
|
|
|
modeSchedule,
|
|
|
|
|
modeAdventure,
|
|
|
|
|
modeLEDs,
|
|
|
|
|
modeAccelerometer,
|
|
|
|
|
modeMusic,
|
|
|
|
|
modeGameSnake,
|
|
|
|
|
modeGameLife,
|
|
|
|
|
modeGameColors,
|
|
|
|
|
modeInfo,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Font size thresholds for pybadge (smaller screen, use smaller fonts)
|
|
|
|
|
const (
|
|
|
|
|
FontWidthThreshold = 150
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
var display st7735.Device
|
|
|
|
|
var buttons shifter.Device
|
|
|
|
|
|
|
|
|
|
func initHardware() {
|
|
|
|
|
machine.SPI1.Configure(machine.SPIConfig{
|
|
|
|
|
SCK: machine.SPI1_SCK_PIN,
|
|
|
|
|
SDO: machine.SPI1_SDO_PIN,
|
|
|
|
|
SDI: machine.SPI1_SDI_PIN,
|
|
|
|
|
Frequency: 8000000,
|
|
|
|
|
})
|
|
|
|
|
machine.I2C0.Configure(machine.I2CConfig{SCL: machine.SCL_PIN, SDA: machine.SDA_PIN})
|
|
|
|
|
|
|
|
|
|
accel = lis3dh.New(machine.I2C0)
|
|
|
|
|
accel.Address = lis3dh.Address0
|
|
|
|
|
accel.Configure()
|
|
|
|
|
|
|
|
|
|
display = st7735.New(machine.SPI1, machine.TFT_RST, machine.TFT_DC, machine.TFT_CS, machine.TFT_LITE)
|
|
|
|
|
display.Configure(st7735.Config{
|
|
|
|
|
Rotation: st7735.ROTATION_90,
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
buttons = shifter.NewButtons()
|
|
|
|
|
buttons.Configure()
|
|
|
|
|
|
|
|
|
|
neo := machine.NEOPIXELS
|
|
|
|
|
neo.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
|
|
|
leds = ws2812.New(neo)
|
|
|
|
|
|
|
|
|
|
bzrPin = machine.A0
|
|
|
|
|
bzrPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
|
|
|
|
|
|
|
|
speaker := machine.SPEAKER_ENABLE
|
|
|
|
|
speaker.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
|
|
|
|
speaker.High()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func getInput() {
|
|
|
|
|
for b := 0; b < 9; b++ {
|
|
|
|
|
buttonsOldState[b] = buttonsState[b]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
buttons.ReadInput()
|
|
|
|
|
|
|
|
|
|
buttonsState[buttonUp] = buttons.Pins[shifter.BUTTON_UP].Get()
|
|
|
|
|
buttonsState[buttonRight] = buttons.Pins[shifter.BUTTON_RIGHT].Get()
|
|
|
|
|
buttonsState[buttonDown] = buttons.Pins[shifter.BUTTON_DOWN].Get()
|
|
|
|
|
buttonsState[buttonLeft] = buttons.Pins[shifter.BUTTON_LEFT].Get()
|
|
|
|
|
buttonsState[buttonA] = buttons.Pins[shifter.BUTTON_A].Get()
|
|
|
|
|
buttonsState[buttonB] = buttons.Pins[shifter.BUTTON_B].Get()
|
|
|
|
|
buttonsState[buttonStart] = buttons.Pins[shifter.BUTTON_START].Get()
|
|
|
|
|
buttonsState[buttonSelect] = buttons.Pins[shifter.BUTTON_SELECT].Get()
|
|
|
|
|
}
|