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

The SUPPLY screen's private seam between supply_screen.c, the state, the commands and the screen's interface, supply_events.c, its touch events and frames, and supply_draw.c, its drawing: the layout the three work on, the rows of SETTINGS' page, the state and the functions one calls in another. Nothing outside shared/ui includes this header; the screen's interface is supply_screen.h. More...

#include <stdbool.h>
#include <stdint.h>
#include "gfx.h"
#include "settings.h"
#include "supply_screen.h"
#include "touch_types.h"
#include "ui_keypad.h"
#include "ui_plot.h"
#include "ui_slider.h"
#include "ui_tabs.h"
#include "ui_text.h"
#include "ui_widgets.h"
#include "ui_workbench.h"

Go to the source code of this file.

Data Structures

struct  limit_row_t
 One row of SETTINGS' page: the setting it edits, its label, its column and its place from the overlay's top. More...
struct  sup_state_t
 The supply screen's state: the plot, the sliders, the set points and what the supply reports, the question about a change, the keypad and the revisions the two frame buffers last drew. More...

Macros

#define W   UI_PANEL_W
#define H   UI_BODY_H
#define PAD   UI_MARGIN
#define INNER   10
#define LEFT_W   620
#define LEFT_X   PAD
#define RIGHT_X   (LEFT_X + LEFT_W + 8)
#define RIGHT_W   (W - PAD - RIGHT_X)
#define RC_X   (RIGHT_X + 12)
#define RC_W   (RIGHT_W - 24)
#define SU_STRIP_X   UI_WB_STRIP_X
 The task strip, LIVE | SETTINGS, at SERVO's and MOTOR & ESC's sizes: tabs of 150 x 40px, 4px apart, from (9, 8); the page from y 56. The shared UI_WB_ figures plus the difference.
#define SU_STRIP_Y   (UI_WB_STRIP_Y + 2)
#define SU_STRIP_H   (UI_WB_STRIP_H + 16)
#define SU_TAB_W   (UI_WB_TAB_W + 38)
#define SU_TAB_GAP   UI_WB_TAB_GAP
#define SU_PAGE_Y   (UI_WB_PAGE_Y + 18)
#define STOP_FLOOR   (UI_ALERT_Y - UI_BAND_H - 4)
 The lowest row a control that stops what the bench drives, or a line of text, may reach: 4px above the alert band.
#define SU_FONT_LABEL   (&gfx_font_10x20)
 The faces of the 1024 x 600 type scale this screen draws in.
#define SU_FONT_FINE   UI_FONT_FINE
#define SU_FONT_BODY   UI_FONT_BODY
#define SU_FONT_HEAD   (&gfx_font_20x36)
#define SU_FONT_NUM   (&gfx_font_num_32x44)
#define LINE_H   20
 A line of SU_FONT_LABEL, px.
#define TASKS   (UI_WB_HAS(UI_WB_LIVE) | UI_WB_HAS(UI_WB_SETTINGS))
 The strip's tasks: LIVE and SETTINGS.
#define INFO_X   (SU_STRIP_X + 2 * SU_TAB_W + SU_TAB_GAP + 3 + 12)
 The header's left edge: 12px right of the strip's trough.
#define INFO_Y   (SU_STRIP_Y + (SU_STRIP_H - LINE_H) / 2)
 Its top: centred on the strip's 40px.
#define TITLE_H   20
 A panel's title strip, the accent tag on its top edge, px.
#define RAIL_Y   SU_PAGE_Y
#define CARD_H   64
#define CARD_GAP   4
#define CTL_Y   (RAIL_Y + 4 * CARD_H + 3 * CARD_GAP + 8)
 The CONTROL card's top: 8px under the fourth reading card.
