rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
settings_screen_int.h
Go to the documentation of this file.
1
15#pragma once
16
17#include <stdbool.h>
18#include <stdint.h>
19
20#include "gfx.h"
21#include "settings.h"
22#include "settings_rows_int.h"
23#include "settings_screen.h"
24#include "ui_icons.h"
25#include "ui_keypad.h"
26#include "ui_screen.h"
27#include "ui_text.h"
28#include "ui_textkey.h"
29
31#define SCREEN_W UI_PANEL_W
32/* The router owns the top UI_BAND_H px and the home tag; this screen gets
33 * the body. */
35#define SCREEN_H UI_BODY_H
37#define MAX_FBS 3
38
50#define HUB_COLS 3
51#define HUB_ROWS 3
52#define HUB_M 10
53#define HUB_TW ((SCREEN_W - (HUB_COLS + 1) * HUB_M) / HUB_COLS)
54#define HUB_TH 130
55
62#define HUB_ICON_DY 14
63#define HUB_ICON 36
64#define HUB_NAME_DY 60
65#define HUB_LINE_DY 94
66
72#define STG_F_HEAD (&gfx_font_20x36)
73#define STG_F_BODY (&gfx_font_12x24)
74#define STG_F_LABEL (&gfx_font_10x20)
75
78#define STRIP_H UI_BTN_H
79#define STRIP_Y (SCREEN_H - UI_ALERT_H - 4 - STRIP_H)
80
88#define SCROLL_W 12
89#define SCROLL_X (SCREEN_W - HUB_M - SCROLL_W)
90#define LIST_X HUB_M
91#define LIST_W (SCROLL_X - 8 - LIST_X)
92#define LIST_Y 8
93#define LIST_H (STRIP_Y - 8 - LIST_Y)
94#define ROW_H 64
95#define ROW_GAP 6
96#define ROW_PITCH (ROW_H + ROW_GAP)
97#define ROW_NAME_DY 3
98#define ROW_HELP_DY 40
99
105#define BTN_W 56
106#define BTN_H UI_TAP_MIN
107_Static_assert(BTN_H <= ROW_H, "a row's buttons fit in the row");
108#define VALUE_FIELD 150
109#define PLUS_X (LIST_X + LIST_W - 12 - BTN_W)
110#define MINUS_X (PLUS_X - 8 - VALUE_FIELD - 8 - BTN_W)
111#define VALUE_R (PLUS_X - 8)
115#define VALUE_X (MINUS_X + BTN_W)
117#define VALUE_W (PLUS_X - VALUE_X)
118
119/*
120 * A "-" or "+" key is a tap: the press arms it and the release steps it
121 * once. The release counts when the same contact makes it inside the key,
122 * no further than DRAG_SLOP from the press in x and in y, with no scroll
123 * and no repeat in between. The list scrolls by a drag that starts
124 * anywhere on it, the keys included, so a key that stepped on the press
125 * would step under every scroll that starts on one.
126 *
127 * A key held repeats: a 0 to 30,000mAh range is 300 taps otherwise. The
128 * first step comes REPEAT_DELAY_S after the press, then REPEAT_SLOW_HZ, and
129 * REPEAT_FAST_HZ once the key is held REPEAT_FAST_S longer. The time runs
130 * only while the contact stays on the key within the slop, and one frame
131 * counts for at most UI_HOLD_MAX_CREDIT_S (0.25s); the release of a key
132 * that has repeated adds no step.
133 */
134#define REPEAT_DELAY_S 0.45f
135#define REPEAT_SLOW_HZ 8.0f
137#define REPEAT_FAST_S 1.8f
138#define REPEAT_FAST_HZ 30.0f
139
140/* A press that moves further than this is a scroll, not a tap. */
145#define DRAG_SLOP 8
146
147enum { HIT_NONE = 0, HIT_TILE, HIT_MINUS, HIT_PLUS, HIT_RESET, HIT_LIST,
148 HIT_SAVE, HIT_STAY, HIT_DISCARD, HIT_LEAVE_SAVE, HIT_TEXT,
149 HIT_VALUE };
150
162#define WARN_X HUB_M
163#define WARN_Y HUB_M
164#define WARN_W (SCREEN_W - 2 * HUB_M)
165#define WARN_H (STRIP_Y - HUB_M - WARN_Y)
166#define WARN_TITLE_Y 12
167#define WARN_WHY_Y 56
168#define WARN_WHY_PITCH 26
169#define WARN_LINE_Y 116
170#define WARN_PITCH 24
171#define WARN_NOTE_Y (WARN_LINE_Y + SETTINGS_WARN_LINES * WARN_PITCH + 4)
172#define WARN_NOTE_PITCH 26
173
174/*
175 * The hub's tiles, in their order on the grid, row by row. A category's
176 * tile names the category and counts its settings; a screen's tile names
177 * the screen by its title, English always, as the menu does. The home tag
178 * of a screen a tile opens leads back here (settings_screen_opens()).
179 * The hub holds the bench-wide tools only: ESC / BENCH's rows are MOTOR &
180 * ESC > SETTINGS', beside the throttle they set.
181 *
182 * Nine fit the grid. A tenth needs a second page, through ui_tabs in the
183 * strip's free columns, which is not built: the build stops at a tenth
184 * entry (the assertion under the table), and so does test_settings_pins_hub.
185 */
189typedef struct {
191 int8_t cat;
192 ui_screen_id_t screen;
194} hub_tile_t;
195
200#define HUB_CATEGORY(cat_, icon_) \
201 { (icon_), (int8_t)(cat_), SCREEN_SETUP, TX_SET_COUNT }
202
206#define HUB_SCREEN(screen_, line_, icon_) \
207 { (icon_), -1, (screen_), (line_) }
208
210static const hub_tile_t k_tiles[] = {
215 HUB_SCREEN(SCREEN_OUTPUTS, TX_SET_HUB_OUTPUTS, ui_icon_list),
216 HUB_SCREEN(SCREEN_PICKER, TX_SET_HUB_PICKER, ui_icon_board),
217 HUB_SCREEN(SCREEN_WIFI, TX_SET_HUB_WIFI, ui_icon_wifi),
218 HUB_SCREEN(SCREEN_UPDATES, TX_SET_HUB_UPDATES, ui_icon_record),
219 HUB_SCREEN(SCREEN_FILES, TX_SET_HUB_FILES, ui_icon_folder),
220};
221
223#define TILE_COUNT ((int)(sizeof(k_tiles) / sizeof(k_tiles[0])))
224
225_Static_assert(TILE_COUNT <= SETTINGS_HUB_SLOTS,
226 "a tenth SETUP tile needs the hub's second page");
227_Static_assert(SETTINGS_HUB_SLOTS == HUB_COLS * HUB_ROWS,
228 "the hub's slots are its grid");
229_Static_assert(HUB_M + HUB_ROWS * (HUB_TH + HUB_M) <= STRIP_Y,
230 "the grid ends above the strip");
231_Static_assert(LIST_Y + LIST_H <= STRIP_Y, "the list ends above the strip");
232_Static_assert(STRIP_Y + STRIP_H <= SCREEN_H - UI_ALERT_H,
233 "the strip ends above the alert band");
234_Static_assert(WARN_WHY_Y + 2 * WARN_WHY_PITCH <= WARN_LINE_Y,
235 "the warning's two lines on unsaved end above the changes");
236_Static_assert(WARN_NOTE_Y + 2 * WARN_NOTE_PITCH <= WARN_H - 4,
237 "the warning's notes end inside its card");
238_Static_assert(HUB_ICON_DY + HUB_ICON <= HUB_NAME_DY
239 && HUB_NAME_DY + 24 <= HUB_LINE_DY
240 && HUB_LINE_DY + 20 <= HUB_TH,
241 "a hub tile's icon, name and line stack inside it");
242
243/* The strings' names, for the warning, a row and its keyboard's title,
244 * and the help line of a row; the DUT name has no row on SETUP. */
251static const struct {
254} k_text_ui[SETTING_TEXT_COUNT] = {
255 [SET_TEXT_DUT_NAME] = { TX_SET_DUT_NAME, TX_COUNT },
256 [SET_TEXT_LOG_AUTO_DIR] = { TX_SET_AUTO_DIR, TX_SET_AUTO_DIR_HELP },
257 [SET_TEXT_LOG_USER_DIR] = { TX_SET_USER_DIR, TX_SET_USER_DIR_HELP },
259
260/*
261 * The keyboard a string's row opens: over the list and the strip, the
262 * warning's card. Nothing under it presses while it is open; OK and
263 * CANCEL are its own, and the home tag closes it as CANCEL does.
264 */
269#define TK_AREA_H (STRIP_Y + STRIP_H - WARN_Y)
270
277#define KP_AREA gfx_rect_make(WARN_X, WARN_Y, WARN_W, TK_AREA_H)
278
284typedef struct {
285 /* The list of cat is open; the hub shows while this is false. */
287 bool list;
289 int scroll;
291
292 /* One contact holds the screen from its DOWN to its UP; any other
293 * presses nothing and ends nothing. */
295 uint8_t press_id;
296
299 bool dragging;
302 int last_y;
303
304 float held_for;
306
310
311 /*
312 * The save button's three inputs as the last frame drew them. The
313 * write is taken by settings_save_tick() outside this screen, so a
314 * pending write completing -- or being refused -- moves them with no
315 * touch to invalidate the cached framebuffers. Without this, a
316 * refusal keeps drawing WHEN IDLE until something else repaints.
317 */
321
322 /* The warning is open and holds the way out to warn_to. drawn_* are
323 * what the last frame drew of it. */
324 bool warn;
325 ui_screen_id_t warn_to;
330
331 /* The keyboard of string tk_text, and its revision as last drawn. */
334 bool drawn_tk;
335 uint32_t drawn_tk_rev;
336
337 /* The keypad of number kp_id, and its revision as last drawn. */
340 bool drawn_kp;
341 uint32_t drawn_kp_rev;
343
344/* Defined in settings_screen.c. */
346extern stg_state_t stg_s;
348#define s stg_s
349
350/* --- settings_screen.c: the geometry and the rows settings_draw.c reads -- */
351
379bool stg_save_offered(void);
384bool stg_bench_armed(void);
399int stg_row_count(void);
404void stg_clamp_scroll(void);
410gfx_rect_t stg_row_rect(int index);
418
419/* --- settings_draw.c ---------------------------------------------------- */
420
427void stg_render(gfx_canvas_t *c, int buffer_index);
#define ROW_H
Definition analyser_screen.c:117
#define LIST_Y
The first check's top.
Definition busfault_screen.c:89
#define SCREEN_H
The body's height, 540px: the router owns the band and hands this screen the body.
Definition files_int.h:36
gfx: an RGB565 (16-bit red, green, blue) rasteriser with no dependencies.
Device settings: a typed schema, a value per entry, and a persistence seam.
setting_cat_t
Definition settings.h:28
@ SET_CAT_IFACE
Definition settings.h:31
@ SET_CAT_SENSORS
Definition settings.h:33
@ SET_CAT_CARD
Definition settings.h:32
@ SET_CAT_APP
Definition settings.h:29
setting_id_t
Every setting's id, in schema order.
Definition settings.h:67
setting_text_id_t
Definition settings.h:230
@ SET_TEXT_LOG_USER_DIR
Definition settings.h:233
@ SET_TEXT_LOG_AUTO_DIR
Definition settings.h:232
@ SET_TEXT_DUT_NAME
Definition settings.h:231
void stg_render(gfx_canvas_t *c, int buffer_index)
SETUP drawn: the keypad alone while it is open, else the warning, or the tiles or a list over the str...
Definition settings_draw.c:348
SETUP's list rows: what settings_rows.c, settings_screen.c and settings_draw.c share and nobody else ...
bool stg_save_offered(void)
Returns whether SAVE is offered: a setting is changed and no save is asked for.
Definition settings_screen.c:227
gfx_rect_t stg_tile_rect(int i)
Returns the rectangle of hub tile i.
Definition settings_screen.c:192
int stg_row_count(void)
Returns the number of rows in the open category's list.
Definition settings_screen.c:357
gfx_rect_t stg_discard_rect(void)
Returns the rectangle of DISCARD, the warning's middle column.
Definition settings_screen.c:253
bool stg_bench_armed(void)
Returns whether the bench is ARMED; DISCARD changes nothing then.
Definition settings_screen.c:243
gfx_rect_t stg_save_rect(void)
Returns the rectangle of SAVE, the strip's last column.
Definition settings_screen.c:221
void stg_clamp_scroll(void)
Limits the list's scroll to 0 to the content's height less the list's.
Definition settings_screen.c:362
gfx_rect_t stg_row_rect(int index)
Returns the rectangle of list row index, from the list's scroll.
Definition settings_screen.c:375
gfx_rect_t stg_reset_rect(void)
Returns the rectangle of RESET, the strip's middle column.
Definition settings_screen.c:216
gfx_rect_t stg_stay_rect(void)
Returns the rectangle of STAY, the warning's first column.
Definition settings_screen.c:248
gfx_rect_t stg_strip_rect(int col)
Returns column col of the strip under the grid and the list.
Definition settings_screen.c:210
settings_row_t stg_row_entry(int index)
Returns the entry of row index; a heading's carries heading or part >= 0, a string's text >= 0.
Definition settings_screen.c:416
stg_state_t stg_s
SETUP's state, in settings_screen.c.
Definition settings_screen.c:53
Settings: a hub of tiles, one per category and one per screen SETUP opens, and a category's entries i...
#define SETTINGS_HUB_SLOTS
Definition settings_screen.h:154
#define HUB_TH
Definition settings_screen_int.h:54
#define TILE_COUNT
Number of tiles, at most SETTINGS_HUB_SLOTS (9).
Definition settings_screen_int.h:223
#define WARN_LINE_Y
Definition settings_screen_int.h:169
#define HUB_NAME_DY
Definition settings_screen_int.h:64
#define HUB_COLS
The hub: three columns by three rows of 328 x 130px tiles (49.2 x 19.5mm) with 10px margins,...
Definition settings_screen_int.h:50
#define HUB_ICON_DY
Inside a hub tile, from its top: the 36px icon box at 14, the name in the body face (12 x 24) at 60,...
Definition settings_screen_int.h:62
#define HUB_CATEGORY(cat_, icon_)
Tile that opens category cat_ with icon icon_; its line counts the settings.
Definition settings_screen_int.h:200
#define HUB_ROWS
Definition settings_screen_int.h:51
static const hub_tile_t k_tiles[]
The hub's tiles in grid order, row by row.
Definition settings_screen_int.h:210
#define WARN_H
Definition settings_screen_int.h:165
#define HUB_LINE_DY
Definition settings_screen_int.h:65
#define HUB_ICON
Definition settings_screen_int.h:63
#define WARN_NOTE_PITCH
Definition settings_screen_int.h:172
static const struct @046117007144013124355113252120245117155235020310 k_text_ui[SETTING_TEXT_COUNT]
Per string setting: the name for the warning, a row and its keyboard's title, and the row's help line...
#define WARN_WHY_Y
Definition settings_screen_int.h:167
#define MAX_FBS
Frame buffers the router renders into.
Definition settings_screen_int.h:37
#define HUB_M
Definition settings_screen_int.h:52
#define HUB_SCREEN(screen_, line_, icon_)
Tile that opens screen screen_ with icon icon_ and the line line_ under its name.
Definition settings_screen_int.h:206
#define WARN_NOTE_Y
Definition settings_screen_int.h:171
#define WARN_WHY_PITCH
Definition settings_screen_int.h:168
#define LIST_H
Definition settings_screen_int.h:93
#define STRIP_Y
Definition settings_screen_int.h:79
#define STRIP_H
The strip under the grid and under the list: three columns, the hub's, UI_BTN_H (48px) tall.
Definition settings_screen_int.h:78
ui_text_id_t label
ui_text_id_t help
Definition gfx.h:129
Definition gfx.h:81
One tile of the hub: a category's list or a screen it opens.
Definition settings_screen_int.h:189
ui_screen_id_t screen
Definition settings_screen_int.h:192
ui_icon_fn icon
Definition settings_screen_int.h:190
ui_text_id_t line
Definition settings_screen_int.h:193
int8_t cat
Definition settings_screen_int.h:191
One row of a list: a setting, a heading, a string or a part's heading.
Definition settings_rows_int.h:19
SETUP's state: the open list and its scroll, the contact that holds the screen, the key repeat,...
Definition settings_screen_int.h:284
setting_text_id_t tk_text
Definition settings_screen_int.h:333
setting_cat_t drawn_cat
Definition settings_screen_int.h:309
bool drawn_list
Definition settings_screen_int.h:308
bool drawn_tk
Definition settings_screen_int.h:334
bool drawn_dirty
Definition settings_screen_int.h:318
bool drawn_kp
Definition settings_screen_int.h:340
bool list
Whether the list of cat is open; the hub shows while false.
Definition settings_screen_int.h:287
int hit_index
Definition settings_screen_int.h:298
bool repeating
Definition settings_screen_int.h:305
bool drawn_failed
Definition settings_screen_int.h:320
bool have_press
Definition settings_screen_int.h:294
int scroll_max
Definition settings_screen_int.h:290
ui_keypad_t kp
Definition settings_screen_int.h:338
int hit_kind
Definition settings_screen_int.h:297
uint32_t drawn_tk_rev
Definition settings_screen_int.h:335
setting_cat_t cat
Definition settings_screen_int.h:288
bool drawn_warn
Definition settings_screen_int.h:326
float held_for
Definition settings_screen_int.h:304
bool drawn_asked
Definition settings_screen_int.h:319
uint8_t press_id
Definition settings_screen_int.h:295
setting_id_t kp_id
Definition settings_screen_int.h:339
int scroll
Definition settings_screen_int.h:289
int last_y
Definition settings_screen_int.h:302
bool warn
Definition settings_screen_int.h:324
int press_y
Definition settings_screen_int.h:301
bool chrome_valid[MAX_FBS]
Definition settings_screen_int.h:307
bool dragging
Definition settings_screen_int.h:299
ui_screen_id_t warn_to
Definition settings_screen_int.h:325
bool drawn_armed
Definition settings_screen_int.h:327
ui_textkey_t tk
Definition settings_screen_int.h:332
int press_x
Definition settings_screen_int.h:300
uint32_t drawn_kp_rev
Definition settings_screen_int.h:341
A numeric keypad: what it was opened with, what is typed, and the press it holds.
Definition ui_keypad.h:61
A keyboard: what it was opened for, what is typed, and the press it holds.
Definition ui_textkey.h:114
#define BTN_H
Definition esc_stick_int.h:70
Icons drawn with primitives rather than stored as bitmaps.
void ui_icon_sliders(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
The settings glyph: three sliders.
Definition ui_icons.c:160
void ui_icon_supply(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
The supply glyph: a bench supply's front.
Definition ui_icons.c:217
void ui_icon_board(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
The board glyph: a board from above with its pads.
Definition ui_icons.c:253
void ui_icon_wifi(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
The Wi-Fi glyph: arcs over a dot.
Definition ui_icons.c:270
void ui_icon_record(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
The record glyph: a recorder with its tray.
Definition ui_icons.c:114
void ui_icon_chart(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
The chart glyph: a trace over its axes.
Definition ui_icons.c:90
void ui_icon_chip(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
The chip glyph: a package and its pins.
Definition ui_icons.c:138
void ui_icon_list(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
The pin list glyph: three rows, each a pin and its line.
Definition ui_icons.c:234
void(*) ui_icon_fn(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
An icon centred on (x, y), inside a box of size x size px around it. Every ui_icon_ function below ha...
Definition ui_icons.h:26
void ui_icon_folder(gfx_canvas_t *c, int x, int y, int size, gfx_color_t color)
A folder: its tab and its body.
Definition ui_icons.c:287
A numeric keypad over part of a screen, for a value a slider is too coarse to place.
#define UI_ALERT_H
The alert band the router draws across the bottom of the panel while an alert shows.
Definition ui_layout.h:43
Screen router.
The interface's words, one table per language.
ui_text_id_t
The screens' strings, TX_<ID> for each UI_TEXT() of ui_text.def.
Definition ui_text.h:43
An on-screen keyboard for a short name: capitals, digits, space and the marks a name or a file needs,...