rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
settings_screen.c File Reference

The settings screen: a hub of tiles, and one renderer over the whole schema. More...

#include "settings_screen.h"
#include <stdio.h>
#include <string.h>
#include "hitec_rx_link.h"
#include "link_pages.h"
#include "sense_link.h"
#include "sensors_rows.h"
#include "settings.h"
#include "settings_rows_int.h"
#include "settings_sensors.h"
#include "tone_link.h"
#include "ui_icons.h"
#include "ui_keypad.h"
#include "ui_pinlist.h"
#include "ui_setting_keypad.h"
#include "ui_text.h"
#include "ui_textkey.h"
#include "ui_widgets.h"
#include "settings_screen_int.h"

Functions

void settings_screen_invalidate (void)
void settings_apply_ui (void)
void settings_screen_set_unheld (uint16_t sense_rows, uint8_t tone_rows)
void settings_screen_set_hitec_rx (uint8_t mark)
const char * settings_screen_help (setting_id_t id)
bool settings_screen_unheld (setting_id_t id)
static void drop_press (void)
bool settings_hub_slot (int index, gfx_rect_t *out)
int settings_hub_tiles (void)
bool settings_screen_opens (ui_screen_id_t id)
int settings_screen_category (void)
gfx_rect_t stg_tile_rect (int i)
 Returns the rectangle of hub tile i.
static int tile_at (int x, int y)
gfx_rect_t stg_strip_rect (int col)
 Returns column col of the strip under the grid and the list.
gfx_rect_t stg_reset_rect (void)
 Returns the rectangle of RESET, the strip's middle column.
gfx_rect_t stg_save_rect (void)
 Returns the rectangle of SAVE, the strip's last column.
bool stg_save_offered (void)
 Returns whether SAVE is offered: a setting is changed and no save is asked for.
static bool leave_held (void)
bool stg_bench_armed (void)
 Returns whether the bench is ARMED; DISCARD changes nothing then.
gfx_rect_t stg_stay_rect (void)
 Returns the rectangle of STAY, the warning's first column.
gfx_rect_t stg_discard_rect (void)
 Returns the rectangle of DISCARD, the warning's middle column.
static void leave_value (setting_id_t id, float value, char *out, size_t n)
 A value of id as the leave question says it: with its unit, joined to a symbol ("6.00V"), a space before a word ("2 cells") and the pin word before its number ("GPIO 4"); no unit after OFF, a SENSORS shunt's 0; and a pin's -1 in the words of the row's help, "open".
static void change_line (int k, char *line, size_t n)
bool settings_screen_warning (void)
bool settings_screen_warn_line (int i, char *line, size_t n)
static bool hold (ui_screen_id_t to)
int stg_row_count (void)
 Returns the number of rows in the open category's list.
void stg_clamp_scroll (void)
 Limits the list's scroll to 0 to the content's height less the list's.
gfx_rect_t stg_row_rect (int index)
 Returns the rectangle of list row index, from the list's scroll.
gfx_rect_t settings_screen_list_rect (void)
 The open list's pane, in the screen's own coordinates (the body under the band): the rows show inside it and nowhere else.
gfx_rect_t settings_screen_row_rect (int row)
 Where list row row lies at the list's present scroll, in the screen's own coordinates; partly or wholly outside the pane for a row scrolled out of it.
gfx_rect_t settings_screen_row_part (int row, settings_row_part_t part)
 Where part of list row row lies; settings_row_part_t says which part. Whether the row has keys or a keypad is the row's own: the rectangle is where they are when it does.
static int row_at (int x, int y)
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.
static bool row_is_heading (int index)
static int row_text (int index)
static setting_id_t row_setting (int index)
static bool on_key (int kind, int index, int x, int y)
static bool on_value (int index, int x, int y)
 Whether (x, y) is on the value of row index: the gap between its "-" and "+" keys, over the row's own height, on a number the keypad takes (ui_setting_keypad_offered()).
