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.
22 #include "test-frame.c"
24 #define BIG_FONT FrutigerLT_Roman_64_font
25 #define VOLT_FONT FrutigerLT_Roman_64_font
26 #define SMALL_FONT NotoMono_12_font
27 #define TINY_FONT NotoMono_10_font
28 #define LOGO_FONT BenguiatGothicStd_Bold_26_font
30 #define LABEL_Y (int16_t) (SMALL_FONT.ascent)
31 #define VALUE_Y (int16_t) (LABEL_Y + BIG_FONT.ascent)
34 #define BOX_LABEL_X 30
35 #define VOLT_LABEL_X 25
36 #define RSSI_LABEL_X 15
37 #define PAD_LABEL_X 95
38 #define SEP_X (PAD_X - 10)
40 static int box_number = 1;
41 static int pad_number = 1;
42 static int do_polys = 1;
43 static int scan_number = 0;
45 static const struct ao_coord trek[] = {
49 { .x = 120, .y = 40 },
52 #define NCOORD_TREK (sizeof(trek)/sizeof(trek[0]))
54 static const struct ao_coord donut[] = {
67 #define NCOORD_DONUT (sizeof(donut)/sizeof(donut[0]))
69 static const struct ao_coord bowtie[] = {
76 #define NCOORD_BOWTIE (sizeof(bowtie)/sizeof(bowtie[0]))
78 static const struct ao_transform logo_transform = {
79 .x_scale = 48, .x_off = 0,
80 .y_scale = 48, .y_off = 0,
83 #define SCAN_X (WIDTH - 100) / 2
87 #define FOUND_WIDTH 14
88 #define MAX_VALID (WIDTH / FOUND_WIDTH)
90 static const struct ao_transform bowtie_transform = {
91 .x_scale = 1, .x_off = 50,
92 .y_scale = 1, .y_off = 20,
95 static const float pad_volts = 12.3f;
96 static const float lco_volts = 4.1f;
97 static const int rssi = -30;
99 static int boxes[] = { 1, 2, 3, 5, 8, 11, 13, 17, 19, 23, 29, 31, 37, 62, 97 };
101 static int max_box = 97;
103 #define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
111 for (i = 0; i < ARRAYSIZE(boxes); i++)
120 for (int n = box_number + 1; n <= max_box; n++)
131 for (int n = box_number - 1; n >= 0; n--)
136 box_number = max_box;
139 void HandleExpose(Display *dpy, Window win, GC gc)
146 ao_rect(&fb, 0, 0, WIDTH, HEIGHT, 0xffffffff, AO_COPY);
149 current_timeout = TIMEOUT;
154 ao_logo(&fb, &logo_transform, &LOGO_FONT, 0x00000000, AO_COPY);
156 ao_rect(&fb, SCAN_X, SCAN_Y, (int16_t) scan_number, SCAN_HEIGHT, 0x00000000, AO_COPY);
159 for (i = scan_number; i > 1; i--) {
166 for (; i <= scan_number; i++) {
168 sprintf(str, "%02d", i);
169 ao_text(&fb, &TINY_FONT, 0 + FOUND_WIDTH * b, FOUND_Y, str, 0x00000000, AO_COPY);
176 ao_poly(&fb, trek, NCOORD_TREK, NULL, 0x00000000, AO_COPY);
177 ao_poly(&fb, donut, NCOORD_DONUT, NULL, 0x00000000, AO_COPY);
180 ao_poly(&fb, bowtie, NCOORD_BOWTIE, &bowtie_transform, 0x00000000, AO_COPY);
184 switch (box_number) {
186 sprintf(str, "%4.1f", lco_volts);
187 ao_text(&fb, &VOLT_FONT, BOX_X, VALUE_Y, str, 0x00000000, AO_COPY);
188 ao_text(&fb, &SMALL_FONT, VOLT_LABEL_X, LABEL_Y, "LCO Battery", 0x00000000, AO_COPY);
191 switch (pad_number) {
193 sprintf(str, "%4.1f", pad_volts);
194 ao_text(&fb, &VOLT_FONT, BOX_X, VALUE_Y, str, 0x00000000, AO_COPY);
195 ao_text(&fb, &SMALL_FONT, VOLT_LABEL_X, LABEL_Y, "Pad Battery", 0x00000000, AO_COPY);
198 sprintf(str, "%4d", rssi);
199 ao_text(&fb, &VOLT_FONT, BOX_X, VALUE_Y, str, 0x00000000, AO_COPY);
200 ao_text(&fb, &SMALL_FONT, RSSI_LABEL_X, LABEL_Y, "Signal Strength", 0x00000000, AO_COPY);
203 sprintf(str, "%02d", box_number);
204 ao_text(&fb, &BIG_FONT, BOX_X, VALUE_Y, str, 0x00000000, AO_COPY);
205 ao_text(&fb, &SMALL_FONT, BOX_LABEL_X, LABEL_Y, "Box", 0x00000000, AO_COPY);
207 sprintf(str, "%d", pad_number);
208 ao_text(&fb, &BIG_FONT, PAD_X, VALUE_Y, str, 0x00000000, AO_COPY);
209 ao_text(&fb, &SMALL_FONT, PAD_LABEL_X, LABEL_Y, "Pad", 0x00000000, AO_COPY);
211 ao_rect(&fb, SEP_X, 0, 2, HEIGHT, 0x00000000, AO_COPY);
218 DoDisplay(dpy, win, gc);
222 HandleKeyPress(Display *dpy, Window win, GC gc, XEvent *ev)
225 if (XLookupString ((XKeyEvent *) ev, string, sizeof (string), 0, 0) >= 1) {
230 if (box_number != 0) {
237 if (box_number != 0) {
264 if (scan_number < 99)
274 HandleExpose(dpy, win, gc);
279 HandleKeyRelease(Display *dpy, Window win, GC gc, XEvent *ev)
288 HandleTimeout(Display *dpy, Window win, GC gc)
291 if (scan_number < 99)
294 box_number = boxes[0];
298 HandleExpose(dpy, win, gc);