#define CTL_H   (H - PAD - CTL_Y)
#define BTN_H   UI_TAP_MIN
#define RESET_Y   (CTL_Y + TITLE_H + 14)
#define OUT_Y   (RESET_Y + BTN_H + 10)
#define OUT_H   60
#define UP_Y   SU_PAGE_Y
#define UP_H   240
#define LO_Y   (UP_Y + UP_H + 8)
#define LO_H   (H - PAD - LO_Y)
#define TAB_X   (LEFT_X + INNER)
#define TAB_Y   (UP_Y + TITLE_H + 6)
#define TAB_H   40
#define TAB_W   200
#define LEG_Y   (TAB_Y + TAB_H + 4)
#define LEG_H   20
#define PLOT_X   (LEFT_X + INNER)
#define PLOT_W   (LEFT_W - 2 * INNER)
#define PLOT_Y   (LEG_Y + LEG_H + 4)
#define PLOT_H   (UP_Y + UP_H - INNER - PLOT_Y)
#define TBL_SET_DX   150
 TABLE's SET column, from PLOT_X: SUP_TABLE_HEAD's cell 15.
#define TBL_NOW_DX   300
#define TBL_UNIT_DX   400
#define TBL_PITCH   30
#define SET_ROW_H   82
#define SET_Y0   (LO_Y + TITLE_H + 4)
#define SET_TEXT_H   LINE_H
#define SET_CTRL_DY   26
#define SET_CTRL_H   UI_TAP_MIN
#define NUDGE_W   72
#define SET_VAL_W   120
#define SET_VAL_X   (LEFT_X + LEFT_W - INNER - SET_VAL_W)
 The value's box: at the card's padding on the right.
#define SET_UP_X   (SET_VAL_X - 8 - NUDGE_W)
 The fine step up: 8px left of the value.
#define SET_TRACK_X   (LEFT_X + INNER + NUDGE_W + 8)
#define SET_TRACK_W   (SET_UP_X - 8 - SET_TRACK_X)
#define NUDGE_V   0.1f
#define NUDGE_I   0.1f
#define OV_X   LEFT_X
#define OV_Y   SU_PAGE_Y
#define OV_W   LEFT_W
#define OV_H   (H - OV_Y - PAD)
#define OV_ROW_H   UI_TAP_MIN
#define OV_PITCH   56
#define OV_HEAD_H   28
#define OV_VAL_W   120
#define OV_COL_W   260
#define OV_COL0_X   (OV_X + INNER)
#define OV_COL1_X   (OV_COL0_X + OV_COL_W + 16)
#define OV_COL1_W   (OV_X + OV_W - INNER - OV_COL1_X)
#define OV_SAVE_Y   (STOP_FLOOR - LINE_H)
#define OV_HELP_PITCH   18
#define OV_CAPS_DY   8
#define OV_RESTART_DY   152
#define OV_HELP_DY   204
#define OV_CONFIRM_DY   268
#define OV_MODRESET_DY   300
#define ASK_BTN_W   240
#define ASK_BTN_H   60
#define ASK_BTN_Y   (OV_Y + 240)
#define ASK_PITCH   26
#define SAMPLE_HZ   20.0f
 The panel loop's sample rate, 20Hz, which is the plot's time base.
#define ROW_COUNT   ((int)(sizeof(k_rows) / sizeof(k_rows[0])))
 Number of rows in k_rows.
#define s   sup_s
 Short name for sup_s inside the supply screen's files.

Enumerations

enum  {
  S_VOLT = 0 , S_CURR , S_POWER , S_READINGS ,
  S_VSET = S_READINGS , S_ISET , S_COUNT
}
enum  {
  P_NONE = 0 , P_OUTPUT , P_RESET , P_V_DOWN ,
  P_V_UP , P_I_DOWN , P_I_UP , P_V_SLIDER ,
  P_I_SLIDER , P_TABS , P_CARD_V , P_CARD_I ,
  P_VALUE_V , P_VALUE_I , P_STRIP , P_ROW ,
  P_KEYPAD , P_APPLY , P_DISCARD , P_MODRESET
}
enum  { FROM_SLIDER = 0 , FROM_KEYPAD }
enum  { KP_NONE = 0 , KP_SET_V , KP_SET_I , KP_SETTING }

Functions

