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

The status band: its chips, STOP and the chips' help boxes. More...

#include "ui_band.h"
#include <stdio.h>
#include <string.h>
#include "link_pages.h"
#include "ui_text.h"
#include "ui_theme.h"
#include "ui_widgets.h"

Data Structures

struct  chips_t
struct  [struct].k_bits

Macros

#define PANEL_W   UI_PANEL_W
 The panel's width, UI_PANEL_W px.
#define STOP_W   168
 STOP's width: 168px.
#define STOP_M   6
 STOP's margin to the band's top, bottom and right edges: 6px.
#define CHIP_Y   8
 A chip's top, from the band's: 8px.
#define CHIP_H   44
 A chip's height: 44px.
#define CHIP_GAP   6
 The gap between two chips: 6px.
#define CHIP_INSET   28
 A label's start from its chip's left edge: 28px.
#define CHIP_PAD_R   4
 A label's end from its chip's right edge: 4px.
#define CHIP_DOT_W   12
 LINK's dot: 12px more right of its label.
#define HELP_W   640
 A help bubble's width: 640px, 60 cells of text.
#define HELP_M   8
 A bubble's least distance to the panel's edges: 8px.
#define HELP_GAP   4
 A bubble's top under the band: 4px.
#define HELP_PAD   16
#define HELP_TOP   30
#define HELP_BOTTOM   10
 The last line to the bubble's bottom edge: 10px.
#define HELP_PITCH   21
 A bubble line to the next: 21px.
#define HELP_PARA   4
 More between two paragraphs: 4px.

Functions

gfx_rect_t ui_band_stop_rect (void)
const char * ui_band_mode (bool link_up)
const char * ui_band_mode_inject (void)
const char * ui_band_armed_label (uint8_t roles)
bool ui_link_refused_label (const ui_bench_status_t *st, char *out, size_t n)
static const char * chip_label (const ui_bench_status_t *st, ui_band_chip_t chip, char *buf, size_t n)
static bool chip_shown (const ui_bench_status_t *st, ui_band_chip_t chip)
static void chips_layout (const ui_bench_status_t *st, chips_t *l)
 Lay out the chips st shows, from STOP leftwards.
bool ui_band_chip_rect (const ui_bench_status_t *st, ui_band_chip_t chip, gfx_rect_t *out)
ui_band_chip_t ui_band_chip_at (const ui_bench_status_t *st, int x, int y)
 The chip a touch lands on.
static bool fault_para (uint16_t faults, int i)
static bool help_para (const ui_bench_status_t *st, ui_band_chip_t chip, int i)
static size_t line_len (const char *s, int cells)
static int help_body (gfx_canvas_t *c, const ui_bench_status_t *st, ui_band_chip_t chip, int x, int y, int cells)
 The bubble's text from (x, y), each paragraph broken into lines of cells.
static int help_cells (int w)
 The cells of a line of a bubble w px wide.
bool ui_band_help_rect (const ui_bench_status_t *st, ui_band_chip_t chip, gfx_rect_t *out)
void ui_band_help_render (gfx_canvas_t *c, const ui_bench_status_t *st, ui_band_chip_t chip)
static void chip_look (const ui_bench_status_t *st, ui_band_chip_t chip, gfx_color_t *dot, gfx_color_t *fill, gfx_color_t *ink)
 How chip is drawn for st: its dot, 0 for none, its fill and its text.
bool ui_band_chip_colors (const ui_bench_status_t *st, ui_band_chip_t chip, gfx_color_t *fill, gfx_color_t *ink)
 The fill and the text colour ui_band_render() draws chip in for st, in the theme in force.
static uint32_t fnv (uint32_t h, const void *p, size_t n)
 One step of the 32-bit FNV-1a hash over n bytes at p.
uint32_t ui_band_key (const char *title, bool show_home, const ui_bench_status_t *st, bool stop_pressed, bool home_pressed)
 A number for what ui_band_render() draws from the same arguments: the title, the home tag's and STOP's presses, the theme, and every chip's place, label and colours. Two calls that return the same number draw the same band, so the router repaints a buffer's band only when the number moves (ui_router_render()).
