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

The balance screen: sensor placement guides and the correction readout. More...

#include "balance_screen.h"
#include <math.h>
#include <stdio.h>
#include <string.h>
#include "ui_keypad.h"
#include "ui_tabs.h"
#include "ui_text.h"
#include "ui_theme.h"
#include "ui_widgets.h"

Data Structures

struct  rule_t
 One naming rule: how to match, and the group and unit it gives. More...
struct  [struct].s
 Driver state of the UART: the claimed machines and the pins. More...

Macros

#define W   UI_PANEL_W
#define H   UI_BODY_H
#define PAD   UI_MARGIN
#define TAB_X   (PAD + 3)
 The pane tabs, BALANCE | TEST RIG | AIRCRAFT: three tabs of 150 x 48px, 4px apart, from x 11 and y 8, a finger tall.
#define TAB_Y   8
#define TAB_H   UI_TAP_MIN
#define TAB_ROW_W   (3 * 150 + 2 * 4)
#define CARD_Y   64
#define TEXT_FLOOR   (UI_ALERT_Y - UI_BAND_H - 4)
 The lowest row a control or a line of text may reach: 4px above the alert band, body y 492.
#define LCARD_W   640
 The rotor's card: 640px, the right card 360.
#define RCARD_X   (PAD + LCARD_W + 8)
#define RCARD_W   (W - RCARD_X - PAD)
#define CARD_H   (H - PAD - CARD_Y)
#define RC_X   (RCARD_X + 14)
#define RC_W   (RCARD_W - 28)
#define BL_FONT_LABEL   (&gfx_font_10x20)
 The faces of the 1024 x 600 type scale this screen draws in: BL_FONT_LABEL (10 x 20) for labels, buttons, rows, callouts and the rules' heads, BL_FONT_FINE (8 x 16) for the notes and the rules' two lines, which the 33 cells of the 10 x 20 face in the right column do not hold.
#define BL_FONT_FINE   UI_FONT_FINE
#define ROTOR_Y   (CARD_Y + 38)
#define ROTOR_H   UI_TAP_MIN
#define BLADES_Y   (ROTOR_Y + ROTOR_H + 10)
#define STEP_W   56
#define STEP_H   UI_TAP_MIN
#define READ_Y   (BLADES_Y + STEP_H + 18)
#define READ_H   36
#define MARK_Y   (READ_Y + 4 * READ_H + 8)
 The SIMULATED pill under the readings, 20px high.
#define NOTE_Y   (MARK_Y + 38)
#define RULE_Y0   (CARD_Y + 40)
 The rules' first row, TEST RIG and AIRCRAFT, px: y 104.
#define RULE_PITCH   64
#define FIG_X   ((LCARD_W - 450) / 2)
#define FIG_Y   (CARD_Y - 40)
#define KP_Y   CARD_Y
 The keypad's top, px.
#define KP_H   (TEXT_FLOOR - KP_Y)
 The keypad's height, px: 428.
#define BLADES_MIN   2
 The fewest blades the count takes.
#define BLADES_MAX   6
 The most blades the count takes.
#define BASE_Y   356
#define POST_X   150
#define POST_W   40
#define ARM_Y   196
#define ARM_H   28
#define MOTOR_X   300
#define MOTOR_W   62
#define SHAFT_Y   210
#define SPIN_X   406
#define BLADE_L   92
#define DISC_CX   (PAD + LCARD_W / 2)
#define DISC_CY   ((CARD_Y + TEXT_FLOOR) / 2)
#define DISC_R   160
 The disc's radius, px: a ducted fan's numbers at DISC_R + 38 and 10px tall end inside the card and above the alert band.
#define HUB_R   32
#define RIG_RULES   ((int)(sizeof(k_rig_rules) / sizeof(k_rig_rules[0])))
#define AIR_RULES   6

Functions

void balance_invalidate (void)
static void reset (void)
 The screen's state cleared: the BALANCE pane, two blades, a propeller, the controls laid out and the keypad closed.
