Skip to content

Commit a148876

Browse files
committed
altos/telelco-v3: Minor UI tweaks
"Box"→"Bank" to match docs. Auto-center text instead of pre-computing. Way easier. Scroll found banks during startup. Signed-off-by: Keith Packard <[email protected]>
1 parent 7977ff5 commit a148876

File tree

2 files changed

+85
-40
lines changed

2 files changed

+85
-40
lines changed

src/drivers/ao_lco_bits.c

+21-1
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,26 @@ ao_lco_set_firing(uint8_t firing)
381381
ao_wakeup(&ao_lco_armed);
382382
}
383383

384+
#if 0
385+
static int16_t fake_boxes[] = {
386+
1, 2, 3, 5, 8, 11, 13, 17, 19, 23, 29, 31, 37, 62, 97
387+
};
388+
#define ARRAYSIZE(a) (sizeof(a) / sizeof((a)[0]))
389+
#define NFAKE ARRAYSIZE(fake_boxes)
390+
391+
static bool
392+
is_fake(int16_t box)
393+
{
394+
unsigned i;
395+
for (i = 0; i < NFAKE; i++)
396+
if (fake_boxes[i] == box)
397+
return true;
398+
return false;
399+
}
400+
#else
401+
#define is_fake(b) false
402+
#endif
403+
384404
void
385405
ao_lco_search(void)
386406
{
@@ -407,7 +427,7 @@ ao_lco_search(void)
407427
ao_lco_tick_offset[box] = 0;
408428
r = ao_lco_query((uint16_t) box, &ao_pad_query, &ao_lco_tick_offset[box]);
409429
PRINTD("box %d result %d offset %d\n", box, r, ao_lco_tick_offset[box]);
410-
if (r == AO_RADIO_CMAC_OK) {
430+
if (r == AO_RADIO_CMAC_OK || is_fake(box)) {
411431
++boxes;
412432
ao_lco_box_set_present(box);
413433
#ifdef AO_LCO_SEARCH_API

src/telelco-v3.0/ao_lco_v3.c

+64-39
Original file line numberDiff line numberDiff line change
@@ -56,19 +56,22 @@ static const struct ao_transform show_transform = {
5656
#define LOGO_FONT BenguiatGothicStd_Bold_26_font
5757

5858
#define LABEL_Y (int16_t) (SMALL_FONT.ascent)
59-
#define VALUE_Y (int16_t) (LABEL_Y + BIG_FONT.ascent + 5)
60-
#define BOX_X 2
61-
#define PAD_X 90
62-
#define BOX_LABEL_X 26
59+
#define VALUE_Y (int16_t) (LABEL_Y + 5 + BIG_FONT.ascent)
60+
61+
#define SEP_X 82
62+
#define SEP_WIDTH 2
63+
64+
#define BOX_X (SEP_X / 2)
65+
#define PAD_X ((WIDTH + SEP_X + SEP_WIDTH) / 2)
66+
6367
#define VALUE_LABEL_X 64
6468
#define RSSI_LABEL_X 15
65-
#define PAD_LABEL_X 95
66-
#define SEP_X (PAD_X - 8)
69+
6770
#define SCAN_X (WIDTH - 100) / 2
6871
#define SCAN_Y 50
6972
#define SCAN_HEIGHT 3
7073
#define FOUND_Y 63
71-
#define FOUND_X 6
74+
#define FOUND_X 3
7275
#define FOUND_WIDTH (WIDTH - 6)
7376
#define CONTRAST_LABEL_X 37
7477
#define CONTRAST_WIDTH 100
@@ -95,42 +98,47 @@ static uint8_t ao_lco_select_mode;
9598
static uint8_t ao_lco_event_debug;
9699

97100
#define PRINTE(...) do { if (!ao_lco_debug && !ao_lco_event_debug) break; printf ("\r%5lu %s: ", (unsigned long) ao_tick_count, __func__); printf(__VA_ARGS__); flush(); } while(0)
98-
#define AO_LCO_SELECT_PAD 0
99-
#define AO_LCO_SELECT_BOX 1
101+
#define AO_LCO_SELECT_BOX 0
102+
#define AO_LCO_SELECT_PAD 1
100103

101104
static uint8_t ao_lco_display_mutex;
102105

106+
static void
107+
_ao_center_text(int16_t x, int16_t y, const struct ao_font *font, const char *str)
108+
{
109+
int16_t width = ao_text_width(font, str);
110+
ao_text(&fb, font, x - width/2, y, str, AO_BLACK, AO_COPY);
111+
}
112+
103113
static void
104114
_ao_lco_show_pad(int8_t pad)
105115
{
106116
char str[5];
107117

118+
_ao_center_text(PAD_X, LABEL_Y, &SMALL_FONT, "Pad");
108119
snprintf(str, sizeof(str), "%d", pad);
109-
ao_text(&fb, &BIG_FONT, PAD_X, VALUE_Y, str, AO_BLACK, AO_COPY);
110-
ao_text(&fb, &SMALL_FONT, PAD_LABEL_X, LABEL_Y, "Pad", AO_BLACK, AO_COPY);
120+
_ao_center_text(PAD_X, VALUE_Y, &BIG_FONT, str);
111121
}
112122

113123
static void
114124
_ao_lco_show_box(int16_t box)
115125
{
116126
char str[7];
117127

118-
snprintf(str, sizeof(str), "%2d", box);
119-
ao_text(&fb, &BIG_FONT, BOX_X, VALUE_Y, str, AO_BLACK, AO_COPY);
120-
ao_text(&fb, &SMALL_FONT, BOX_LABEL_X, LABEL_Y, "Box", AO_BLACK, AO_COPY);
128+
_ao_center_text(BOX_X, LABEL_Y, &SMALL_FONT, "Bank");
129+
snprintf(str, sizeof(str), "%d", box);
130+
_ao_center_text(BOX_X, VALUE_Y, &BIG_FONT, str);
121131
}
122132

123133
static void
124134
_ao_lco_show_voltage(uint16_t decivolts, const char *label)
125135
{
126136
char str[7];
127-
int16_t width;
128137

129138
PRINTD("voltage %d\n", decivolts);
130-
snprintf(str, sizeof(str), "%2d.%d", decivolts / 10, decivolts % 10);
131-
ao_text(&fb, &VOLT_FONT, BOX_X, VALUE_Y, str, AO_BLACK, AO_COPY);
132-
width = ao_text_width(&SMALL_FONT, label);
133-
ao_text(&fb, &SMALL_FONT, VALUE_LABEL_X - width/2, LABEL_Y, label, AO_BLACK, AO_COPY);
139+
_ao_center_text(WIDTH/2, LABEL_Y, &SMALL_FONT, label);
140+
snprintf(str, sizeof(str), "%d.%d", decivolts / 10, decivolts % 10);
141+
_ao_center_text(WIDTH/2, VALUE_Y, &BIG_FONT, str);
134142
}
135143

136144
static void
@@ -151,14 +159,11 @@ _ao_lco_show_contrast(void)
151159
char buf[8];
152160
uint8_t brightness = ao_st7565_get_brightness();
153161
int16_t contrast = (int16_t) (brightness * CONTRAST_WIDTH / AO_LCO_MAX_CONTRAST);
154-
int16_t width;
155162

156-
ao_text(&fb, &SMALL_FONT, CONTRAST_LABEL_X, LABEL_Y, "Contrast", AO_BLACK, AO_COPY);
163+
_ao_center_text(WIDTH/2, LABEL_Y, &SMALL_FONT, "Contrast");
157164
ao_rect(&fb, CONTRAST_X, CONTRAST_Y, contrast, CONTRAST_HEIGHT, AO_BLACK, AO_COPY);
158-
/* this "knows" that CONTRAST_WIDTH == 100 */
159-
snprintf(buf, sizeof(buf), "%d %%", contrast);
160-
width = ao_text_width(&SMALL_FONT, buf);
161-
ao_text(&fb, &SMALL_FONT, BACKLIGHT_VALUE_X - width / 2, BACKLIGHT_VALUE_Y, buf, AO_BLACK, AO_COPY);
165+
snprintf(buf, sizeof(buf), "%d %%", brightness * 100 / AO_LCO_MAX_CONTRAST);
166+
_ao_center_text(WIDTH/2, CONTRAST_VALUE_Y, &SMALL_FONT, buf);
162167
}
163168

164169
static void
@@ -167,14 +172,11 @@ _ao_lco_show_backlight(void)
167172
char buf[8];
168173
int32_t backlight = ao_lco_get_backlight();
169174
int16_t value = (int16_t) (backlight * BACKLIGHT_WIDTH / AO_LCO_MAX_BACKLIGHT);
170-
int16_t width;
171175

172-
ao_text(&fb, &SMALL_FONT, BACKLIGHT_LABEL_X, LABEL_Y, "Backlight", AO_BLACK, AO_COPY);
176+
_ao_center_text(WIDTH/2, LABEL_Y, &SMALL_FONT, "Backlight");
173177
ao_rect(&fb, BACKLIGHT_X, BACKLIGHT_Y, value, BACKLIGHT_HEIGHT, AO_BLACK, AO_COPY);
174-
/* this "knows" that BACKLIGHT_WIDTH == 100 */
175-
snprintf(buf, sizeof(buf), "%d %%", value);
176-
width = ao_text_width(&SMALL_FONT, buf);
177-
ao_text(&fb, &SMALL_FONT, BACKLIGHT_VALUE_X - width / 2, BACKLIGHT_VALUE_Y, buf, AO_BLACK, AO_COPY);
178+
snprintf(buf, sizeof(buf), "%ld %%", backlight * 100 / AO_LCO_MAX_BACKLIGHT);
179+
_ao_center_text(WIDTH/2, BACKLIGHT_VALUE_Y, &SMALL_FONT, buf);
178180
}
179181

180182
static int16_t info_y;
@@ -210,7 +212,7 @@ _ao_lco_show_rssi(void)
210212
{
211213
char label[20];
212214
int16_t width;
213-
snprintf(label, sizeof(label), "Box %d RSSI", ao_lco_box);
215+
snprintf(label, sizeof(label), "Bank %d RSSI", ao_lco_box);
214216
width = ao_text_width(&SMALL_FONT, label);
215217
ao_text(&fb, &SMALL_FONT, VALUE_LABEL_X - width / 2, LABEL_Y, label, AO_BLACK, AO_COPY);
216218
if (!(ao_lco_valid[ao_lco_box] & AO_LCO_VALID_LAST))
@@ -225,7 +227,7 @@ static void
225227
_ao_lco_show_pad_battery(void)
226228
{
227229
char label[20];
228-
snprintf(label, sizeof(label), "Box %d Battery", ao_lco_box);
230+
snprintf(label, sizeof(label), "Bank %d Battery", ao_lco_box);
229231
_ao_lco_show_voltage(ao_pad_query.battery, label);
230232
}
231233

@@ -258,7 +260,7 @@ ao_lco_show(void)
258260
default:
259261
_ao_lco_show_pad(ao_lco_pad);
260262
_ao_lco_show_box(ao_lco_box);
261-
ao_rect(&fb, SEP_X, 0, 2, HEIGHT, AO_BLACK, AO_COPY);
263+
ao_rect(&fb, SEP_X, 0, SEP_WIDTH, HEIGHT, AO_BLACK, AO_COPY);
262264
}
263265
break;
264266
}
@@ -420,14 +422,18 @@ static struct ao_task ao_lco_monitor_task;
420422
static struct ao_task ao_lco_arm_warn_task;
421423
static struct ao_task ao_lco_igniter_status_task;
422424

423-
static int16_t found_x;
425+
static int16_t found_width;
426+
#define MAX_FOUND 32
427+
static int16_t found_boxes[MAX_FOUND];
428+
static uint8_t nfound;
424429

425430
void
426431
ao_lco_search_start(void)
427432
{
428433
ao_rect(&fb, 0, 0, WIDTH, HEIGHT, AO_WHITE, AO_COPY);
429434
ao_logo(&fb, &logo_transform, &LOGO_FONT, AO_BLACK, AO_COPY);
430-
found_x = FOUND_X;
435+
found_width = 0;
436+
nfound = 0;
431437
}
432438

433439
void
@@ -442,11 +448,30 @@ void
442448
ao_lco_search_box_present(int16_t box)
443449
{
444450
char str[8];
445-
if (found_x < FOUND_WIDTH)
451+
int16_t width;
452+
int16_t box_top = FOUND_Y - TINY_FONT.ascent;
453+
int16_t x;
454+
uint8_t n;
455+
456+
snprintf(str, sizeof(str), "%s%u", nfound ? ", " : "", box);
457+
width = ao_text_width(&TINY_FONT, str);
458+
while (found_width + width > FOUND_WIDTH || nfound == MAX_FOUND)
446459
{
447-
snprintf(str, sizeof(str), "%s%02u", found_x ? ", " : "", box);
448-
found_x = ao_text(&fb, &TINY_FONT, found_x, FOUND_Y, str, AO_BLACK, AO_COPY);
460+
snprintf(str, sizeof(str), "%u, ", found_boxes[0]);
461+
found_width -= ao_text_width(&TINY_FONT, str);
462+
memmove(&found_boxes[0], &found_boxes[1], (nfound - 1) * sizeof (int16_t));
463+
nfound--;
464+
}
465+
found_boxes[nfound++] = box;
466+
467+
ao_rect(&fb, FOUND_X, FOUND_Y - TINY_FONT.ascent, FOUND_WIDTH, HEIGHT - box_top, AO_WHITE, AO_COPY);
468+
x = FOUND_X;
469+
for (n = 0; n < nfound; n++) {
470+
snprintf(str, sizeof(str), "%s%u", n ? ", " : "", found_boxes[n]);
471+
int16_t next_x = ao_text(&fb, &TINY_FONT, x, FOUND_Y, str, AO_BLACK, AO_COPY);
472+
x = next_x;
449473
}
474+
found_width = x - FOUND_X;
450475
}
451476

452477
void

0 commit comments

Comments
 (0)