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

The private seam between motor_screen.c, the MOTOR & ESC screen's state, commands and interface, motor_events.c, its touch events and frames, and motor_draw.c, its drawing: LIVE's layout inside motor_screen_int.h's, the channels, the state and the functions one calls in another. The other files of the screen (motor_workbench.c, motor_program_page.c, motor_settings_page.c) keep their own state and do not include this header. Nothing outside shared/ui includes it. More...

#include <stdbool.h>
#include <stdint.h>
#include "gfx.h"
#include "motor_screen.h"
#include "touch_types.h"
#include "ui_plot.h"
#include "ui_slider.h"
#include "ui_tabs.h"
#include "ui_text.h"
#include "ui_value_gate.h"
#include "ui_widgets.h"
#include "motor_screen_int.h"

Go to the source code of this file.

Data Structures

struct  mo_state_t
 MOTOR & ESC's LIVE state: the plot, the throttle slider and the bench's report, the ARM gate, the knob's pending command, the revisions each frame buffer last drew and the touches tracked. More...

Macros

#define SUB_Y   (UP_Y + TITLE_H + 6)
#define SUB_H   40
#define SUB_W   200
#define LEG_Y   (SUB_Y + SUB_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 RATE_X   (PLOT_X + SUB_W + 14)
 The poll rate and the link's errors, right of PLOT | TABLE.
#define ROW_Y   (LO_Y + 4)
#define READOUT_W   260
#define READOUT_H   46
#define READOUT_X   (LEFT_X + LEFT_W - INNER - READOUT_W)
#define NUDGE_W   72
#define NUDGE_H   56
#define CTRL_Y   (ROW_Y + READOUT_H + 4)
#define TRACK_H   48
#define TRACK_Y   (CTRL_Y + (NUDGE_H - TRACK_H) / 2)
#define TRACK_X   (LEFT_X + INNER + NUDGE_W + 8)
#define THR_R   (RC_X - UI_TAP_MIN)
 The right end of the step keys' row: UI_TAP_MIN left of the rail's column, so a finger that misses DISARM to its left lands on no throttle control. +1 is x 528 to 599, DISARM from x 648.
#define TRACK_W   (THR_R - NUDGE_W - 8 - TRACK_X)
 The track's length: 422px, between the two step keys.
#define HINT_Y   (CTRL_Y + NUDGE_H + 8)
#define HINT_X   (LEFT_X + INNER)
 The hint's left edge, at the card's padding. The hint draws in MO_FONT_FINE: the German one is 61 cells, 488px.
#define ARM_HOLD_S   UI_HOLD_S
 ARM is a hold, not a press: two seconds from the OK green to the danger red, and the command goes when the fade completes. A release before then arms nothing, and neither does a finger that leaves the button: the gesture is contact with the control, not with the panel. A bench that spins a propeller should not do it on a touch that could have been an elbow.
#define SAMPLE_HZ   20.0f
 The panel's polling rate, 20Hz: one sample per plot column, so the time base is PLOT_W / 20s.
#define s   mo_s
 Short name for mo_s inside the MOTOR & ESC files.

Enumerations

enum  {
  S_VOLT = 0 , S_CURR , S_POWER , S_RPM ,
  S_COUNT
}

Functions

void mo_bind_colours (void)
 Sets the plot's and the slider's colours from the active theme.
bool mo_value_live (void)
 Returns whether the throttle follows its controls: only in UI_VALUE_LIVE, not on a disarmed bench, not between the ARM hold and the bench's answer, and not after a DISARM or STOP until the bench reports disarmed.
void mo_end_drag (void)
 Ends a drag on the track and keeps the knob out of the frame.
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, except that a pending DISARM survives everything.
bool mo_arm_locked (void)
 Whether ARM takes no press: the servo programmer holds a port, or the binding names no motor pin. DISARM takes a press in both.
bool mo_no_motor_pin (void)
 Whether the throttle's binding is read and names no motor pin: no GPIO (general-purpose input/output) pin and no DShot port. The TARGET row then reads NO MOTOR PIN, and nothing can be driven.
void mo_throttle_from_zero (void)
 Puts the slider, the readout and the step keys at 0% across an arm or disarm edge, drops a pending throttle and releases a drag.
bool mo_bench_safe (void)
 Returns whether the bench is SAFE as this screen sees it: disarmed, with no ARM or DISARM asked and unanswered.
bool mo_endpoints_free (void)
 Returns whether the Idle pulse and Full pulse may change: SAFE and ARM not held.
bool mo_target_locked (void)
 Returns whether the TARGET row takes no press: the bench is not SAFE, ARM is held or the servo programmer holds its port.
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 ABORT, or DISARM while the button reads DISARM.
void mo_event (const touch_event_t *evt)
 Takes a touch event.
void mo_tick (float dt_s)
 Advances the screen by one frame: the ARM hold and flash animations, the knob and the polled state.
void mo_render (gfx_canvas_t *c, int buffer_index)
 Draws the screen into frame buffer buffer_index.

Variables

mo_state_t mo_s
 MOTOR & ESC's LIVE state, in motor_screen.c.
const ui_plot_series_t mo_series [S_COUNT]
 The four channels' plot series: volts, amps, power and RPM.
