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

The string tables and the lookup. See include/ui_text.h. More...

#include "ui_text.h"
#include "ui_card_text.h"
#include <math.h>
#include <stdatomic.h>
#include <stdio.h>
#include <string.h>
#include "gfx.h"
#include "ui_pinlist.h"

Macros

#define DE(en, de)
 The IDs' names, for the host's checks; the panel image carries none.

Functions

void ui_text_set_language (ui_lang_t lang)
ui_lang_t ui_text_language (void)
const ui_language_t * ui_text_table (ui_lang_t lang)
static const char * entry (const char *const *table, int i)
const char * ui_tr_in (ui_lang_t lang, ui_text_id_t id)
const char * ui_tr (ui_text_id_t id)
const char * ui_tr_pad (const ui_text_id_t *set, int count, int i, char *buf, size_t n)
int ui_text_has (ui_lang_t lang, ui_text_id_t id)
int ui_text_cells (ui_text_id_t id)
const char * ui_text_name (ui_text_id_t id)
const char * ui_setting_label (setting_id_t id)
const char * ui_setting_help (setting_id_t id)
const char * ui_setting_category (setting_cat_t cat)
static const char *const * lang_options (setting_id_t id)
 A setting's option list in the language showing.
const char * ui_setting_option (setting_id_t id, int k)
const char * ui_on_off (int on)
const char * ui_setting_value (setting_id_t id, char *buf, size_t n)
const char * ui_setting_value_of (setting_id_t id, float value, char *buf, size_t n)
const char *const * ui_servo_table (void)
const char * ui_servo_str (servo_str_t id)
ui_text_id_t ui_card_text_id (card_state_t state, ui_card_at_t at)
const char * ui_card_text (card_state_t state, ui_card_at_t at)
static int is_symbol_part (const char *s, size_t n)
 Whether s, up to its end or its "/", is one of the symbols.
int ui_unit_is_symbol (const char *unit)
 Whether unit is a unit symbol, written with no space after its number: one of k_unit_symbols (ui_text.c), which holds the symbols of tools/check_units.py, alone or followed by a "/" part ("rpm/V", "%/s").
const char * ui_pin_holder (const char *held_by)
 What holds a reserved pin, in the language showing: the words out_bind.c gives a catalogue's LINK_PIN_* values ("heartbeat", "flash", "debug", "sensor", "in use") from the text table, and any other name ("CAN INT", "CAN") as it is.
const char * ui_unit_gap (const char *unit)
 What stands between a number and unit: "" before a symbol ("6.00V", "1000.0mΩ", "40s") and before no unit, " " before a word that follows its number. A word that leads (ui_unit_is_prefix(), "GPIO 4") also gets " ".
int ui_unit_is_prefix (const char *unit)
 Whether unit is written before its number: the pin word UI_PIN_WORD, "GPIO", so that a pin reads "GPIO 4" (ui_pin_name()) and not as a count of four GPIOs. Every other unit follows its number.

Variables

static const char *const k_en [TX_COUNT]
 The screens' strings in English, by TX_ ID.
static const unsigned char k_cells [TX_COUNT]
 The cells each string's field has, 0 where –fit measures it.
static const char *const k_de_text [TX_COUNT]
 The screens' strings in German, by TX_ ID; NULL shows the English.
static const char *const k_de_label [SETTING_COUNT]
 The settings' labels in German, by setting ID.
static const char *const k_de_help [SETTING_COUNT]
 The settings' help lines in German, by setting ID.
static const char *const k_de_category [SET_CAT_COUNT]
 The settings categories' names in German.
static const char *const *const k_de_options []
 One array k_de_opts_<name> per option list, in German.
static const char *const k_de_servo [SERVO_STR_COUNT]
 The servo test's words in German, by SERVO_STR_ ID.
const ui_language_t ui_lang_de
 The German tables, as ui_text.h declares them.
