-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
display_lcd.go
88 lines (77 loc) · 1.94 KB
/
display_lcd.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package main
import (
"fmt"
"image/color"
"machine"
"strings"
"time"
"github.com/itohio/FishFeeder/st7735"
"tinygo.org/x/drivers"
"tinygo.org/x/drivers/image/png"
)
var display Display
type Display struct {
st7735.Device
}
var _ drivers.Displayer = &Display{}
func newDisplay() Display {
spi := machine.SPI3
spi.Configure(machine.SPIConfig{
Frequency: 32000000,
SCK: displaySCK,
SDO: displaySDO,
})
time.Sleep(time.Second)
display := st7735.New(spi, displayRST, displayDC, displayCS, displayBL)
display.Configure(st7735.Config{
Model: st7735.MINI80x160,
Width: 80,
Height: 160,
ColumnOffset: 26,
RowOffset: 1,
Rotation: st7735.ROTATION_270,
})
return Display{
Device: display,
}
}
func (d *Display) Bar(x, y, i, w int16, c color.RGBA) {
if i < 0 {
i = 0
}
if i > w {
i = w
}
if i != 0 {
d.FillRectangle(x, y, i, 7, c)
}
if i != w {
d.FillRectangle(x+i, y, w-i, 7, color.RGBA{20, 20, 20, 255})
}
}
var buffer [3 * 256]uint16
// NOTE: This part does not work with tinygo version 0.23.0 windows/amd64 (using go version go1.18 and LLVM version 14.0.0)
// The effect is that some memory overwrite occurs (serios BUG that should be isolated) and panics happen.
// However, it is mostly not needed due to the fact, that raw bytes of the icons are smaller than embedded PNG files.
func (d *Display) DrawPng(x0, y0 int16, pngImage string) error {
p := strings.NewReader(pngImage)
png.SetCallback(buffer[:], func(data []uint16, x, y, w, h, width, height int16) {
W, H := d.Size()
println(x0+x, y0+y, w, h, width, height, W, H, len(data))
err := d.DrawRGBBitmap(x0+x, y0+y, data[:w*h], w, h)
if err != nil {
println(fmt.Errorf("error drawPng: %s", err))
}
})
println("decode")
w, h := d.Size()
println(w, h)
_, err := png.Decode(p)
println("decode done")
w, h = d.Size()
println(w, h)
if err != nil {
println(fmt.Errorf("error drawPng: %s", err))
}
return err
}