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

The overlay of the programmer for KST and Chaservo servos: its state, rows, shared helpers, geometry and the caller's side. More...

#include "kst_panel.h"
#include <stdio.h>
#include <string.h>
#include "kst_card.h"
#include "kst_port.h"
#include "kst_reg.h"
#include "link_pages.h"
#include "settings.h"
#include "ui_card_text.h"
#include "ui_tabs.h"
#include "ui_text.h"
#include "ui_textkey.h"
#include "ui_widgets.h"
#include "kst_panel_int.h"

Functions

static card_state_t card_state (void)
ui_text_id_t kpn_card_text_id (ui_card_at_t at)
 The card's words for at, for the slot as the feed says it.
const char * kpn_card_tr (ui_card_at_t at)
 The same words, translated.
unsigned kpn_ones (uint64_t v)
 The bits set in v.
uint8_t kpn_port_no (void)
 The programming port the overlay works on: the SERVO screen's target, and the first port while that is the servo outputs.
bool kpn_on_port (void)
 Whether the SERVO screen's tester drives a programming port.
bool kpn_flag (uint16_t f)
 Whether flag f is set in the port's report.
bool kpn_programming (void)
 Whether the port is in programming.
unsigned kpn_servo_type (void)
 The servo's type as the card names it; 0 without a servo.
const char * kpn_row_label (const row_t *r)
 A row's label: its text, or for PORT and SERVO what they hold now.
const char * kpn_field_name (unsigned id)
 The name a field has on its row; NULL for one without a row.
bool kpn_in_set (kst_field_set_t set, unsigned id)
 Whether field id is in set.
const char * kpn_unit_of (kst_field_id_t id)
 A field's unit as its value shows it; "" for none.
int kpn_decimals_of (kst_field_id_t id)
 Digits after the point a field's displayed value has.
void kpn_fmt_value (kst_field_id_t id, uint16_t raw, char *out, size_t n, bool unit)
 A field's value as its row shows it.
void kpn_fmt_field (kst_field_id_t id, uint16_t raw, char *out, size_t n)
 kpn_fmt_value() with the unit.
bool kpn_changed (kst_field_id_t id)
 Whether the draft holds another value of id than the servo.
static int text_cells (void)
 The cells of KP_FONT a line of text has: the area less 10px on each side, 60 on SERVO's left card of 620px.
static size_t row_len (const char *s)
static const char * next_row (const char *s, size_t len)
int kst_panel_text_rows (const char *s)
 The rows of 10 x 20 cells a line of a message, a note or a warning page takes, wrapped at a space to the overlay's width less 10px a side, one cell a row at least (before kst_panel_init(), say): 60 cells a row on SERVO's left card of 620px.
int kpn_text_rows (gfx_canvas_t *c, int x, int y, const char *s, gfx_color_t color)
 s in rows of the area's width, a row each LINE_H.
gfx_rect_t kpn_tabs_rect (void)
 The tabs.
int kpn_foot (void)
 Where a control at the area's foot ends.
int kpn_notes_foot (void)
 Where the notes and the message under a page end.
gfx_rect_t kpn_row_rect (const row_t *r)
 Row r, its label and its control.
static gfx_rect_t control_rect (const row_t *r)
gfx_rect_t kpn_value_rect (const row_t *r)
 Row r's value, between its keys where it has them.
gfx_rect_t kpn_step_rect (const row_t *r, bool up)
 Row r's plus key (up) or minus key.
const row_t * kpn_row_at (int page, int row, int col)
 The row at (row, col) of page page, or NULL.
gfx_rect_t kst_panel_tab_rect (int page)
 A tab, one fifth of the row left of CLOSE, 48px tall.
gfx_rect_t kst_panel_close_rect (void)
 CLOSE, 120 x 48px at the top right.
gfx_rect_t kst_panel_value_rect (int page, int row, int col)
 A row's value: 150px, a wide row's 260px less its keys.
gfx_rect_t kst_panel_step_rect (int page, int row, bool up)
 A stepped row's minus or plus key, 56 x 48px.
gfx_rect_t kst_panel_choice_rect (int i)
 A list's entry, 48px tall at a 56px pitch under the title.
gfx_rect_t kst_panel_choice_cancel_rect (void)
 A list's CANCEL, 150 x 48px at the foot's right.
gfx_rect_t kst_panel_apply_rect (void)
 A warning page's hold button, 300 x 56px at the foot's left.
gfx_rect_t kst_panel_cancel_rect (void)
 A warning page's CANCEL, 180 x 56px at the foot's right.
