diff --git a/examples/clue-scanner/main.go b/examples/clue-scanner/main.go deleted file mode 100644 index 7a09087..0000000 --- a/examples/clue-scanner/main.go +++ /dev/null @@ -1,87 +0,0 @@ -package main - -import ( - "fmt" - "image/color" - "machine" - "time" - - "tinygo.org/x/bluetooth" - "tinygo.org/x/drivers/st7789" - "tinygo.org/x/tinyfont/proggy" - "tinygo.org/x/tinyterm" -) - -var ( - display st7789.Device - terminal = tinyterm.NewTerminal(&display) - - black = color.RGBA{0, 0, 0, 255} - font = &proggy.TinySZ8pt7b - - adapter = bluetooth.DefaultAdapter -) - -func main() { - initDisplay() - time.Sleep(time.Second) - - fmt.Fprintf(terminal, "\nenable interface...") - println("enable interface...") - must("enable BLE interface", adapter.Enable()) - time.Sleep(time.Second) - - println("start scan...") - fmt.Fprintf(terminal, "\nstart scan...") - - must("start scan", adapter.Scan(scanHandler)) - - for { - time.Sleep(time.Minute) - println("scanning...") - fmt.Fprintf(terminal, "\nscanning...") - } -} - -func scanHandler(adapter *bluetooth.Adapter, device bluetooth.ScanResult) { - println("device:", device.Address.String(), device.RSSI, device.LocalName()) - fmt.Fprintf(terminal, "\n%s %d %s", device.Address.String(), device.RSSI, device.LocalName()) -} - -func must(action string, err error) { - if err != nil { - for { - println("failed to " + action + ": " + err.Error()) - time.Sleep(time.Second) - } - } -} - -func initDisplay() { - machine.SPI1.Configure(machine.SPIConfig{ - Frequency: 8000000, - SCK: machine.TFT_SCK, - SDO: machine.TFT_SDO, - SDI: machine.TFT_SDO, - Mode: 0, - }) - - display = st7789.New(machine.SPI1, - machine.TFT_RESET, - machine.TFT_DC, - machine.TFT_CS, - machine.TFT_LITE) - display.Configure(st7789.Config{ - Rotation: st7789.ROTATION_180, - Height: 320, - FrameRate: st7789.FRAMERATE_111, - VSyncLines: st7789.MAX_VSYNC_SCANLINES, - }) - display.FillScreen(black) - - terminal.Configure(&tinyterm.Config{ - Font: font, - FontHeight: 10, - FontOffset: 6, - }) -} diff --git a/examples/tinyscan/clue.go b/examples/tinyscan/clue.go new file mode 100644 index 0000000..62957ec --- /dev/null +++ b/examples/tinyscan/clue.go @@ -0,0 +1,48 @@ +//go:build clue + +package main + +import ( + "machine" + + "tinygo.org/x/drivers/st7789" + "tinygo.org/x/tinyfont/proggy" + "tinygo.org/x/tinyterm" +) + +var ( + font = &proggy.TinySZ8pt7b +) + +func initTerminal() { + machine.SPI1.Configure(machine.SPIConfig{ + Frequency: 8000000, + SCK: machine.TFT_SCK, + SDO: machine.TFT_SDO, + SDI: machine.TFT_SDO, + Mode: 0, + }) + + display := st7789.New(machine.SPI1, + machine.TFT_RESET, + machine.TFT_DC, + machine.TFT_CS, + machine.TFT_LITE) + + display.Configure(st7789.Config{ + Rotation: st7789.ROTATION_90, + //Height: 320, + FrameRate: st7789.FRAMERATE_111, + VSyncLines: st7789.MAX_VSYNC_SCANLINES, + }) + + display.FillScreen(black) + + terminal = tinyterm.NewTerminal(&display) + terminal.Configure(&tinyterm.Config{ + Font: font, + FontHeight: 10, + FontOffset: 6, + UseSoftwareScroll: true, + }) +} diff --git a/examples/tinyscan/main.go b/examples/tinyscan/main.go new file mode 100644 index 0000000..ebc36dd --- /dev/null +++ b/examples/tinyscan/main.go @@ -0,0 +1,55 @@ +package main + +import ( + "fmt" + "image/color" + "time" + + "tinygo.org/x/bluetooth" + "tinygo.org/x/tinyterm" +) + +var ( + terminal *tinyterm.Terminal + + black = color.RGBA{0, 0, 0, 255} + adapter = bluetooth.DefaultAdapter +) + +func main() { + initTerminal() + + terminalOutput("enable interface...") + + must("enable BLE interface", adapter.Enable()) + time.Sleep(time.Second) + + terminalOutput("start scan...") + + must("start scan", adapter.Scan(scanHandler)) + + for { + time.Sleep(time.Minute) + terminalOutput("scanning...") + } +} + +func scanHandler(adapter *bluetooth.Adapter, device bluetooth.ScanResult) { + msg := fmt.Sprintf("%s %d %s", device.Address.String(), device.RSSI, device.LocalName()) + terminalOutput(msg) +} + +func must(action string, err error) { + if err != nil { + for { + terminalOutput("failed to " + action + ": " + err.Error()) + + time.Sleep(time.Second) + } + } +} + +func terminalOutput(s string) { + println(s) + fmt.Fprintf(terminal, "\n%s", s) +} diff --git a/examples/tinyscan/pybadge.go b/examples/tinyscan/pybadge.go new file mode 100644 index 0000000..ec2c480 --- /dev/null +++ b/examples/tinyscan/pybadge.go @@ -0,0 +1,39 @@ +//go:build pybadge + +package main + +import ( + "machine" + + "tinygo.org/x/drivers/st7735" + "tinygo.org/x/tinyfont" + "tinygo.org/x/tinyterm" +) + +var ( + font = &tinyfont.Picopixel +) + +func initTerminal() { + machine.SPI1.Configure(machine.SPIConfig{ + SCK: machine.SPI1_SCK_PIN, + SDO: machine.SPI1_SDO_PIN, + SDI: machine.SPI1_SDI_PIN, + Frequency: 8000000, + }) + + 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, + }) + + display.FillScreen(black) + + terminal = tinyterm.NewTerminal(&display) + terminal.Configure(&tinyterm.Config{ + Font: font, + FontHeight: 8, + FontOffset: 4, + UseSoftwareScroll: true, + }) +} diff --git a/examples/tinyscan/pyportal.go b/examples/tinyscan/pyportal.go new file mode 100644 index 0000000..fbec92c --- /dev/null +++ b/examples/tinyscan/pyportal.go @@ -0,0 +1,45 @@ +//go:build pyportal + +package main + +import ( + "machine" + + "tinygo.org/x/drivers/ili9341" + "tinygo.org/x/tinyfont/proggy" + "tinygo.org/x/tinyterm" +) + +var ( + font = &proggy.TinySZ8pt7b +) + +func initTerminal() { + display := ili9341.NewParallel( + machine.LCD_DATA0, + machine.TFT_WR, + machine.TFT_DC, + machine.TFT_CS, + machine.TFT_RESET, + machine.TFT_RD, + ) + + // configure backlight + backlight := machine.TFT_BACKLIGHT + backlight.Configure(machine.PinConfig{machine.PinOutput}) + + // configure display + display.Configure(ili9341.Config{}) + display.SetRotation(ili9341.Rotation270) + display.FillScreen(black) + + backlight.High() + + terminal = tinyterm.NewTerminal(display) + terminal.Configure(&tinyterm.Config{ + Font: font, + FontHeight: 10, + FontOffset: 6, + UseSoftwareScroll: true, + }) +}