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

The SUPPLY screen. See supply_screen.h. This file holds the state, the commands and the screen's interface; supply_events.c takes the touch events and frames, supply_draw.c draws, and supply_screen_int.h is what the three share. More...

#include "supply_screen.h"
#include <math.h>
#include <stdint.h>
#include <string.h>
#include "settings.h"
#include "ui_keypad.h"
#include "ui_plot.h"
#include "ui_slider.h"
#include "ui_tabs.h"
#include "ui_text.h"
#include "ui_theme.h"
#include "ui_widgets.h"
#include "ui_workbench.h"
#include "supply_screen_int.h"

Functions

static void forget_drawn (void)
void supply_invalidate (void)
 Everything SUPPLY draws is drawn again on its next frame.
void sup_bind_colours (void)
 Sets the plot's series colours from the active theme.
static int16_t set_ctrl_y (int row)
 The top of set point row's controls.
static gfx_rect_t set_track (int row)
 Set point row's track, between its two step keys.
static gfx_rect_t nudge_rect (int row, bool up)
 Set point row's fine step key, down at the track's left end or up at its right.
gfx_rect_t sup_set_value_rect (int row)
 A set point's value, at the right end of its controls: tapped, the keypad.
gfx_rect_t sup_card_rect (int i)
 Returns the rectangle of reading card i on the rail.
gfx_rect_t sup_strip_area (void)
 The strip's row with its trough's 3px around it.
static void strip_widen (void)
 The strip's tabs laid out again at SUPPLY's sizes, SU_TAB_W x SU_STRIP_H from (SU_STRIP_X, SU_STRIP_Y): the tasks, their order and their labels as ui_wb_strip_init() set them.
bool sup_on_live (void)
 Returns whether the LIVE task shows.
gfx_rect_t sup_overlay_area (void)
 Returns the area the keypad, the question and SETTINGS' page take.
gfx_rect_t sup_row_rect (int i)
 SETTINGS' row i: its label and its value, in its column.
gfx_rect_t sup_row_value_rect (int i)
 The value of SETTINGS' row i, at the row's right end: tapped, the keypad or a switch's flip.
static void apply_caps (void)
static supply_limits_t limits_from_settings (void)
void sup_refresh_limits (void)
 Re-reads the operator's limits from the settings and narrows the caps.
static void reset (void)
 The screen at its start: the state cleared, every control laid out, the model's set points.
void sup_owner_settle (void)
 Clears the owner and any owed OFF once the output is off with no ON asked.
void sup_post_on (supply_by_t by)
 Asks for the output ON, unless an OFF is pending or a programming port holds the supply.
void sup_post_off (void)
 Asks for the output OFF.
bool supply_screen_poll_cmd (supply_cmd_t *out)
void supply_screen_push (const supply_state_t *st)
const supply_state_t * supply_screen_reading (void)
void sup_let_go (void)
 Ends the press on a slider or key and lets the set points follow the supply.
void supply_screen_set_output (bool on)
void supply_screen_set_caps (const supply_caps_t *caps)
void supply_screen_set_baud (uint32_t baud)
void supply_screen_set_pins (int tx, int rx)
 The PD mini's UART pins, IOmcu GPIO numbers, named in the header ("PD MINI TX GPIO 12 RX GPIO 13").
void supply_screen_set_model (bool model)
bool supply_screen_model (void)
 Whether the numbers come from the panel's model.
float supply_screen_set_v (void)
float supply_screen_set_i (void)
 The current limit's set point as the screen holds it, snapped to the caps.
void supply_screen_settings_loaded (void)
bool sup_confirm_needed (int from)
 Returns whether a change waits for a confirmation: only while the output is on and as the operator's settings ask.
void sup_propose (int from)
 Gives a set point change to the supply, or opens the question when one is needed.
bool sup_confirm_stands (void)
 Returns whether the question about a live output still stands: the output on or an ON on its way, and no stop since it was asked.
void sup_confirm_close (bool apply)
 Closes the question, applying the pending change or dropping it.