ui_keypad_t * kst_panel_keypad (void)
const char * kpn_shown (const char *name)
 A file name as a line shows it: whole up to KST_PANEL_NAME_TYPED characters, else its start and "..".
ui_textkey_t * kst_panel_textkey (void)
const char * kst_panel_warning_line (int i)
int kst_panel_warning_level (int i)
const char * kst_panel_label (int page, int row, int col)
const char * kst_panel_choice_title (void)
const char * kst_panel_choice_label (int i)
int kst_panel_page (void)
int kst_panel_editor (void)
void kst_panel_gate (kst_prog_gate_t *g)
static bool holds_setting (setting_id_t id)
 The settings that reach the port: what the tester drives and whether the port renders its pulse. Held while nothing but the programmer reaches the port.
void kst_panel_init (gfx_rect_t area)
static void options_fresh (void)
 The options are read where the settings are there: at a screen entry and at an opening, never at kst_panel_init(), which runs before the settings are loaded. A session keeps the values it began with, except one found running by a panel that has read none yet.
void kst_panel_screen_entry (void)
void kst_panel_open (void)
 Opens the overlay and reads the programmer's options from the settings.
bool kst_panel_is_open (void)
 Returns whether the overlay is open.
bool kst_panel_holds_port (void)
uint32_t kst_panel_revision (void)
uint32_t kst_panel_hold_revision (void)
static uint32_t signature (void)
 Everything of the model a render shows, as one number.
static void model_moved (void)
 Follows the model's state after a feed or an operation: closes editors that asked for the state they were opened in and counts the revision when the picture changes.
void kst_panel_feed (const kst_prog_feed_t *f)
 Gives the model the link task's feed for this frame and updates the overlay's revision.
void kst_panel_set_hv (bool on)
bool kst_panel_take (kst_prog_cmd_t *out)
 Takes the next command for the link task.
void kst_panel_bench_armed (bool armed)
bool kst_panel_card_look (void)
bool kst_panel_card_take (kst_prog_card_req_t *out)
void kst_panel_card_done (const kst_prog_card_done_t *done)
 Gives the model the outcome of a card operation.
size_t kst_panel_file_take (char *out, size_t n)
 Takes the name of the file the card is to hold; the text itself is copied into out.
void kst_panel_file_done (bool ok)
 Gives the model the result of the file write the card made.
bool kst_panel_file_load (const char *text, size_t len)
 Loads the text of a servo file the card read into the draft.
bool kst_panel_file_late (const char *text, size_t len)

Variables

const row_t kpn_rows []
 The overlay's rows, ROW_COUNT of them.
static const ui_text_id_t k_pages [PG_COUNT]
kst_panel_state_t kst_panel_k
 The state, kst_panel_k, in kst_panel.c, so its .bss stays where psram_bss.lf puts kst_panel's. The files read it as k, the name it had as the one file's static: the object's own name keeps it apart from every other screen's state.
static kst_prog_gate_t * s_gate
 Not part of k: a start of the screens leaves it.
const prog_page_set_t kst_panel_pages

Detailed Description

The overlay of the programmer for KST and Chaservo servos: its state, rows, shared helpers, geometry and the caller's side.

The overlay of the programmer for KST and Chaservo servos. See kst_panel.h.

This file is the state, the rows, the helpers the other files share, the geometry, and the caller's side: the feed, the hooks and the page set. The texts are kst_panel_text.c, the warning pages kst_panel_warn.c, the editors kst_panel_edit.c, the presses kst_panel_touch.c, the limit run's sessions kst_panel_run.c and the drawing kst_panel_draw.c, with kst_panel_int.h between them.

SPDX-License-Identifier: MIT

Function Documentation

◆ kpn_card_text_id()

ui_text_id_t kpn_card_text_id ( ui_card_at_t at)

The card's words for at, for the slot as the feed says it.

Parameters
atwhere the card is
Returns
the text id

◆ kpn_card_tr()

const char * kpn_card_tr ( ui_card_at_t at)

The same words, translated.

Parameters
atwhere the card is
Returns
the text

◆ kpn_changed()

bool kpn_changed ( kst_field_id_t id)

Whether the draft holds another value of id than the servo.

Parameters
idthe field
Returns
true when the draft differs from the servo

◆ kpn_decimals_of()

int kpn_decimals_of ( kst_field_id_t id)

Digits after the point a field's displayed value has.

Parameters
idthe field
Returns
the number of digits

◆ kpn_field_name()

const char * kpn_field_name ( unsigned id)

The name a field has on its row; NULL for one without a row.

Parameters
idthe field id
Returns
the name, or NULL

◆ kpn_flag()

bool kpn_flag ( uint16_t f)

