|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The multi-series plot on one time base. See ui_plot.h. More...
#include "ui_plot.h"#include <math.h>#include <stdio.h>#include <string.h>#include "ui_text.h"#include "ui_theme.h"#include "ui_widgets.h"Macros | |
| #define | SHRINK_HOLD 60 |
| #define | HEADROOM 1.12f |
| #define | RAIL_W 6 |
| #define | RAIL_PITCH 10 |
| #define | TICKS 8 |
Functions | |
| float | ui_plot_nice_ceil (float v) |
Round v up to 1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8 or 10 times a power of ten. | |
| static int | leader_of (const ui_plot_t *p, int k) |
| void | ui_plot_init (ui_plot_t *p, const ui_plot_series_t *series, int count, float span_s) |
An empty, running plot of series. | |
| void | ui_plot_push (ui_plot_t *p, const float *values) |
| Push one sample per series, newest last. | |
| void | ui_plot_set_running (ui_plot_t *p, bool running) |
| Start or stop the trace. Stopping holds it; starting does not clear it. | |
| void | ui_plot_clear (ui_plot_t *p) |
| Drop every sample and return each scale to its floor. Keeps the series, the time base, the focus and what is hidden. | |
| float | ui_plot_sample (const ui_plot_t *p, int series, int back) |
| A sample of a series. | |
| void | ui_plot_update_scales (ui_plot_t *p, int visible_samples) |
| Recompute the scales. | |
| void | ui_plot_touch_series (ui_plot_t *p, int series) |
| Tap a legend chip: focus it, or hide it if it was already focused. | |
| int | ui_plot_map_y (const ui_plot_t *p, int series, float value, int y0, int h) |
Where value lands inside a plot h tall. | |
| void | ui_plot_render_legend (const ui_plot_t *p, gfx_canvas_t *c, gfx_rect_t r) |
| A row of swatch + name + full scale, one entry per series. | |
| void | ui_plot_render (const ui_plot_t *p, gfx_canvas_t *c, gfx_rect_t r) |
| The plot body: grid, traces, the focused series' scale. One sample a pixel column, in the first UI_PLOT_HISTORY columns from the left edge, the newest in the last of them. | |
The multi-series plot on one time base. See ui_plot.h.
SPDX-License-Identifier: MIT
| void ui_plot_clear | ( | ui_plot_t * | p | ) |
Drop every sample and return each scale to its floor. Keeps the series, the time base, the focus and what is hidden.
| p | The plot. |
| void ui_plot_init | ( | ui_plot_t * | p, |
| const ui_plot_series_t * | series, | ||
| int | count, | ||
| float | span_s ) |
An empty, running plot of series.
| p | The plot. |
| series | The series, copied. |
| count | How many, at most UI_PLOT_MAX_SERIES. |
| span_s | The width of the time base, for the axis label. |
| int ui_plot_map_y | ( | const ui_plot_t * | p, |
| int | series, | ||
| float | value, | ||
| int | y0, | ||
| int | h ) |
Where value lands inside a plot h tall.
| p | The plot. |
| series | The series whose scale it is on. |
| value | The value. |
| y0 | The plot's top. |
| h | The plot's height. |
| float ui_plot_nice_ceil | ( | float | v | ) |
Round v up to 1, 1.2, 1.5, 2, 2.5, 3, 4, 5, 6, 8 or 10 times a power of ten.
The finer steps keep a 6S pack (25.2V) on a 0 to 30V scale rather than the 0 to 50V a 1/2/5 ladder gives.
| v | The value. |
| void ui_plot_push | ( | ui_plot_t * | p, |
| const float * | values ) |
Push one sample per series, newest last.
A non-finite value is a gap: not drawn and not in the autorange. A stopped plot counts the call and drops the sample.
| p | The plot. |
| values | One value per series: count of them. |
| void ui_plot_render | ( | const ui_plot_t * | p, |
| gfx_canvas_t * | c, | ||
| gfx_rect_t | r ) |
The plot body: grid, traces, the focused series' scale. One sample a pixel column, in the first UI_PLOT_HISTORY columns from the left edge, the newest in the last of them.
| p | The plot. |
| c | Canvas. |
| r | The plot's box. |
| void ui_plot_render_legend | ( | const ui_plot_t * | p, |
| gfx_canvas_t * | c, | ||
| gfx_rect_t | r ) |
A row of swatch + name + full scale, one entry per series.
| p | The plot. |
| c | Canvas. |
| r | The legend's row. |
| float ui_plot_sample | ( | const ui_plot_t * | p, |
| int | series, | ||
| int | back ) |
A sample of a series.
| p | The plot. |
| series | The series. |
| back | How far back: the newest is 0. |
| void ui_plot_set_running | ( | ui_plot_t * | p, |
| bool | running ) |
Start or stop the trace. Stopping holds it; starting does not clear it.
Two calls rather than one setter that also empties the ring: this widget has no idea what a run is, and a start that silently wiped the samples would be a trap for the next caller that wanted to resume one.
| p | The plot. |
| running | Whether the trace advances. |
| void ui_plot_touch_series | ( | ui_plot_t * | p, |
| int | series ) |
Tap a legend chip: focus it, or hide it if it was already focused.
| p | The plot. |
| series | The series of the chip. |
| void ui_plot_update_scales | ( | ui_plot_t * | p, |
| int | visible_samples ) |
Recompute the scales.
A scale grows immediately and shrinks only after 60 consecutive samples (3s at 20Hz) below it, so a brief spike does not rescale the plot twice.
| p | The plot. |
| visible_samples | The newest samples the plot shows. |