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

The screen router: the band, the alert band, and the touches between them and the screens. More...

#include "busfault_screen.h"
#include "coproc_update_screen.h"
#include "files_screen.h"
#include "outputs_screen.h"
#include "picker_screen.h"
#include "supply_screen.h"
#include "upd_screen.h"
#include "wifi_screen.h"
#include "ui_screen.h"
#include <stdio.h>
#include <string.h>
#include "log_viewer_screen.h"
#include "motor_screen.h"
#include "analyser_screen.h"
#include "balance_screen.h"
#include "battery_screen.h"
#include "servo_screen.h"
#include "settings_screen.h"
#include "overview_screen.h"
#include "splash_screen.h"
#include "ui_band.h"
#include "ui_theme.h"
#include "ui_watermark.h"
#include "ui_widgets.h"

Data Structures

struct  [struct].s
 Driver state of the UART: the claimed machines and the pins. More...
struct  [struct].k_openers

Macros

#define PANEL_W   UI_PANEL_W
 The panel's width, UI_PANEL_W px.
#define PANEL_H   UI_PANEL_H
 The panel's height, UI_PANEL_H px.
#define ALERT_H   UI_ALERT_H
 The alert band's height, across the bottom.
#define ALERT_TEXT_X   12
 The alert text's left edge: 12px.
#define ALERT_TEXT_W   (PANEL_W - 2 * ALERT_TEXT_X - 24)
 The alert text's width: 976px, 97 cells, clear of the "x".
#define ALERT_PITCH   20
 An alert row to the next: 20px.
#define ALERT_FONT   UI_FONT_BAND
 The alert's face: 10 x 20px.

Functions

static bool has_band (ui_screen_id_t id)
static bool opens (ui_screen_id_t opener, ui_screen_id_t id)
static const ui_screen_t * screen_for (ui_screen_id_t id)
const char * ui_router_title (ui_screen_id_t id)
void ui_router_init (void)
void ui_router_goto (ui_screen_id_t id)
ui_screen_id_t ui_router_current (void)
ui_screen_id_t ui_router_parent (ui_screen_id_t id)
 Where the home tag of screen id leads when it leaves the screen. A screen with several openers returns to the one that last opened it: WI-FI and FILES to LOGS or SETUP, OUTPUTS to MOTOR & ESC, SERVO or SETUP. A screen a tile of SETUP opens returns to SETUP, and every other to the menu. WI-FI, FILES or OUTPUTS not yet opened from an opener returns to SETUP.
uint32_t ui_router_navigations (void)
uint32_t ui_router_dispatched (void)
void ui_router_invalidate (void)
static void clear_alert (void)
void ui_router_tick (float dt_s)
void ui_router_set_status (const ui_bench_status_t *status)
ui_band_chip_t ui_router_help (void)
bool ui_router_help_rect (gfx_rect_t *out)
const ui_bench_status_t * ui_router_status (void)
bool ui_router_take_stop (void)
 Whether a press came down on STOP since the last call; clears it.
bool ui_router_stop_live (void)
static bool in_alert (const touch_event_t *evt)
static bool has_home (ui_screen_id_t id)
static void router_hand (touch_event_t evt)
static bool router_safe_at (const touch_event_t *evt)
static void release_owned (void)
static void help_open (ui_band_chip_t chip)
static void router_back (void)
static int owned_find (uint8_t id)
void ui_router_event (const touch_event_t *evt)
void ui_router_cancel_gestures (void)
void ui_router_set_alert (const char *text)
 Show text in a 34px band across the bottom of every screen, or NULL to clear it.
uint32_t ui_router_alert_number (void)
bool ui_router_withdraw_alert (uint32_t number)
void ui_router_hold_alert (const char *text)
const char * ui_router_alert (void)
int ui_router_alert_rows (const char *text)
 The rows the alert band gives text.
static void draw_alert (gfx_canvas_t *c, const char *text, bool closable)
 Draw the alert band across the bottom of the panel.
void ui_router_render (gfx_canvas_t *c, int buffer_index)

Variables

static struct  s
static const struct  k_openers []

Detailed Description

The screen router: the band, the alert band, and the touches between them and the screens.

SPDX-License-Identifier: MIT

Function Documentation

◆ draw_alert()

void draw_alert ( gfx_canvas_t * c,
const char * text,
bool closable )
static

Draw the alert band across the bottom of the panel.

Parameters
cThe canvas, the panel's.
textThe alert, on one row centred or on two from the top.
closableA tap closes it: the "x" at its right end shows.

◆ ui_router_alert()

const char * ui_router_alert ( void )

The alert showing: the passing one, else the held one, else NULL.

◆ ui_router_alert_number()

uint32_t ui_router_alert_number ( void )

The number of the alert ui_router_set_alert() shows now, 0 while none does. Every call that sets one gives it the next number, so a caller that noted the number can tell whether its alert still shows: not once time or a tap cleared it or another replaced it.

◆ ui_router_alert_rows()

int ui_router_alert_rows ( const char * text)

The rows the alert band gives text.

The band draws two rows of the 10 x 20 face (UI_FONT_BAND), 20px apart, each 97 cells (ALERT_TEXT_W in ui_router.c: 976px of the 1024px panel).

Parameters
textThe alert's text.
Returns
1 for a text of up to 97 cells, 2 when it breaks at a space onto a second row, more for a text the band cannot hold.

