diff options
author | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-02-05 19:04:33 +0000 |
---|---|---|
committer | Jonathan McCrohan <jmccrohan@gmail.com> | 2012-02-05 19:04:33 +0000 |
commit | f3410da7f0bd208a5f2d792131b215454e782e93 (patch) | |
tree | 6e79c9acde383b91f5f21eb3a72f33e9c7fbbfce /lhist_scr.c | |
parent | 03dfbc2efa31d3c4fd7e576111883ea488e3e179 (diff) | |
download | wavemon-f3410da7f0bd208a5f2d792131b215454e782e93.tar.gz |
Imported Upstream version 0.7.3upstream/0.7.3
Diffstat (limited to 'lhist_scr.c')
-rw-r--r-- | lhist_scr.c | 58 |
1 files changed, 38 insertions, 20 deletions
diff --git a/lhist_scr.c b/lhist_scr.c index c09e48e..e93359f 100644 --- a/lhist_scr.c +++ b/lhist_scr.c @@ -19,8 +19,6 @@ */ #include "iw_if.h" -/* CONSTANTS */ - /* Number of lines in the key window at the bottom */ #define KEY_WIN_HEIGHT 3 @@ -34,6 +32,9 @@ */ #define HIST_MAXYLEN (HIST_WIN_HEIGHT - 1) +/* Position (relative to right border) and maximum length of dBm level tags. */ +#define LEVEL_TAG_POS 5 + /* GLOBALS */ static WINDOW *w_lhist, *w_key; @@ -160,6 +161,11 @@ static double hist_level(double val, int min, int max) return map_range(val, min, max, 1, HIST_MAXYLEN); } +static double hist_level_inverse(int y_level, int min, int max) +{ + return map_range(y_level, 1, HIST_MAXYLEN, min, max); +} + /* Order needs to be reversed as y-coordinates grow downwards */ static int hist_y(int yval) { @@ -239,6 +245,24 @@ static void display_lhist(void) noise_level = hist_level(iwl.noise, conf.noise_min, conf.noise_max); plot_colour = noise_level > snr_level ? CP_STATNOISE : CP_STATNOISE_S; hist_plot(noise_level, x, plot_colour); + + } else if (x == LEVEL_TAG_POS && ! (iwl.flags & IW_QUAL_LEVEL_INVALID)) { + char tmp[LEVEL_TAG_POS + 1]; + int len; + /* + * Tag the horizontal grid lines with dBm levels. + * This is only supported for signal levels, when the screen is not + * shared by several graphs (each having a different scale). + */ + wattrset(w_lhist, COLOR_PAIR(CP_STATSIG)); + for (y = 1; y <= HIST_MAXYLEN; y++) { + if (y != 1 && (y % 5) && y != HIST_MAXYLEN) + continue; + len = snprintf(tmp, sizeof(tmp), "%.0f", + hist_level_inverse(y, conf.sig_min, + conf.sig_max)); + mvwaddstr(w_lhist, hist_y(y), hist_x(len), tmp); + } } if (! (iwl.flags & IW_QUAL_LEVEL_INVALID)) { @@ -280,10 +304,11 @@ static void display_key(WINDOW *w_key) wrefresh(w_key); } -static void redraw_lhist(void) +static void redraw_lhist(int signum) { static int vcount = 1; + sampling_do_poll(); if (!--vcount) { vcount = conf.slotsize; display_lhist(); @@ -291,34 +316,27 @@ static void redraw_lhist(void) } } -enum wavemon_screen scr_lhist(WINDOW *w_menu) +void scr_lhist_init(void) { - int key = 0; - w_lhist = newwin_title(0, HIST_WIN_HEIGHT, "Level histogram", true); w_key = newwin_title(HIST_MAXYLEN + 1, KEY_WIN_HEIGHT, "Key", false); init_extrema(&e_signal); init_extrema(&e_noise); init_extrema(&e_snr); + sampling_init(redraw_lhist); display_key(w_key); +} - iw_stat_redraw = redraw_lhist; - while (key < KEY_F(1) || key > KEY_F(10)) { - while ((key = wgetch(w_menu)) <= 0) - usleep(5000); - - /* Keyboard shortcuts */ - if (key == 'q') - key = KEY_F(10); - else if (key == 'i') - key = KEY_F(1); - } - iw_stat_redraw = NULL; +int scr_lhist_loop(WINDOW *w_menu) +{ + return wgetch(w_menu); +} +void scr_lhist_fini(void) +{ + sampling_stop(); delwin(w_lhist); delwin(w_key); - - return key - KEY_F(1); } |