rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
motor_live_int.h
Go to the documentation of this file.
1
17#pragma once
18
19#include <stdbool.h>
20#include <stdint.h>
21
22#include "gfx.h"
23#include "motor_screen.h"
24#include "touch_types.h"
25#include "ui_plot.h"
26#include "ui_slider.h"
27#include "ui_tabs.h"
28#include "ui_text.h"
29#include "ui_value_gate.h"
30#include "ui_widgets.h"
31
32#include "motor_screen_int.h"
33
34/*
35 * Inside the telemetry card: the title line, PLOT | TABLE with the poll
36 * rate beside them, the legend, then the plot. The table takes the
37 * legend's and the plot's place.
38 */
39#define SUB_Y (UP_Y + TITLE_H + 6)
40#define SUB_H 40
41#define SUB_W 200
42#define LEG_Y (SUB_Y + SUB_H + 4)
43#define LEG_H 20
44#define PLOT_X (LEFT_X + INNER)
45#define PLOT_W (LEFT_W - 2 * INNER)
46#define PLOT_Y (LEG_Y + LEG_H + 4)
47#define PLOT_H (UP_Y + UP_H - INNER - PLOT_Y)
49#define RATE_X (PLOT_X + SUB_W + 14)
50
51/*
52 * Inside the THROTTLE card: the readout on the title line's right, then
53 * the track with a step key at each end, then the hint, which ends above
54 * the alert band.
55 */
56#define ROW_Y (LO_Y + 4)
57#define READOUT_W 260
58#define READOUT_H 46
59#define READOUT_X (LEFT_X + LEFT_W - INNER - READOUT_W)
60#define NUDGE_W 72
61#define NUDGE_H 56
62#define CTRL_Y (ROW_Y + READOUT_H + 4)
63#define TRACK_H 48
64#define TRACK_Y (CTRL_Y + (NUDGE_H - TRACK_H) / 2)
65#define TRACK_X (LEFT_X + INNER + NUDGE_W + 8)
71#define THR_R (RC_X - UI_TAP_MIN)
73#define TRACK_W (THR_R - NUDGE_W - 8 - TRACK_X)
74#define HINT_Y (CTRL_Y + NUDGE_H + 8)
77#define HINT_X (LEFT_X + INNER)
78_Static_assert(TRACK_X + TRACK_W + 8 + NUDGE_W + UI_TAP_MIN <= RC_X,
79 "+1 ends a finger's width left of DISARM");
80_Static_assert(HINT_Y + 20 <= STOP_FLOOR,
81 "the throttle's hint ends above the alert band");
82_Static_assert(ROW_Y + READOUT_H <= CTRL_Y,
83 "the readout ends above the step keys");
84
97#define ARM_HOLD_S UI_HOLD_S
98
99enum { S_VOLT = 0, S_CURR, S_POWER, S_RPM, S_COUNT };
100
101/*
102 * The panel polls at 20Hz, one sample per plot column, so the time base is
103 * the plot width in samples: PLOT_W / 20s.
104 */
109#define SAMPLE_HZ 20.0f
115typedef struct {
120 /* Whether the throttle follows its controls (ui_value_gate.h): the
121 * bench's report, an ARM the hold has asked for and a DISARM or STOP not
122 * yet answered. gate.armed is what the ARM button reads. */
129 /* The knob's throttle command waiting in `pending`, and what to put back
130 * if it is withdrawn: the slider's value before the knob moved it, and
131 * whether a throttle was pending before it. */
136 float knob_prev;
137 /* A finger owned the slider at some point since knob_frame(). */
141 unsigned drawn_mask;
142 /* The arm state of the bench itself, which is what bounds a run. Kept
143 * apart from the gate: leave() reads the bench as disarmed for a disarm
144 * it has only asked for. */
146 /* The push count last painted into each framebuffer; UINT32_MAX
147 * means "no paint recorded", which is not a count push can reach. */
152 uint32_t drawn_push[2];
153 /* And the plot revision, which moves for fewer reasons: a stopped plot
154 * takes no samples, so a disarmed bench repaints its readouts and leaves
155 * the trace alone. */
156 uint32_t drawn_plot[2];
157 /* The telemetry tag last painted, 0xFF for none. It changes on an arm
158 * edge rather than with the numbers, so it cannot ride drawn_push. */
162 uint8_t drawn_title[2];
163 /* Bumped by anything that changes a button's or the tab row's
164 * appearance. The throttle carries its own, because a drag moves it on
165 * every frame and repainting the buttons with it costs the row's full
166 * 800 x 90px rather than the readout's 396 x 30. */
167 uint32_t ctrl_rev;
168 uint32_t drawn_ctrl[2];
169 uint32_t thr_rev;
170 uint32_t drawn_thr[2];
171 /* ARM animates, so it gets a third counter and repaints its own rect. */
172 uint32_t arm_rev;
173 uint32_t drawn_arm[2];
174 int esc_kv;
175 /* The GPIOs bound as throttle (bit n is GPIO n) and whether a binding
176 * was read: what the throttle panel names as its target. */
177 uint64_t thr_pins;
179 /* The protocol they are bound as: an outbind_protos() index, 0 for
180 * none known, MOTOR_PROTO_MIXED for several. */
185 uint8_t thr_proto;
186 /* port_view_revision() when the TARGET row last named the DShot
187 * programming ports. */
193 /* The strip's and SETTINGS' page's revisions last painted into each
194 * framebuffer, and whether the TARGET row was drawn locked. */
195 uint32_t drawn_strip[2];
197 uint32_t drawn_page[2];
199 /* PROGRAM's session as each framebuffer last had it: whether it was
200 * shown, its revision, and the output strip's text (a signature). */
203 uint32_t drawn_sess[2];
205 uint32_t drawn_ostrip[2];
206 /* Whether each channel's peak is a measurement: a valid live reading
207 * has arrived since the run started. Kept apart from the live flags,
208 * which a source that stops answering mid-run clears while the run's
209 * peaks it measured stand. */
210 bool pk_ok[S_COUNT];
212 bool kst_held;
213 bool no_pin;
219 uint8_t press_id;
221} mo_state_t;
222
223/* Defined in motor_screen.c. */
225extern mo_state_t mo_s;
227#define s mo_s
228
229/* --- motor_screen.c: the channels, the state's rules and the commands --- */
230
232extern const ui_plot_series_t mo_series[S_COUNT];
234extern const uint16_t mo_ok[S_COUNT];
236extern const ui_text_id_t mo_names[S_COUNT];
237
239void mo_bind_colours(void);
247bool mo_value_live(void);
249void mo_end_drag(void);
256void mo_post(motor_cmd_kind_t kind, float value);
257bool mo_arm_locked(void);
258bool mo_no_motor_pin(void);
263void mo_throttle_from_zero(void);
269bool mo_bench_safe(void);
275bool mo_endpoints_free(void);
281bool mo_target_locked(void);
282
283/* --- motor_events.c ----------------------------------------------------- */
284
293bool mo_safe_at(int x, int y);
298void mo_event(const touch_event_t *evt);
304void mo_tick(float dt_s);
305
306/* --- motor_draw.c ------------------------------------------------------- */
307
313void mo_render(gfx_canvas_t *c, int buffer_index);
#define RC_X
Definition balance_screen.c:57
#define ROW_Y
Definition battery_screen.c:72
gfx: an RGB565 (16-bit red, green, blue) rasteriser with no dependencies.
void mo_render(gfx_canvas_t *c, int buffer_index)
Draws the screen into frame buffer buffer_index.
Definition motor_draw.c:601
void mo_event(const touch_event_t *evt)
Takes a touch event.
Definition motor_events.c:120
void mo_tick(float dt_s)
Advances the screen by one frame: the ARM hold and flash animations, the knob and the polled state.
Definition motor_events.c:292
bool mo_safe_at(int x, int y)
Returns whether a DOWN at (x, y) is on a control whose press stops what the bench drives: a session's...
Definition motor_events.c:111
#define TRACK_X
Definition motor_live_int.h:65
bool mo_endpoints_free(void)
Returns whether the Idle pulse and Full pulse may change: SAFE and ARM not held.
Definition motor_screen.c:437
bool mo_value_live(void)
Returns whether the throttle follows its controls: only in UI_VALUE_LIVE, not on a disarmed bench,...
Definition motor_screen.c:156
#define HINT_Y
Definition motor_live_int.h:74
bool mo_arm_locked(void)
Whether ARM takes no press: the servo programmer holds a port, or the binding names no motor pin....
Definition motor_screen.c:288
#define CTRL_Y
Definition motor_live_int.h:62
bool mo_bench_safe(void)
Returns whether the bench is SAFE as this screen sees it: disarmed, with no ARM or DISARM asked and u...
Definition motor_screen.c:426
mo_state_t mo_s
MOTOR & ESC's LIVE state, in motor_screen.c.
Definition motor_screen.c:68
void mo_bind_colours(void)
Sets the plot's and the slider's colours from the active theme.
Definition motor_screen.c:97
void mo_post(motor_cmd_kind_t kind, float value)
Posts a command in the one slot, coalescing: a new command overwrites the pending one,...
Definition motor_screen.c:211
#define READOUT_H
Definition motor_live_int.h:58
#define TRACK_W
The track's length: 422px, between the two step keys.
Definition motor_live_int.h:73
bool mo_no_motor_pin(void)
Whether the throttle's binding is read and names no motor pin: no GPIO (general-purpose input/output)...
Definition motor_screen.c:278
const ui_plot_series_t mo_series[S_COUNT]
The four channels' plot series: volts, amps, power and RPM.
Definition motor_screen.c:45
const ui_text_id_t mo_names[S_COUNT]
Per channel, the text id of its name.
Definition motor_screen.c:61
#define NUDGE_W
Definition motor_live_int.h:60
bool mo_target_locked(void)
Returns whether the TARGET row takes no press: the bench is not SAFE, ARM is held or the servo progra...
Definition motor_screen.c:445
const uint16_t mo_ok[S_COUNT]
Per channel, the bench report flags that make its reading valid.
Definition motor_screen.c:54
void mo_end_drag(void)
Ends a drag on the track and keeps the knob out of the frame.
Definition motor_screen.c:163
void mo_throttle_from_zero(void)
Puts the slider, the readout and the step keys at 0% across an arm or disarm edge,...
Definition motor_screen.c:330
The motor and ESC (electronic speed controller) bench screen.
motor_cmd_kind_t
Definition motor_screen.h:36
The MOTOR & ESC screen's private seam between motor_screen.c, the screen and LIVE's page (with motor_...
#define STOP_FLOOR
The lowest row a control that stops what the bench drives, or a line of text, may reach: 4px above th...
Definition motor_screen_int.h:75
The bench readings in the units a person reads: V, A, W and rpm, with their peaks.
Definition bench_state.h:54
Definition gfx.h:129
Definition gfx.h:81
MOTOR & ESC's LIVE state: the plot, the throttle slider and the bench's report, the ARM gate,...
Definition motor_live_int.h:115
uint32_t drawn_ostrip[2]
The output strip's text signature in each frame buffer.
Definition motor_live_int.h:205
unsigned drawn_mask
Bit per frame buffer: its title and strip were drawn.
Definition motor_live_int.h:141
bool knob_pending
Whether the knob's throttle command waits in pending.
Definition motor_live_int.h:133
bool no_pin
Definition motor_live_int.h:213
ui_value_gate_t gate
Whether the throttle follows its controls; gate.armed is what the ARM button reads.
Definition motor_live_int.h:127
uint8_t thr_proto
Protocol they are bound as: an outbind_protos() index, 0 for none known, MOTOR_PROTO_MIXED for severa...
Definition motor_live_int.h:185
gfx_rect_t down_rect
Definition motor_live_int.h:216
gfx_rect_t up_rect
Definition motor_live_int.h:217
int esc_kv
Definition motor_live_int.h:174
uint32_t arm_rev
Definition motor_live_int.h:172
bool bench_armed
Definition motor_live_int.h:145
bool pk_ok[S_COUNT]
Definition motor_live_int.h:210
uint32_t drawn_thr[2]
Definition motor_live_int.h:170
ui_plot_t plot
Definition motor_live_int.h:116
uint32_t drawn_plot[2]
Definition motor_live_int.h:156
bench_state_t bench
Definition motor_live_int.h:119
uint8_t press_id
Definition motor_live_int.h:219
bool have_press
Definition motor_live_int.h:220
uint32_t drawn_strip[2]
Definition motor_live_int.h:195
bool knob_had_cmd
Whether a throttle was pending before the knob moved.
Definition motor_live_int.h:135
gfx_rect_t arm_rect
Definition motor_live_int.h:214
bool drawn_sess_shown[2]
Whether PROGRAM's session was shown in each frame buffer.
Definition motor_live_int.h:202
ui_tabs_t tabs
Definition motor_live_int.h:118
gfx_rect_t reset_rect
Definition motor_live_int.h:215
uint32_t drawn_ctrl[2]
Definition motor_live_int.h:168
int pressed
Definition motor_live_int.h:218
motor_cmd_t pending
Definition motor_live_int.h:128
uint32_t thr_rev
Definition motor_live_int.h:169
uint32_t drawn_push[2]
Push count last painted into each frame buffer; UINT32_MAX for none.
Definition motor_live_int.h:152
bool kst_held
Definition motor_live_int.h:212
uint32_t ctrl_rev
Definition motor_live_int.h:167
uint32_t drawn_page[2]
SETTINGS page revision last painted into each frame buffer.
Definition motor_live_int.h:197
bool thr_pins_known
Definition motor_live_int.h:178
uint64_t thr_pins
Definition motor_live_int.h:177
float knob_prev
Definition motor_live_int.h:136
ui_slider_t slider
Definition motor_live_int.h:117
uint32_t thr_ports_rev
Port_view_revision() when the TARGET row last named the DShot programming ports.
Definition motor_live_int.h:192
bool knob_finger
Whether a finger owned the slider since knob_frame().
Definition motor_live_int.h:139
uint32_t drawn_sess[2]
Definition motor_live_int.h:203
uint8_t drawn_title[2]
Telemetry tag last painted into each frame buffer; 0xFF for none.
Definition motor_live_int.h:162
uint32_t drawn_arm[2]
Definition motor_live_int.h:173
ui_hold_t arm
Definition motor_live_int.h:211
bool target_locked
Definition motor_live_int.h:198
Definition motor_screen.h:44
A DOWN, MOVE or UP of one contact.
Definition touch_types.h:69
Definition ui_widgets.h:415
Definition ui_plot.h:38
Definition ui_plot.h:56
Definition ui_slider.h:42
A row of tabs: their labels, where they are, which is selected and the press under way.
Definition ui_tabs.h:27
Definition ui_value_gate.h:40
Plain data types shared by the touch controller driver, the coordinate mapper and the event tracker....
#define UI_TAP_MIN
The smallest touch target for a control, in pixels: 48px, 7.2mm.
Definition ui_layout.h:71
A multi-series plot on one time base, with a scale per series.
A draggable value with presets: the throttle, and any other control that needs coarse reach and fine ...
The pane selector: one bench, several views of it.
The interface's words, one table per language.
ui_text_id_t
The screens' strings, TX_<ID> for each UI_TEXT() of ui_text.def.
Definition ui_text.h:43
Stateless drawing helpers shared by every screen.