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

The settings, as a schema the screen draws rather than a screen per setting. More...

#include "settings.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "link_pages.h"
#include "out_bind.h"
#include "settings_sensors.h"
#include "settings_opts.h"

Data Structures

struct  [struct].k_text_defs
struct  [struct].s
 Driver state of the UART: the claimed machines and the pins. More...

Macros

#define DEF(i)
#define ENUM_OPTS(name)
 An enum row's options: list name of ui_text.def (settings_opts.h).
#define DECIMALS_MAX   3
 The most digits after the point a step carries: 0.001A, the servo programmer's current.

Functions

static bool value_differs (int i)
static bool differs_from_stored (void)
static void mark_dirty (void)
static void take_stored (void)
static float clampf (float v, float lo, float hi)
const setting_def_t * settings_def (setting_id_t id)
bool settings_derived (setting_id_t id)
void settings_set_hold (settings_hold_fn fn)
void settings_set_armed (settings_armed_fn fn)
 Install the ARMED source (settings.h).
bool settings_safe_only (setting_id_t id)
 Whether id changes on a SAFE bench only (settings.h).
bool settings_held (setting_id_t id)
 Whether id is held now: settings_set(), settings_adjust(), settings_reset() and settings_reset_all() leave it, and SETUP draws its row without keys.
const char * settings_category_name (setting_cat_t cat)
 A category's name in English, from ui_text.def.
static float snap_to_step (const setting_def_t *d, float v)
bool settings_sense_sda_valid (int gpio)
bool settings_tap_pin_valid (int gpio)
 Whether Tap pin takes gpio: an IOmcu GPIO the RP2350-CAN brings out and does not reserve, outbind_reserved_mask(), that is no ADC pin – the TONE page refuses GP26 to GP29 of the RP2350A and GP40 to GP47 of the RP2354B. That leaves 0, 1, 2, 4, 5, 6, 7 and 13 to 22. A pin an output, the supply or the sensor bus holds is not known here; the page refuses it and SETUP marks the row.
bool settings_pdmini_same_pin (void)
static bool pin_takes (setting_id_t id, int pin)
static float coerce (const setting_def_t *d, float v)
static bool derive (void)
static void notify_changed (int id, float before)
static bool text_to (int i, const char *text)
void settings_reset (setting_cat_t cat)
static void defaults (bool held)
void settings_reset_all (void)
void settings_set_store (const settings_store_t *store)
void settings_set_observer (settings_observer_fn fn)
void settings_set_text_observer (settings_text_observer_fn fn)
void settings_init (void)
float settings_get (setting_id_t id)
int settings_get_int (setting_id_t id)
bool settings_get_bool (setting_id_t id)
void settings_set (setting_id_t id, float value)
bool settings_cycles (setting_id_t id)
void settings_adjust (setting_id_t id, int steps)
int settings_in_category (setting_cat_t cat, setting_id_t *out, int max)
int settings_decimals (setting_id_t id)
 The digits after the point a number of id is shown and typed with: as many as its step has.
const char * settings_value_text (setting_id_t id, char *buf, size_t n)
 Render the value as it should appear on screen, unit excluded: a float with settings_decimals() digits after the point.
const char * settings_value_text_of (setting_id_t id, float v, char *buf, size_t n)
 Render value as settings_value_text() renders the value of id.
bool settings_dirty (void)
bool settings_save (void)
const char * settings_text (setting_text_id_t id)
const char * settings_text_key (setting_text_id_t id)
void settings_set_text (setting_text_id_t id, const char *text)
setting_cat_t settings_text_category (setting_text_id_t id)
int settings_texts_in_category (setting_cat_t cat, setting_text_id_t *out, int max)
bool settings_save_failed (void)
void settings_request_save (void)
bool settings_save_asked (void)
void settings_cancel_save (void)
bool settings_save_tick (bool safe)
float settings_stored (setting_id_t id)
const char * settings_stored_text (setting_text_id_t id)
bool settings_differs (setting_id_t id)
bool settings_text_differs (setting_text_id_t id)
int settings_changes (void)
int settings_discard (void)

Variables

static const setting_def_t k_defs [SETTING_COUNT]
static const char *const k_cat_names [SET_CAT_COUNT]
 The categories' names in English, from ui_text.def.
static const struct  k_text_defs [SETTING_TEXT_COUNT]
static struct  s

Detailed Description

The settings, as a schema the screen draws rather than a screen per setting.

Every setting is one row in a table – its type, its range, its step, its default – and the settings screen renders whatever the table says, so adding a setting is a row and never new UI code. The values live behind an injectable store (NVS, non-volatile storage, on the panel; memory in a test) and every change goes through one observer, which is the single place a changed value reaches the rest of the bench.

A stored value is never trusted to match the schema. A word read back from flash can be off the declared grid or outside the range (written by another build, stale, or corrupt), so a value is coerced onto the step and clamped into range on the way out, rather than cycling round or being handed to a screen that assumes it is valid.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ DEF