void sup_bind_colours (void)
 Sets the plot's series colours from the active theme.
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.
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.
void sup_refresh_limits (void)
 Re-reads the operator's limits from the settings and narrows the caps.
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.
void sup_let_go (void)
 Ends the press on a slider or key and lets the set points follow the supply.
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.
void sup_drop_press (void)
 Drops the press as a lost release: a gesture asks for nothing, except a tap on OUTPUT OFF, which is sent.
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.
void sup_event (const touch_event_t *evt)
 Takes a touch event: presses, drags and releases on the screen's controls.
void sup_tick (float dt_s)
 Advances the screen by one frame: holds, repeats and the question about a live output.
void sup_render (gfx_canvas_t *c, int buffer_index)
 A frame: the chrome once per framebuffer, then each part on its own counter.

Variables

static const limit_row_t k_rows []
 The settings SETTINGS' page edits, in two columns; a start value is capped like the set point it starts and a trip of 0 is off.
sup_state_t sup_s
 The supply screen's state, in supply_screen.c.
const ui_plot_series_t sup_series [S_COUNT]
 The plot's five series: voltage, current, power, and the voltage and current set points.

Detailed Description

The SUPPLY screen's private seam between supply_screen.c, the state, the commands and the screen's interface, supply_events.c, its touch events and frames, and supply_draw.c, its drawing: the layout the three work on, the rows of SETTINGS' page, the state and the functions one calls in another. Nothing outside shared/ui includes this header; the screen's interface is supply_screen.h.

Included last: its layout macros have short names (W, H, PAD) and it names the state s, which no header included after it may meet. What one file calls or reads in another carries the prefix sup_.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ ASK_BTN_H

#define ASK_BTN_H   60

Their height, px.

◆ ASK_BTN_W

#define ASK_BTN_W   240

APPLY and CANCEL, px.

◆ ASK_BTN_Y

#define ASK_BTN_Y   (OV_Y + 240)

Their top: y 296.

◆ ASK_PITCH

#define ASK_PITCH   26

Its sentences' lines, px.

◆ BTN_H

#define BTN_H   UI_TAP_MIN

RESET PEAKS' height, px.

◆ CARD_GAP

#define CARD_GAP   4

Between two of them, px.

◆ CARD_H

#define CARD_H   64

A reading card's height.

◆ CTL_H

#define CTL_H   (H - PAD - CTL_Y)

To the body's margin.

◆ H

#define H   UI_BODY_H

The body's height under the band, px.

◆ INNER

#define INNER   10

A card's own padding, px.

◆ LEFT_W

#define LEFT_W   620

The left column, px.

◆ LEFT_X

#define LEFT_X   PAD

Its left edge, px.

◆ LEG_H

#define LEG_H   20

Its height, px.

◆ LEG_Y

#define LEG_Y   (TAB_Y + TAB_H + 4)

The legend, px.

◆ LO_H

#define LO_H   (H - PAD - LO_Y)

To the body's margin.

◆ LO_Y

#define LO_Y   (UP_Y + UP_H + 8)

SET POINTS: y 304.

◆ NUDGE_I

#define NUDGE_I   0.1f

The current's step, A.

◆ NUDGE_V

#define NUDGE_V   0.1f

The voltage's step, V.

◆ NUDGE_W

#define NUDGE_W   72

A step key's width, px.

◆ OUT_H

#define OUT_H   60

Its height: 9.0mm.

◆ OUT_Y

#define OUT_Y   (RESET_Y + BTN_H + 10)

OUTPUT ON / OFF: y 424.

◆ OV_CAPS_DY

#define OV_CAPS_DY   8

LIMITS and TRIPS, px.

◆ OV_COL0_X

#define OV_COL0_X   (OV_X + INNER)

Its left edge: x 18.

◆ OV_COL1_W

#define OV_COL1_W   (OV_X + OV_W - INNER - OV_COL1_X)

Its width: 324.

◆ OV_COL1_X

#define OV_COL1_X   (OV_COL0_X + OV_COL_W + 16)

The right: 294.

◆ OV_COL_W

#define OV_COL_W   260

The left column, px.

◆ OV_CONFIRM_DY

