rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
ui_plot.h
Go to the documentation of this file.
1
16#pragma once
17
18#include <stdbool.h>
19#include <stdint.h>
20
21#include "gfx.h"
22#include "ui_layout.h"
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
29#define UI_PLOT_MAX_SERIES 6
36#define UI_PLOT_HISTORY UI_PANEL_W
37
38typedef struct {
39 const char *name;
40 const char *unit;
41 gfx_color_t color;
42 int decimals;
45 float floor;
53 uint8_t follows;
55
56typedef struct {
58 int count;
59
61 int head;
62 int filled;
63
64 float scale[UI_PLOT_MAX_SERIES];
65 int shrink_hold[UI_PLOT_MAX_SERIES];
66 bool hidden[UI_PLOT_MAX_SERIES];
67 int focus;
68
69 float span_s;
70
79 bool running;
80
89 uint32_t pushes;
90
102 uint32_t revision;
103} ui_plot_t;
104
114float ui_plot_nice_ceil(float v);
115
123void ui_plot_init(ui_plot_t *p, const ui_plot_series_t *series, int count,
124 float span_s);
125
134void ui_plot_push(ui_plot_t *p, const float *values);
135
146void ui_plot_set_running(ui_plot_t *p, bool running);
147
153void ui_plot_clear(ui_plot_t *p);
154
163float ui_plot_sample(const ui_plot_t *p, int series, int back);
164
173void ui_plot_update_scales(ui_plot_t *p, int visible_samples);
174
180void ui_plot_touch_series(ui_plot_t *p, int series);
181
191int ui_plot_map_y(const ui_plot_t *p, int series, float value, int y0, int h);
192
201void ui_plot_render(const ui_plot_t *p, gfx_canvas_t *c, gfx_rect_t r);
202
210
211#ifdef __cplusplus
212}
213#endif
gfx: an RGB565 (16-bit red, green, blue) rasteriser with no dependencies.
Definition gfx.h:129
Definition gfx.h:81
Definition ui_plot.h:38
uint8_t follows
Definition ui_plot.h:53
float floor
Lower bound of the autorange: a 0 to 0.4A scale on an idle bench draws noise at full height.
Definition ui_plot.h:45
Definition ui_plot.h:56
int head
Definition ui_plot.h:61
int filled
Definition ui_plot.h:62
bool running
Definition ui_plot.h:79
uint32_t pushes
Definition ui_plot.h:89
float span_s
Definition ui_plot.h:69
uint32_t revision
Bumped when what ui_plot_render() would draw changes: an accepted push, a clear, or a change of runni...
Definition ui_plot.h:102
int focus
Definition ui_plot.h:67
The panel's geometry, in one place.
void ui_plot_clear(ui_plot_t *p)
Drop every sample and return each scale to its floor. Keeps the series, the time base,...
Definition ui_plot.c:115
#define UI_PLOT_MAX_SERIES
The most series one plot draws.
Definition ui_plot.h:29
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,...
Definition ui_plot.c:285
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.
Definition ui_plot.c:25
void ui_plot_update_scales(ui_plot_t *p, int visible_samples)
Recompute the scales.
Definition ui_plot.c:149
void ui_plot_push(ui_plot_t *p, const float *values)
Push one sample per series, newest last.
Definition ui_plot.c:79
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.
Definition ui_plot.c:220
void ui_plot_set_running(ui_plot_t *p, bool running)
Start or stop the trace. Stopping holds it; starting does not clear it.
Definition ui_plot.c:105
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.
Definition ui_plot.c:201
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.
Definition ui_plot.c:58
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.
Definition ui_plot.c:244
float ui_plot_sample(const ui_plot_t *p, int series, int back)
A sample of a series.
Definition ui_plot.c:136
#define UI_PLOT_HISTORY
The samples a series keeps: one per pixel column of a plot as wide as the panel, UI_PANEL_W,...
Definition ui_plot.h:36