void ui_band_render (gfx_canvas_t *c, const char *title, bool show_home, const ui_bench_status_t *st, bool stop_pressed, bool home_pressed)

Variables

static const ui_band_chip_t k_order []
 The chips from STOP leftwards.
static char s_para [640]
static char s_line [400]
static const struct  k_bits []

Detailed Description

The status band: its chips, STOP and the chips' help boxes.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ HELP_PAD

#define HELP_PAD   16

text from the bubble's sides

◆ HELP_TOP

#define HELP_TOP   30

the first line from the top: tab and 10

Function Documentation

◆ chip_look()

void chip_look ( const ui_bench_status_t * st,
ui_band_chip_t chip,
gfx_color_t * dot,
gfx_color_t * fill,
gfx_color_t * ink )
static

How chip is drawn for st: its dot, 0 for none, its fill and its text.

Parameters
stthe bench's status
chipthe chip
dotits dot's colour, 0 for none
fillits fill
inkits text colour: the theme's text, and on the bright fills of FAULT's warning and of the armed badge the dark text of the buttons on bright fills

◆ chips_layout()

void chips_layout ( const ui_bench_status_t * st,
chips_t * l )
static

Lay out the chips st shows, from STOP leftwards.

Parameters
stThe bench status.
lThe layout, filled.

◆ help_body()

int help_body ( gfx_canvas_t * c,
const ui_bench_status_t * st,
ui_band_chip_t chip,
int x,
int y,
int cells )
static

The bubble's text from (x, y), each paragraph broken into lines of cells.

Draws when c is not NULL and measures either way, so the bubble is measured by the code that draws it.

Parameters
cThe canvas, or NULL to measure.
stThe bench status the text follows.
chipThe chip whose bubble it is.
xThe text's left edge.
yIts top.
cellsThe cells of a line.
Returns
The text's height in pixels.

◆ help_cells()

int help_cells ( int w)
static

The cells of a line of a bubble w px wide.

Parameters
wThe bubble's width.
Returns
Its width less the padding, in cells of UI_FONT_BAND.

◆ ui_band_armed_label()

const char * ui_band_armed_label ( uint8_t roles)

The armed chip's label for roles, UI_ARMED_* bits: ARMED MOTOR, ARMED SERVO, or ARMED for both and for none. English in every language, as STOP and the other controls are.

◆ ui_band_chip_at()

ui_band_chip_t ui_band_chip_at ( const ui_bench_status_t * st,
int x,
int y )

The chip a touch lands on.

A chip is hit across the band's whole height and 3px either side, half the gap to the next one; STOP and the home tag are not chips.

Parameters
stThe bench status the band shows.
xThe touch's panel x.
yThe touch's panel y.
Returns
The chip, or UI_BAND_CHIP_NONE.

◆ ui_band_chip_colors()

bool ui_band_chip_colors ( const ui_bench_status_t * st,
ui_band_chip_t chip,
gfx_color_t * fill,
gfx_color_t * ink )

The fill and the text colour ui_band_render() draws chip in for st, in the theme in force.

The armed badge and the FAULT chip draw the dark text of the buttons on bright fills; the other chips draw the theme's text on its sunk panel.

Parameters
stThe bench status the band shows.
chipThe chip.
fillThe chip's fill, or NULL.
inkThe chip's text colour, or NULL.
Returns
False, with both untouched, for st NULL or a chip that is not one of the band's.

◆ ui_band_chip_rect()

bool ui_band_chip_rect ( const ui_bench_status_t * st,
ui_band_chip_t chip,
gfx_rect_t * out )

Where chip is drawn for st, in panel coordinates, into out (which may be NULL). False when st draws no such chip: no FAULT chip while the bitmap is 0, no clock before a run, no mode chip without a mode.

◆ ui_band_help_rect()

bool ui_band_help_rect ( const ui_bench_status_t * st,
ui_band_chip_t chip,
gfx_rect_t * out )