static const ui_language_t *const k_langs [UI_LANG_COUNT]
static atomic_int s_lang = UI_LANG_EN
static const ui_text_id_t k_card_text [UI_CARD_AT_COUNT][3]
static const char *const k_unit_symbols []
 The unit symbols, as tools/check_units.py's UNITS lists them ("%%", its printf spelling of "%", as "%"); test_check_units.py holds the two lists to each other.

Detailed Description

The string tables and the lookup. See include/ui_text.h.

A lookup is two loads and a test: the language's entry, else the English. The language is an atomic int, read once per string, so the control task's alerts read it from the other core without a lock: a change lands between two lookups and never inside one.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ DE

#define DE ( en,
de )
Value:
(de)

The IDs' names, for the host's checks; the panel image carries none.

Picks the German column of an entry of ui_text.def.

Each language but English is a block like this one: its tables are ui_text.def's entries with its pick choosing the language's column. A language added to the table adds a column to every entry, a parameter to every entry macro and a block of its own.

Function Documentation

◆ is_symbol_part()

int is_symbol_part ( const char * s,
size_t n )
static

Whether s, up to its end or its "/", is one of the symbols.

Parameters
sthe part
nits bytes
Returns
1 for a symbol, else 0

◆ lang_options()

const char *const * lang_options ( setting_id_t id)
static

A setting's option list in the language showing.

Parameters
idThe setting.
Returns
The list, as long as the English one, or NULL for English and for a setting that is no choice.

◆ ui_card_text()

const char * ui_card_text ( card_state_t state,
ui_card_at_t at )

ui_card_text_id() in the language showing.

◆ ui_card_text_id()

ui_text_id_t ui_card_text_id ( card_state_t state,
ui_card_at_t at )

The text ID for state at at. CARD_STATE_MOUNTED and a state out of range take the place's no-card text: a caller asks when it found no volume, and a mount since then changes nothing said. A place out of range takes LOGS' no-card text.

◆ ui_on_off()

const char * ui_on_off ( int on)

ON or OFF in the language showing.

◆ ui_pin_holder()

const char * ui_pin_holder ( const char * held_by)

What holds a reserved pin, in the language showing: the words out_bind.c gives a catalogue's LINK_PIN_* values ("heartbeat", "flash", "debug", "sensor", "in use") from the text table, and any other name ("CAN INT", "CAN") as it is.

Parameters
held_byan outbind_pin_t's held_by, or NULL
Returns
the text to show; "" for NULL

◆ ui_servo_str()

const char * ui_servo_str ( servo_str_t id)

The servo test's words for the screen and the report, in the language showing. servo_str() stays English: it writes the CSV, which tools read.

◆ ui_servo_table()

const char *const * ui_servo_table ( void )

The servo table to hand a run for its report: NULL is English.

◆ ui_setting_option()

const char * ui_setting_option ( setting_id_t id,
int k )

Option k of an enum setting; "?" for one out of range.

◆ ui_setting_value()

const char * ui_setting_value ( setting_id_t id,
char * buf,
size_t n )

As settings_value_text(), with ON, OFF and the options translated.

◆ ui_setting_value_of()

const char * ui_setting_value_of ( setting_id_t id,
float value,
char * buf,
size_t n )

As ui_setting_value(), for value rather than the value in force.

◆ ui_text_cells()

int ui_text_cells ( ui_text_id_t id)

The cells id may take where it is drawn, from ui_text.def, or 0 when the fit check measures it on a rendered screen instead.

◆ ui_text_has()

int ui_text_has ( ui_lang_t lang,
ui_text_id_t id )

Whether lang's own table has id, rather than falling back.

◆ ui_text_name()

const char * ui_text_name ( ui_text_id_t id)

The ID's name without the TX_ prefix, for the host's checks; "" on the panel, which carries no names.

◆ ui_text_set_language()

void ui_text_set_language ( ui_lang_t lang)

Show lang from now on; one out of range is English.

◆ ui_text_table()

