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

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.

Detailed Description

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

Macro Definition Documentation

◆ BAR_MAX

#define BAR_MAX   48

A bar's widest, px.

◆ BT_FONT_BODY

#define BT_FONT_BODY   UI_FONT_BODY

12 x 24.

◆ BT_FONT_FINE

#define BT_FONT_FINE   UI_FONT_FINE

8 x 16.

◆ BT_FONT_HEAD

#define BT_FONT_HEAD   (&gfx_font_20x36)

20 x 36.

◆ H

#define H   UI_BODY_H

The body's height under the band, px.

◆ MEAN_Y

#define MEAN_Y   232

The mean's row, px.

◆ NOTE_LINES

#define NOTE_LINES   4

The lines the note takes.

◆ NOTE_PITCH

#define NOTE_PITCH   22

A wrapped line of the note.

◆ NOTE_Y

#define NOTE_Y   (RULE2_Y + 10)

The note: y 392.

◆ NUM_Y

#define NUM_Y   (MEAN_Y + REACH + 14)

The cell numbers' row: y 410.

◆ PAD

#define PAD   UI_MARGIN

The screen's outer margin, px.

◆ PLOT_W

#define PLOT_W   (LCARD_W - 36)

Its width: 604px.

◆ PLOT_X

#define PLOT_X   (PAD + 18)

The plot's left edge: x 26.

◆ RCARD_W

#define RCARD_W   (W - RCARD_X - PAD)

360px.

◆ RCARD_X

#define RCARD_X   (PAD + LCARD_W + 8)

x 656.

◆ REACH

#define REACH   164

Pixels for the full divergence scale.

◆ ROW_PITCH

#define ROW_PITCH   36

A row, px.

◆ ROW_Y

#define ROW_Y   (RULE1_Y + 8)

The first row: y 160.

◆ RULE1_Y

#define RULE1_Y   (WHY_Y + WHY_LINES * WHY_PITCH + 8)

y 152.

◆ RULE2_Y

#define RULE2_Y   (ROW_Y + 6 * ROW_PITCH + 6)

y 382.

◆ SCALE_FLOOR_MV

#define SCALE_FLOOR_MV   12.0f

The scale's floor, mV.

◆ SPREAD_BAD_MV

#define SPREAD_BAD_MV   60.0f

REPLACE from this spread, mV.

◆ SPREAD_WATCH_MV

#define SPREAD_WATCH_MV   30.0f

WATCH from this spread, mV.

◆ VERDICT_H

#define VERDICT_H   64

Its height, px.

◆ VERDICT_Y

#define VERDICT_Y   20

The verdict box's top, px.

◆ VOLT_Y

#define VOLT_Y   (NUM_Y + 30)

The voltages' row: y 440.

◆ W

#define W   UI_PANEL_W

The panel's width, px.

◆ WHY_LINES

#define WHY_LINES   2

The lines the reason takes.

◆ WHY_PITCH

#define WHY_PITCH   26

A wrapped line of the reason.

◆ WHY_Y

#define WHY_Y   (VERDICT_Y + VERDICT_H + 8)

Its reason: y 92.

Function Documentation

◆ battery_invalidate()

void battery_invalidate ( void )

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

◆ battery_screen()

const ui_screen_t * battery_screen ( void )

The BATTERY screen.

Returns
The screen.

◆ battery_screen_cells_font()

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.

Parameters
cellsThe pack's cells; under 1 counts as 1.
Returns
The face.

◆ battery_screen_set()

void battery_screen_set ( const battery_state_t * b)

What the balance lead says. NULL, or valid false, means nothing is on.

Parameters
bThe pack, copied; NULL clears it.

◆ battery_screen_spread_mv()

float battery_screen_spread_mv ( void )

The widest gap between any two cells.

Returns
Millivolts; 0 with no pack.

◆ battery_screen_text_lines()

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.

Parameters
textThe text, as the screen shows it.
noteTrue for the note's face, false for the reason's.
Returns
The lines, 0 for NULL or an empty text.

◆ draw_cells()

void draw_cells ( gfx_canvas_t * c)
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.

Parameters
cThe canvas.

◆ draw_right()

void draw_right ( gfx_canvas_t * c)
static

The right card: the verdict, the six rows and the note; with no pack the rows read "---" and the note is left out.

Parameters
cThe canvas.

◆ draw_verdict()

void draw_verdict ( gfx_canvas_t * c)
static

The verdict box, its word in the 20 x 36 face, and its reason under it.

Parameters
cThe canvas.

◆ line_len()

size_t line_len ( const char * at,
int cells )
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.

Parameters
atThe text from the line's start.
cellsThe line's width, in cells.
Returns
The line's length, in bytes.

◆ mean_v()

float mean_v ( void )
static

The pack's mean cell voltage.

Returns
Volts; 0 with no pack.

◆ render()

void render ( gfx_canvas_t * c,
int buffer_index )
static

The screen drawn on a revision not yet drawn: both cards whole.

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

◆ row()

void row ( gfx_canvas_t * c,
int i,
const char * k,
const char * v,
gfx_color_t ink )
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.

Parameters
cThe canvas.
iThe row, 0 for the first.
kThe label.
vThe value.
inkThe value's colour.

◆ scale_mv()

float scale_mv ( void )
static

Full deflection: the pack's own worst departure with a little headroom, never less than the floor.

Returns
Millivolts.

◆ wrap_in()

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

Parameters
cThe canvas, or NULL to measure only.
boxThe first line's box; its height is not used.
textThe text.
fThe face.
pitchA line under the one before, px.
inkThe colour.
alignThe lines' alignment.
Returns
The y under the last line.

Variable Documentation

◆ k_screen

const ui_screen_t k_screen
static
Initial value:
= {
.title = "BATTERY",
.reset = reset,
.enter = NULL,
.leave = NULL,
.tick = NULL,
.event = NULL,
.render = render,
}
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

The screen, as the router takes it.

◆ s

struct [struct].s s

The screen's state.