mirror of
git://projects.qi-hardware.com/ben-wpan.git
synced 2024-12-22 23:22:25 +02:00
tools/atrf-rssi/: added WLAN channel display (US, EU, and JP)
- gui.c (wlan_area): the currently displayed regulation domain - gui.c (wlan_channels): return the number of WLAN channels - gui.c (show_wlan_channel): determine whether the specified channel should be used in the currently displayed regulation domain - gui.c (label_wlan_channels): show WLAN channel numbers and their width - gui.c (gui): switch regulation domain with E (Europe), J (Japan), and U (US) - gui.c (gui): quit now only if Q is pressed instead of any key - gui.c (gui): call label_wlan_channels to display the WLAN channels
This commit is contained in:
parent
7c12bf02c1
commit
9af0f937de
@ -1,8 +1,8 @@
|
||||
/*
|
||||
* atrf-rssi/gui.c - Graphical output for atrf-rssi
|
||||
*
|
||||
* Written 2010 by Werner Almesberger
|
||||
* Copyright 2010 Werner Almesberger
|
||||
* Written 2010-2011 by Werner Almesberger
|
||||
* Copyright 2010-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
|
||||
@ -40,6 +40,8 @@
|
||||
#define BG_RGBA 0x00408080 /* grid background color */
|
||||
#define CHAN_RGBA 0xff4040ff /* channel number color */
|
||||
#define FREQ_RGBA 0x20ff00ff /* frequency color */
|
||||
#define WCHAN_RGBA 0xffff00e0 /* WLAN channel number color */
|
||||
#define WLAN_RGBA 0x8080ffff /* WLAN channel occupancy color */
|
||||
|
||||
#define X_STEP 17 /* grid x step */
|
||||
#define Y_STEP 2 /* grid y step */
|
||||
@ -48,6 +50,19 @@
|
||||
#define X_OFFSET 7 /* x coordinate of lower left grid corner */
|
||||
#define Y_OFFSET 40 /* y coordinate of lower left grid corner */
|
||||
|
||||
#define X_WLAN_OFFSET 31
|
||||
#define Y_WLAN_OFFSET 15
|
||||
|
||||
#define WLAN_XR (X_STEP*9.5/5)
|
||||
#define WLAN_YH 6
|
||||
|
||||
|
||||
static enum {
|
||||
area_us,
|
||||
area_eu,
|
||||
area_jp,
|
||||
} wlan_area = area_us;
|
||||
|
||||
|
||||
static struct timeval t0;
|
||||
|
||||
@ -95,6 +110,8 @@ static void clear(SDL_Surface *s)
|
||||
x-5+(pos)*6, x-1+(pos)*6, y+8, y+4, y, CHAN_RGBA
|
||||
#define CSMALL(pos) \
|
||||
x-7+(pos)*4, x-5+(pos)*4, y+15, y+13, y+11, FREQ_RGBA
|
||||
#define CWLAN(pos) \
|
||||
x-4+(pos)*5, x-1+(pos)*5, y+6, y+3, y, WCHAN_RGBA
|
||||
|
||||
|
||||
static void label_channels(SDL_Surface *s, int sx, int x0, int y0)
|
||||
@ -121,6 +138,66 @@ static void label_channels(SDL_Surface *s, int sx, int x0, int y0)
|
||||
}
|
||||
|
||||
|
||||
static int wlan_channels(void)
|
||||
{
|
||||
switch (wlan_area) {
|
||||
case area_us:
|
||||
return 11;
|
||||
case area_eu:
|
||||
return 13;
|
||||
case area_jp:
|
||||
return 14;
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static int show_wlan_channel(int c)
|
||||
{
|
||||
switch (wlan_area) {
|
||||
case area_jp:
|
||||
if (c == 14)
|
||||
return 1;
|
||||
/* fall through */
|
||||
case area_us:
|
||||
return !((c-1) % 5);
|
||||
case area_eu:
|
||||
return !((c-1) % 4);
|
||||
default:
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void label_wlan_channels(SDL_Surface *s, int sx, int x0, int y0)
|
||||
{
|
||||
int x, xb, y, i, c;
|
||||
|
||||
xb = x0;
|
||||
y = s->h-y0+4;
|
||||
for (i = 0; i != wlan_channels(); i++) {
|
||||
c = i+1;
|
||||
/* Japan special channel: 22 MHz from channel 13 */
|
||||
if (c == 14)
|
||||
xb += X_STEP*12/5-X_STEP;
|
||||
if (c > 9) {
|
||||
x = xb;
|
||||
digit(s, c/10, CWLAN(0));
|
||||
} else {
|
||||
x = xb-3;
|
||||
}
|
||||
digit(s, c % 10, CWLAN(1));
|
||||
if (show_wlan_channel(c)) {
|
||||
hlineColor(s, xb-WLAN_XR, xb+WLAN_XR, y-WLAN_YH,
|
||||
WLAN_RGBA);
|
||||
vlineColor(s, xb, y-2, y-WLAN_YH+1, WLAN_RGBA);
|
||||
}
|
||||
xb += sx;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void gui(struct atrf_dsc *dsc)
|
||||
{
|
||||
SDL_Surface *surf;
|
||||
@ -143,10 +220,31 @@ void gui(struct atrf_dsc *dsc)
|
||||
}
|
||||
|
||||
while (1) {
|
||||
while (SDL_PollEvent(&event))
|
||||
if (event.type == SDL_KEYDOWN ||
|
||||
event.type == SDL_QUIT)
|
||||
while (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_KEYDOWN:
|
||||
switch (event.key.keysym.sym) {
|
||||
case SDLK_j:
|
||||
wlan_area = area_jp;
|
||||
break;
|
||||
case SDLK_e:
|
||||
wlan_area = area_eu;
|
||||
break;
|
||||
case SDLK_u:
|
||||
wlan_area = area_us;
|
||||
break;
|
||||
case SDLK_q:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case SDL_QUIT:
|
||||
return;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
shift_grid(z, N_CHAN, N_TIME);
|
||||
sweep(dsc, z);
|
||||
@ -159,6 +257,7 @@ void gui(struct atrf_dsc *dsc)
|
||||
X_OFFSET, Y_OFFSET,
|
||||
FG_RGBA, BG_RGBA);
|
||||
label_channels(surf, X_STEP, X_OFFSET, Y_OFFSET);
|
||||
label_wlan_channels(surf, X_STEP, X_WLAN_OFFSET, Y_WLAN_OFFSET);
|
||||
|
||||
SDL_UnlockSurface(surf);
|
||||
SDL_UpdateRect(surf, 0, 0, 0, 0);
|
||||
|
Loading…
Reference in New Issue
Block a user