supply_limits_t supply_screen_limits (void)
supply_caps_t supply_screen_caps (void)
const ui_keypad_t * supply_screen_keypad (void)
 The keypad of the set points and of SETTINGS' rows, open or closed, for a test to read what it opened with and where its keys are.
bool supply_screen_typed_asks (void)
static void port_held_apply (bool held)
 The supply's lock as the two programmers' words make it: held while either holds a port.
void supply_screen_set_port_held (bool held)
void supply_screen_set_hitec_held (bool held)
 The Hitec programmer's word on the same hold: the supply is held while either programmer says so. supply_screen_set_port_held() is the KST programmer's.
bool supply_screen_port_held (void)
 Whether a programming port holds the supply (supply_screen_set_port_held()).
void supply_screen_adopt (float v, float i)
void supply_screen_put (float v, float i)
bool supply_screen_output_on (void)
 Whether the output is on as this screen believes it: what the supply reported, with an OFF this screen asked for and has not yet seen answered counted as off.
bool supply_screen_output_live (void)
uint32_t supply_screen_off_count (void)
void supply_screen_ask_on (supply_by_t by)
supply_by_t supply_screen_owner (void)
bool supply_screen_off_owed (void)
void supply_screen_claim (supply_by_t by)
void supply_screen_entered (supply_by_t by)
void supply_screen_left (supply_by_t by)
void supply_screen_ask_off (void)
bool supply_screen_off_pending (void)
bool supply_screen_output_held (void)
void supply_screen_limits_changed (void)
void supply_screen_set_on_coming (bool coming)
void supply_screen_cancel_on (void)
static void leave (void)
static void enter (void)
int supply_screen_task (void)
static void cancel (void)
static bool back (void)
const ui_screen_t * supply_screen (void)
 The SUPPLY screen as the router drives it.

Variables

const ui_plot_series_t sup_series [S_COUNT]
 The plot's five series: voltage, current, power, and the voltage and current set points.
static const ui_text_id_t k_tab_labels []
sup_state_t sup_s
 The supply screen's state, in supply_screen.c.
static const ui_screen_t k_screen

Detailed Description

The SUPPLY screen. See supply_screen.h. This file holds the state, the commands and the screen's interface; supply_events.c takes the touch events and frames, supply_draw.c draws, and supply_screen_int.h is what the three share.

MOTOR & ESC's frame and its rules for what repaints when: chrome once per framebuffer, the numbers when a sample arrives, the plot when it moves, and each control on its own counter.

SPDX-License-Identifier: MIT

Function Documentation

◆ nudge_rect()

gfx_rect_t nudge_rect ( int row,
bool up )
static

Set point row's fine step key, down at the track's left end or up at its right.

Parameters
row0 the voltage, 1 the current limit
upthe step up
Returns
the key

◆ port_held_apply()

void port_held_apply ( bool held)
static

The supply's lock as the two programmers' words make it: held while either holds a port.

Parameters
heldwhether a programming port holds the supply

◆ set_ctrl_y()

int16_t set_ctrl_y ( int row)
static

The top of set point row's controls.

Parameters
row0 the voltage, 1 the current limit
Returns
their top, px

◆ set_track()

gfx_rect_t set_track ( int row)
static

Set point row's track, between its two step keys.

Parameters
row0 the voltage, 1 the current limit
Returns
the track

◆ sup_card_rect()

gfx_rect_t sup_card_rect ( int i)

Returns the rectangle of reading card i on the rail.

Parameters
icard index, 0 to 3
Returns
the card's rectangle

◆ sup_confirm_close()

void sup_confirm_close ( bool apply)

Closes the question, applying the pending change or dropping it.

Parameters
applytrue for APPLY, false for CANCEL

◆ sup_confirm_needed()

bool sup_confirm_needed ( int from)

Returns whether a change waits for a confirmation: only while the output is on and as the operator's settings ask.

Parameters
fromwhere the change came from, FROM_SLIDER or FROM_KEYPAD
Returns
true when the question is asked

