Amit Arora | 39f2954 | 2010-09-14 12:03:22 +0530 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | * Copyright (C) 2010, Linaro |
| 3 | * Copyright (C) 2010, IBM Corporation |
| 4 | * |
| 5 | * This file is part of PowerDebug. |
| 6 | * |
| 7 | * All rights reserved. This program and the accompanying materials |
| 8 | * are made available under the terms of the Eclipse Public License v1.0 |
| 9 | * which accompanies this distribution, and is available at |
| 10 | * http://www.eclipse.org/legal/epl-v10.html |
| 11 | * |
| 12 | * Contributors: |
| 13 | * Amit Arora <amit.arora@linaro.org> (IBM Corporation) |
| 14 | * - initial API and implementation |
| 15 | *******************************************************************************/ |
| 16 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 17 | #include "powerdebug.h" |
| 18 | |
| 19 | #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0) |
| 20 | #define NUM_FOOTER_ITEMS 5 |
| 21 | |
| 22 | static WINDOW *header_win; |
| 23 | static WINDOW *regulator_win; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 24 | static WINDOW *clock_win; |
| 25 | static WINDOW *sensor_win; |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 26 | static WINDOW *selected_win; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 27 | static WINDOW *footer_win; |
| 28 | |
| 29 | int maxx, maxy; |
| 30 | char footer_items[NUM_FOOTER_ITEMS][64]; |
| 31 | |
| 32 | |
| 33 | void fini_curses(void) { |
| 34 | endwin(); |
| 35 | } |
| 36 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 37 | /* "all" : Kill header and footer windows too ? */ |
| 38 | void killall_windows(int all) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 39 | { |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 40 | if (all && header_win) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 41 | delwin(header_win); |
| 42 | header_win = NULL; |
| 43 | } |
| 44 | if (regulator_win) { |
| 45 | delwin(regulator_win); |
| 46 | regulator_win = NULL; |
| 47 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 48 | if (clock_win) { |
| 49 | delwin(clock_win); |
| 50 | clock_win = NULL; |
| 51 | } |
| 52 | if (sensor_win) { |
| 53 | delwin(sensor_win); |
| 54 | sensor_win = NULL; |
| 55 | } |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 56 | if (all && footer_win) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 57 | delwin(footer_win); |
| 58 | footer_win = NULL; |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | void init_curses(void) |
| 63 | { |
| 64 | initscr(); |
| 65 | start_color(); |
| 66 | keypad(stdscr, TRUE); |
| 67 | noecho(); |
| 68 | cbreak(); |
| 69 | curs_set(0); |
| 70 | nonl(); |
| 71 | use_default_colors(); |
| 72 | |
| 73 | init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 74 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 75 | //init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE); |
| 76 | init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 77 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW); |
| 78 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 79 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 80 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE); |
| 81 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 82 | |
| 83 | atexit(fini_curses); |
| 84 | } |
| 85 | |
| 86 | |
| 87 | void create_windows(void) |
| 88 | { |
| 89 | |
| 90 | getmaxyx(stdscr, maxy, maxx); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 91 | killall_windows(1); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 92 | |
| 93 | header_win = subwin(stdscr, 1, maxx, 0, 0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 94 | // regulator_win = subwin(stdscr, maxy/2 - 2, maxx, 1, 0); |
| 95 | // clock_win = subwin(stdscr, maxy/2 - 2, maxx, maxy/2, 0); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 96 | |
| 97 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 98 | |
| 99 | strcpy(footer_items[0], " Q (Quit) "); |
| 100 | strcpy(footer_items[1], " R (Refresh) "); |
| 101 | |
| 102 | werase(stdscr); |
| 103 | refresh(); |
| 104 | |
| 105 | } |
| 106 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 107 | void create_selectedwindow(void) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 108 | { |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 109 | WINDOW *win; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 110 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 111 | killall_windows(0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 112 | |
| 113 | getmaxyx(stdscr, maxy, maxx); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 114 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 115 | win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 116 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 117 | switch (selectedwindow) { |
| 118 | case REGULATOR: regulator_win = win; |
| 119 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 120 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 121 | case CLOCK: clock_win = win; |
| 122 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 123 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 124 | case SENSOR: sensor_win = win; |
| 125 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 126 | } |
| 127 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 128 | selected_win = win; |
| 129 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 130 | refresh(); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 131 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 132 | |
| 133 | void show_header(void) |
| 134 | { |
| 135 | int i, j = 0; |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 136 | //char format[64]; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 137 | |
| 138 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 139 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 140 | werase(header_win); |
| 141 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 142 | print(header_win, 0, 0, "PowerDebug %s", |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 143 | VERSION); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 144 | //print(header_win, 50, 0, "Refresh Rate %4.2f Secs", ticktime); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 145 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 146 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 147 | if (selectedwindow == i) |
| 148 | wattron(header_win, A_REVERSE); |
| 149 | else |
| 150 | wattroff(header_win, A_REVERSE); |
| 151 | |
| 152 | //sprintf(format, " %%-%ds ", sizeof(win_names[i]) + 2); |
| 153 | //sprintf(format, " %%s "); |
| 154 | |
| 155 | print(header_win, i*(maxx / TOTAL_FEATURE_WINS) + 20, 0, |
| 156 | " %s ", win_names[i]); |
| 157 | } |
| 158 | wrefresh(header_win); |
| 159 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 160 | |
| 161 | werase(footer_win); |
| 162 | |
| 163 | for (i=0; i<NUM_FOOTER_ITEMS; i++) { |
| 164 | if (strlen(footer_items[i])==0) |
| 165 | continue; |
| 166 | wattron(footer_win, A_REVERSE); |
| 167 | print(footer_win, j, 0, "%s", footer_items[i]); |
| 168 | wattroff(footer_win, A_REVERSE); |
| 169 | j+= strlen(footer_items[i])+1; |
| 170 | } |
| 171 | wrefresh(footer_win); |
| 172 | } |
| 173 | |
| 174 | |
| 175 | void show_regulator_info(int verbose) |
| 176 | { |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 177 | int i, count = 1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 178 | |
Amit Arora | bf50db9 | 2010-10-07 14:09:05 +0530 | [diff] [blame^] | 179 | (void)verbose; |
| 180 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 181 | werase(regulator_win); |
| 182 | wattron(regulator_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 183 | print(regulator_win, 0, 0, "Name"); |
| 184 | print(regulator_win, 12, 0, "Status"); |
| 185 | print(regulator_win, 24, 0, "State"); |
| 186 | print(regulator_win, 36, 0, "Type"); |
| 187 | print(regulator_win, 48, 0, "Users"); |
| 188 | print(regulator_win, 60, 0, "Microvolts"); |
| 189 | print(regulator_win, 72, 0, "Min u-volts"); |
| 190 | print(regulator_win, 84, 0, "Max u-volts"); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 191 | wattroff(regulator_win, A_BOLD); |
| 192 | |
| 193 | for (i=0; i<numregulators; i++) { |
| 194 | int col = 0; |
| 195 | |
| 196 | if((i + 2) > (maxy-2)) |
| 197 | break; |
| 198 | |
Amit Arora | bf50db9 | 2010-10-07 14:09:05 +0530 | [diff] [blame^] | 199 | if(regulators_info[i].num_users > 0) |
| 200 | wattron(regulator_win, WA_BOLD); |
| 201 | else |
| 202 | wattroff(regulator_win, WA_BOLD); |
| 203 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 204 | print(regulator_win, col, count, "%s", |
| 205 | regulators_info[i].name); |
| 206 | col += 12; |
| 207 | print(regulator_win, col, count, "%s", |
| 208 | regulators_info[i].status); |
| 209 | col += 12; |
| 210 | print(regulator_win, col, count, "%s", |
| 211 | regulators_info[i].state); |
| 212 | col += 12; |
| 213 | print(regulator_win, col, count, "%s", |
| 214 | regulators_info[i].type); |
| 215 | col += 12; |
| 216 | print(regulator_win, col, count, "%d", |
Amit Arora | 6a943ec | 2010-10-07 11:49:25 +0530 | [diff] [blame] | 217 | regulators_info[i].num_users); |
| 218 | col += 12; |
| 219 | print(regulator_win, col, count, "%d", |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 220 | regulators_info[i].microvolts); |
| 221 | col += 12; |
| 222 | print(regulator_win, col, count, "%d", |
| 223 | regulators_info[i].min_microvolts); |
| 224 | col += 12; |
| 225 | print(regulator_win, col, count, "%d", |
| 226 | regulators_info[i].max_microvolts); |
| 227 | |
| 228 | count++; |
| 229 | } |
| 230 | wrefresh(regulator_win); |
| 231 | } |
| 232 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 233 | |
| 234 | void print_clock_header(int level) |
| 235 | { |
| 236 | char lev[NAME_MAX]; |
| 237 | |
| 238 | sprintf(lev, "(Level %d)\n", level); |
| 239 | werase(clock_win); |
| 240 | wattron(clock_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 241 | print(clock_win, 0, 0, "Name %s", lev); |
| 242 | print(clock_win, 48, 0, "Flags"); |
| 243 | print(clock_win, 60, 0, "Rate"); |
| 244 | print(clock_win, 72, 0, "Usecount"); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 245 | wattroff(clock_win, A_BOLD); |
| 246 | wrefresh(clock_win); |
| 247 | } |
| 248 | |
| 249 | void print_sensor_header(void) |
| 250 | { |
| 251 | werase(sensor_win); |
| 252 | wattron(sensor_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 253 | print(sensor_win, 0, 0, "Name"); |
| 254 | print(sensor_win, 36, 0, "Temperature"); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 255 | wattroff(sensor_win, A_BOLD); |
| 256 | wattron(sensor_win, A_BLINK); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 257 | print(sensor_win, 0, 1, "Currently Sensor information available" |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 258 | " only in Dump mode!"); |
| 259 | wattroff(sensor_win, A_BLINK); |
| 260 | wrefresh(sensor_win); |
| 261 | } |
| 262 | |
| 263 | void print_clock_info_line(int line, char *clockname, int flags, int rate, |
| 264 | int usecount, int highlight) |
| 265 | { |
Amit Arora | 29cb757 | 2010-10-05 17:40:29 +0530 | [diff] [blame] | 266 | if (usecount) |
| 267 | wattron(clock_win, WA_BOLD); |
| 268 | else { |
| 269 | wattroff(clock_win, WA_BOLD); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 270 | wattron(clock_win, WA_DIM); |
Amit Arora | 29cb757 | 2010-10-05 17:40:29 +0530 | [diff] [blame] | 271 | } |
| 272 | |
| 273 | if (highlight) |
| 274 | wattron(clock_win, WA_REVERSE); |
| 275 | else |
| 276 | wattroff(clock_win, WA_REVERSE); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 277 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 278 | print(clock_win, 0, line + 1, "%s", clockname); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 279 | if (strcmp(clockname, "..")) { |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 280 | print(clock_win, 48, line + 1, "%d", flags); |
| 281 | print(clock_win, 60, line + 1, "%d", rate); |
| 282 | print(clock_win, 72, line + 1, "%d", usecount); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 283 | } |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 284 | |
| 285 | if (highlight) |
| 286 | wattroff(clock_win, WA_BOLD|WA_STANDOUT); |
| 287 | else |
| 288 | wattroff(clock_win, WA_DIM); |
| 289 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 290 | wrefresh(clock_win); |
| 291 | } |