◆ ui_router_cancel_gestures()

void ui_router_cancel_gestures ( void )

Tell every screen that touch events were lost, so a gesture that completes on a timer cannot finish on a contact that is no longer there. Called once per frame in which the panel could not deliver every event. The contacts on the glass are no screen's until they lift and come down again.

◆ ui_router_dispatched()

uint32_t ui_router_dispatched ( void )

Count of touch events handed to a screen's event() since ui_router_init(), a release the router makes up for a contact that left the body included. An event the router keeps – the band's, the alert strip's, one of a contact no screen owns – does not count.

◆ ui_router_event()

void ui_router_event ( const touch_event_t * evt)

One touch event, in panel coordinates, in the order the tracker emits them.

A contact has one owner from its DOWN to its UP. The screen on top owns a contact whose DOWN it was handed, and is handed a MOVE or an UP of no other: a contact that came down on the band or on the alert strip, or that was down when the screen changed or gestures were cancelled, reaches no screen. One exception: a contact that comes down on a control the screen's safe_at names is the screen's, under the alert strip or with the help bubble open, and the strip or the bubble closes. A contact the screen owns that reaches the band (y below UI_BAND_H) is released for the screen with an UP at the last point the screen was handed, flagged TOUCH_FLAG_NO_TAP, and is the router's from then on. A flagged UP ends a press or a drag and activates no control. STOP and the home tag answer to a DOWN on them only.

◆ ui_router_goto()

void ui_router_goto ( ui_screen_id_t id)

Switch screens. Calls leave() on the old and enter() on the new.

◆ ui_router_help()

ui_band_chip_t ui_router_help ( void )

The chip whose help bubble is open, or UI_BAND_CHIP_NONE.

A tap on a chip of the band opens its bubble under the band. The bubble follows the status as it changes and closes when its chip is no longer drawn, when the screen changes, or on the next DOWN anywhere; that DOWN reaches no screen, except that a DOWN on STOP presses STOP as well.

◆ ui_router_help_rect()

bool ui_router_help_rect ( gfx_rect_t * out)

Where the open bubble is drawn, in panel coordinates; false when none is.

◆ ui_router_hold_alert()

void ui_router_hold_alert ( const char * text)

An alert that neither time nor a tap clears, or NULL to clear it: for a fault that lasts until restart and leaves no touch to tap with, such as a touch controller that did not answer at start. It is kept apart from the alert ui_router_set_alert() shows: that one shows over it, without an x for the held one, and once cleared the held one shows again.

◆ ui_router_invalidate()

void ui_router_invalidate ( void )

Repaint every screen's cached chrome into every framebuffer.

◆ ui_router_navigations()

uint32_t ui_router_navigations ( void )

Count of navigations since ui_router_init(): every switch to a different screen adds one. Two reads that differ tell that the router moved between them, including away and back to the same screen, which comparing ui_router_current() cannot.

◆ ui_router_parent()

ui_screen_id_t ui_router_parent ( ui_screen_id_t id)

Where the home tag of screen id leads when it leaves the screen. A screen with several openers returns to the one that last opened it: WI-FI and FILES to LOGS or SETUP, OUTPUTS to MOTOR & ESC, SERVO or SETUP. A screen a tile of SETUP opens returns to SETUP, and every other to the menu. WI-FI, FILES or OUTPUTS not yet opened from an opener returns to SETUP.

Parameters
idthe screen
Returns
the screen the home tag leads to

◆ ui_router_set_alert()

void ui_router_set_alert ( const char * text)

Show text in a 34px band across the bottom of every screen, or NULL to clear it.

For faults the screen itself does not show, such as a touch controller that has stopped answering. At the bottom, it covers controls rather than readings. The band clears after UI_ALERT_SHOW_S of ui_router_tick(), or when a tap lands on it and lifts there; a tap on the band reaches no screen. A press on a control under it that stops what the bench drives – DISARM, ABORT, STOP TEST – reaches the screen as if the band were not there, and clears the band (ui_screen_t's safe_at). Setting an alert again, even the same text, restarts its time.

Parameters
textthe alert, or NULL to clear it

◆ ui_router_stop_live()

bool ui_router_stop_live ( void )

True while a STOP button is drawn; false on the splash, which has none.

◆ ui_router_take_stop()

bool ui_router_take_stop ( void )

Whether a press came down on STOP since the last call; clears it.

The press acts at once; its release does nothing. A latch rather than a callback: the application drains it in the loop that drives the heartbeat, so the UI (user interface) never calls into hardware.

Returns
true once after each press on STOP

◆ ui_router_withdraw_alert()

bool ui_router_withdraw_alert ( uint32_t number)

Clear the alert ui_router_set_alert() shows if it is still number number (ui_router_alert_number()): for an alert whose cause is over before its time is. Another alert, a held one and a number of 0 are left as they are. True when it cleared one.

Variable Documentation

◆ k_openers

const struct [struct].k_openers k_openers[]
Initial value:
= {
{ SCREEN_WIFI, SCREEN_LOGS },
{ SCREEN_WIFI, SCREEN_SETUP },
{ SCREEN_FILES, SCREEN_LOGS },
{ SCREEN_FILES, SCREEN_SETUP },
{ SCREEN_OUTPUTS, SCREEN_MOTOR },
{ SCREEN_OUTPUTS, SCREEN_SERVO },
{ SCREEN_OUTPUTS, SCREEN_SETUP },
}