diff options
Diffstat (limited to 'tools/thermal/tmon/tui.c')
-rw-r--r-- | tools/thermal/tmon/tui.c | 45 |
1 files changed, 36 insertions, 9 deletions
diff --git a/tools/thermal/tmon/tui.c b/tools/thermal/tmon/tui.c index 89f8ef0e15c8..b5d1c6b22dd3 100644 --- a/tools/thermal/tmon/tui.c +++ b/tools/thermal/tmon/tui.c | |||
@@ -30,6 +30,18 @@ | |||
30 | 30 | ||
31 | #include "tmon.h" | 31 | #include "tmon.h" |
32 | 32 | ||
33 | #define min(x, y) ({ \ | ||
34 | typeof(x) _min1 = (x); \ | ||
35 | typeof(y) _min2 = (y); \ | ||
36 | (void) (&_min1 == &_min2); \ | ||
37 | _min1 < _min2 ? _min1 : _min2; }) | ||
38 | |||
39 | #define max(x, y) ({ \ | ||
40 | typeof(x) _max1 = (x); \ | ||
41 | typeof(y) _max2 = (y); \ | ||
42 | (void) (&_max1 == &_max2); \ | ||
43 | _max1 > _max2 ? _max1 : _max2; }) | ||
44 | |||
33 | static PANEL *data_panel; | 45 | static PANEL *data_panel; |
34 | static PANEL *dialogue_panel; | 46 | static PANEL *dialogue_panel; |
35 | static PANEL *top; | 47 | static PANEL *top; |
@@ -98,6 +110,18 @@ void write_status_bar(int x, char *line) | |||
98 | wrefresh(status_bar_window); | 110 | wrefresh(status_bar_window); |
99 | } | 111 | } |
100 | 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 | |||
101 | void setup_windows(void) | 125 | void setup_windows(void) |
102 | { | 126 | { |
103 | int y_begin = 1; | 127 | int y_begin = 1; |
@@ -122,7 +146,7 @@ void setup_windows(void) | |||
122 | * 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 |
123 | */ | 147 | */ |
124 | 148 | ||
125 | dialogue_window = subwin(stdscr, ptdata.nr_cooling_dev+5, maxx-50, | 149 | dialogue_window = subwin(stdscr, diag_dev_rows() + 5, maxx-50, |
126 | DIAG_Y, DIAG_X); | 150 | DIAG_Y, DIAG_X); |
127 | 151 | ||
128 | thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor * | 152 | thermal_data_window = subwin(stdscr, ptdata.nr_tz_sensor * |
@@ -258,21 +282,26 @@ void show_cooling_device(void) | |||
258 | } | 282 | } |
259 | 283 | ||
260 | const char DIAG_TITLE[] = "[ TUNABLES ]"; | 284 | const char DIAG_TITLE[] = "[ TUNABLES ]"; |
261 | #define DIAG_DEV_ROWS 5 | ||
262 | void show_dialogue(void) | 285 | void show_dialogue(void) |
263 | { | 286 | { |
264 | int j, x = 0, y = 0; | 287 | int j, x = 0, y = 0; |
288 | int rows, cols; | ||
265 | WINDOW *w = dialogue_window; | 289 | WINDOW *w = dialogue_window; |
266 | 290 | ||
267 | if (tui_disabled || !w) | 291 | if (tui_disabled || !w) |
268 | return; | 292 | return; |
269 | 293 | ||
294 | getmaxyx(w, rows, cols); | ||
295 | |||
296 | /* Silence compiler 'unused' warnings */ | ||
297 | (void)cols; | ||
298 | |||
270 | werase(w); | 299 | werase(w); |
271 | box(w, 0, 0); | 300 | box(w, 0, 0); |
272 | mvwprintw(w, 0, maxx/4, DIAG_TITLE); | 301 | mvwprintw(w, 0, maxx/4, DIAG_TITLE); |
273 | /* list all the available tunables */ | 302 | /* list all the available tunables */ |
274 | for (j = 0; j <= ptdata.nr_cooling_dev; j++) { | 303 | for (j = 0; j <= ptdata.nr_cooling_dev; j++) { |
275 | y = j % DIAG_DEV_ROWS; | 304 | y = j % diag_dev_rows(); |
276 | if (y == 0 && j != 0) | 305 | if (y == 0 && j != 0) |
277 | x += 20; | 306 | x += 20; |
278 | if (j == ptdata.nr_cooling_dev) | 307 | if (j == ptdata.nr_cooling_dev) |
@@ -283,12 +312,10 @@ void show_dialogue(void) | |||
283 | ptdata.cdi[j].type, ptdata.cdi[j].instance); | 312 | ptdata.cdi[j].type, ptdata.cdi[j].instance); |
284 | } | 313 | } |
285 | wattron(w, A_BOLD); | 314 | wattron(w, A_BOLD); |
286 | mvwprintw(w, DIAG_DEV_ROWS+1, 1, "Enter Choice [A-Z]?"); | 315 | mvwprintw(w, diag_dev_rows()+1, 1, "Enter Choice [A-Z]?"); |
287 | wattroff(w, A_BOLD); | 316 | wattroff(w, A_BOLD); |
288 | /* y size of dialogue win is nr cdev + 5, so print legend | 317 | /* print legend at the bottom line */ |
289 | * at the bottom line | 318 | mvwprintw(w, rows - 2, 1, |
290 | */ | ||
291 | mvwprintw(w, ptdata.nr_cooling_dev+3, 1, | ||
292 | "Legend: A=Active, P=Passive, C=Critical"); | 319 | "Legend: A=Active, P=Passive, C=Critical"); |
293 | 320 | ||
294 | wrefresh(dialogue_window); | 321 | wrefresh(dialogue_window); |
@@ -437,7 +464,7 @@ static void handle_input_choice(int ch) | |||
437 | snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ", | 464 | snprintf(buf, sizeof(buf), "New Value for %.10s-%2d: ", |
438 | ptdata.cdi[cdev_id].type, | 465 | ptdata.cdi[cdev_id].type, |
439 | ptdata.cdi[cdev_id].instance); | 466 | ptdata.cdi[cdev_id].instance); |
440 | write_dialogue_win(buf, DIAG_DEV_ROWS+2, 2); | 467 | write_dialogue_win(buf, diag_dev_rows() + 2, 2); |
441 | handle_input_val(cdev_id); | 468 | handle_input_val(cdev_id); |
442 | } else { | 469 | } else { |
443 | snprintf(buf, sizeof(buf), "Invalid selection %d", ch); | 470 | snprintf(buf, sizeof(buf), "Invalid selection %d", ch); |