◆ sup_confirm_stands()

bool sup_confirm_stands ( void )

Returns whether the question about a live output still stands: the output on or an ON on its way, and no stop since it was asked.

Returns
true when APPLY may still apply the change

◆ sup_on_live()

bool sup_on_live ( void )

Returns whether the LIVE task shows.

Returns
true on LIVE, false on SETTINGS

◆ sup_overlay_area()

gfx_rect_t sup_overlay_area ( void )

Returns the area the keypad, the question and SETTINGS' page take.

Returns
the left column under the strip, 620px wide

◆ sup_post_on()

void sup_post_on ( supply_by_t by)

Asks for the output ON, unless an OFF is pending or a programming port holds the supply.

Parameters
bythe screen the ON belongs to

◆ sup_propose()

void sup_propose ( int from)

Gives a set point change to the supply, or opens the question when one is needed.

Parameters
fromwhere the change came from, FROM_SLIDER or FROM_KEYPAD

◆ sup_row_rect()

gfx_rect_t sup_row_rect ( int i)

SETTINGS' row i: its label and its value, in its column.

Parameters
ithe row, an index of k_rows
Returns
the row, px

◆ sup_row_value_rect()

gfx_rect_t sup_row_value_rect ( int i)

The value of SETTINGS' row i, at the row's right end: tapped, the keypad or a switch's flip.

Parameters
ithe row, an index of k_rows
Returns
the value's box, px

◆ sup_set_value_rect()

gfx_rect_t sup_set_value_rect ( int row)

A set point's value, at the right end of its controls: tapped, the keypad.

Parameters
row0 the voltage, 1 the current limit
Returns
the value's box

◆ sup_strip_area()

gfx_rect_t sup_strip_area ( void )

The strip's row with its trough's 3px around it.

Returns
the row, px

◆ supply_screen()

const ui_screen_t * supply_screen ( void )

The SUPPLY screen as the router drives it.

Returns
The screen; never NULL.

◆ supply_screen_adopt()

void supply_screen_adopt ( float v,
float i )

The set points a programming port gave the supply, onto the screen: supply_screen_put() for the one caller that reports and does not ask.

◆ supply_screen_ask_off()

void supply_screen_ask_off ( void )

OUTPUT OFF tapped elsewhere: an OFF is posted, and any ON dropped.

◆ supply_screen_ask_on()

void supply_screen_ask_on ( supply_by_t by)

OUTPUT ON's hold completed elsewhere, as it does here: an ON is posted unless an OFF already is, and the output is by's from then on.

◆ supply_screen_cancel_on()

void supply_screen_cancel_on ( void )

A hold under way is abandoned and a pending ON dropped: STOP.

◆ supply_screen_caps()

supply_caps_t supply_screen_caps ( void )

The set points' range: the supply's caps narrowed by the operator's.

◆ supply_screen_claim()

void supply_screen_claim ( supply_by_t by)

An output reported on that nobody here asked for becomes by's: the servo programmer's CONNECT, which switches a PD mini on through the IOmcu and not through this screen. An owned output keeps its owner.

◆ supply_screen_entered()

void supply_screen_entered ( supply_by_t by)

Screen by is shown again: an OFF owed for leaving it is dropped.

◆ supply_screen_keypad()

const ui_keypad_t * supply_screen_keypad ( void )

The keypad of the set points and of SETTINGS' rows, open or closed, for a test to read what it opened with and where its keys are.

Returns
The keypad; never NULL.

◆ supply_screen_left()

void supply_screen_left ( supply_by_t by)

Screen by is left. An output it owns – on, or an ON on its way – is switched off. While a servo programming port holds the supply (supply_screen_set_port_held()) an OFF would end the port's session and cut a write on the wire: the OFF is owed instead, and sent when the port lets go, unless supply_screen_entered() came first. An output another screen owns, or none, stays as it is.

◆ supply_screen_limits()

supply_limits_t supply_screen_limits ( void )