static void value_changed (setting_id_t id)
 A setting changed by a step or by the keypad: the PANEL rows reach the interface at once, and the list is drawn again.
static void step_row (int index, int steps)
 The "-" or "+" key of row index stepped steps times through settings_adjust(); a heading's and a string's row take none.
static void close_keypad (void)
 The keypad closes, with nothing typed taken.
static void open_keypad (int index)
 A tap on the value of row index: the keypad of its number, over the list and the strip.
static void reset (void)
 The screen's state cleared: the tiles, PANEL's list kept for the first tap, no press, the keyboard and the keypad closed.
static void enter (void)
 SETUP shown: it opens on its tiles, from the menu and from a screen a tile opened alike. The list keeps its category and its scroll; the keyboard and the keypad are closed.
static void leave (void)
 SETUP left: the warning, the keyboard and the keypad close, and what was typed is not taken.
static bool back (void)
 The home tag: on a list it goes back to the tiles; on the tiles it leaves, through hold(). Over the warning it is STAY, over the keyboard and the keypad CANCEL.
static void tick (float dt_s)
 A frame: the save button's inputs followed, a keypad whose row is held since it opened closed, and a held "-" or "+" repeated.
static void open_tile (int index)
static void open_text (setting_text_id_t id)
static void press (const touch_event_t *evt, int x, int y)
 The DOWN of the contact that holds the screen: what it presses.
static void release (int kind, int index, bool repeated, int x, int y)
 The UP of a tap the finger made: what it activates.
static void textkey_event (const touch_event_t *evt)
static void keypad_event (const touch_event_t *evt)
 An event while the keypad is open goes to the keypad alone. OK sets the value through settings_set(), as a step does, and SAVE keeps it; a value the steps never reach keeps the keypad open, refused (ui_setting_keypad_ok()).
static void event (const touch_event_t *evt)
 One touch event: to the keypad or the keyboard while one is open, else to the press, the scroll and the release it ends in.
static void cancel (void)
 Touch events were lost between two frames, so this screen's record of what is on the glass cannot be trusted.
const ui_screen_t * settings_screen (void)
int settings_screen_scroll (int *max)
 How far the open category's list is scrolled.
const ui_textkey_t * settings_screen_textkey (void)
const ui_keypad_t * settings_screen_keypad (void)
 The keypad a tap on a number's value opens: over the list and the strip until OK sets the value (settings_set(), as a step does), CANCEL or the home tag drops it, or SETUP is left.
int settings_screen_keypad_setting (void)
 The setting the open keypad types.

Variables

stg_state_t stg_s
 SETUP's state, in settings_screen.c.
static uint16_t s_sense_unheld
static uint8_t s_tone_unheld
static uint8_t s_hitec_rx_mark
static const ui_screen_t s_screen

Detailed Description

The settings screen: a hub of tiles, and one renderer over the whole schema.

SETUP opens on a grid of tiles, the menu's kind: one per category it holds (PANEL, INTERFACES, SD CARD, SENSORS), and one per screen of its own that SETUP reaches (OUTPUTS, PICK A PIN, WI-FI, UPDATES). A category's tile opens its list across the screen's width. The list walks the rows shared/settings declares (settings_rows.c; SENSORS lists a fitted part's rows only, sensors_rows.h) and draws each row by its type: a stepper for a number, a toggle for a bool, a choice for an enum. A tap on a number's value, between its "-" and "+" keys, opens the keypad over the list (ui_setting_keypad.h); its OK sets the value through settings_set(), as a step does. A category's strings follow its settings, each a row that shows its text and opens the on-screen keyboard on a tap (SD CARD's two log folders, in the keyboard's folder mode). A new setting is a schema row, and a new tile is a line of k_tiles (settings_screen_int.h); nothing else here changes. settings_draw.c draws the screen.

