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