The operator's limits as the screen last read them from the settings.

◆ supply_screen_limits_changed()

void supply_screen_limits_changed ( void )

The caps were changed in the settings from elsewhere, so read them again.

◆ supply_screen_model()

bool supply_screen_model ( void )

Whether the numbers come from the panel's model.

Returns
True for the model, false for a supply.

◆ supply_screen_off_count()

uint32_t supply_screen_off_count ( void )

How many times the output has been reported going off. A question about a live output records it and stands only while it is unchanged: an OFF and a new ON between two frames end the run it was about.

◆ supply_screen_off_owed()

bool supply_screen_off_owed ( void )

Whether an OFF is owed for a screen left while a port held the supply.

◆ supply_screen_off_pending()

bool supply_screen_off_pending ( void )

Whether an OFF is posted and not yet taken by supply_screen_poll_cmd().

◆ supply_screen_output_held()

bool supply_screen_output_held ( void )

Whether OUTPUT ON is being held on this screen: a press on the switch that began with the output off.

◆ supply_screen_output_live()

bool supply_screen_output_live ( void )

The output on, or an ON asked for and still on its way: what a set point change is asked about.

◆ supply_screen_output_on()

bool supply_screen_output_on ( void )

Whether the output is on as this screen believes it: what the supply reported, with an OFF this screen asked for and has not yet seen answered counted as off.

Returns
True for on.

◆ supply_screen_owner()

supply_by_t supply_screen_owner ( void )

The screen whose ON the output is, or SUPPLY_BY_NONE: off, no ON on its way, or an OFF asked since.

◆ supply_screen_poll_cmd()

bool supply_screen_poll_cmd ( supply_cmd_t * out)

True when anything was asked; clears it.

◆ supply_screen_port_held()

bool supply_screen_port_held ( void )

Whether a programming port holds the supply (supply_screen_set_port_held()).

Returns
True while it holds it.

◆ supply_screen_push()

void supply_screen_push ( const supply_state_t * s)

One sample, for the readouts and, while the output is on, the plot.

◆ supply_screen_put()

void supply_screen_put ( float v,
float i )

Both set points, typed elsewhere and confirmed where they needed it; snapped to the caps.

◆ supply_screen_reading()

const supply_state_t * supply_screen_reading ( void )

The newest sample supply_screen_push() took, as it took it: zeroed, so not online, before the first.

◆ supply_screen_set_baud()

void supply_screen_set_baud ( uint32_t baud)

The PD mini's UART (universal asynchronous receiver-transmitter) rate in baud, shown after ONLINE in the header ("ONLINE 38400"); 0 shows none. Not shown for the model, nor while the module does not answer.

◆ supply_screen_set_caps()

void supply_screen_set_caps ( const supply_caps_t * caps)

What the set points may be; the sliders and steps follow it.

◆ supply_screen_set_hitec_held()

void supply_screen_set_hitec_held ( bool held)

The Hitec programmer's word on the same hold: the supply is held while either programmer says so. supply_screen_set_port_held() is the KST programmer's.

Parameters
heldwhether the Hitec programmer, or the SUPPLY page's own LINK_SP_PORT, says a programming port holds the supply

◆ supply_screen_set_i()

float supply_screen_set_i ( void )

The current limit's set point as the screen holds it, snapped to the caps.

Returns
The set point, A.

◆ supply_screen_set_model()

void supply_screen_set_model ( bool model)

Whether the numbers come from the panel's model rather than a supply.

◆ supply_screen_set_on_coming()

void supply_screen_set_on_coming ( bool coming)

Whether an ON this screen asked for can still be on its way: false once the application has taken every ON it sent and the output is not on, so an ON it dropped – stale, or lost to a full queue – stops counting as live. An ON this screen holds and has not handed over still counts.

◆ supply_screen_set_output()

void supply_screen_set_output ( bool on)

Whether the supply's output is on, as the supply reports it. That bounds a run: switching on clears the plot and starts it, switching off holds it.

◆ supply_screen_set_pins()