The home tag that leaves SETUP with settings unsaved and no save asked is held: a warning lists what differs from the stored values and offers SAVE, DISCARD and STAY. A tile that opens a screen of its own is not a way out, and no route the application takes is held (ui_screen_t.hold).

SPDX-License-Identifier: MIT

Function Documentation

◆ back()

bool back ( void )
static

The home tag: on a list it goes back to the tiles; on the tiles it leaves, through hold(). Over the warning it is STAY, over the keyboard and the keypad CANCEL.

Returns
True when it closed something or climbed to the tiles; false to leave SETUP.

◆ cancel()

void cancel ( void )
static

Touch events were lost between two frames, so this screen's record of what is on the glass cannot be trusted.

A hit held open acts on its release and a drag owns its track id, and the GT911 reuses ids: a later contact that began somewhere else would be taken for this one and press a control nobody touched. The repeat on the plus and minus keys runs on the frame timer while a hit stands, so it stops here too. A key held on the keyboard or the keypad is let go; what was typed stays.

◆ event()

void event ( const touch_event_t * evt)
static

One touch event: to the keypad or the keyboard while one is open, else to the press, the scroll and the release it ends in.

Parameters
evtThe event, in the screen's coordinates.

◆ keypad_event()

void keypad_event ( const touch_event_t * evt)
static

An event while the keypad is open goes to the keypad alone. OK sets the value through settings_set(), as a step does, and SAVE keeps it; a value the steps never reach keeps the keypad open, refused (ui_setting_keypad_ok()).

Parameters
evtThe event.

◆ leave_value()

void leave_value ( setting_id_t id,
float value,
char * out,
size_t n )
static

A value of id as the leave question says it: with its unit, joined to a symbol ("6.00V"), a space before a word ("2 cells") and the pin word before its number ("GPIO 4"); no unit after OFF, a SENSORS shunt's 0; and a pin's -1 in the words of the row's help, "open".

Parameters
idthe setting
valueits value
outtakes the text
nbytes at out

◆ on_value()

bool on_value ( int index,
int x,
int y )
static

Whether (x, y) is on the value of row index: the gap between its "-" and "+" keys, over the row's own height, on a number the keypad takes (ui_setting_keypad_offered()).

Parameters
indexThe row.
xThe point's x, in the screen's coordinates.
yThe point's y.
Returns
True where a tap opens the row's keypad.

◆ open_keypad()

void open_keypad ( int index)
static

A tap on the value of row index: the keypad of its number, over the list and the strip.

Parameters
indexThe row.

◆ press()

void press ( const touch_event_t * evt,
int x,
int y )
static

The DOWN of the contact that holds the screen: what it presses.

Parameters
evtThe DOWN.
xIts x, in the screen's coordinates.
yIts y.

◆ release()

void release ( int kind,
int index,
bool repeated,
int x,
int y )
static

The UP of a tap the finger made: what it activates.

Parameters
kindThe HIT_ kind the press took.
indexThe tile or row it took.
repeatedWhether a held key has repeated, which adds no step.
xThe UP's x, in the screen's coordinates.
yIts y.

◆ settings_apply_ui()

void settings_apply_ui ( void )

Push the display-related settings – language, theme, brightness and contrast – into the interface and repaint every screen. Call at startup, and whenever an application setting changes.

◆ settings_hub_slot()

bool settings_hub_slot ( int index,
gfx_rect_t * out )

Where the hub draws its entry index, in the screen's own coordinates (the body under the band), into out when it is not NULL. False for an index outside 0 to SETTINGS_HUB_SLOTS - 1: a tenth entry has no slot on the page.

◆ settings_hub_tiles()

int settings_hub_tiles ( void )

The entries of the hub's tile table: its categories and its screens.

◆ settings_screen_category()

int settings_screen_category ( void )

The category whose list is open, or -1 while the hub's tiles show.

◆ settings_screen_help()

const char * settings_screen_help ( setting_id_t id)

