2011-04-13 04:52:39 +03:00
|
|
|
/*
|
|
|
|
* atrf-path/gui.c - Graphical output for atrf-path
|
|
|
|
*
|
|
|
|
* Written 2011 by Werner Almesberger
|
|
|
|
* Copyright 2011 Werner Almesberger
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <unistd.h>
|
2011-05-28 18:21:56 +03:00
|
|
|
#include <string.h>
|
2011-04-13 04:52:39 +03:00
|
|
|
|
|
|
|
#include "SDL.h"
|
|
|
|
#include "SDL_gfxPrimitives.h"
|
|
|
|
|
|
|
|
#include "at86rf230.h"
|
|
|
|
#include "atrf.h"
|
|
|
|
#include "misctxrx.h"
|
|
|
|
|
|
|
|
#include "sweep.h"
|
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
|
|
|
|
#define XRES 320
|
|
|
|
#define YRES 240
|
|
|
|
|
|
|
|
#define FG_RGBA 0xffffffff /* measurement color */
|
2011-04-13 15:13:46 +03:00
|
|
|
#define OK_RGBA 0x00ff00ff
|
atrf-path: option -P to load a min/max profile; pass/fail indication in GUI
- sweep.h (MIN_DIFF, MAX_DIFF, struct sweep): added min/max profile
- sweep.h (do_sweep), atrf-path.c (do_half_sweep, do_sweep): compare
result against limits and return pass/fail decision
- sweep.h (N_CHAN), atrf-path.c (do_half_sweep, do_sweeps), gui.c
(N_CHAN): declare number of channels in one central place instead of
scattering it all around the program
- atrf-path.c (do_read_profile, read_profile, usage, main): new option -P
to read a min/max profile
- gui.c (indicate, main): moved indicator to separate function and
improved blink logic
- gui.c (OVER_RGBA, UNDER_RGBA, indicate, main): change color to indicate
pass/fail
2011-04-14 00:40:39 +03:00
|
|
|
#define OVER_RGBA 0xffff00ff
|
|
|
|
#define UNDER_RGBA 0xff0000ff
|
2011-04-14 01:08:23 +03:00
|
|
|
#define LIMIT_RGBA 0xff0000ff
|
2011-05-28 18:21:56 +03:00
|
|
|
#define DUMP_RGBA 0x4040ffff
|
2011-04-13 04:52:39 +03:00
|
|
|
|
|
|
|
#define CHAN_STEP 20 /* 4 pixels/MHz */
|
|
|
|
#define SIDE_STEP 2
|
|
|
|
#define CHAN_X_OFFSET 10
|
|
|
|
#define Y_MIN -94
|
|
|
|
#define Y_MAX -10
|
|
|
|
|
2011-04-13 15:13:46 +03:00
|
|
|
#define STATUS_X (XRES-15)
|
|
|
|
#define STATUS_Y 15
|
|
|
|
#define STATUS_R 8
|
|
|
|
|
2011-04-13 04:52:39 +03:00
|
|
|
|
2011-05-28 18:21:56 +03:00
|
|
|
static struct sample **dumps = NULL;
|
|
|
|
static int n_dumps = 0;
|
|
|
|
|
|
|
|
|
2011-04-14 01:08:23 +03:00
|
|
|
static int avg2y(double avg)
|
|
|
|
{
|
|
|
|
return YRES-(avg-Y_MIN)/(Y_MAX-Y_MIN)*YRES-1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-13 04:52:39 +03:00
|
|
|
static void segment(SDL_Surface *s, int *last_x, int *last_y, int x,
|
2011-05-28 18:21:56 +03:00
|
|
|
const struct sample *res, int first, uint32_t color)
|
2011-04-13 04:52:39 +03:00
|
|
|
{
|
2011-04-14 01:08:23 +03:00
|
|
|
int y = avg2y(res->avg);
|
2011-04-13 04:52:39 +03:00
|
|
|
|
2011-04-13 20:01:12 +03:00
|
|
|
if (!first) {
|
2011-05-28 18:21:56 +03:00
|
|
|
aalineColor(s, *last_x, *last_y, x, y, color);
|
2011-04-13 04:52:39 +03:00
|
|
|
}
|
|
|
|
*last_x = x;
|
|
|
|
*last_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-28 18:21:56 +03:00
|
|
|
static void draw(SDL_Surface *s, const struct sample *res, int cont_tx,
|
|
|
|
uint32_t color)
|
2011-04-13 04:52:39 +03:00
|
|
|
{
|
|
|
|
int last_x, last_y;
|
2011-04-13 20:01:12 +03:00
|
|
|
int first, x, i;
|
2011-04-13 04:52:39 +03:00
|
|
|
|
|
|
|
x = CHAN_X_OFFSET;
|
2011-04-13 20:01:12 +03:00
|
|
|
first = 1;
|
2011-04-13 04:52:39 +03:00
|
|
|
for (i = 0; i != N_CHAN; i++) {
|
2011-04-13 20:01:12 +03:00
|
|
|
if (cont_tx != CONT_TX_P500K) {
|
2011-05-28 18:21:56 +03:00
|
|
|
segment(s, &last_x, &last_y, x, res, first, color);
|
2011-04-13 20:01:12 +03:00
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
res++;
|
2011-04-13 04:52:39 +03:00
|
|
|
x += 2*SIDE_STEP;
|
2011-04-13 20:01:12 +03:00
|
|
|
|
|
|
|
if (cont_tx != CONT_TX_M500K) {
|
2011-05-28 18:21:56 +03:00
|
|
|
segment(s, &last_x, &last_y, x, res, first, color);
|
2011-04-13 20:01:12 +03:00
|
|
|
first = 0;
|
|
|
|
}
|
|
|
|
res++;
|
2011-04-13 04:52:39 +03:00
|
|
|
x += CHAN_STEP-2*SIDE_STEP;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-14 01:08:23 +03:00
|
|
|
static void draw_limit(SDL_Surface *s, const double *v)
|
|
|
|
{
|
|
|
|
int x, y, i, last = 0;
|
|
|
|
|
|
|
|
x = CHAN_X_OFFSET;
|
|
|
|
for (i = 0; i != N_CHAN; i++) {
|
|
|
|
y = avg2y(*v);
|
|
|
|
if (i)
|
|
|
|
vlineColor(s, x-CHAN_STEP/2, last, y, LIMIT_RGBA);
|
|
|
|
hlineColor(s, x-CHAN_STEP/2, x+CHAN_STEP/2, y, LIMIT_RGBA);
|
|
|
|
last = y;
|
|
|
|
x += CHAN_STEP;
|
|
|
|
v++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-14 03:32:02 +03:00
|
|
|
static void disc(SDL_Surface *s, uint32_t color)
|
|
|
|
{
|
|
|
|
filledCircleColor(s, STATUS_X, STATUS_Y, STATUS_R, color);
|
|
|
|
aacircleColor(s, STATUS_X, STATUS_Y, STATUS_R, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void triangle(SDL_Surface *s, int cx, int cy, int r, uint32_t color)
|
|
|
|
{
|
|
|
|
filledTrigonColor(s, cx, cy-r, cx+r*1.2, cy+r, cx-r*1.2, cy+r, color);
|
|
|
|
// aatrigonColor(s, cx, cy-r, cx+r*1.2, cy+r, cx-r*1.2, cy+r, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void up(SDL_Surface *s, uint32_t color)
|
|
|
|
{
|
|
|
|
triangle(s, STATUS_X, STATUS_Y, STATUS_R, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void down(SDL_Surface *s, uint32_t color)
|
|
|
|
{
|
|
|
|
triangle(s, STATUS_X, STATUS_Y, -STATUS_R, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
atrf-path: option -P to load a min/max profile; pass/fail indication in GUI
- sweep.h (MIN_DIFF, MAX_DIFF, struct sweep): added min/max profile
- sweep.h (do_sweep), atrf-path.c (do_half_sweep, do_sweep): compare
result against limits and return pass/fail decision
- sweep.h (N_CHAN), atrf-path.c (do_half_sweep, do_sweeps), gui.c
(N_CHAN): declare number of channels in one central place instead of
scattering it all around the program
- atrf-path.c (do_read_profile, read_profile, usage, main): new option -P
to read a min/max profile
- gui.c (indicate, main): moved indicator to separate function and
improved blink logic
- gui.c (OVER_RGBA, UNDER_RGBA, indicate, main): change color to indicate
pass/fail
2011-04-14 00:40:39 +03:00
|
|
|
static void indicate(SDL_Surface *s, int fail)
|
|
|
|
{
|
|
|
|
static uint32_t last = 0;
|
|
|
|
uint32_t color;
|
|
|
|
|
|
|
|
switch (fail) {
|
|
|
|
case 0:
|
|
|
|
color = OK_RGBA;
|
|
|
|
break;
|
|
|
|
case 1:
|
|
|
|
color = OVER_RGBA;
|
|
|
|
break;
|
|
|
|
case -1:
|
|
|
|
color = UNDER_RGBA;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
abort();
|
|
|
|
}
|
|
|
|
if (color == last)
|
|
|
|
color = 0;
|
|
|
|
last = color;
|
2011-04-14 03:32:02 +03:00
|
|
|
switch (color) {
|
|
|
|
case OK_RGBA:
|
|
|
|
disc(s, color);
|
|
|
|
break;
|
|
|
|
case OVER_RGBA:
|
|
|
|
up(s, color);
|
|
|
|
break;
|
|
|
|
case UNDER_RGBA:
|
|
|
|
down(s, color);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
atrf-path: option -P to load a min/max profile; pass/fail indication in GUI
- sweep.h (MIN_DIFF, MAX_DIFF, struct sweep): added min/max profile
- sweep.h (do_sweep), atrf-path.c (do_half_sweep, do_sweep): compare
result against limits and return pass/fail decision
- sweep.h (N_CHAN), atrf-path.c (do_half_sweep, do_sweeps), gui.c
(N_CHAN): declare number of channels in one central place instead of
scattering it all around the program
- atrf-path.c (do_read_profile, read_profile, usage, main): new option -P
to read a min/max profile
- gui.c (indicate, main): moved indicator to separate function and
improved blink logic
- gui.c (OVER_RGBA, UNDER_RGBA, indicate, main): change color to indicate
pass/fail
2011-04-14 00:40:39 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-13 04:52:39 +03:00
|
|
|
static void clear(SDL_Surface *s)
|
|
|
|
{
|
|
|
|
SDL_FillRect(s, NULL, SDL_MapRGB(s->format, 0, 0, 0));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-05-28 18:21:56 +03:00
|
|
|
static void dump(const struct sweep *sweep, const struct sample *res)
|
|
|
|
{
|
|
|
|
const size_t size = sizeof(struct sample)*N_CHAN*2;
|
|
|
|
|
|
|
|
print_sweep(sweep, res);
|
|
|
|
|
|
|
|
dumps = realloc(dumps, (n_dumps+1)*sizeof(struct sample *));
|
|
|
|
if (!dumps) {
|
|
|
|
perror("realloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
dumps[n_dumps] = malloc(size);
|
|
|
|
if (!dumps[n_dumps]) {
|
|
|
|
perror("malloc");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
memcpy(dumps[n_dumps], res, size);
|
|
|
|
n_dumps++;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void draw_dumps(SDL_Surface *s, int cont_tx)
|
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i != n_dumps; i++)
|
|
|
|
draw(s, dumps[i], cont_tx, DUMP_RGBA);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-04-13 14:54:26 +03:00
|
|
|
/* --- temporarily, for optimizing --- */
|
|
|
|
|
2011-04-14 02:40:26 +03:00
|
|
|
#if 0
|
|
|
|
|
2011-04-13 14:54:26 +03:00
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
|
|
|
|
|
|
static double t0;
|
|
|
|
|
|
|
|
|
|
|
|
static double t(void)
|
|
|
|
{
|
|
|
|
struct timeval tv;
|
|
|
|
|
|
|
|
gettimeofday(&tv, NULL);
|
|
|
|
return tv.tv_sec+tv.tv_usec/1000000.0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void tstart(void)
|
|
|
|
{
|
|
|
|
t0 = t();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void tstop(void)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "%.3f\n", t()-t0);
|
|
|
|
}
|
|
|
|
|
2011-04-14 02:40:26 +03:00
|
|
|
#else
|
|
|
|
|
|
|
|
static void tstart(void) {}
|
|
|
|
static void tstop(void) {}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2011-04-13 14:54:26 +03:00
|
|
|
|
2011-04-14 02:24:50 +03:00
|
|
|
int gui(const struct sweep *sweep, int sweeps)
|
2011-04-13 04:52:39 +03:00
|
|
|
{
|
|
|
|
SDL_Surface *surf;
|
|
|
|
SDL_Event event;
|
2011-04-14 01:34:00 +03:00
|
|
|
int cycle;
|
2011-04-14 02:24:50 +03:00
|
|
|
int fail = 0;
|
2011-04-13 04:52:39 +03:00
|
|
|
|
|
|
|
if (SDL_Init(SDL_INIT_VIDEO) < 0) {
|
|
|
|
fprintf(stderr, "SDL_init: %s\n", SDL_GetError());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
atexit(SDL_Quit);
|
|
|
|
|
|
|
|
surf = SDL_SetVideoMode(XRES, YRES, 0, SDL_SWSURFACE);
|
|
|
|
if (!surf) {
|
|
|
|
fprintf(stderr, "SDL_SetVideoMode: %s\n", SDL_GetError());
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2011-04-14 01:34:00 +03:00
|
|
|
for (cycle = 0; cycle != sweeps || !sweeps; cycle++) {
|
2011-04-13 04:52:39 +03:00
|
|
|
struct sample res[N_CHAN*2];
|
|
|
|
|
2011-04-14 02:24:50 +03:00
|
|
|
/*
|
|
|
|
* Pass/fail logic:
|
|
|
|
*
|
|
|
|
* Quit exit at any time, without making a pass/fail decision
|
|
|
|
* Pass exit if the current result is "pass"
|
|
|
|
* ignored if the current result is "over"/"under"
|
|
|
|
* Fail exit if the current result is "under"
|
|
|
|
* ignored if the current result is "pass"
|
|
|
|
* ignored if the current result is "over", because this
|
|
|
|
* indicates an invalid measurement, not a defective
|
|
|
|
* device
|
|
|
|
*/
|
|
|
|
|
2011-04-13 04:52:39 +03:00
|
|
|
while (SDL_PollEvent(&event))
|
2011-04-14 02:24:50 +03:00
|
|
|
switch (event.type) {
|
|
|
|
case SDL_KEYDOWN:
|
|
|
|
switch (event.key.keysym.sym) {
|
|
|
|
case SDLK_f:
|
|
|
|
if (cycle && fail < 0)
|
|
|
|
return -1;
|
|
|
|
break;
|
|
|
|
case SDLK_p:
|
|
|
|
if (cycle && !fail)
|
|
|
|
return 1;
|
|
|
|
break;
|
2011-05-28 18:03:23 +03:00
|
|
|
case SDLK_d:
|
|
|
|
if (cycle)
|
2011-05-28 18:21:56 +03:00
|
|
|
dump(sweep, res);
|
2011-05-28 18:03:23 +03:00
|
|
|
break;
|
2011-04-14 02:24:50 +03:00
|
|
|
case SDLK_q:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SDL_QUIT:
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-04-13 14:54:26 +03:00
|
|
|
tstart();
|
atrf-path: option -P to load a min/max profile; pass/fail indication in GUI
- sweep.h (MIN_DIFF, MAX_DIFF, struct sweep): added min/max profile
- sweep.h (do_sweep), atrf-path.c (do_half_sweep, do_sweep): compare
result against limits and return pass/fail decision
- sweep.h (N_CHAN), atrf-path.c (do_half_sweep, do_sweeps), gui.c
(N_CHAN): declare number of channels in one central place instead of
scattering it all around the program
- atrf-path.c (do_read_profile, read_profile, usage, main): new option -P
to read a min/max profile
- gui.c (indicate, main): moved indicator to separate function and
improved blink logic
- gui.c (OVER_RGBA, UNDER_RGBA, indicate, main): change color to indicate
pass/fail
2011-04-14 00:40:39 +03:00
|
|
|
fail = do_sweep(sweep, res);
|
2011-04-13 14:54:26 +03:00
|
|
|
tstop();
|
2011-04-13 04:52:39 +03:00
|
|
|
|
|
|
|
SDL_LockSurface(surf);
|
|
|
|
|
|
|
|
clear(surf);
|
2011-04-13 15:13:46 +03:00
|
|
|
|
2011-05-28 18:21:56 +03:00
|
|
|
draw_dumps(surf, sweep->cont_tx);
|
2011-04-14 01:08:23 +03:00
|
|
|
draw_limit(surf, sweep->min);
|
|
|
|
draw_limit(surf, sweep->max);
|
atrf-path: option -P to load a min/max profile; pass/fail indication in GUI
- sweep.h (MIN_DIFF, MAX_DIFF, struct sweep): added min/max profile
- sweep.h (do_sweep), atrf-path.c (do_half_sweep, do_sweep): compare
result against limits and return pass/fail decision
- sweep.h (N_CHAN), atrf-path.c (do_half_sweep, do_sweeps), gui.c
(N_CHAN): declare number of channels in one central place instead of
scattering it all around the program
- atrf-path.c (do_read_profile, read_profile, usage, main): new option -P
to read a min/max profile
- gui.c (indicate, main): moved indicator to separate function and
improved blink logic
- gui.c (OVER_RGBA, UNDER_RGBA, indicate, main): change color to indicate
pass/fail
2011-04-14 00:40:39 +03:00
|
|
|
indicate(surf, fail);
|
2011-05-28 18:21:56 +03:00
|
|
|
draw(surf, res, sweep->cont_tx, FG_RGBA);
|
2011-04-13 04:52:39 +03:00
|
|
|
|
|
|
|
SDL_UnlockSurface(surf);
|
|
|
|
SDL_UpdateRect(surf, 0, 0, 0, 0);
|
|
|
|
}
|
2011-04-14 02:24:50 +03:00
|
|
|
|
|
|
|
return 0;
|
2011-04-13 04:52:39 +03:00
|
|
|
}
|