int balance_screen_blades (void)
int balance_screen_rotor (void)
const ui_keypad_t * balance_screen_keypad (void)
 The keypad a tap on the blade count opens over both cards, for tests and the renderer.
gfx_rect_t balance_screen_blades_rect (void)
 Where the blade count is drawn and tapped, in the screen's coordinates: between BLADES and the "-" key.
static void kp_follow (void)
 The keypad's revision moved: the frame draws it again.
static void kp_event (const touch_event_t *evt)
 One event while the keypad is open: it takes them all. OK sets the count; the keypad holds it to 2 to 6.
static void kp_close (void)
 The keypad closes, with nothing typed taken: the home tag over it and leaving the screen.
static bool back (void)
 The home tag: over the keypad it is CANCEL.
static void leave (void)
 The screen is left: the keypad closes, with nothing typed taken.
static float balance_screen_angle (void)
const char * balance_screen_model_mark (void)
const char * balance_screen_model_note (void)
static void event (const touch_event_t *evt)
 One touch event: the tabs first, then the keypad while it is open, then the BALANCE pane's controls. The rotor buttons and the count's "-" and "+" act on the press; the count opens its keypad on the release of a tap on it.
static void callout (gfx_canvas_t *c, int px, int py, int lx, int ly, const char *text, gfx_color_t ink)
static int left_of (int lx, int right, int gap, const char *text)
 Where a callout's label starts so that it ends gap px left of right, or at lx where it already does.
static void draw_rig (gfx_canvas_t *c)
static void draw_aircraft (gfx_canvas_t *c)
static void disc_at (float deg, int r, int *x, int *y)
static void draw_measure (gfx_canvas_t *c)
void balance_nearest_blades (float angle, int blades, int *lo, int *hi)
static void draw_readings (gfx_canvas_t *c)
 The BALANCE pane's right column: ROTOR, BLADES, the four readings, the SIMULATED pill and the note.
static void draw_rules (gfx_canvas_t *c, const rule_t *rules, int count)
 TEST RIG's or AIRCRAFT's right column: COMMON MISTAKES and the numbered rules, each its head over its two lines.
static void render (gfx_canvas_t *c, int buffer_index)
 The screen drawn on a revision not yet drawn: the tabs, then the keypad alone while it is open, else both cards of the pane.
static void cancel (void)
 The panel could not hand over every touch event, so this screen's record of the glass is stale.
const ui_screen_t * balance_screen (void)

Variables

static const ui_text_id_t k_tabs []
static struct  s
static const rule_t k_rig_rules []
static const rule_t k_air_rules []
static const ui_screen_t k_screen

Detailed Description

The balance screen: sensor placement guides and the correction readout.

A balance answer is a magnitude and an angle, both derived from two sensors whose placement decides whether the answer is valid. A vibration sensor on a compliant mount reads a filtered version of the bearing's motion; an index mark on a blade instead of the bell gives one pulse per blade and an angle wrong by a blade spacing. Neither error is visible on screen, so the screen carries the placement diagrams.

The blade count takes 2 to 6 from its "-" and "+" keys, which step on the press, or from the keypad a tap on the count opens over both cards. A tab tapped while the keypad is open closes it, the count as it was.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ BL_FONT_FINE

#define BL_FONT_FINE   UI_FONT_FINE

8 x 16.

◆ BLADES_Y

#define BLADES_Y   (ROTOR_Y + ROTOR_H + 10)

The BLADES row: y 160.

◆ CARD_H

#define CARD_H   (H - PAD - CARD_Y)

468px, to y 532.

◆ CARD_Y

#define CARD_Y   64

Both cards' top, px.

◆ DISC_CX

#define DISC_CX   (PAD + LCARD_W / 2)

x 328.

◆ DISC_CY

#define DISC_CY   ((CARD_Y + TEXT_FLOOR) / 2)

y 278.

◆ FIG_X

#define FIG_X   ((LCARD_W - 450) / 2)

x 95.

◆ FIG_Y

