|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The battery screen: each cell's departure from the pack's mean. More...
#include "battery_screen.h"#include <math.h>#include <stdio.h>#include <string.h>#include "ui_text.h"#include "ui_theme.h"#include "ui_widgets.h"Data Structures | |
| 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 | LCARD_W 640 |
| The plot card's width, px: 640, the right card 360. | |
| #define | RCARD_X (PAD + LCARD_W + 8) |
| #define | RCARD_W (W - RCARD_X - PAD) |
| #define | TEXT_FLOOR (UI_ALERT_Y - UI_BAND_H - 4) |
| The lowest row a line of text may reach: 4px above the alert band, body y 492. | |
| #define | BT_FONT_LABEL (&gfx_font_10x20) |
| The faces of the 1024 x 600 type scale this screen draws in: BT_FONT_LABEL (10 x 20) for the title, the rows and the note, BT_FONT_FINE (8 x 16) for the plot's scale, BT_FONT_BODY (12 x 24) for the verdict's line, the cells row and the empty plot's line, BT_FONT_HEAD (20 x 36) for the verdict. | |
| #define | BT_FONT_FINE UI_FONT_FINE |
| #define | BT_FONT_BODY UI_FONT_BODY |
| #define | BT_FONT_HEAD (&gfx_font_20x36) |
| #define | PLOT_X (PAD + 18) |
| #define | PLOT_W (LCARD_W - 36) |
| #define | MEAN_Y 232 |
| #define | REACH 164 |
| #define | NUM_Y (MEAN_Y + REACH + 14) |
| #define | VOLT_Y (NUM_Y + 30) |
| #define | BAR_MAX 48 |
| #define | VERDICT_Y 20 |
| #define | VERDICT_H 64 |
| #define | WHY_Y (VERDICT_Y + VERDICT_H + 8) |
| #define | WHY_PITCH 26 |
| #define | WHY_LINES 2 |
| #define | RULE1_Y (WHY_Y + WHY_LINES * WHY_PITCH + 8) |
| #define | ROW_Y (RULE1_Y + 8) |
| #define | ROW_PITCH 36 |
| #define | RULE2_Y (ROW_Y + 6 * ROW_PITCH + 6) |
| #define | NOTE_Y (RULE2_Y + 10) |
| #define | NOTE_PITCH 22 |
| #define | NOTE_LINES 4 |
| #define | SCALE_FLOOR_MV 12.0f |
| #define | SPREAD_WATCH_MV 30.0f |
| #define | SPREAD_BAD_MV 60.0f |
Functions | |
| void | battery_invalidate (void) |
| static void | reset (void) |
| The screen's state cleared: no pack. | |
| void | battery_screen_set (const battery_state_t *b) |
| What the balance lead says. NULL, or valid false, means nothing is on. | |
| static float | mean_v (void) |
| The pack's mean cell voltage. | |
| float | battery_screen_spread_mv (void) |
| The widest gap between any two cells. | |
| static float | scale_mv (void) |
| Full deflection: the pack's own worst departure with a little headroom, never less than the floor. | |
| const gfx_font_t * | battery_screen_cells_font (int cells) |
The face of the cells row under the plot for a pack of cells: 12 x 24 while a voltage ("3.81") fits its cell's slot, else the 10 x 20 face, else 8 x 16. | |
| static void | draw_cells (gfx_canvas_t *c) |
| The plot card: the mean, the band a pack is fine inside, the scale, and each cell's bar with its number and voltage under it. | |
| static size_t | line_len (const char *at, int cells) |
The bytes of the next line of at that fit cells: up to the last space in it, or the whole width where no space falls after its start. | |
| static int | wrap_in (gfx_canvas_t *c, gfx_rect_t box, const char *text, const gfx_font_t *f, int pitch, gfx_color_t ink, gfx_align_t align) |
text in lines of face f as wide as box, broken after a space, from the box's top down by pitch, aligned in the box by align. | |
| static void | row (gfx_canvas_t *c, int i, const char *k, const char *v, gfx_color_t ink) |
| One reading row of the right card: its label at the left, its value at the right, centred in a row ROW_PITCH tall. | |
| int | battery_screen_text_lines (const char *text, bool note) |
The lines text takes in the right card's column: the verdict's reason in the 12 x 24 face (the card shows two lines), or a part of the note in the 10 x 20 face. | |
| static void | draw_verdict (gfx_canvas_t *c) |
| The verdict box, its word in the 20 x 36 face, and its reason under it. | |
| static void | draw_right (gfx_canvas_t *c) |
| The right card: the verdict, the six rows and the note; with no pack the rows read "---" and the note is left out. | |
| static void | render (gfx_canvas_t *c, int buffer_index) |
| The screen drawn on a revision not yet drawn: both cards whole. | |
| const ui_screen_t * | battery_screen (void) |
| The BATTERY screen. | |
Variables | |
| static struct | s |
| static const ui_screen_t | k_screen |
| The screen, as the router takes it. | |
The battery screen: each cell's departure from the pack's mean.
Six cell voltages that agree to two decimals hide a cell 40mV adrift, so the cells are drawn as departures from their own mean, and the verdict follows the spread: the widest gap between any two cells. The absolute voltage of each cell is printed under its bar.
SPDX-License-Identifier: MIT
| #define BAR_MAX 48 |
A bar's widest, px.
| #define BT_FONT_BODY UI_FONT_BODY |
12 x 24.
| #define BT_FONT_FINE UI_FONT_FINE |
8 x 16.
| #define BT_FONT_HEAD (&gfx_font_20x36) |
20 x 36.
| #define H UI_BODY_H |
The body's height under the band, px.
| #define MEAN_Y 232 |
The mean's row, px.
| #define NOTE_LINES 4 |
The lines the note takes.
| #define NOTE_PITCH 22 |
A wrapped line of the note.
| #define NOTE_Y (RULE2_Y + 10) |
The note: y 392.
| #define PAD UI_MARGIN |
The screen's outer margin, px.
| #define PLOT_W (LCARD_W - 36) |
Its width: 604px.
| #define PLOT_X (PAD + 18) |
The plot's left edge: x 26.
| #define REACH 164 |
Pixels for the full divergence scale.
| #define ROW_PITCH 36 |
A row, px.
| #define ROW_Y (RULE1_Y + 8) |
The first row: y 160.
| #define SCALE_FLOOR_MV 12.0f |
The scale's floor, mV.
| #define SPREAD_BAD_MV 60.0f |
REPLACE from this spread, mV.
| #define SPREAD_WATCH_MV 30.0f |
WATCH from this spread, mV.
| #define VERDICT_H 64 |
Its height, px.
| #define VERDICT_Y 20 |
The verdict box's top, px.
| #define VOLT_Y (NUM_Y + 30) |
The voltages' row: y 440.
| #define W UI_PANEL_W |
The panel's width, px.
| #define WHY_LINES 2 |
The lines the reason takes.
| #define WHY_PITCH 26 |
A wrapped line of the reason.
| void battery_invalidate | ( | void | ) |
Drop the cached chrome, so the next frame repaints it.
| const ui_screen_t * battery_screen | ( | void | ) |
The BATTERY screen.
| const gfx_font_t * battery_screen_cells_font | ( | int | cells | ) |
The face of the cells row under the plot for a pack of cells: 12 x 24 while a voltage ("3.81") fits its cell's slot, else the 10 x 20 face, else 8 x 16.
| cells | The pack's cells; under 1 counts as 1. |
| void battery_screen_set | ( | const battery_state_t * | b | ) |
What the balance lead says. NULL, or valid false, means nothing is on.
| b | The pack, copied; NULL clears it. |
| float battery_screen_spread_mv | ( | void | ) |
The widest gap between any two cells.
| int battery_screen_text_lines | ( | const char * | text, |
| bool | note ) |
The lines text takes in the right card's column: the verdict's reason in the 12 x 24 face (the card shows two lines), or a part of the note in the 10 x 20 face.
| text | The text, as the screen shows it. |
| note | True for the note's face, false for the reason's. |
|
static |
The plot card: the mean, the band a pack is fine inside, the scale, and each cell's bar with its number and voltage under it.
| c | The canvas. |
|
static |
The right card: the verdict, the six rows and the note; with no pack the rows read "---" and the note is left out.
| c | The canvas. |
|
static |
The verdict box, its word in the 20 x 36 face, and its reason under it.
| c | The canvas. |
|
static |
The bytes of the next line of at that fit cells: up to the last space in it, or the whole width where no space falls after its start.
| at | The text from the line's start. |
| cells | The line's width, in cells. |
|
static |
The pack's mean cell voltage.
|
static |
The screen drawn on a revision not yet drawn: both cards whole.
| c | The canvas. |
| buffer_index | The framebuffer, whose revision it follows. |
|
static |
One reading row of the right card: its label at the left, its value at the right, centred in a row ROW_PITCH tall.
| c | The canvas. |
| i | The row, 0 for the first. |
| k | The label. |
| v | The value. |
| ink | The value's colour. |
|
static |
Full deflection: the pack's own worst departure with a little headroom, never less than the floor.
|
static |
text in lines of face f as wide as box, broken after a space, from the box's top down by pitch, aligned in the box by align.
| c | The canvas, or NULL to measure only. |
| box | The first line's box; its height is not used. |
| text | The text. |
| f | The face. |
| pitch | A line under the one before, px. |
| ink | The colour. |
| align | The lines' alignment. |
|
static |
The screen, as the router takes it.
| struct [struct].s s |
The screen's state.