2 * Copyright © 2023 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
20 #include <ao_st7565.h>
22 #define WIDTH AO_ST7565_WIDTH
23 #define HEIGHT AO_ST7565_HEIGHT
24 #define STRIDE AO_BITMAP_STRIDE(WIDTH)
26 static uint32_t image[STRIDE * HEIGHT];
28 static struct ao_bitmap fb = {
33 .damage = AO_BOX_INIT,
39 ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
40 ao_st7565_update(&fb);
41 ao_text(&fb, &BitstreamVeraSans_Roman_24_font,
42 0, 20, "hello world", AO_BLACK, AO_COPY);
43 ao_st7565_update(&fb);
46 static int16_t x1 = 32, _y1 = 10, x2 = 32, y2 = 40;
47 static int16_t dx1 = 2, dy1 = 2, dx2 = -2, dy2 = -1;
49 #define bounds(v,m,M,d) \
63 for (i = 0; i < 100; i++) {
64 ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
65 ao_line(&fb, x1, _y1, x2, y2, AO_BLACK, AO_COPY);
66 ao_st7565_update(&fb);
71 printf("%d,%d - %d,%d\n", x1, _y1, x2, y2);
73 bounds(x1, 0, WIDTH, dx1);
74 bounds(x2, 0, WIDTH, dx2);
75 bounds(_y1, 0, HEIGHT, dy1);
76 bounds(y2, 0, HEIGHT, dy2);
77 ao_delay(AO_MS_TO_TICKS(200));
81 static const float pad_volts = 12.3f;
82 static const float lco_volts = 4.1f;
83 static const int rssi = -30;
85 static int boxes[] = { 1, 2, 3, 5, 8, 11, 13, 17, 19, 23, 29, 31, 37, 62, 97 };
87 //static int max_box = 97;
89 #define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
97 for (i = 0; i < ARRAYSIZE(boxes); i++)
107 for (int n = box_number + 1; n <= max_box; n++)
118 for (int n = box_number - 1; n >= 0; n--)
123 box_number = max_box;
127 static const struct ao_transform logo_transform = {
128 .x_scale = 48, .x_off = 2,
129 .y_scale = 48, .y_off = 0,
132 #define BIG_FONT BitstreamVeraSans_Roman_58_font
133 #define VOLT_FONT BitstreamVeraSans_Roman_58_font
134 #define SMALL_FONT BitstreamVeraSans_Roman_12_font
135 #define TINY_FONT BitstreamVeraSans_Roman_10_font
136 #define LOGO_FONT BenguiatGothicStd_Bold_26_font
138 #define LABEL_Y (int16_t) (SMALL_FONT.ascent)
139 #define VALUE_Y (int16_t) (LABEL_Y + BIG_FONT.ascent + 5)
142 #define BOX_LABEL_X 30
143 #define VOLT_LABEL_X 25
144 #define RSSI_LABEL_X 15
145 #define PAD_LABEL_X 95
146 #define SEP_X (PAD_X - 8)
147 #define SCAN_X (WIDTH - 100) / 2
149 #define SCAN_HEIGHT 3
152 #define FOUND_WIDTH 17
153 #define MAX_VALID (WIDTH / FOUND_WIDTH)
155 static int16_t box_number = 88;
156 static int16_t pad_number = 8;
168 for (scan_number = 0; scan_number < 100; scan_number++) {
169 ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
170 ao_logo(&fb, &logo_transform, &LOGO_FONT, AO_BLACK, AO_COPY);
172 ao_rect(&fb, SCAN_X, SCAN_Y, (int16_t) scan_number, SCAN_HEIGHT, AO_BLACK, AO_COPY);
176 for (i = scan_number; i > 1; i--) {
185 for (; i <= scan_number; i++) {
187 sprintf(str, "%02d%s", i, i == last_box ? "" : ",");
188 ao_text(&fb, &TINY_FONT, (int16_t) (FOUND_X + FOUND_WIDTH * b),
189 FOUND_Y, str, AO_BLACK, AO_COPY);
194 ao_st7565_update(&fb);
195 ao_delay(AO_MS_TO_TICKS(50));
197 ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
198 switch (box_number) {
200 sprintf(str, "%4.1f", lco_volts);
201 ao_text(&fb, &VOLT_FONT, BOX_X, VALUE_Y, str, AO_BLACK, AO_COPY);
202 ao_text(&fb, &SMALL_FONT, VOLT_LABEL_X, LABEL_Y, "LCO Battery", AO_BLACK, AO_COPY);
205 switch (pad_number) {
207 sprintf(str, "%4.1f", pad_volts);
208 ao_text(&fb, &VOLT_FONT, BOX_X, VALUE_Y, str, AO_BLACK, AO_COPY);
209 ao_text(&fb, &SMALL_FONT, VOLT_LABEL_X, LABEL_Y, "Pad Battery", AO_BLACK, AO_COPY);
212 sprintf(str, "%4d", rssi);
213 ao_text(&fb, &VOLT_FONT, BOX_X, VALUE_Y, str, AO_BLACK, AO_COPY);
214 ao_text(&fb, &SMALL_FONT, RSSI_LABEL_X, LABEL_Y, "Signal Strength", AO_BLACK, AO_COPY);
217 sprintf(str, "%02d", box_number);
218 ao_text(&fb, &BIG_FONT, BOX_X, VALUE_Y, str, AO_BLACK, AO_COPY);
219 ao_text(&fb, &SMALL_FONT, BOX_LABEL_X, LABEL_Y, "Box", AO_BLACK, AO_COPY);
221 sprintf(str, "%d", pad_number);
222 ao_text(&fb, &BIG_FONT, PAD_X, VALUE_Y, str, AO_BLACK, AO_COPY);
223 ao_text(&fb, &SMALL_FONT, PAD_LABEL_X, LABEL_Y, "Pad", AO_BLACK, AO_COPY);
225 ao_rect(&fb, SEP_X, 0, 2, HEIGHT, AO_BLACK, AO_COPY);
229 ao_st7565_update(&fb);
232 const struct ao_cmds ao_st7565_cmds[] = {
233 { ao_st7565_test, "g\0Test ST7565 display" },
234 { ao_st7565_line, "l\0Draw lines" },
235 { ao_st7565_poly, "p\0Draw polygon" },
251 ao_cmd_register(ao_st7565_cmds);
252 ao_start_scheduler();