1
0
mirror of git://projects.qi-hardware.com/ben-blinkenlights.git synced 2025-04-21 12:27:27 +03:00

ubb-la/: display sample rate and sample interval in the GUI

This commit is contained in:
Werner Almesberger
2013-01-31 00:47:14 -03:00
parent e1be0f242b
commit 5bb086e0e8
4 changed files with 55 additions and 7 deletions

View File

@@ -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) {