const ui_language_t * ui_text_table ( ui_lang_t lang)

The table of lang; NULL for English.

◆ ui_tr()

const char * ui_tr ( ui_text_id_t id)

id in the language showing; "" for an ID out of range.

◆ ui_tr_in()

const char * ui_tr_in ( ui_lang_t lang,
ui_text_id_t id )

id in lang, falling back to English as ui_tr() does.

◆ ui_tr_pad()

const char * ui_tr_pad ( const ui_text_id_t * set,
int count,
int i,
char * buf,
size_t n )

Entry i of set in the language showing, padded with spaces to the cells of the longest entry of set, into buf. For a label one of several replaces in place: each lays out the same width, so one repaints over another without a clear.

◆ ui_unit_gap()

const char * ui_unit_gap ( const char * unit)

What stands between a number and unit: "" before a symbol ("6.00V", "1000.0mΩ", "40s") and before no unit, " " before a word that follows its number. A word that leads (ui_unit_is_prefix(), "GPIO 4") also gets " ".

Parameters
unitthe unit, or NULL
Returns
"" or " "

◆ ui_unit_is_prefix()

int ui_unit_is_prefix ( const char * unit)

Whether unit is written before its number: the pin word UI_PIN_WORD, "GPIO", so that a pin reads "GPIO 4" (ui_pin_name()) and not as a count of four GPIOs. Every other unit follows its number.

Parameters
unitthe unit, or NULL
Returns
1 for a pin word, else 0

◆ ui_unit_is_symbol()

int ui_unit_is_symbol ( const char * unit)

Whether unit is a unit symbol, written with no space after its number: one of k_unit_symbols (ui_text.c), which holds the symbols of tools/check_units.py, alone or followed by a "/" part ("rpm/V", "%/s").