Whether flag f is set in the port's report.

Parameters
fthe flag
Returns
true when the flag is set

◆ kpn_fmt_field()

void kpn_fmt_field ( kst_field_id_t id,
uint16_t raw,
char * out,
size_t n )

kpn_fmt_value() with the unit.

Parameters
idthe field
rawits raw value
outthe text
nthe size of out, bytes

◆ kpn_fmt_value()

void kpn_fmt_value ( kst_field_id_t id,
uint16_t raw,
char * out,
size_t n,
bool unit )

A field's value as its row shows it.

Parameters
idthe field
rawits raw value
outthe text
nthe size of out, bytes
unitwith the unit; without where a line gives it once behind two values

◆ kpn_foot()

int kpn_foot ( void )

Where a control at the area's foot ends.

Returns
the lower of 8px above the area's foot and FOOT_GAP above the alert band, in the area's coordinates (body pixels)

◆ kpn_in_set()

bool kpn_in_set ( kst_field_set_t set,
unsigned id )

Whether field id is in set.

Parameters
setthe set of fields
idthe field id
Returns
true when the field is in the set

◆ kpn_notes_foot()

int kpn_notes_foot ( void )

Where the notes and the message under a page end.

Returns
the lower of 6px above the area's foot and FOOT_GAP above the alert band, in the area's coordinates (body pixels): no text lies under the band

◆ kpn_on_port()

bool kpn_on_port ( void )

Whether the SERVO screen's tester drives a programming port.

Returns
true when the tester drives a programming port

◆ kpn_ones()

unsigned kpn_ones ( uint64_t v)

The bits set in v.

Parameters
vthe bit set
Returns
the number of ones

◆ kpn_port_no()

uint8_t kpn_port_no ( void )

The programming port the overlay works on: the SERVO screen's target, and the first port while that is the servo outputs.

Returns
the port number

◆ kpn_programming()

bool kpn_programming ( void )

Whether the port is in programming.

Returns
true when the port is in programming

◆ kpn_row_at()

const row_t * kpn_row_at ( int page,
int row,
int col )

The row at (row, col) of page page, or NULL.

Parameters
pagethe page
rowthe row on the page
colthe column in the row
Returns
the row, or NULL

◆ kpn_row_label()

const char * kpn_row_label ( const row_t * r)

A row's label: its text, or for PORT and SERVO what they hold now.

Parameters
rthe row
Returns
the label

◆ kpn_row_rect()

gfx_rect_t kpn_row_rect ( const row_t * r)

Row r, its label and its control.

Parameters
rthe row
Returns
the rectangle

◆ kpn_servo_type()

unsigned kpn_servo_type ( void )

The servo's type as the card names it; 0 without a servo.

Returns
the type, 0 for none

◆ kpn_shown()

const char * kpn_shown ( const char * name)

A file name as a line shows it: whole up to KST_PANEL_NAME_TYPED characters, else its start and "..".

Parameters
namethe file name
Returns
the text, static

◆ kpn_step_rect()

gfx_rect_t kpn_step_rect ( const row_t * r,
bool up )

Row r's plus key (up) or minus key.

Parameters
rthe row
uptrue for the plus key, false for the minus key
Returns
the key's rectangle

◆ kpn_tabs_rect()

gfx_rect_t kpn_tabs_rect ( void )

The tabs.

Returns
the tabs' rectangle

◆ kpn_text_rows()

int kpn_text_rows ( gfx_canvas_t * c,
int x,
int y,
const char * s,
gfx_color_t color )

s in rows of the area's width, a row each LINE_H.

Returns
the y under the last row
Parameters
cthe canvas
xthe left edge, px
ythe top edge, px
sthe text
colorthe text colour

◆ kpn_unit_of()

const char * kpn_unit_of ( kst_field_id_t id)

A field's unit as its value shows it; "" for none.

Parameters
idthe field
Returns
the unit

◆ kpn_value_rect()

gfx_rect_t kpn_value_rect ( const row_t * r)

Row r's value, between its keys where it has them.

Parameters
rthe row
Returns
the rectangle

◆ kst_panel_apply_rect()

gfx_rect_t kst_panel_apply_rect ( void )

A warning page's hold button, 300 x 56px at the foot's left.

Returns
its rectangle

◆ kst_panel_bench_armed()

void kst_panel_bench_armed ( bool armed)

The bench is armed or asked to arm: CONNECT and every operation that sends frames are refused with KST_PROG_MSG_NEED_DISARM. No screen takes an arm while kst_panel_holds_port(): ARM on the SERVO and MOTOR screens takes no press, and the ESC stick programmer starts no run.

