mirror of
git://projects.qi-hardware.com/ben-blinkenlights.git
synced 2024-11-16 19:15:55 +02:00
ubb-la/: display sample rate and sample interval in the GUI
This commit is contained in:
parent
e1be0f242b
commit
5bb086e0e8
48
ubb-la/gui.c
48
ubb-la/gui.c
@ -35,6 +35,7 @@
|
||||
#define XRES 320 /* canvas width */
|
||||
#define YRES 240 /* canvas height */
|
||||
|
||||
#define TEXT_RGBA 0xffffffff /* general text */
|
||||
#define MAP_BUF_RGBA 0x808080ff /* buffer in the map */
|
||||
#define MAP_VIEW_RGBA 0xffffffff /* current view in the map */
|
||||
#define LEVEL_RGBA 0xffff00ff /* constant level or single change */
|
||||
@ -55,6 +56,11 @@
|
||||
|
||||
#define MAX_ZOOM 3
|
||||
|
||||
#define FREQ_X 0
|
||||
#define FREQ_Y 220
|
||||
#define INTERVAL_X 0
|
||||
#define INTERVAL_Y 230
|
||||
|
||||
#define REPEAT_DELAY_MS 300
|
||||
#define REPEAT_INTERVAL_MS 30
|
||||
|
||||
@ -297,6 +303,45 @@ static void show_buffer(const uint8_t *buf, int skip, int nibbles,
|
||||
}
|
||||
|
||||
|
||||
/* ----- Display the sample frequency -------------------------------------- */
|
||||
|
||||
|
||||
static void si_text(int x, int y, double v, const char *unit)
|
||||
{
|
||||
const char *pfx;
|
||||
|
||||
if (v >= 1e6) {
|
||||
v /= 1e6;
|
||||
pfx = "M";
|
||||
} else if (v >= 1e3) {
|
||||
v /= 1e3;
|
||||
pfx = "k";
|
||||
} else if (v >= 1) {
|
||||
pfx = " ";
|
||||
} else if (v >= 1e-3) {
|
||||
v *= 1e3;
|
||||
pfx = "m";
|
||||
} else if (v >= 1e-6) {
|
||||
v *= 1e6;
|
||||
pfx = "u";
|
||||
} else {
|
||||
v *= 1e9;
|
||||
pfx = "n";
|
||||
}
|
||||
if (v >= 10)
|
||||
textf(x, y, TEXT_RGBA, "%3d%s%s", (int) (v+0.5), pfx, unit);
|
||||
else
|
||||
textf(x, y, TEXT_RGBA, "%3.1f%s%s", v, pfx, unit);
|
||||
}
|
||||
|
||||
|
||||
static void show_freq(double freq)
|
||||
{
|
||||
si_text(FREQ_X, FREQ_Y, freq, "Sa/s");
|
||||
si_text(INTERVAL_X, INTERVAL_Y, 1/freq, "s/Sa");
|
||||
}
|
||||
|
||||
|
||||
/* ----- Main event loop --------------------------------------------------- */
|
||||
|
||||
|
||||
@ -306,7 +351,7 @@ static int pos_step(int zoom)
|
||||
}
|
||||
|
||||
|
||||
void gui(const uint8_t *buf, int skip, int nibbles)
|
||||
void gui(const uint8_t *buf, int skip, int nibbles, double freq)
|
||||
{
|
||||
SDL_Event event;
|
||||
int pos = (skip+nibbles) >> 1;
|
||||
@ -322,6 +367,7 @@ void gui(const uint8_t *buf, int skip, int nibbles)
|
||||
for (i = 0; i != 4; i++)
|
||||
textf(0, ch_y(i, 1), LABEL_RGBA, "CH%d", i);
|
||||
show_buffer(buf, skip, nibbles, CH_XOFF, XRES, zoom, pos);
|
||||
show_freq(freq);
|
||||
update();
|
||||
|
||||
while (1) {
|
||||
|
@ -18,6 +18,6 @@
|
||||
|
||||
|
||||
void gui_init(void);
|
||||
void gui(const uint8_t *buf, int skip, int nibbles);
|
||||
void gui(const uint8_t *buf, int skip, int nibbles, double freq);
|
||||
|
||||
#endif /* !GUI_H */
|
||||
|
@ -1,9 +1,10 @@
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "gui.h"
|
||||
|
||||
|
||||
int main(void)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
static uint8_t buf[4000];
|
||||
int i;
|
||||
@ -11,6 +12,6 @@ int main(void)
|
||||
for (i = 0; i != 8000; i++)
|
||||
buf[i >> 1] |= (i & 0xf) << 4*(~i & 1);
|
||||
gui_init();
|
||||
gui(buf, 0, 8000);
|
||||
gui(buf, 0, 8000, argv[1] ? atof(argv[1]) : 1e6);
|
||||
return 0;
|
||||
}
|
||||
|
@ -268,7 +268,8 @@ static void print_samples(FILE *file, uint8_t *buf, int skip, int nibbles)
|
||||
/* ----- Capture ----------------------------------------------------------- */
|
||||
|
||||
|
||||
static int do_buf(int nibbles, uint32_t trigger, uint32_t mask, int use_gui)
|
||||
static int do_buf(int nibbles, uint32_t trigger, uint32_t mask,
|
||||
const struct mmcclk *clk, int use_gui)
|
||||
{
|
||||
uint8_t *buf = physmem_malloc(4096);
|
||||
struct physmem_vec vec;
|
||||
@ -291,7 +292,7 @@ static int do_buf(int nibbles, uint32_t trigger, uint32_t mask, int use_gui)
|
||||
return 0;
|
||||
|
||||
if (use_gui)
|
||||
gui(buf, INITIAL_SKIP, nibbles);
|
||||
gui(buf, INITIAL_SKIP, nibbles, clk->bus_clk_hz);
|
||||
else
|
||||
print_samples(stdout, buf, INITIAL_SKIP, nibbles);
|
||||
|
||||
@ -459,7 +460,7 @@ int main(int argc, char **argv)
|
||||
gui_init();
|
||||
|
||||
if (!multi) {
|
||||
res = !do_buf(8128, trigger, mask, use_gui);
|
||||
res = !do_buf(8128, trigger, mask, &clk, use_gui);
|
||||
} else {
|
||||
frequency(&fast_clk, 84e6, 1);
|
||||
do_bufs(multi, 8128, &clk, &fast_clk);
|
||||
|
Loading…
Reference in New Issue
Block a user