Parameters
unitthe unit, UTF-8 ("mΩ"); NULL or "" is none
Returns
1 for a symbol ("V", "S", a battery's cell count), 0 for a word ("GPIO"), none or NULL

Variable Documentation

◆ k_card_text

const ui_text_id_t k_card_text[UI_CARD_AT_COUNT][3]
static
Initial value:
= {
[UI_CARD_AT_LOGS] = { TX_LOG_NO_CARD, TX_LOG_CARD_NO_FAT,
TX_LOG_CARD_UNREADABLE },
[UI_CARD_AT_SPLASH] = { TX_SPLASH_NO_CARD, TX_SPLASH_CARD_NO_FAT,
TX_SPLASH_CARD_UNREADABLE },
[UI_CARD_AT_RUN] = { TX_ALERT_NO_CARD_RUN, TX_ALERT_CARD_NO_FAT_RUN,
TX_ALERT_CARD_UNREADABLE },
[UI_CARD_AT_TEST] = { TX_ALERT_CARD_SERVO, TX_ALERT_CARD_SERVO_NO_FAT,
TX_ALERT_CARD_SERVO_UNREADABLE },
[UI_CARD_AT_KP_WRITE] = { TX_KP_WRITE_NO_CARD, TX_KP_WRITE_NO_FAT,
TX_KP_WRITE_UNREADABLE },
[UI_CARD_AT_KP_NO_FILE] = { TX_KP_NO_FILE_1, TX_KP_NO_FILE_1_NO_FAT,
TX_KP_NO_FILE_1_UNREADABLE },
[UI_CARD_AT_KP_NO_BACKUP] = { TX_KP_NO_BACKUP_FILE, TX_KP_NO_BACKUP_NO_FAT,
TX_KP_NO_BACKUP_UNREADABLE },
[UI_CARD_AT_KP_MSG] = { TX_KP_M_CARD_NONE, TX_KP_M_CARD_NO_FAT,
TX_KP_M_CARD_UNREADABLE },
}

◆ k_cells

const unsigned char k_cells[TX_COUNT]
static
Initial value:
= {
}

The cells each string's field has, 0 where –fit measures it.

◆ k_de_category

const char* const k_de_category[SET_CAT_COUNT]
static
Initial value:
= {
}

The settings categories' names in German.

◆ k_de_help

const char* const k_de_help[SETTING_COUNT]
static
Initial value:
= {
}

The settings' help lines in German, by setting ID.

◆ k_de_label

const char* const k_de_label[SETTING_COUNT]
static
Initial value:
= {
}

The settings' labels in German, by setting ID.

◆ k_de_options

const char* const* const k_de_options[]
static
Initial value:
= {
}

One array k_de_opts_<name> per option list, in German.

The German option lists, in the order of the table, which is the order settings_option_list() counts.

◆ k_de_servo

const char* const k_de_servo[SERVO_STR_COUNT]
static
Initial value:
= {
}

The servo test's words in German, by SERVO_STR_ ID.

◆ k_de_text

const char* const k_de_text[TX_COUNT]
static
Initial value:
= {
}

The screens' strings in German, by TX_ ID; NULL shows the English.

◆ k_en

const char* const k_en[TX_COUNT]
static
Initial value:
= {
}

The screens' strings in English, by TX_ ID.

◆ k_langs

const ui_language_t* const k_langs[UI_LANG_COUNT]
static
Initial value:
= {
[UI_LANG_EN] = NULL,
[UI_LANG_DE] = &ui_lang_de,
}
const ui_language_t ui_lang_de
The German tables, as ui_text.h declares them.
Definition ui_text.c:124

◆ k_unit_symbols

const char* const k_unit_symbols[]
static
Initial value:
= {
"kbit/s", "Mbit/s", "bit/s", "kB/s", "MB/s", "KB/s", "B/s", "KiB/s",
"MiB/s", "°/s", "deg/s",
"mAh", "mWh", "kWh", "Wh", "Ah",
"GHz", "MHz", "kHz", "Hz",
"µs", "μs", "us", "ns", "ms", "min", "s", "h",
"kV", "mV", "µV", "μV", "V", "mA", "µA", "μA", "uA", "nA", "A", "mW",
"kW", "W",
"mΩ", "kΩ", "MΩ", "Ω", "mOhm", "kOhm", "Ohm", "ohm",
"°C", "°F", "°", "%", "deg",
"KiB", "MiB", "GiB", "kB", "KB", "MB", "GB", "B", "kbps", "Mbps", "bps",
"px", "dBm", "dB", "rpm", "RPM", "eRPM", "fps", "ppm", "sps",
"mm", "cm", "µm", "nm", "m", "kg", "g", "Ncm", "Nm", "N",
"µF", "μF", "uF", "nF", "pF", "mF", "F", "µH", "uH", "mH", "nH", "H", "K",
"C", "S",
}

The unit symbols, as tools/check_units.py's UNITS lists them ("%%", its printf spelling of "%", as "%"); test_check_units.py holds the two lists to each other.

◆ ui_lang_de

const ui_language_t ui_lang_de
Initial value:
= {
.text = k_de_text,
.setting_label = k_de_label,
.setting_help = k_de_help,
.options = k_de_options,
.category = k_de_category,
.servo = k_de_servo,
}
static const char *const k_de_category[SET_CAT_COUNT]
The settings categories' names in German.
Definition ui_text.c:89
static const char *const k_de_text[TX_COUNT]
The screens' strings in German, by TX_ ID; NULL shows the English.
Definition ui_text.c:65
static const char *const k_de_help[SETTING_COUNT]
The settings' help lines in German, by setting ID.
Definition ui_text.c:81
static const char *const *const k_de_options[]
One array k_de_opts_<name> per option list, in German.
Definition ui_text.c:106
static const char *const k_de_label[SETTING_COUNT]
The settings' labels in German, by setting ID.
Definition ui_text.c:73
static const char *const k_de_servo[SERVO_STR_COUNT]
The servo test's words in German, by SERVO_STR_ ID.
Definition ui_text.c:114

The German tables, as ui_text.h declares them.