◆ kst_panel_cancel_rect()

gfx_rect_t kst_panel_cancel_rect ( void )

A warning page's CANCEL, 180 x 56px at the foot's right.

Returns
its rectangle

◆ kst_panel_card_done()

void kst_panel_card_done ( const kst_prog_card_done_t * done)

Gives the model the outcome of a card operation.

Parameters
donethe outcome

◆ kst_panel_card_look()

bool kst_panel_card_look ( void )

True once after the overlay was opened or one of its actions tapped with a feed: the caller, which has the card, looks at the slot, mounts a card put in or swapped and lets one taken out go.

◆ kst_panel_card_take()

bool kst_panel_card_take ( kst_prog_card_req_t * out)

The servo files: a request for the task that has the card, and what it made of it (kst_card_run()).

◆ kst_panel_choice_cancel_rect()

gfx_rect_t kst_panel_choice_cancel_rect ( void )

A list's CANCEL, 150 x 48px at the foot's right.

Returns
its rectangle

◆ kst_panel_choice_rect()

gfx_rect_t kst_panel_choice_rect ( int i)

A list's entry, 48px tall at a 56px pitch under the title.

Parameters
ithe entry, from 0
Returns
its rectangle

◆ kst_panel_choice_title()

const char * kst_panel_choice_title ( void )

The open list's title; NULL while none is open.

◆ kst_panel_close_rect()

gfx_rect_t kst_panel_close_rect ( void )

CLOSE, 120 x 48px at the top right.

Returns
its rectangle

◆ kst_panel_editor()

int kst_panel_editor ( void )

What is open over the page: 0 none, 1 keypad, 2 choice list, 3 warning, 4 the keyboard for a file's name.

◆ kst_panel_feed()

void kst_panel_feed ( const kst_prog_feed_t * f)

Gives the model the link task's feed for this frame and updates the overlay's revision.

Parameters
fthe feed

◆ kst_panel_file_done()

void kst_panel_file_done ( bool ok)

Gives the model the result of the file write the card made.

Parameters
oktrue when the card wrote the file

◆ kst_panel_file_late()

bool kst_panel_file_late ( const char * text,
size_t len )

The same for the file of a card mounted after the start. A record the model holds already stands, before and after the read that follows the interrupted write: the text is not used then, and false is returned with nothing said.

◆ kst_panel_file_load()

bool kst_panel_file_load ( const char * text,
size_t len )

Loads the text of a servo file the card read into the draft.

Parameters
textthe file's text
lenthe length of text, bytes
Returns
true when the model took the file

◆ kst_panel_file_take()

size_t kst_panel_file_take ( char * out,
size_t n )

Takes the name of the file the card is to hold; the text itself is copied into out.

Parameters
outbuffer written to
nsize of out, bytes
Returns
the length written

◆ kst_panel_gate()

void kst_panel_gate ( kst_prog_gate_t * g)

The gate the task that owns the link module claims each START at (kst_prog_gate_set()). Kept over kst_panel_init(). NULL for none.

◆ kst_panel_hold_revision()

uint32_t kst_panel_hold_revision ( void )

Changes while a warning's button fills; kst_panel_apply_rect() is where.

◆ kst_panel_holds_port()

bool kst_panel_holds_port ( void )

The port is in programming, or moves: the overlay is shown.

◆ kst_panel_init()

void kst_panel_init ( gfx_rect_t area)

Start over: closed, no servo, nothing stored. area is the overlay's.

◆ kst_panel_is_open()

bool kst_panel_is_open ( void )

Returns whether the overlay is open.

Returns
true when open

◆ kst_panel_label()

const char * kst_panel_label ( int page,
int row,
int col )

The label of the row at page, row, col as it is drawn now.

◆ kst_panel_page()

int kst_panel_page ( void )

The tab shown: 0 SERVO, 1 TUNE, 2 PULSE, 3 FAILSAFE, 4 LOCKED.

◆ kst_panel_revision()

uint32_t kst_panel_revision ( void )

Changes whenever a render would show something else.

◆ kst_panel_screen_entry()

void kst_panel_screen_entry ( void )

The SERVO screen was entered: ENABLE WRITE TO SERVO goes off.

◆ kst_panel_set_hv()

void kst_panel_set_hv ( bool on)

HV SERVO of the SERVO screen: off, the programming voltage stays at or below KST_PANEL_STD_MV, and one set above it goes back to KST_PROG_SUPPLY_MV. On, it allows a voltage above KST_PANEL_STD_MV through the warning page and its hold; no such voltage is stored or loaded.

◆ kst_panel_step_rect()