#define OV_CONFIRM_DY   268

CONFIRM WHILE ON, px.

◆ OV_H

#define OV_H   (H - OV_Y - PAD)

To the body's margin.

◆ OV_HEAD_H

#define OV_HEAD_H   28

A heading's line, px.

◆ OV_HELP_DY

#define OV_HELP_DY   204

The trips' help, px.

◆ OV_HELP_PITCH

#define OV_HELP_PITCH   18

The help's lines, px.

◆ OV_MODRESET_DY

#define OV_MODRESET_DY   300

RESET PD MINI, px.

◆ OV_PITCH

#define OV_PITCH   56

From row to row, px.

◆ OV_RESTART_DY

#define OV_RESTART_DY   152

AFTER RESTART, px.

◆ OV_ROW_H

#define OV_ROW_H   UI_TAP_MIN

A row's height, px.

◆ OV_SAVE_Y

#define OV_SAVE_Y   (STOP_FLOOR - LINE_H)

The save line, px.

◆ OV_VAL_W

#define OV_VAL_W   120

A row's value, px.

◆ OV_W

#define OV_W   LEFT_W

620px.

◆ OV_X

#define OV_X   LEFT_X

The left column, px.

◆ OV_Y

#define OV_Y   SU_PAGE_Y

Under the strip: y 56.

◆ PAD

#define PAD   UI_MARGIN

The outer margin, px.

◆ PLOT_H

#define PLOT_H   (UP_Y + UP_H - INNER - PLOT_Y)

Its height: 136px.

◆ PLOT_W

#define PLOT_W   (LEFT_W - 2 * INNER)

Its width: 600px.

◆ PLOT_X

#define PLOT_X   (LEFT_X + INNER)

The plot's left edge, px.

◆ PLOT_Y

#define PLOT_Y   (LEG_Y + LEG_H + 4)

Its top, px.

◆ RAIL_Y

#define RAIL_Y   SU_PAGE_Y

The first card, px.

◆ RC_W

#define RC_W   (RIGHT_W - 24)

Its width: 356px.

◆ RC_X

#define RC_X   (RIGHT_X + 12)

The rail's column: x 648.

◆ RESET_Y

#define RESET_Y   (CTL_Y + TITLE_H + 14)

RESET PEAKS: y 366.

◆ RIGHT_W

#define RIGHT_W   (W - PAD - RIGHT_X)

Its width: 380px.

◆ RIGHT_X

#define RIGHT_X   (LEFT_X + LEFT_W + 8)

The rail: x 636.

◆ SET_CTRL_DY

#define SET_CTRL_DY   26

From label to controls.

◆ SET_CTRL_H

#define SET_CTRL_H   UI_TAP_MIN

Keys, track, value, px.

◆ SET_ROW_H

#define SET_ROW_H   82

From row to row, px.

◆ SET_TEXT_H

#define SET_TEXT_H   LINE_H

A label's line, px.

◆ SET_TRACK_W

#define SET_TRACK_W   (SET_UP_X - 8 - SET_TRACK_X)

Its length: 312.

◆ SET_TRACK_X

#define SET_TRACK_X   (LEFT_X + INNER + NUDGE_W + 8)

The track: x 98.

◆ SET_VAL_W

#define SET_VAL_W   120

The value's box, px.

◆ SET_Y0

#define SET_Y0   (LO_Y + TITLE_H + 4)

The first label: y 328.

◆ SU_FONT_BODY

#define SU_FONT_BODY   UI_FONT_BODY

12 x 24: sentences.

◆ SU_FONT_FINE

#define SU_FONT_FINE   UI_FONT_FINE

8 x 16: help lines.

◆ SU_FONT_HEAD

#define SU_FONT_HEAD   (&gfx_font_20x36)

20 x 36: MODE, titles.

◆ SU_FONT_LABEL

#define SU_FONT_LABEL   (&gfx_font_10x20)

The faces of the 1024 x 600 type scale this screen draws in.