#define DEF ( i)
Value:
(*settings_def((setting_id_t)(i)))
setting_id_t
Every setting's id, in schema order.
Definition settings.h:67

◆ ENUM_OPTS

#define ENUM_OPTS ( name)
Value:
.options = settings_opts_##name, \
.option_count = (uint8_t)settings_opts_n_##name

An enum row's options: list name of ui_text.def (settings_opts.h).

Function Documentation

◆ settings_adjust()

void settings_adjust ( setting_id_t id,
int steps )

Step by steps increments. A number stops at its range's ends. Booleans and enums cycle (settings_cycles()), except the INA228 and INA3221 addresses, which stop at the first and the last of their list. Sensor SDA steps from one value settings_sense_sda_valid() takes to the next and stops at the first and the last. PD mini TX and PD mini RX step over the GPIO the other holds, so a step never sets them to one pin; with that GPIO at the end of the range the step stays where it is. -1, not wired, is a step for both.

◆ settings_cancel_save()

void settings_cancel_save ( void )

Forget a request that has not been taken.

◆ settings_category_name()

const char * settings_category_name ( setting_cat_t cat)

A category's name in English, from ui_text.def.

Parameters
catThe category.
Returns
Its name; "" for one out of range. ui_setting_category() gives it in the language showing.

◆ settings_changes()

int settings_changes ( void )

How many values and strings differ from their stored ones.

◆ settings_cycles()

bool settings_cycles ( setting_id_t id)

Whether settings_adjust() wraps id round from one end to the other: a switch or a choice, drawn with < and > keys. False for a number and for the monitors' addresses, which stop at their ends and are drawn with - and + keys; false for an id out of range.

◆ settings_decimals()

int settings_decimals ( setting_id_t id)

The digits after the point a number of id is shown and typed with: as many as its step has.

Parameters
idThe setting.
Returns
0 for a step of 1 or more, 1 for 0.1, 2 for 0.05, 0.02 and 0.01, 3 for 0.001; 0 for an id out of range and a step of 0.

◆ settings_derived()

bool settings_derived ( setting_id_t id)

Whether id follows another setting: settings_set() and settings_adjust() leave it, and SETUP draws its row without keys. Sensor SCL, which is the GPIO after Sensor SDA.

◆ settings_differs()

bool settings_differs ( setting_id_t id)

Whether the value of id in force differs from its stored value.

◆ settings_dirty()

bool settings_dirty ( void )

Whether the values in force differ from the stored copy, or the copy is not known to be the medium: true after a refused save until a save succeeds. An edit back to the stored value leaves it false.

◆ settings_discard()

int settings_discard ( void )

Put every changed value and string back to its stored one, by settings_set() and settings_set_text(): the observer hears each value that moves as it hears an edit by hand, in schema order. A held value is left, as settings_set() leaves it; a derived one follows its source. After a refused save, when the medium can hold part of that write, it also asks for a save (settings_request_save()), so a restart loads the values put back. Returns how many values and strings still differ: the held ones.

◆ settings_held()

bool settings_held ( setting_id_t id)

Whether id is held now: settings_set(), settings_adjust(), settings_reset() and settings_reset_all() leave it, and SETUP draws its row without keys.

The servo tester's target and the port's pulse while the servo programmer holds the port (kst_panel.h); a SAFE-only setting while the bench is ARMED (settings_safe_only()).

Parameters
idThe setting.
Returns
True while held; false for an id out of range.

◆ settings_in_category()

int settings_in_category ( setting_cat_t cat,
setting_id_t * out,
int max )

Ids in a category, in schema order. Returns how many there are.

◆ settings_init()

void settings_init ( void )

Reset to defaults, then load from the store if one is set.

◆ settings_pdmini_same_pin()

bool settings_pdmini_same_pin ( void )

Whether PD mini TX and PD mini RX hold one GPIO, 0 or above. The steps never set that; a stored set-up can hold it. The panel writes such a wiring to the SUPPLY page disabled (supply_link.c), so the PD mini stays off, and SETUP marks both rows.

◆ settings_request_save()

void settings_request_save ( void )

Ask for the values to be written, without writing them.

A save is a flash write, and on the panel a flash write disables the cache and stalls both cores: the task that beats the safety line does not run for its duration. So the operator says when they want it kept and the application says when that is survivable, which is the same split the IOmcu's own store already makes.

◆ settings_reset()

void settings_reset ( setting_cat_t cat)

Restore one category, or all of them, to the schema defaults: its values and its strings (settings_text_category()).

◆ settings_safe_only()

bool settings_safe_only ( setting_id_t id)

Whether id changes on a SAFE bench only (settings.h).

Whether id changes on a SAFE bench only: held while the source settings_set_armed() installed says ARMED, as the throttle endpoints on MOTOR & ESC > SETTINGS are locked while ARMED. Screen rotation, which moves every control under the finger.

Whether id changes on a SAFE bench only (settings.h).

Parameters
idThe setting.
Returns
True for SET_SCREEN_ROT.