#define FIG_Y   (CARD_Y - 40)

y 24.

◆ H

#define H   UI_BODY_H

The body's height under the band, px.

◆ HUB_R

#define HUB_R   32

The hub's, px.

◆ MARK_Y

#define MARK_Y   (READ_Y + 4 * READ_H + 8)

The SIMULATED pill under the readings, 20px high.

y 378.

◆ NOTE_Y

#define NOTE_Y   (MARK_Y + 38)

The note's first line: y 416.

◆ PAD

#define PAD   UI_MARGIN

The screen's outer margin, px.

◆ RC_W

#define RC_W   (RCARD_W - 28)

Its width: 332px.

◆ RC_X

#define RC_X   (RCARD_X + 14)

The right column: x 670.

◆ RCARD_W

#define RCARD_W   (W - RCARD_X - PAD)

360px.

◆ RCARD_X

#define RCARD_X   (PAD + LCARD_W + 8)

x 656.

◆ READ_H

#define READ_H   36

A reading's row, px.

◆ READ_Y

#define READ_Y   (BLADES_Y + STEP_H + 18)

The first reading: y 226.

◆ ROTOR_H

#define ROTOR_H   UI_TAP_MIN

Their height: 48px.

◆ ROTOR_Y

#define ROTOR_Y   (CARD_Y + 38)

PROPELLER and EDF: y 102.

◆ RULE_PITCH

#define RULE_PITCH   64

A rule under the one before, px.

◆ STEP_H

#define STEP_H   UI_TAP_MIN

Their height: 48px.

◆ STEP_W

#define STEP_W   56

The "-" and "+" keys' width, px.

◆ TAB_H

#define TAB_H   UI_TAP_MIN

A tab's height: 48px.

◆ TAB_ROW_W

#define TAB_ROW_W   (3 * 150 + 2 * 4)

The row: 458px.

◆ TAB_Y

#define TAB_Y   8

The tabs' top, px.

◆ W

#define W   UI_PANEL_W

The panel's width, px.

Function Documentation

◆ back()

bool back ( void )
static

The home tag: over the keypad it is CANCEL.

Returns
True when it closed the keypad; false to go home.

◆ balance_invalidate()

void balance_invalidate ( void )

Drop the cached chrome, so the next frame repaints it.

◆ balance_nearest_blades()

void balance_nearest_blades ( float angle,
int blades,
int * lo,
int * hi )

The two blades a correction at angle (degrees from the index mark) falls between, on a rotor of blades blades. Both are 1..blades and wrap, so a correction past the last blade reads "between N and 1".

◆ balance_screen_blades()

int balance_screen_blades ( void )

How many blades the rotor has, 2 to 6.

◆ balance_screen_blades_rect()

gfx_rect_t balance_screen_blades_rect ( void )

Where the blade count is drawn and tapped, in the screen's coordinates: between BLADES and the "-" key.

Returns
The value's rectangle.

◆ balance_screen_keypad()

const ui_keypad_t * balance_screen_keypad ( void )

The keypad a tap on the blade count opens over both cards, for tests and the renderer.

Returns
The keypad, open or closed.

◆ balance_screen_model_mark()

const char * balance_screen_model_mark ( void )

The MODELLED mark the BALANCE pane shows beside its readings, or NULL on the other panes: the angle and both masses are fixed values.

◆ balance_screen_model_note()

const char * balance_screen_model_note ( void )

The words beside the mark ("Not measured."), or NULL where it is not shown.

◆ balance_screen_rotor()

int balance_screen_rotor ( void )

Propeller or ducted fan.

◆ cancel()

void cancel ( void )
static

The panel could not hand over every touch event, so this screen's record of the glass is stale.

The tab row, a press on the blade count and a keypad key hold state between a press and its release: a press kept would own a track id the controller reuses, and a later contact that began elsewhere and lifts over the tab would switch the pane on a tap nobody made. Each is let go; what the keypad has typed stays.

◆ draw_readings()

void draw_readings ( gfx_canvas_t * c)
static

