diff options
author | Brian Norris <computersforpeace@gmail.com> | 2015-02-17 21:18:32 -0500 |
---|---|---|
committer | Zhang Rui <rui.zhang@intel.com> | 2015-02-28 00:52:47 -0500 |
commit | 3bbcc529ee7f1d5807f3fe84cfdbdd1599530ad0 (patch) | |
tree | 932cc06e37f926bdee56b47880f38ef1aa20ecca /tools | |
parent | 0e7b766dc0aeedd47c8264242e06f3a470f5d589 (diff) |
tools/thermal: tmon: fixup tui windowing calculations
The number of rows in the dialog vary according to the number of cooling
devices. However, some of the windowing computations were assuming a
fixed number of rows. This computation is OK when we have between 4 and
9 cooling devices (and they wrap to the next column), but with fewer
devices, we end up printing off the end of the window.
This unifies the row computation into a single function and uses that
throughout the TUI code. This also accounts for increasing the number of
rows when there are more than 9 total cooling devices.
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Acked-by: Jacob Pan <jacob.jun.pan@linux.intel.com>
Reviewed-by: Florian Fainelli <f.fainelli@gmail.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/thermal/tmon/tui.c | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/tools/thermal/tmon/tui.c b/tools/thermal/tmon/tui.c index 2779573a53cb..36e1f86c8452 100644 --- a/tools/thermal/tmon/tui.c +++ b/tools/thermal/tmon/tui.c | |||
@@ -110,6 +110,18 @@ void write_status_bar(int x, char *line) | |||
110 | wrefresh(status_bar_window); | 110 | wrefresh(status_bar_window); |
111 | } | 111 | } |
112 | 112 | ||
113 | /* wrap at 5 */ | ||
114 | #define DIAG_DEV_ROWS 5 | ||
115 | /* | ||
116 | * list cooling devices + "set temp" entry; wraps after 5 rows, if they fit | ||
117 | */ | ||
118 | static int diag_dev_rows(void) | ||
119 | { | ||
120 | int entries = ptdata.nr_cooling_dev + 1; | ||
121 | int rows = max(DIAG_DEV_ROWS, (entries + 1) / 2); | ||
122 | return min(rows, entries); | ||
123 | } | ||
124 | |||
113 | void setup_windows(void) | 125 | void setup_windows(void) |
114 | { | 126 | { |
115 | int y_begin = 1; | 127 | int y_begin = 1; |
@@ -134,7 +146,7 @@ void setup_windows(void) | |||
134 | * dialogue window is a pop-up, when needed it lays on top of cdev win | 146 | * dialogue window is a pop-up, when needed it lays on top of cdev win |
135 | */ | 147 | */ |
136 | 148 | ||
137 | dialogue_window = subwin(stdscr, ptdata.nr_cooling_dev+5, maxx-50, | 149 | dialogue_window = subwin(stdscr, diag_dev_rows() + 5, maxx-50, |
138 | DIAG_Y, DIAG_X); | 150 | DIAG_Y, DIAG_X); |
139 | 151 | ||
140 | thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor * | 152 | thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor * |
@@ -270,7 +282,6 @@ void show_cooling_device(void) | |||
270 | } | 282 | } |
271 | 283 | ||
272 | const char DIAG_TITLE[] = "[ TUNABLES ]"; | 284 | const char DIAG_TITLE[] = "[ TUNABLES ]"; |
273 | #define DIAG_DEV_ROWS 5 | ||
274 | void show_dialogue(void) | 285 | void show_dialogue(void) |
275 | { | 286 | { |
276 | int j, x = 0, y = 0; | 287 | int j, x = 0, y = 0; |
@@ -287,7 +298,7 @@ void show_dialogue(void) | |||
287 | mvwprintw(w, 0, maxx/4, DIAG_TITLE); | 298 | mvwprintw(w, 0, maxx/4, DIAG_TITLE); |
288 | /* list all the available tunables */ | 299 | /* list all the available tunables */ |
289 | for (j = 0; j <= ptdata.nr_cooling_dev; j++) { | 300 | for (j = 0; j <= ptdata.nr_cooling_dev; j++) { |
290 | y = j % DIAG_DEV_ROWS; | 301 | y = j % diag_dev_rows(); |
291 | if (y == 0 && j != 0) | 302 | if (y == 0 && j != 0) |
292 | x += 20; | 303 | x += 20; |
293 | if (j == ptdata.nr_cooling_dev) | 304 | if (j == ptdata.nr_cooling_dev) |
@@ -298,7 +309,7 @@ void show_dialogue(void) | |||
298 | ptdata.cdi[j].type, ptdata.cdi[j].instance); | 309 | ptdata.cdi[j].type, ptdata.cdi[j].instance); |
299 | } | 310 | } |
300 | wattron(w, A_BOLD); | 311 | wattron(w, A_BOLD); |
301 | mvwprintw(w, DIAG_DEV_ROWS+1, 1, "Enter Choice [A-Z]?"); | 312 | mvwprintw(w, diag_dev_rows()+1, 1, "Enter Choice [A-Z]?"); |
302 | wattroff(w, A_BOLD); | 313 | wattroff(w, A_BOLD); |
303 | /* print legend at the bottom line */ | 314 | /* print legend at the bottom line */ |
304 | mvwprintw(w, rows - 2, 1, | 315 | mvwprintw(w, rows - 2, 1, |
@@ -450,7 +461,7 @@ static void handle_input_choice(int ch) | |||
450 | snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ", | 461 | snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ", |
451 | ptdata.cdi[cdev_id].type, | 462 | ptdata.cdi[cdev_id].type, |
452 | ptdata.cdi[cdev_id].instance); | 463 | ptdata.cdi[cdev_id].instance); |
453 | write_dialogue_win(buf, DIAG_DEV_ROWS+2, 2); | 464 | write_dialogue_win(buf, diag_dev_rows() + 2, 2); |
454 | handle_input_val(cdev_id); | 465 | handle_input_val(cdev_id); |
455 | } else { | 466 | } else { |
456 | snprintf(buf, sizeof(buf), "Invalid selection %d", ch); | 467 | snprintf(buf, sizeof(buf), "Invalid selection %d", ch); |