The help bubble of chip for st, in panel coordinates: under the band, at the chip's left edge, moved left as far as the panel's right edge needs, and as tall as its text. FAULT's spans the panel, so a line per bit has room. False when the chip is not drawn.

◆ ui_band_help_render()

void ui_band_help_render ( gfx_canvas_t * c,
const ui_bench_status_t * st,
ui_band_chip_t chip )

Draw the help bubble of chip for st: the chip's label as its title, then what the state means for the bench and what to do about it, in the language showing. Built from st each time, so it follows the state.

◆ ui_band_key()

uint32_t ui_band_key ( const char * title,
bool show_home,
const ui_bench_status_t * st,
bool stop_pressed,
bool home_pressed )

A number for what ui_band_render() draws from the same arguments: the title, the home tag's and STOP's presses, the theme, and every chip's place, label and colours. Two calls that return the same number draw the same band, so the router repaints a buffer's band only when the number moves (ui_router_render()).

Parameters
titlethe current screen's title, or NULL
show_homewhether the title is the home tag
stthe bench's status, or NULL
stop_pressedSTOP is pressed
home_pressedthe home tag is pressed
Returns
the number, a 32-bit FNV-1a hash

◆ ui_band_mode()

const char * ui_band_mode ( bool link_up)

The mode the band names: BENCH while the link is up and the panel drives the IOmcu's outputs, SIM while it runs on its own models. Mode names, so English in every language.

◆ ui_band_mode_inject()

const char * ui_band_mode_inject ( void )

INJECT: the mode a panel built with RCBENCH_TOUCH_INJECTOR names in place of BENCH and SIM while a touch injector (testbench/touch-injector) is attached. A mode name, so English in every language. A build with RCBENCH_TOUCH_INJECTOR=OFF has neither this nor INJECT's bubble text.

◆ ui_band_render()

void ui_band_render ( gfx_canvas_t * c,
const char * title,
bool show_home,
const ui_bench_status_t * st,
bool stop_pressed,
bool home_pressed )

Draw the band. title is the current screen's title, or NULL on the splash, which has no home tag and no bench status.

◆ ui_band_stop_rect()

gfx_rect_t ui_band_stop_rect ( void )

Where STOP is, in panel coordinates. The router hit-tests it.

◆ ui_link_refused_label()

bool ui_link_refused_label ( const ui_bench_status_t * st,
char * out,
size_t n )

The label for the IOmcu's refused link frames, "Rejected link frames: N" in the language in force, into out of n bytes: the one place it is built. MOTOR & ESC shows it in its header strip. False, with out empty, while the link is down or the count (st->link_refused) is 0, so an IOmcu older than 4.21, which sends no count, shows no label.

Variable Documentation

◆ k_bits

const struct [struct].k_bits k_bits[]
Initial value:
= {
{ LINK_FAULT_LINK_SILENT, "LINK_SILENT", TX_BH_F_LINK_SILENT, false },
{ LINK_FAULT_OVERCURRENT, "OVERCURRENT", TX_BH_F_OVERCURRENT, true },
{ LINK_FAULT_OVERTEMP, "OVERTEMP", TX_BH_F_OVERTEMP, true },
{ LINK_FAULT_STALL, "STALL", TX_BH_F_STALL, true },
{ LINK_FAULT_HEARTBEAT, "HEARTBEAT", TX_BH_F_HEARTBEAT, false },
{ LINK_FAULT_VERSION, "VERSION", TX_BH_F_VERSION, true },
{ LINK_FAULT_STORE_OFF, "STORE_OFF", TX_BH_F_STORE_OFF, false },
}

◆ k_order

const ui_band_chip_t k_order[]
static
Initial value:
= {
}
@ UI_BAND_CHIP_LINK
Definition ui_screen.h:281
@ UI_BAND_CHIP_FAULT
Definition ui_screen.h:283
@ UI_BAND_CHIP_ARMED
Definition ui_screen.h:284
@ UI_BAND_CHIP_CLOCK
Definition ui_screen.h:285
@ UI_BAND_CHIP_MODE
Definition ui_screen.h:282

The chips from STOP leftwards.