void supply_screen_set_pins ( int tx,
int rx )

The PD mini's UART pins, IOmcu GPIO numbers, named in the header ("PD MINI TX GPIO 12 RX GPIO 13").

With either pin not set, or both on one GPIO, the header says "PD MINI NO PINS": the page holds no pins then. Not shown for the model.

Parameters
txthe TX pin; negative is not set
rxthe RX pin; negative is not set

◆ supply_screen_set_port_held()

void supply_screen_set_port_held ( bool held)

The output as the supply last reported it. Whether a servo programming port is out of PWM. The IOmcu then takes an OFF from the panel and no other command (supply_page.h), and this screen offers the same: OUTPUT OFF and RESET PEAKS work, OUTPUT ON, the sliders, the steps and the set points' keypads take no press and are drawn dimmed, supply_screen_put() and supply_screen_ask_on() do nothing, and the MODE card says who holds the supply. What was under way when the port left PWM – a hold on OUTPUT ON, a drag, a keypad of a set point, a question – ends unanswered.

◆ supply_screen_set_v()

float supply_screen_set_v ( void )

The set points as the screen holds them, snapped to the caps.

◆ supply_screen_settings_loaded()

void supply_screen_settings_loaded ( void )

The settings have been loaded: take the limits from them and start the set points at the start values. Called once after settings_init(); the screen reads nothing from the settings before it.

◆ supply_screen_task()

int supply_screen_task ( void )

The task shown, a ui_wb_task_t: LIVE or SETTINGS. A tile opens LIVE; a tap on the other tab switches, and takes an open keypad with it.

◆ supply_screen_typed_asks()

bool supply_screen_typed_asks ( void )

Whether a set point typed now waits for a question before it reaches the supply: the output live or an ON on its way, and SETTINGS, CONFIRM WHILE ON, KEYPAD on.

Variable Documentation

◆ k_screen

const ui_screen_t k_screen
static
Initial value:
= {
.title = "SUPPLY",
.reset = reset,
.enter = enter,
.leave = leave,
.tick = sup_tick,
.event = sup_event,
.cancel = cancel,
.render = sup_render,
.back = back,
.safe_at = sup_safe_at,
}
static void cancel(void)
The panel could not hand over every touch event, so this screen's record of the glass is stale.
Definition analyser_screen.c:658
static void reset(void)
The screen's state cleared: CHANNELS shown, nothing decoded, the tabs laid out.
Definition analyser_screen.c:176
static bool back(void)
The home tag: over the keypad it is CANCEL.
Definition balance_screen.c:251
static void leave(void)
The screen is left: the keypad closes, with nothing typed taken.
Definition balance_screen.c:264
void sup_render(gfx_canvas_t *c, int buffer_index)
A frame: the chrome once per framebuffer, then each part on its own counter.
Definition supply_draw.c:632
void sup_event(const touch_event_t *evt)
Takes a touch event: presses, drags and releases on the screen's controls.
Definition supply_events.c:421
void sup_tick(float dt_s)
Advances the screen by one frame: holds, repeats and the question about a live output.
Definition supply_events.c:544
bool sup_safe_at(int x, int y)
Returns whether (x, y) is on OUTPUT OFF, the one control here whose press stops what the bench drives...
Definition supply_events.c:416

◆ k_tab_labels

const ui_text_id_t k_tab_labels[]
static
Initial value:
= { TX_MO_TAB_PLOT,
TX_MO_TAB_TABLE }

◆ sup_series

const ui_plot_series_t sup_series[S_COUNT]
Initial value:
= {
{ "VOLT", "V", 0, 2, 5.0f, 0 },
{ "CURR", "A", 0, 2, 1.0f, 0 },
{ "PWR", "W", 0, 1, 10.0f, 0 },
{ "VSET", "V", 0, 2, 5.0f, 1 + S_VOLT },
{ "ISET", "A", 0, 2, 1.0f, 1 + S_CURR },
}

The plot's five series: voltage, current, power, and the voltage and current set points.