diff --git a/tools/atrf-rssi/Makefile b/tools/atrf-rssi/Makefile index b7d19c2..71c803d 100644 --- a/tools/atrf-rssi/Makefile +++ b/tools/atrf-rssi/Makefile @@ -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)) diff --git a/tools/atrf-rssi/gui.c b/tools/atrf-rssi/gui.c index 35047d9..2cc510f 100644 --- a/tools/atrf-rssi/gui.c +++ b/tools/atrf-rssi/gui.c @@ -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); diff --git a/tools/atrf-rssi/letter.c b/tools/atrf-rssi/letter.c new file mode 100644 index 0000000..8e470d4 --- /dev/null +++ b/tools/atrf-rssi/letter.c @@ -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 + +#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(); + } +} diff --git a/tools/atrf-rssi/letter.h b/tools/atrf-rssi/letter.h new file mode 100644 index 0000000..0b9848f --- /dev/null +++ b/tools/atrf-rssi/letter.h @@ -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 + +#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 */