◆ settings_save()

bool settings_save ( void )

Persist through the store and clear the dirty flag.

◆ settings_save_asked()

bool settings_save_asked ( void )

Whether a save has been asked for and not yet taken.

◆ settings_save_failed()

bool settings_save_failed ( void )

Whether the last attempt failed and nothing has been written since.

◆ settings_save_tick()

bool settings_save_tick ( bool safe)

Take the save if one was asked for and safe says now will do.

Returns true when it wrote. Call it wherever the application knows the bench is idle – an armed bench is not the moment to stop both cores.

◆ settings_sense_sda_valid()

bool settings_sense_sda_valid ( int gpio)

Whether Sensor SDA takes gpio: -1, the bus's pins not set, or an IOmcu GPIO the sensor bus can have its SDA on with SCL on the GPIO after it. That is one I2C block's pair, link_sn_pins_pair() – the rule the IOmcu's SENSE page judges a write by – on two pins the RP2350-CAN brings out and does not reserve, outbind_reserved_mask(): the mask the IOmcu reserves at boot. 0, 4, 6, 14, 16, 18, 20 and 26. A pin an output, the supply or the phase tap holds is not known here; the page refuses it and SETUP marks the row.

◆ settings_set()

void settings_set ( setting_id_t id,
float value )

Clamped to the schema; enums wrap. Fires the observer when it changes. A derived setting and a held one are left as they are.

◆ settings_set_armed()

void settings_set_armed ( settings_armed_fn fn)

Install the ARMED source (settings.h).

Install who says whether the bench is ARMED, or NULL for a bench that is never ARMED. Asked at every change, as the hold is.

Install the ARMED source (settings.h).

Parameters
fnThe source; the panel's reads the router's status.

◆ settings_set_hold()

void settings_set_hold ( settings_hold_fn fn)

Who says which settings are held, or NULL for none. Asked at every change, so a hold begins and ends with what it names.

◆ settings_set_text()

void settings_set_text ( setting_text_id_t id,
const char * text )

Set it, cut to SETTINGS_TEXT_MAX - 1 characters; an edit like any other.

◆ settings_stored()

float settings_stored ( setting_id_t id)

The stored value of id; 0 for an id out of range.

◆ settings_stored_text()

const char * settings_stored_text ( setting_text_id_t id)

The stored string of id; "" for an id out of range. Never NULL.

◆ settings_tap_pin_valid()

bool settings_tap_pin_valid ( int gpio)

Whether Tap pin takes gpio: an IOmcu GPIO the RP2350-CAN brings out and does not reserve, outbind_reserved_mask(), that is no ADC pin – the TONE page refuses GP26 to GP29 of the RP2350A and GP40 to GP47 of the RP2354B. That leaves 0, 1, 2, 4, 5, 6, 7 and 13 to 22. A pin an output, the supply or the sensor bus holds is not known here; the page refuses it and SETUP marks the row.

Parameters
gpioAn IOmcu GPIO number.
Returns
true when Tap pin takes it.

◆ settings_text()

const char * settings_text ( setting_text_id_t id)

A string setting. Never NULL.

◆ settings_text_category()

setting_cat_t settings_text_category ( setting_text_id_t id)

The category a string is set in on SETUP, or SET_CAT_COUNT for one set elsewhere: the DUT name, on SERVO > SETTINGS.

◆ settings_text_differs()

bool settings_text_differs ( setting_text_id_t id)

Whether the string of id differs from its stored string.

◆ settings_text_key()

const char * settings_text_key ( setting_text_id_t id)

Its NVS key, 15 characters or fewer. NULL for an id out of range.

◆ settings_texts_in_category()

int settings_texts_in_category ( setting_cat_t cat,
setting_text_id_t * out,
int max )

The strings of cat, in id order. Returns how many there are.

◆ settings_value_text()

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

Render the value as it should appear on screen, unit excluded: a float with settings_decimals() digits after the point.

Parameters
idThe setting.
bufWhere the text goes.
nThe size of buf in bytes.
Returns
buf; "" for a NULL buf or an n of 0.

◆ settings_value_text_of()

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

Render value as settings_value_text() renders the value of id.

Parameters
idThe setting.
valueThe value.
bufWhere the text goes.
nIts size.
Returns
buf; "" for no buffer.

Variable Documentation

◆ k_cat_names

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

The categories' names in English, from ui_text.def.

◆ k_text_defs

const struct [struct].k_text_defs k_text_defs[SETTING_TEXT_COUNT]
Initial value:
= {
[SET_TEXT_DUT_NAME] = { "srv_dut", "SERVO", SET_CAT_COUNT },
[SET_TEXT_LOG_AUTO_DIR] = { "log_auto_dir", "BENCH/LOGS", SET_CAT_CARD },
[SET_TEXT_LOG_USER_DIR] = { "log_user_dir", "USER/LOGS", SET_CAT_CARD },
}
@ SET_CAT_CARD
Definition settings.h:32
@ 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