1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-12-22 23:54:16 +02:00

tools/atrf-rssi/: added menu for regulation area selection

- gui.c (area_off, gui): don't show a regulation area by default
- letter.h, letter.c: drawing of limited character set
- Makefile (OBJS_host, OBJS_ben_jlime): added letter.o
- gui.c (print, area_selector, gui): show regulation area selector
This commit is contained in:
Werner Almesberger 2011-06-24 22:29:17 -03:00
parent 9af0f937de
commit 5392401c0a
4 changed files with 144 additions and 4 deletions

View File

@ -18,11 +18,11 @@ 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 zgrid.o digit.o
OBJS_host = gui.o zgrid.o digit.o letter.o
CFLAGS_ben_jlime += $(shell sdl-config --cflags)
MACROS_ben_jlime += -DHAVE_GFX
LDLIBS_ben_jlime += -lSDL -lSDL_gfx
OBJS_ben_jlime = gui.o zgrid.o digit.o
OBJS_ben_jlime = gui.o zgrid.o digit.o letter.o
$(MAIN): $(OBJS_$(TARGET))

View File

@ -26,6 +26,7 @@
#include "zgrid.h"
#include "digit.h"
#include "letter.h"
#include "gui.h"
@ -42,6 +43,7 @@
#define FREQ_RGBA 0x20ff00ff /* frequency color */
#define WCHAN_RGBA 0xffff00e0 /* WLAN channel number color */
#define WLAN_RGBA 0x8080ffff /* WLAN channel occupancy color */
#define SEL_RGBA WLAN_RGBA /* WLAN area selector */
#define X_STEP 17 /* grid x step */
#define Y_STEP 2 /* grid y step */
@ -56,12 +58,16 @@
#define WLAN_XR (X_STEP*9.5/5)
#define WLAN_YH 6
#define X_SEL (XRES-20)
#define Y_SEL (YRES-50)
static enum {
area_off,
area_us,
area_eu,
area_jp,
} wlan_area = area_us;
} wlan_area = area_off;
static struct timeval t0;
@ -112,6 +118,8 @@ static void clear(SDL_Surface *s)
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
#define CSEL(pos) \
x-4+(pos)*5, x-1+(pos)*5, y+6, y+3, y, SEL_RGBA
static void label_channels(SDL_Surface *s, int sx, int x0, int y0)
@ -138,6 +146,47 @@ static void label_channels(SDL_Surface *s, int sx, int x0, int y0)
}
static void print(SDL_Surface *s, int x, int y, const char *t)
{
int i = 0;
while (*t) {
letter(s, *t, CSEL(i));
t++;
i++;
}
}
static void area_selector(SDL_Surface *s, int x0, int y0)
{
int x, y, r;
print(s, x0, y0, "EU");
print(s, x0, y0+9, "JP");
print(s, x0, y0+18, "US");
switch (wlan_area) {
case area_off:
return;
case area_eu:
y = 0;
break;
case area_jp:
y = 1;
break;
case area_us:
y = 2;
break;
default:
abort();
}
y = y0+9*y+3;
x = x0-8;
r = 6;
filledTrigonColor(s, x, y, x-r, y+r/2, x-r, y-r/2, SEL_RGBA);
}
static int wlan_channels(void)
{
switch (wlan_area) {
@ -257,7 +306,10 @@ 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);
area_selector(surf, X_SEL, Y_SEL);
if (wlan_area != area_off)
label_wlan_channels(surf, X_STEP, X_WLAN_OFFSET,
Y_WLAN_OFFSET);
SDL_UnlockSurface(surf);
SDL_UpdateRect(surf, 0, 0, 0, 0);

63
tools/atrf-rssi/letter.c Normal file
View File

@ -0,0 +1,63 @@
/*
* atrf-rssi/letter.c - Draw 7 segment style letters
*
* 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 <stdint.h>
#include "SDL.h"
#include "SDL_gfxPrimitives.h"
#include "letter.h"
static void hlines_3(SDL_Surface *s, int x0, int x1, int y0, int ym, int y1,
uint32_t fg)
{
hlineColor(s, x0, x1, y0, fg);
hlineColor(s, x0, x1, ym, fg);
hlineColor(s, x0, x1, y1, fg);
}
void letter(SDL_Surface *s, char c, int x0, int x1, int y0, int ym, int y1,
uint32_t fg)
{
switch (c) {
case 'E':
hlines_3(s, x0, x1, y0, ym, y1, fg);
vlineColor(s, x0, y0, y1, fg);
break;
case 'U':
vlineColor(s, x0, ym, y1, fg);
/* fall through */
case 'J':
hlineColor(s, x0, x1, y0, fg);
vlineColor(s, x1, y0, y1, fg);
vlineColor(s, x0, y0, ym, fg);
break;
case 'P':
hlineColor(s, x0, x1, y1, fg);
hlineColor(s, x0, x1, ym, fg);
vlineColor(s, x1, ym, y1, fg);
vlineColor(s, x0, y0, y1, fg);
break;
case 'S':
hlines_3(s, x0, x1, y0, ym, y1, fg);
vlineColor(s, x0, ym, y1, fg);
vlineColor(s, x1, y0, ym, fg);
break;
hlineColor(s, x0, x1, y0, fg);
vlineColor(s, x0, y0, y1, fg);
default:
abort();
}
}

25
tools/atrf-rssi/letter.h Normal file
View File

@ -0,0 +1,25 @@
/*
* atrf-rssi/letter.h - Draw 7 segment style letters
*
* 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 LETTER_H
#define LETTER_H
#include <stdint.h>
#include "SDL.h"
void letter(SDL_Surface *s, char c, int x0, int x1, int y0, int ym, int y1,
uint32_t fg);
#endif /* !LETTER_H */