-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathfont.go
More file actions
203 lines (187 loc) · 6.99 KB
/
Copy pathfont.go
File metadata and controls
203 lines (187 loc) · 6.99 KB
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
package main
// Variable-width 8-pixel high font matching the C firmware
// Format: first byte is width, following bytes are column data (one per column)
// Each column byte: bit 7 = top pixel, bit 0 = bottom pixel
const FONT_HEIGHT = 8
// Maximum width of any character (for fixed array size)
const FONT_MAX_WIDTH = 8
// Font data for printable ASCII characters (0x20-0x7F)
// Each entry: [0]=width, [1..width]=column data
// Converted from tiny-firmware/gen/font.inc
var fontData = [96][FONT_MAX_WIDTH + 1]byte{
/* 0x20 */ {0x01, 0x00},
/* 0x21 ! */ {0x02, 0xfa, 0xfa},
/* 0x22 " */ {0x03, 0xc0, 0x00, 0xc0},
/* 0x23 # */ {0x05, 0x6c, 0xfe, 0x6c, 0xfe, 0x6c},
/* 0x24 $ */ {0x05, 0x32, 0xff, 0x5a, 0xff, 0x4c},
/* 0x25 % */ {0x06, 0xc0, 0xc6, 0x1c, 0x70, 0xc6, 0x06},
/* 0x26 & */ {0x06, 0x5c, 0xfe, 0xb2, 0xfe, 0x4c, 0x1e},
/* 0x27 ' */ {0x01, 0xc0},
/* 0x28 ( */ {0x03, 0x38, 0x7c, 0x82},
/* 0x29 ) */ {0x03, 0x82, 0x7c, 0x38},
/* 0x2a * */ {0x05, 0x6c, 0x38, 0xfe, 0x38, 0x6c},
/* 0x2b + */ {0x05, 0x10, 0x10, 0x7c, 0x10, 0x10},
/* 0x2c , */ {0x02, 0x03, 0x06},
/* 0x2d - */ {0x04, 0x10, 0x10, 0x10, 0x10},
/* 0x2e . */ {0x02, 0x06, 0x06},
/* 0x2f / */ {0x03, 0x0e, 0x38, 0xe0},
/* 0x30 0 */ {0x05, 0x7c, 0xfe, 0x82, 0xfe, 0x7c},
/* 0x31 1 */ {0x03, 0x40, 0xfe, 0xfe},
/* 0x32 2 */ {0x05, 0x8e, 0x9e, 0x92, 0xf2, 0x62},
/* 0x33 3 */ {0x05, 0x82, 0x92, 0x92, 0xfe, 0x6c},
/* 0x34 4 */ {0x05, 0x18, 0x28, 0x48, 0xfe, 0xfe},
/* 0x35 5 */ {0x05, 0xe2, 0xa2, 0xa2, 0xbe, 0x1c},
/* 0x36 6 */ {0x05, 0x7c, 0xfe, 0xa2, 0xbe, 0x1c},
/* 0x37 7 */ {0x05, 0x80, 0x8e, 0xbe, 0xf0, 0xc0},
/* 0x38 8 */ {0x05, 0x6c, 0xfe, 0x92, 0xfe, 0x6c},
/* 0x39 9 */ {0x05, 0x70, 0xfa, 0x8a, 0xfe, 0x7c},
/* 0x3a : */ {0x02, 0x36, 0x36},
/* 0x3b ; */ {0x02, 0x33, 0x36},
/* 0x3c < */ {0x04, 0x10, 0x38, 0x6c, 0xc6},
/* 0x3d = */ {0x04, 0x28, 0x28, 0x28, 0x28},
/* 0x3e > */ {0x04, 0xc6, 0x6c, 0x38, 0x10},
/* 0x3f ? */ {0x05, 0x80, 0x9a, 0xba, 0xe0, 0x40},
/* 0x40 @ */ {0x06, 0x7c, 0xfe, 0xaa, 0xba, 0xfa, 0x78},
/* 0x41 A */ {0x05, 0x7e, 0xfe, 0x88, 0xfe, 0x7e},
/* 0x42 B */ {0x05, 0xfe, 0xfe, 0xa2, 0xfe, 0x5c},
/* 0x43 C */ {0x05, 0x7c, 0xfe, 0x82, 0x82, 0x82},
/* 0x44 D */ {0x05, 0xfe, 0xfe, 0x82, 0xfe, 0x7c},
/* 0x45 E */ {0x05, 0xfe, 0xfe, 0xa2, 0xa2, 0x82},
/* 0x46 F */ {0x05, 0xfe, 0xfe, 0xa0, 0xa0, 0x80},
/* 0x47 G */ {0x05, 0x7c, 0xfe, 0x82, 0x9e, 0x1e},
/* 0x48 H */ {0x05, 0xfe, 0xfe, 0x20, 0xfe, 0xfe},
/* 0x49 I */ {0x02, 0xfe, 0xfe},
/* 0x4a J */ {0x04, 0x02, 0x02, 0xfe, 0xfc},
/* 0x4b K */ {0x06, 0xfe, 0xfe, 0x38, 0x6c, 0xc6, 0x82},
/* 0x4c L */ {0x04, 0xfe, 0xfe, 0x02, 0x02},
/* 0x4d M */ {0x07, 0xfe, 0x7e, 0x30, 0x18, 0x30, 0x7e, 0xfe},
/* 0x4e N */ {0x06, 0xfe, 0x7e, 0x30, 0x18, 0xfc, 0xfe},
/* 0x4f O */ {0x06, 0x7c, 0xfe, 0x82, 0x82, 0xfe, 0x7c},
/* 0x50 P */ {0x05, 0xfe, 0xfe, 0x88, 0xf8, 0x70},
/* 0x51 Q */ {0x06, 0x7c, 0xfe, 0x82, 0x86, 0xff, 0x7d},
/* 0x52 R */ {0x05, 0xfe, 0xfe, 0x88, 0xfe, 0x72},
/* 0x53 S */ {0x04, 0x62, 0xf2, 0x9e, 0x8c},
/* 0x54 T */ {0x06, 0x80, 0x80, 0xfe, 0xfe, 0x80, 0x80},
/* 0x55 U */ {0x05, 0xfc, 0xfe, 0x02, 0xfe, 0xfc},
/* 0x56 V */ {0x06, 0xe0, 0xf8, 0x1e, 0x1e, 0xf8, 0xe0},
/* 0x57 W */ {0x07, 0xf0, 0xfe, 0x1e, 0x3c, 0x1e, 0xfe, 0xf0},
/* 0x58 X */ {0x06, 0xc6, 0xee, 0x38, 0x38, 0xee, 0xc6},
/* 0x59 Y */ {0x06, 0xc0, 0xe0, 0x3e, 0x3e, 0xe0, 0xc0},
/* 0x5a Z */ {0x05, 0x8e, 0x9e, 0xba, 0xf2, 0xe2},
/* 0x5b [ */ {0x03, 0xfe, 0xfe, 0x82},
/* 0x5c \ */ {0x03, 0xe0, 0x38, 0x0e},
/* 0x5d ] */ {0x03, 0x82, 0xfe, 0xfe},
/* 0x5e ^ */ {0x03, 0x60, 0xc0, 0x60},
/* 0x5f _ */ {0x06, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02},
/* 0x60 ` */ {0x02, 0x80, 0x40},
/* 0x61 a */ {0x05, 0x04, 0x2e, 0x2a, 0x3e, 0x1e},
/* 0x62 b */ {0x05, 0xfe, 0xfe, 0x22, 0x3e, 0x1c},
/* 0x63 c */ {0x05, 0x1c, 0x3e, 0x22, 0x36, 0x14},
/* 0x64 d */ {0x05, 0x1c, 0x3e, 0x22, 0xfe, 0xfe},
/* 0x65 e */ {0x05, 0x1c, 0x3e, 0x2a, 0x3a, 0x1a},
/* 0x66 f */ {0x03, 0x7e, 0xfe, 0xa0},
/* 0x67 g */ {0x05, 0x18, 0x3d, 0x25, 0x3f, 0x3e},
/* 0x68 h */ {0x05, 0xfe, 0xfe, 0x20, 0x3e, 0x1e},
/* 0x69 i */ {0x02, 0xbe, 0xbe},
/* 0x6a j */ {0x03, 0x01, 0xbf, 0xbe},
/* 0x6b k */ {0x05, 0xfe, 0xfe, 0x1c, 0x36, 0x22},
/* 0x6c l */ {0x02, 0xfe, 0xfe},
/* 0x6d m */ {0x08, 0x3e, 0x3e, 0x20, 0x3e, 0x3e, 0x20, 0x3e, 0x1e},
/* 0x6e n */ {0x05, 0x3e, 0x3e, 0x20, 0x3e, 0x1e},
/* 0x6f o */ {0x05, 0x1c, 0x3e, 0x22, 0x3e, 0x1c},
/* 0x70 p */ {0x05, 0x3f, 0x3f, 0x24, 0x3c, 0x18},
/* 0x71 q */ {0x05, 0x18, 0x3c, 0x24, 0x3f, 0x3f},
/* 0x72 r */ {0x04, 0x3e, 0x3e, 0x10, 0x30},
/* 0x73 s */ {0x04, 0x1a, 0x3a, 0x2e, 0x2c},
/* 0x74 t */ {0x03, 0xfc, 0xfe, 0x22},
/* 0x75 u */ {0x05, 0x3c, 0x3e, 0x02, 0x3e, 0x3e},
/* 0x76 v */ {0x05, 0x30, 0x3c, 0x0e, 0x3c, 0x30},
/* 0x77 w */ {0x07, 0x38, 0x3e, 0x06, 0x1c, 0x06, 0x3e, 0x38},
/* 0x78 x */ {0x05, 0x36, 0x3e, 0x08, 0x3e, 0x36},
/* 0x79 y */ {0x05, 0x38, 0x3d, 0x05, 0x3f, 0x3e},
/* 0x7a z */ {0x05, 0x26, 0x2e, 0x3a, 0x32, 0x22},
/* 0x7b { */ {0x04, 0x10, 0x7c, 0xee, 0x82},
/* 0x7c | */ {0x02, 0xff, 0xff},
/* 0x7d } */ {0x04, 0x82, 0xee, 0x7c, 0x10},
/* 0x7e ~ */ {0x04, 0x08, 0x10, 0x08, 0x10},
/* 0x7f */ {0x01, 0x00},
}
// fontCharWidth returns the width of a character in pixels
func fontCharWidth(c byte) int {
if c < 32 || c > 127 {
return 1
}
return int(fontData[c-32][0])
}
// oledDrawChar draws a single character at position (x, y)
// Returns the width of the character plus 1 pixel spacing
func oledDrawChar(x, y int, c byte) int {
if c < 32 || c > 127 {
c = '?'
}
data := &fontData[c-32]
width := int(data[0])
// Draw each column of the character
// Font data: bit 7 = top pixel, bit 0 = bottom pixel
for col := 0; col < width; col++ {
colData := data[1+col]
for row := 0; row < FONT_HEIGHT; row++ {
if colData&(1<<(7-row)) != 0 {
oledSetPixel(x+col, y+row, true)
}
}
}
return width + 1 // Character width + 1 pixel spacing
}
// oledDrawString draws a string at position (x, y)
func oledDrawString(x, y int, s string) {
curX := x
for i := 0; i < len(s); i++ {
curX += oledDrawChar(curX, y, s[i])
}
}
// oledDrawStringCenter draws a string centered horizontally
func oledDrawStringCenter(y int, s string) {
// Calculate string width
width := 0
for i := 0; i < len(s); i++ {
width += fontCharWidth(s[i]) + 1
}
if width > 0 {
width-- // Remove trailing space
}
x := (OLED_WIDTH - width) / 2
oledDrawString(x, y, s)
}
// oledDrawInt draws an integer at position (x, y)
func oledDrawInt(x, y int, val int) {
if val == 0 {
oledDrawChar(x, y, '0')
return
}
// Handle negative
if val < 0 {
x += oledDrawChar(x, y, '-')
val = -val
}
// Convert to string (reverse order)
var digits [10]byte
n := 0
for val > 0 && n < 10 {
digits[n] = byte('0' + val%10)
val /= 10
n++
}
// Draw in correct order
for i := n - 1; i >= 0; i-- {
x += oledDrawChar(x, y, digits[i])
}
}
// oledDrawHex draws a hex value at position (x, y)
func oledDrawHex(x, y int, val uint32, digits int) {
hexChars := "0123456789ABCDEF"
for i := digits - 1; i >= 0; i-- {
nibble := (val >> (i * 4)) & 0xF
x += oledDrawChar(x, y, hexChars[nibble])
}
}