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

Screen router. More...

#include <math.h>
#include <stdbool.h>
#include <stdint.h>
#include "gfx.h"
#include "touch_types.h"
#include "ui_layout.h"

Go to the source code of this file.

Data Structures

struct  ui_screen_t
struct  ui_bench_status_t

Macros

#define UI_ARMED_MOTOR   0x01u
#define UI_ARMED_SERVO   0x02u
#define UI_ALERT_MAX   128
#define UI_ALERT_SHOW_S   30.0f

Enumerations

enum  ui_screen_id_t {
  SCREEN_SPLASH = 0 , SCREEN_OVERVIEW , SCREEN_MOTOR , SCREEN_SERVO ,
  SCREEN_ANALYSER , SCREEN_LOGS , SCREEN_SETUP , SCREEN_BATTERY ,
  SCREEN_BALANCE , SCREEN_OUTPUTS , SCREEN_PICKER , SCREEN_SUPPLY ,
  SCREEN_BUSFAULT , SCREEN_WIFI , SCREEN_UPDATE , SCREEN_COPROC_UPDATE ,
  SCREEN_UPDATES , SCREEN_UPD_REMIND , SCREEN_FILES , SCREEN_COUNT
}
enum  ui_band_chip_t {
  UI_BAND_CHIP_NONE = 0 , UI_BAND_CHIP_LINK , UI_BAND_CHIP_MODE , UI_BAND_CHIP_FAULT ,
  UI_BAND_CHIP_ARMED , UI_BAND_CHIP_CLOCK , UI_BAND_CHIP_COUNT
}

Functions

int ui_router_alert_rows (const char *text)
 The rows the alert band gives text.
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)
const char * ui_router_title (ui_screen_id_t id)
void ui_router_tick (float dt_s)
void ui_router_event (const touch_event_t *evt)
void ui_router_cancel_gestures (void)
void ui_router_render (gfx_canvas_t *c, int buffer_index)
void ui_router_invalidate (void)
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)
bool ui_router_stop_live (void)
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.
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)

Detailed Description

Screen router.

The router owns the top 60px of the panel, the status band with STOP, and hands each screen a sub-canvas of the remaining 1024 x 540px through gfx_canvas_sub, so a screen cannot draw over STOP. The band is horizontal because horizontal spans are the cheap direction on a panel whose frame rate is bound by PSRAM (pseudo-static random-access memory) bandwidth.

Pure C with no ESP-IDF (Espressif Internet-of-Things Development Framework), so the whole navigation model renders on the host.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ UI_ALERT_MAX

#define UI_ALERT_MAX   128

Longest alert the router will show, including the terminator.

◆ UI_ALERT_SHOW_S

#define UI_ALERT_SHOW_S   30.0f

How long an alert shows before it clears itself, in seconds.

◆ UI_ARMED_MOTOR

#define UI_ARMED_MOTOR   0x01u

What the band shows. The application fills it in from the link and hands it over; the router computes none of it. What an arm covers, for the band's chip: the motor's outputs, the servos' and the programming ports'.

Enumeration Type Documentation

◆ ui_band_chip_t

The band's chips, each of which opens a help bubble when tapped. NONE is no chip.

Enumerator
UI_BAND_CHIP_LINK 

LINK or NO LINK

UI_BAND_CHIP_MODE 

BENCH or SIM, ui_band_mode()

UI_BAND_CHIP_FAULT 

FAULT and the link_fault_t bitmap

UI_BAND_CHIP_ARMED 

SAFE, ARMED, ARMED MOTOR or ARMED SERVO

UI_BAND_CHIP_CLOCK 

the run clock

Function Documentation

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