1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-07-01 04:43:15 +03:00

atrf-path: added basic graphical output

- gui.h, gui.c: plot sweep results with SDL_gfx
- Makefile: added target-specific variables for SDL and SDL_gfx
- atrf-path.c (main): invoke the GUI if the number of sweeps is zero
This commit is contained in:
Werner Almesberger 2011-04-12 22:52:39 -03:00
parent 2967f99966
commit 0a409103eb
4 changed files with 156 additions and 1 deletions

View File

@ -14,3 +14,15 @@
MAIN = atrf-path
include ../Makefile.common
CFLAGS_host += $(shell sdl-config --cflags)
MACROS_host += -DHAVE_GFX
LDLIBS_host += $(shell sdl-config --libs) -lSDL_gfx
OBJS_host = gui.o
CFLAGS_ben_jlime += $(shell sdl-config --cflags)
MACROS_ben_jlime += -DHAVE_GFX
LDLIBS_ben_jlime += -lSDL -lSDL_gfx
OBJS_ben_jlime = gui.o
$(MAIN): $(OBJS_$(TARGET))

View File

@ -21,6 +21,7 @@
#include "cwtest.h"
#include "atrf.h"
#include "gui.h"
#include "sweep.h"
@ -211,7 +212,10 @@ int main(int argc, char **argv)
return 1;
sweep.power = 15-power;
do_sweeps(&sweep, sweeps);
if (sweeps) /* @@@ hack */
do_sweeps(&sweep, sweeps);
else
gui(&sweep);
atrf_reg_write(sweep.tx, REG_TRX_STATE, TRX_CMD_TRX_OFF);
atrf_reg_write(sweep.rx, REG_TRX_STATE, TRX_CMD_TRX_OFF);

112
tools/atrf-path/gui.c Normal file
View File

@ -0,0 +1,112 @@
/*
* 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>
#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 N_CHAN 16
#define FG_RGBA 0xffffffff /* measurement color */
#define CHAN_STEP 20 /* 4 pixels/MHz */
#define SIDE_STEP 2
#define CHAN_X_OFFSET 10
#define Y_MIN -94
#define Y_MAX -10
static void segment(SDL_Surface *s, int *last_x, int *last_y, int x,
const struct sample *res, int have_last)
{
int y = YRES-(res->avg-Y_MIN)/(Y_MAX-Y_MIN)*YRES-1;
if (have_last) {
aalineColor(s, *last_x, *last_y, x, y, FG_RGBA);
}
*last_x = x;
*last_y = y;
}
static void draw(SDL_Surface *s, const struct sample *res)
{
int last_x, last_y;
int x, i;
x = CHAN_X_OFFSET;
for (i = 0; i != N_CHAN; i++) {
segment(s, &last_x, &last_y, x, res++, i);
x += 2*SIDE_STEP;
segment(s, &last_x, &last_y, x, res++, 1);
x += CHAN_STEP-2*SIDE_STEP;
}
}
static void clear(SDL_Surface *s)
{
SDL_FillRect(s, NULL, SDL_MapRGB(s->format, 0, 0, 0));
}
void gui(const struct sweep *sweep)
{
SDL_Surface *surf;
SDL_Event event;
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);
}
while (1) {
struct sample res[N_CHAN*2];
while (SDL_PollEvent(&event))
if (event.type == SDL_KEYDOWN ||
event.type == SDL_QUIT)
return;
do_sweep(sweep, res);
SDL_LockSurface(surf);
clear(surf);
draw(surf, res);
SDL_UnlockSurface(surf);
SDL_UpdateRect(surf, 0, 0, 0, 0);
}
}

27
tools/atrf-path/gui.h Normal file
View File

@ -0,0 +1,27 @@
/*
* atrf-path/gui.h - 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.
*/
#ifndef GUI_H
#define GUI_H
#include <stdlib.h>
#include "sweep.h"
#ifdef HAVE_GFX
void gui(const struct sweep *sweep);
#else
#define gui(sweep) abort()
#endif
#endif /* !GUI_H */