The help line of the row of id: PD mini TX and RX on one pin first, then a mark's line, then the setting's help. Hitec D receive's help follows its value: PULL-UP the setting's, PRECHARGE its own.

◆ settings_screen_keypad()

const ui_keypad_t * settings_screen_keypad ( void )

The keypad a tap on a number's value opens: over the list and the strip until OK sets the value (settings_set(), as a step does), CANCEL or the home tag drops it, or SETUP is left.

Returns
The keypad, open or closed.

◆ settings_screen_keypad_setting()

int settings_screen_keypad_setting ( void )

The setting the open keypad types.

Returns
Its setting_id_t, or -1 while the keypad is closed.

◆ settings_screen_list_rect()

gfx_rect_t settings_screen_list_rect ( void )

The open list's pane, in the screen's own coordinates (the body under the band): the rows show inside it and nowhere else.

Returns
The pane.

◆ settings_screen_opens()

bool settings_screen_opens ( ui_screen_id_t id)

Whether a tile of the hub opens screen id. The home tag of such a screen leads back to SETUP rather than to the menu.

◆ settings_screen_row_part()

gfx_rect_t settings_screen_row_part ( int row,
settings_row_part_t part )

Where part of list row row lies; settings_row_part_t says which part. Whether the row has keys or a keypad is the row's own: the rectangle is where they are when it does.

Parameters
rowThe row, from 0.
partThe part.
Returns
The part's rectangle.

◆ settings_screen_row_rect()

gfx_rect_t settings_screen_row_rect ( int row)

Where list row row lies at the list's present scroll, in the screen's own coordinates; partly or wholly outside the pane for a row scrolled out of it.

Parameters
rowThe row, from 0.
Returns
The row's rectangle.

◆ settings_screen_scroll()

int settings_screen_scroll ( int * max)

How far the open category's list is scrolled.

Parameters
maxIts scroll range into, when not NULL: 0 for a list that fits its 428px.
Returns
The scroll, in px from the list's top: 0 to the range.

◆ settings_screen_set_hitec_rx()

void settings_screen_set_hitec_rx ( uint8_t mark)

What the IOmcu holds of Hitec D receive (SET_HITEC_RX), a hitec_rx_link_mark_t: HITEC_RX_LINK_HELD draws the row plain, the others mark it as an unheld row; HITEC_RX_LINK_OLD says in its help line that the IOmcu receives with PULL-UP.

◆ settings_screen_set_unheld()

void settings_screen_set_unheld ( uint16_t sense_rows,
uint8_t tone_rows )

The INTERFACES rows whose value the IOmcu does not hold: sense_rows is sense_link_unheld()'s SENSE_LINK_ROW_* and tone_rows tone_link_unheld()'s TONE_LINK_ROWS_*. Such a row is drawn marked – its edge and its value in the warning colour, and "Not taken by the IOmcu" in place of its help line – until a call names it no longer. Sensor SDA and Sensor SCL are one mark: the pins are one frame.

◆ settings_screen_textkey()

const ui_textkey_t * settings_screen_textkey ( void )

The keyboard a string's row opens, in folder mode for SD CARD's log folders (ui_textkey.h): open over the list and the strip until OK takes the text, CANCEL or the home tag drops it, or SETUP is left. OK sets the string as an edit; SAVE keeps it.

◆ settings_screen_unheld()

bool settings_screen_unheld ( setting_id_t id)

Whether the row of id is marked by settings_screen_set_unheld() or settings_screen_set_hitec_rx().

◆ settings_screen_warn_line()

bool settings_screen_warn_line ( int i,
char * line,
size_t n )

Line i of the warning's changes into line, as drawn: "name: saved -> now", the values as the list shows them, each with its unit; the values in schema order, then the strings. With more changes than SETTINGS_WARN_LINES, the last line counts the rest. False past the last line, and while the warning does not show.

◆ settings_screen_warning()

bool settings_screen_warning ( void )