SU_FONT_LABEL (10 x 20) for every label, button, row and value; SU_FONT_FINE (8 x 16) for SETTINGS' help lines; SU_FONT_BODY (12 x 24) for the question's sentences; SU_FONT_HEAD (20 x 36) for MODE's letters, the question's title and its change; SU_FONT_NUM (32 x 44, digits, sign, point and space only) for the readings.

◆ SU_FONT_NUM

#define SU_FONT_NUM   (&gfx_font_num_32x44)

32 x 44: the readings.

◆ SU_PAGE_Y

#define SU_PAGE_Y   (UI_WB_PAGE_Y + 18)

The page's top: 56px.

◆ SU_STRIP_H

#define SU_STRIP_H   (UI_WB_STRIP_H + 16)

A tab's height: 40px.

◆ SU_STRIP_Y

#define SU_STRIP_Y   (UI_WB_STRIP_Y + 2)

The strip's top: 8px.

◆ SU_TAB_GAP

#define SU_TAB_GAP   UI_WB_TAB_GAP

Between two tabs: 4px.

◆ SU_TAB_W

#define SU_TAB_W   (UI_WB_TAB_W + 38)

A tab's width: 150px.

◆ TAB_H

#define TAB_H   40

Their height, px.

◆ TAB_W

#define TAB_W   200

The row: two of 100px.

◆ TAB_X

#define TAB_X   (LEFT_X + INNER)

PLOT | TABLE, px.

◆ TAB_Y

#define TAB_Y   (UP_Y + TITLE_H + 6)

Their top: y 82.

◆ TBL_NOW_DX

#define TBL_NOW_DX   300

NOW: its cell 30, px.

◆ TBL_PITCH

#define TBL_PITCH   30

From row to row, px.

◆ TBL_UNIT_DX

#define TBL_UNIT_DX   400

The unit, px.

◆ UP_H

#define UP_H   240

Its height, px.

◆ UP_Y

#define UP_Y   SU_PAGE_Y

The output card, px.

◆ W

#define W   UI_PANEL_W

The panel's width, px: the screen's own.

Function Documentation

◆ 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_event()

void sup_event ( const touch_event_t * evt)

Takes a touch event: presses, drags and releases on the screen's controls.

Parameters
evtthe event

◆ 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_render()

void sup_render ( gfx_canvas_t * c,
int buffer_index )

A frame: the chrome once per framebuffer, then each part on its own counter.

Parameters
cthe canvas
buffer_indexthe framebuffer drawn into, 0 or 1

◆ 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_safe_at()

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.

Parameters
xcolumn, px
yrow, px
Returns
true when the point is on OUTPUT OFF while the output is on

◆ 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

◆ sup_tick()

void sup_tick ( float dt_s)

Advances the screen by one frame: holds, repeats and the question about a live output.

Parameters
dt_stime since the last tick, s

Variable Documentation

◆ k_rows

const limit_row_t k_rows[]
static
Initial value:
= {
{ SET_SUPPLY_V_MAX, TX_SUP_ROW_V_MAX, 0, 36, 2 },
{ SET_SUPPLY_I_MAX, TX_SUP_ROW_I_MAX, 0, 92, 2 },
{ SET_SUPPLY_V_START, TX_SUP_ROW_V_START, 0, 180, 2 },
{ SET_SUPPLY_I_START, TX_SUP_ROW_I_START, 0, 236, 2 },
{ SET_SUPPLY_TRIP_I, TX_SUP_ROW_TRIP_I, 1, 36, 2 },
{ SET_SUPPLY_TRIP_V, TX_SUP_ROW_TRIP_V, 1, 92, 2 },
{ SET_SUPPLY_TRIP_MS, TX_SUP_ROW_TRIP_MS, 1, 148, 0 },
{ SET_SUPPLY_CONFIRM_SLIDE, TX_SUP_ROW_CONFIRM_SLIDE, 1, 296, 0 },
{ SET_SUPPLY_CONFIRM_KEYS, TX_SUP_ROW_CONFIRM_KEYS, 1, 352, 0 },
}

The settings SETTINGS' page edits, in two columns; a start value is capped like the set point it starts and a trip of 0 is off.