const uint16_t mo_ok [S_COUNT]
 Per channel, the bench report flags that make its reading valid.
const ui_text_id_t mo_names [S_COUNT]
 Per channel, the text id of its name.

Detailed Description

The private seam between motor_screen.c, the MOTOR & ESC screen's state, commands and interface, motor_events.c, its touch events and frames, and motor_draw.c, its drawing: LIVE's layout inside motor_screen_int.h's, the channels, the state and the functions one calls in another. The other files of the screen (motor_workbench.c, motor_program_page.c, motor_settings_page.c) keep their own state and do not include this header. Nothing outside shared/ui includes it.

Included last: it names the state s, which no header included after it may meet. What one file calls or reads in another carries the prefix mo_.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ ARM_HOLD_S

#define ARM_HOLD_S   UI_HOLD_S

ARM is a hold, not a press: two seconds from the OK green to the danger red, and the command goes when the fade completes. A release before then arms nothing, and neither does a finger that leaves the button: the gesture is contact with the control, not with the panel. A bench that spins a propeller should not do it on a touch that could have been an elbow.

The timing, the fade and the flash are ui_widgets' (UI_HOLD_S, ui_hold_fill, ui_hold_flash), so the other gesture that is held rather than pressed cannot come to look different from this one.

◆ CTRL_Y

#define CTRL_Y   (ROW_Y + READOUT_H + 4)

The step keys' top, px.

◆ HINT_Y

#define HINT_Y   (CTRL_Y + NUDGE_H + 8)

The hint's line, px.

◆ LEG_H

#define LEG_H   20

Its height, px.

◆ LEG_Y

#define LEG_Y   (SUB_Y + SUB_H + 4)

The legend, px.

◆ NUDGE_H

#define NUDGE_H   56

Its height, px.

◆ NUDGE_W

#define NUDGE_W   72

A step key's width, px.

◆ PLOT_H

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

Its height: 184px.

◆ 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.

◆ READOUT_H

#define READOUT_H   46

Its height, px.

◆ READOUT_W

#define READOUT_W   260

Its box, at the right, px.

◆ READOUT_X

#define READOUT_X   (LEFT_X + LEFT_W - INNER - READOUT_W)

Its left.

◆ ROW_Y

#define ROW_Y   (LO_Y + 4)

The readout's top, px.

◆ SUB_H

#define SUB_H   40

Their height, px.

◆ SUB_W

#define SUB_W   200

Their row: two of 98px.

◆ SUB_Y

#define SUB_Y   (UP_Y + TITLE_H + 6)

PLOT | TABLE, px.

◆ TRACK_H

#define TRACK_H   48

The track's height, px.

◆ TRACK_X

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

Its left end, px.

◆ TRACK_Y

#define TRACK_Y   (CTRL_Y + (NUDGE_H - TRACK_H) / 2)

Its top, px.

Function Documentation

◆ mo_arm_locked()

bool mo_arm_locked ( void )

Whether ARM takes no press: the servo programmer holds a port, or the binding names no motor pin. DISARM takes a press in both.

Returns
true when ARM is dimmed and refused

◆ mo_bench_safe()

bool mo_bench_safe ( void )

Returns whether the bench is SAFE as this screen sees it: disarmed, with no ARM or DISARM asked and unanswered.

Returns
true when SAFE

◆ mo_endpoints_free()

bool mo_endpoints_free ( void )

Returns whether the Idle pulse and Full pulse may change: SAFE and ARM not held.

Returns
true when the endpoints are free

◆ mo_event()

void mo_event ( const touch_event_t * evt)

Takes a touch event.

Parameters
evtthe event

◆ mo_no_motor_pin()

bool mo_no_motor_pin ( void )

Whether the throttle's binding is read and names no motor pin: no GPIO (general-purpose input/output) pin and no DShot port. The TARGET row then reads NO MOTOR PIN, and nothing can be driven.

Returns
true when the binding is read and empty

◆ mo_post()

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, except that a pending DISARM survives everything.

Parameters
kindthe command
valuethe throttle for MOTOR_CMD_THROTTLE, percent

◆ mo_render()

void mo_render ( gfx_canvas_t * c,
int buffer_index )

Draws the screen into frame buffer buffer_index.

Parameters
ccanvas drawn on
buffer_indexthe frame buffer

◆ mo_safe_at()

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 ABORT, or DISARM while the button reads DISARM.

Parameters
xcolumn, px
yrow, px
Returns
true when the point is on such a control

◆ mo_target_locked()

bool mo_target_locked ( void )

Returns whether the TARGET row takes no press: the bench is not SAFE, ARM is held or the servo programmer holds its port.

Returns
true when the row is locked

◆ mo_tick()

void mo_tick ( float dt_s)

Advances the screen by one frame: the ARM hold and flash animations, the knob and the polled state.

Parameters
dt_stime since the last tick, s

◆ mo_value_live()

bool mo_value_live ( void )

Returns whether the throttle follows its controls: only in UI_VALUE_LIVE, not on a disarmed bench, not between the ARM hold and the bench's answer, and not after a DISARM or STOP until the bench reports disarmed.

Returns
true when the throttle is live