Whether the warning shows: the home tag left SETUP with settings unsaved and no save asked (settings_dirty() and not settings_save_asked()), and nothing has answered it yet. STAY, the home tag again, SAVE, DISCARD and any change of screen close it.

◆ step_row()

void step_row ( int index,
int steps )
static

The "-" or "+" key of row index stepped steps times through settings_adjust(); a heading's and a string's row take none.

Parameters
indexThe row.
stepsThe steps, negative for "-".

◆ stg_bench_armed()

bool stg_bench_armed ( void )

Returns whether the bench is ARMED; DISCARD changes nothing then.

Returns
true when ARMED

◆ stg_discard_rect()

gfx_rect_t stg_discard_rect ( void )

Returns the rectangle of DISCARD, the warning's middle column.

Returns
the rectangle

◆ stg_reset_rect()

gfx_rect_t stg_reset_rect ( void )

Returns the rectangle of RESET, the strip's middle column.

Returns
the rectangle

◆ stg_row_count()

int stg_row_count ( void )

Returns the number of rows in the open category's list.

Returns
the row count

◆ stg_row_entry()

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.

Parameters
indexrow index
Returns
the entry

◆ stg_row_rect()

gfx_rect_t stg_row_rect ( int index)

Returns the rectangle of list row index, from the list's scroll.

Screen-space rect of a row, or an empty rect when it is scrolled away.

Parameters
indexrow index
Returns
the row's rectangle

◆ stg_save_offered()

bool stg_save_offered ( void )

Returns whether SAVE is offered: a setting is changed and no save is asked for.

Returns
true when SAVE is enabled

◆ stg_save_rect()

gfx_rect_t stg_save_rect ( void )

Returns the rectangle of SAVE, the strip's last column.

Returns
the rectangle

◆ stg_stay_rect()

gfx_rect_t stg_stay_rect ( void )

Returns the rectangle of STAY, the warning's first column.

Returns
the rectangle

◆ stg_strip_rect()

gfx_rect_t stg_strip_rect ( int col)

Returns column col of the strip under the grid and the list.

Parameters
colstrip column, 0 to 2
Returns
the column's rectangle

◆ stg_tile_rect()

gfx_rect_t stg_tile_rect ( int i)

Returns the rectangle of hub tile i.

Parameters
itile index, 0 to TILE_COUNT - 1
Returns
the tile's rectangle

◆ tick()

void tick ( float dt_s)
static

A frame: the save button's inputs followed, a keypad whose row is held since it opened closed, and a held "-" or "+" repeated.

Parameters
dt_sThe frame's time, s.

◆ value_changed()

void value_changed ( setting_id_t id)
static

A setting changed by a step or by the keypad: the PANEL rows reach the interface at once, and the list is drawn again.

Parameters
idThe setting that changed.

Variable Documentation

◆ s_screen

const ui_screen_t s_screen
static
Initial value:
= {
.title = "SETUP",
.reset = reset,
.enter = enter,
.leave = leave,
.tick = tick,
.event = event,
.cancel = cancel,
.render = stg_render,
.back = back,
.hold = hold,
}
static void enter(void)
On the way in: both panes read, from their first pages the first time and as they were left after tha...
Definition files_screen.c:1026
static void tick(float dt_s)
Time passed: the answer taken when it is in, the progress and the gate followed for the drawing.
Definition files_screen.c:1059
static bool back(void)
The home tag: a box or the keyboard closes, a job's box cancels a copy and stays; with the panes on t...
Definition files_screen.c:1096
static void leave(void)
On the way out: the keyboard and the boxes close; a job under way goes on, and its box shows again on...
Definition files_screen.c:1045
static void reset(void)
The screen as a start leaves it: the card's root on the left, USER LOG FOLDER on the right,...
Definition files_screen.c:1006
static void cancel(void)
The panel could not hand over every touch event, so this screen's record of the glass is stale....
Definition log_viewer_screen.c:545
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