The BALANCE pane's right column: ROTOR, BLADES, the four readings, the SIMULATED pill and the note.

Parameters
cThe canvas.

◆ draw_rules()

void draw_rules ( gfx_canvas_t * c,
const rule_t * rules,
int count )
static

TEST RIG's or AIRCRAFT's right column: COMMON MISTAKES and the numbered rules, each its head over its two lines.

Parameters
cThe canvas.
rulesThe rules.
countHow many.

◆ event()

void event ( const touch_event_t * evt)
static

One touch event: the tabs first, then the keypad while it is open, then the BALANCE pane's controls. The rotor buttons and the count's "-" and "+" act on the press; the count opens its keypad on the release of a tap on it.

Parameters
evtThe event, or NULL.

◆ kp_event()

void kp_event ( const touch_event_t * evt)
static

One event while the keypad is open: it takes them all. OK sets the count; the keypad holds it to 2 to 6.

Parameters
evtThe event.

◆ left_of()

int left_of ( int lx,
int right,
int gap,
const char * text )
static

Where a callout's label starts so that it ends gap px left of right, or at lx where it already does.

Parameters
lxThe label's start as drawn for a short word.
rightThe column it must end left of.
gapThe room left before right, px.
textThe label.
Returns
The label's start.

◆ render()

void render ( gfx_canvas_t * c,
int buffer_index )
static

The screen drawn on a revision not yet drawn: the tabs, then the keypad alone while it is open, else both cards of the pane.

Parameters
cThe canvas.
buffer_indexThe framebuffer, whose revision it follows.

Variable Documentation

◆ k_air_rules

const rule_t k_air_rules[]
static
Initial value:
= {
{ TX_BAL_AIR_1, TX_BAL_AIR_1A, TX_BAL_AIR_1B },
{ TX_BAL_AIR_2, TX_BAL_AIR_2A, TX_BAL_AIR_2B },
{ TX_BAL_AIR_3, TX_BAL_AIR_3A, TX_BAL_AIR_3B },
{ TX_BAL_AIR_4, TX_BAL_AIR_4A, TX_BAL_AIR_4B },
{ TX_BAL_AIR_5, TX_BAL_AIR_5A, TX_BAL_AIR_5B },
{ TX_BAL_AIR_6, TX_BAL_AIR_6A, TX_BAL_AIR_6B },
}

◆ k_rig_rules

const rule_t k_rig_rules[]
static
Initial value:
= {
{ TX_BAL_RIG_1, TX_BAL_RIG_1A, TX_BAL_RIG_1B },
{ TX_BAL_RIG_2, TX_BAL_RIG_2A, TX_BAL_RIG_2B },
{ TX_BAL_RIG_3, TX_BAL_RIG_3A, TX_BAL_RIG_3B },
{ TX_BAL_RIG_4, TX_BAL_RIG_4A, TX_BAL_RIG_4B },
{ TX_BAL_RIG_5, TX_BAL_RIG_5A, TX_BAL_RIG_5B },
{ TX_BAL_RIG_6, TX_BAL_RIG_6A, TX_BAL_RIG_6B },
}

◆ k_screen

const ui_screen_t k_screen
static
Initial value:
= {
.title = "BALANCE",
.reset = reset,
.enter = NULL,
.leave = leave,
.tick = NULL,
.event = event,
.cancel = cancel,
.render = render,
.back = back,
}
static void event(const touch_event_t *evt)
One touch event: the tabs are the screen's one control.
Definition analyser_screen.c:242
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 void render(gfx_canvas_t *c, int buffer_index)
The screen drawn on a revision not yet drawn: both cards once per framebuffer, then the tabs,...
Definition analyser_screen.c:618
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

◆ k_tabs

const ui_text_id_t k_tabs[]
static
Initial value:
= { TX_BAL_TAB_BALANCE, TX_BAL_TAB_RIG,
TX_BAL_TAB_AIRCRAFT }

◆ s

struct [struct].s s

The screen's state.