Skip to content

Commit 553633e

Browse files
committed
examples: tinyscan to replace clue-scanner, also works on pyportal and pybadge+airlift
Signed-off-by: deadprogram <[email protected]>
1 parent b6fde65 commit 553633e

File tree

5 files changed

+187
-87
lines changed

5 files changed

+187
-87
lines changed

examples/clue-scanner/main.go

Lines changed: 0 additions & 87 deletions
This file was deleted.

examples/tinyscan/clue.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//go:build clue
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/st7789"
9+
"tinygo.org/x/tinyfont/proggy"
10+
"tinygo.org/x/tinyterm"
11+
)
12+
13+
var (
14+
font = &proggy.TinySZ8pt7b
15+
)
16+
17+
func initTerminal() {
18+
machine.SPI1.Configure(machine.SPIConfig{
19+
Frequency: 8000000,
20+
SCK: machine.TFT_SCK,
21+
SDO: machine.TFT_SDO,
22+
SDI: machine.TFT_SDO,
23+
Mode: 0,
24+
})
25+
26+
display := st7789.New(machine.SPI1,
27+
machine.TFT_RESET,
28+
machine.TFT_DC,
29+
machine.TFT_CS,
30+
machine.TFT_LITE)
31+
32+
display.Configure(st7789.Config{
33+
Rotation: st7789.ROTATION_90,
34+
//Height: 320,
35+
FrameRate: st7789.FRAMERATE_111,
36+
VSyncLines: st7789.MAX_VSYNC_SCANLINES,
37+
})
38+
39+
display.FillScreen(black)
40+
41+
terminal = tinyterm.NewTerminal(&display)
42+
terminal.Configure(&tinyterm.Config{
43+
Font: font,
44+
FontHeight: 10,
45+
FontOffset: 6,
46+
UseSoftwareScroll: true,
47+
})
48+
}

examples/tinyscan/main.go

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"image/color"
6+
"time"
7+
8+
"tinygo.org/x/bluetooth"
9+
"tinygo.org/x/tinyterm"
10+
)
11+
12+
var (
13+
terminal *tinyterm.Terminal
14+
15+
black = color.RGBA{0, 0, 0, 255}
16+
adapter = bluetooth.DefaultAdapter
17+
)
18+
19+
func main() {
20+
initTerminal()
21+
22+
terminalOutput("enable interface...")
23+
24+
must("enable BLE interface", adapter.Enable())
25+
time.Sleep(time.Second)
26+
27+
terminalOutput("start scan...")
28+
29+
must("start scan", adapter.Scan(scanHandler))
30+
31+
for {
32+
time.Sleep(time.Minute)
33+
terminalOutput("scanning...")
34+
}
35+
}
36+
37+
func scanHandler(adapter *bluetooth.Adapter, device bluetooth.ScanResult) {
38+
msg := fmt.Sprintf("%s %d %s", device.Address.String(), device.RSSI, device.LocalName())
39+
terminalOutput(msg)
40+
}
41+
42+
func must(action string, err error) {
43+
if err != nil {
44+
for {
45+
terminalOutput("failed to " + action + ": " + err.Error())
46+
47+
time.Sleep(time.Second)
48+
}
49+
}
50+
}
51+
52+
func terminalOutput(s string) {
53+
println(s)
54+
fmt.Fprintf(terminal, "\n%s", s)
55+
}

examples/tinyscan/pybadge.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//go:build pybadge
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/st7735"
9+
"tinygo.org/x/tinyfont"
10+
"tinygo.org/x/tinyterm"
11+
)
12+
13+
var (
14+
font = &tinyfont.Picopixel
15+
)
16+
17+
func initTerminal() {
18+
machine.SPI1.Configure(machine.SPIConfig{
19+
SCK: machine.SPI1_SCK_PIN,
20+
SDO: machine.SPI1_SDO_PIN,
21+
SDI: machine.SPI1_SDI_PIN,
22+
Frequency: 8000000,
23+
})
24+
25+
display := st7735.New(machine.SPI1, machine.TFT_RST, machine.TFT_DC, machine.TFT_CS, machine.TFT_LITE)
26+
display.Configure(st7735.Config{
27+
Rotation: st7735.ROTATION_90,
28+
})
29+
30+
display.FillScreen(black)
31+
32+
terminal = tinyterm.NewTerminal(&display)
33+
terminal.Configure(&tinyterm.Config{
34+
Font: font,
35+
FontHeight: 8,
36+
FontOffset: 4,
37+
UseSoftwareScroll: true,
38+
})
39+
}

examples/tinyscan/pyportal.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
//go:build pyportal
2+
3+
package main
4+
5+
import (
6+
"machine"
7+
8+
"tinygo.org/x/drivers/ili9341"
9+
"tinygo.org/x/tinyfont/proggy"
10+
"tinygo.org/x/tinyterm"
11+
)
12+
13+
var (
14+
font = &proggy.TinySZ8pt7b
15+
)
16+
17+
func initTerminal() {
18+
display := ili9341.NewParallel(
19+
machine.LCD_DATA0,
20+
machine.TFT_WR,
21+
machine.TFT_DC,
22+
machine.TFT_CS,
23+
machine.TFT_RESET,
24+
machine.TFT_RD,
25+
)
26+
27+
// configure backlight
28+
backlight := machine.TFT_BACKLIGHT
29+
backlight.Configure(machine.PinConfig{machine.PinOutput})
30+
31+
// configure display
32+
display.Configure(ili9341.Config{})
33+
display.SetRotation(ili9341.Rotation270)
34+
display.FillScreen(black)
35+
36+
backlight.High()
37+
38+
terminal = tinyterm.NewTerminal(display)
39+
terminal.Configure(&tinyterm.Config{
40+
Font: font,
41+
FontHeight: 10,
42+
FontOffset: 6,
43+
UseSoftwareScroll: true,
44+
})
45+
}

0 commit comments

Comments
 (0)