gfx_rect_t kst_panel_step_rect ( int page,
int row,
bool up )

A stepped row's minus or plus key, 56 x 48px.

Parameters
pagethe tab
rowthe row, from the top; column 0
upthe plus key; else the minus key
Returns
its rectangle; empty for no such row

◆ kst_panel_tab_rect()

gfx_rect_t kst_panel_tab_rect ( int page)

A tab, one fifth of the row left of CLOSE, 48px tall.

Parameters
pagethe tab, PG_SERVO to PG_LOCKED; another is the first
Returns
its rectangle

◆ kst_panel_take()

bool kst_panel_take ( kst_prog_cmd_t * out)

Takes the next command for the link task.

Parameters
outthe command
Returns
true when a command was taken

◆ kst_panel_text_rows()

int kst_panel_text_rows ( const char * s)

The rows of 10 x 20 cells a line of a message, a note or a warning page takes, wrapped at a space to the overlay's width less 10px a side, one cell a row at least (before kst_panel_init(), say): 60 cells a row on SERVO's left card of 620px.

Parameters
sthe line
Returns
its rows, 0 for an empty line

◆ kst_panel_value_rect()

gfx_rect_t kst_panel_value_rect ( int page,
int row,
int col )

A row's value: 150px, a wide row's 260px less its keys.

Parameters
pagethe tab
rowthe row, from the top
colthe column, 0 or 1
Returns
its rectangle; empty for no such row

◆ kst_panel_warning_level()

int kst_panel_warning_level ( int i)

The level line i of the open warning page is drawn in: a kst_prog_level_t; KST_PROG_INFO past the last.

◆ kst_panel_warning_line()

const char * kst_panel_warning_line ( int i)

Line i of the open warning page, entry i of the open list; NULL past the last and while none is open.

Variable Documentation

◆ k_pages

const ui_text_id_t k_pages[PG_COUNT]
static
Initial value:
= {
TX_KP_TAB_SERVO, TX_KP_TAB_TUNE, TX_KP_TAB_PULSE, TX_KP_TAB_FAILSAFE,
TX_KP_TAB_LOCKED,
}

◆ kst_panel_pages

const prog_page_set_t kst_panel_pages
Initial value:
= {
.init = kst_panel_init,
.open = kst_panel_open,
.is_open = kst_panel_is_open,
.back = kst_panel_back,
.holds_port = kst_panel_holds_port,
.tick = kst_panel_tick,
.has_press = kst_panel_has_press,
.event = kst_panel_event,
.render = kst_panel_render,
.revision = kst_panel_revision,
.hold_revision = kst_panel_hold_revision,
.hold_rect = kst_panel_apply_rect,
.leave = kst_panel_leave,
.cancel = kst_panel_cancel,
.pin = kst_panel_pin,
.safe_at = kst_panel_safe_at,
}
void kst_panel_event(const touch_event_t *evt)
Definition kst_panel_touch.c:299
uint32_t kst_panel_revision(void)
Definition kst_panel.c:601
gfx_rect_t kst_panel_apply_rect(void)
A warning page's hold button, 300 x 56px at the foot's left.
Definition kst_panel.c:445
void kst_panel_cancel(void)
Definition kst_panel_touch.c:314
uint8_t kst_panel_pin(void)
Definition kst_panel_touch.c:156
void kst_panel_render(gfx_canvas_t *c)
Draws the overlay: the keypad or the keyboard alone while one is open, else the warning,...
Definition kst_panel_draw.c:904
bool kst_panel_safe_at(int x, int y)
Definition kst_panel_touch.c:147
void kst_panel_back(void)
Definition kst_panel_touch.c:134
void kst_panel_bench_armed(bool armed)
Definition kst_panel.c:708
bool kst_panel_holds_port(void)
Definition kst_panel.c:593
uint32_t kst_panel_hold_revision(void)
Definition kst_panel.c:606
void kst_panel_screen_entry(void)
Definition kst_panel.c:569
void kst_panel_leave(void)
Definition kst_panel_touch.c:325
void kst_panel_open(void)
Opens the overlay and reads the programmer's options from the settings.
Definition kst_panel.c:576
void kst_panel_init(gfx_rect_t area)
Definition kst_panel.c:543
bool kst_panel_is_open(void)
Returns whether the overlay is open.
Definition kst_panel.c:588
void kst_panel_tick(float dt_s)
Advances the overlay by one frame: the warning's hold and the key repeats.
Definition kst_panel_touch.c:333
bool kst_panel_has_press(uint8_t id)
Definition kst_panel_touch.c:286

The session's hooks for its row on SERVO > PROGRAM.