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 | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 26 | static WINDOW *footer_win; |
| 27 | |
| 28 | int maxx, maxy; |
| 29 | char footer_items[NUM_FOOTER_ITEMS][64]; |
| 30 | |
| 31 | |
| 32 | void fini_curses(void) { |
| 33 | endwin(); |
| 34 | } |
| 35 | |
| 36 | void killall_windows(void) |
| 37 | { |
| 38 | if (header_win) { |
| 39 | delwin(header_win); |
| 40 | header_win = NULL; |
| 41 | } |
| 42 | if (regulator_win) { |
| 43 | delwin(regulator_win); |
| 44 | regulator_win = NULL; |
| 45 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 46 | if (clock_win) { |
| 47 | delwin(clock_win); |
| 48 | clock_win = NULL; |
| 49 | } |
| 50 | if (sensor_win) { |
| 51 | delwin(sensor_win); |
| 52 | sensor_win = NULL; |
| 53 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 54 | if (footer_win) { |
| 55 | delwin(footer_win); |
| 56 | footer_win = NULL; |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | void init_curses(void) |
| 61 | { |
| 62 | initscr(); |
| 63 | start_color(); |
| 64 | keypad(stdscr, TRUE); |
| 65 | noecho(); |
| 66 | cbreak(); |
| 67 | curs_set(0); |
| 68 | nonl(); |
| 69 | use_default_colors(); |
| 70 | |
| 71 | init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 72 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 73 | init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 74 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW); |
| 75 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 76 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 77 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE); |
| 78 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 79 | |
| 80 | atexit(fini_curses); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | void create_windows(void) |
| 85 | { |
| 86 | |
| 87 | getmaxyx(stdscr, maxy, maxx); |
| 88 | killall_windows(); |
| 89 | |
| 90 | header_win = subwin(stdscr, 1, maxx, 0, 0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 91 | // regulator_win = subwin(stdscr, maxy/2 - 2, maxx, 1, 0); |
| 92 | // clock_win = subwin(stdscr, maxy/2 - 2, maxx, maxy/2, 0); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 93 | |
| 94 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 95 | |
| 96 | strcpy(footer_items[0], " Q (Quit) "); |
| 97 | strcpy(footer_items[1], " R (Refresh) "); |
| 98 | |
| 99 | werase(stdscr); |
| 100 | refresh(); |
| 101 | |
| 102 | } |
| 103 | |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 104 | /* |
| 105 | * maxrows is the MAXIMUM number of rows we need for this window |
| 106 | * pshare is the minimum number of rows we should have for this (in %age) |
| 107 | * maxrows prevails in case of an argument ! |
| 108 | */ |
| 109 | int create_regulator_win(int row, int maxrows, int *pshare) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 110 | { |
| 111 | int numrows; |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 112 | int idealrows; // Based on pshare provided to us |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 113 | |
| 114 | if (regulator_win) { |
| 115 | delwin(regulator_win); |
| 116 | regulator_win = NULL; |
| 117 | } |
| 118 | |
| 119 | getmaxyx(stdscr, maxy, maxx); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 120 | |
| 121 | idealrows = ((maxy - 2) * (*pshare)) / 100; |
| 122 | if (maxrows < idealrows) { |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 123 | numrows = maxrows; |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 124 | *pshare = (numrows * 100) / maxy; |
| 125 | } else |
| 126 | numrows = idealrows; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 127 | regulator_win = subwin(stdscr, numrows, maxx, row, 0); |
| 128 | |
| 129 | refresh(); |
| 130 | |
| 131 | return numrows + row; |
| 132 | } |
| 133 | |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 134 | int create_clock_win(int row, int maxrows, int *pshare) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 135 | { |
| 136 | int numrows; |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 137 | int idealrows; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 138 | |
| 139 | if (clock_win) { |
| 140 | delwin(clock_win); |
| 141 | clock_win = NULL; |
| 142 | } |
| 143 | |
| 144 | getmaxyx(stdscr, maxy, maxx); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 145 | idealrows = ((maxy - 2) * (*pshare)) / 100; |
| 146 | |
| 147 | if (maxrows < idealrows) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 148 | numrows = maxrows; |
| 149 | else |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 150 | numrows = idealrows; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 151 | clock_win = subwin(stdscr, numrows, maxx, row, 0); |
| 152 | |
| 153 | refresh(); |
| 154 | |
| 155 | return numrows + row; |
| 156 | } |
| 157 | |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 158 | int create_sensor_win(int row, int maxrows, int *pshare) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 159 | { |
| 160 | int numrows; |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 161 | int idealrows; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 162 | |
| 163 | if (sensor_win) { |
| 164 | delwin(sensor_win); |
| 165 | sensor_win = NULL; |
| 166 | } |
| 167 | |
| 168 | getmaxyx(stdscr, maxy, maxx); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 169 | idealrows = ((maxy - 2) * (*pshare)) / 100; |
| 170 | |
| 171 | if (maxrows < idealrows) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 172 | numrows = maxrows; |
| 173 | else |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 174 | numrows = idealrows; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 175 | sensor_win = subwin(stdscr, numrows, maxx, row, 0); |
| 176 | |
| 177 | refresh(); |
| 178 | |
| 179 | return numrows + row; |
| 180 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 181 | |
| 182 | void show_header(void) |
| 183 | { |
| 184 | int i, j = 0; |
| 185 | |
| 186 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 187 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 188 | werase(header_win); |
| 189 | |
| 190 | print(header_win, 0, 0, "PowerDebug version %s (C) Linaro", |
| 191 | VERSION); |
| 192 | |
| 193 | wrefresh(header_win); |
| 194 | |
| 195 | werase(footer_win); |
| 196 | |
| 197 | for (i=0; i<NUM_FOOTER_ITEMS; i++) { |
| 198 | if (strlen(footer_items[i])==0) |
| 199 | continue; |
| 200 | wattron(footer_win, A_REVERSE); |
| 201 | print(footer_win, j, 0, "%s", footer_items[i]); |
| 202 | wattroff(footer_win, A_REVERSE); |
| 203 | j+= strlen(footer_items[i])+1; |
| 204 | } |
| 205 | wrefresh(footer_win); |
| 206 | } |
| 207 | |
| 208 | |
| 209 | void show_regulator_info(int verbose) |
| 210 | { |
| 211 | int i, count = 2; |
| 212 | |
| 213 | werase(regulator_win); |
| 214 | wattron(regulator_win, A_BOLD); |
| 215 | wattron(regulator_win, A_STANDOUT); |
| 216 | print(regulator_win, 0, 0, "Regulator Information"); |
| 217 | wattroff(regulator_win, A_STANDOUT); |
| 218 | print(regulator_win, 0, 1, "Name"); |
| 219 | print(regulator_win, 12, 1, "Status"); |
| 220 | print(regulator_win, 24, 1, "State"); |
| 221 | print(regulator_win, 36, 1, "Type"); |
| 222 | print(regulator_win, 48, 1, "Microvolts"); |
| 223 | print(regulator_win, 60, 1, "Min u-volts"); |
| 224 | print(regulator_win, 72, 1, "Max u-volts"); |
| 225 | wattroff(regulator_win, A_BOLD); |
| 226 | |
| 227 | for (i=0; i<numregulators; i++) { |
| 228 | int col = 0; |
| 229 | |
| 230 | if((i + 2) > (maxy-2)) |
| 231 | break; |
| 232 | |
| 233 | if(!verbose && !strncmp(regulators_info[i].state, "disabled", 8)) |
| 234 | continue; |
| 235 | |
| 236 | print(regulator_win, col, count, "%s", |
| 237 | regulators_info[i].name); |
| 238 | col += 12; |
| 239 | print(regulator_win, col, count, "%s", |
| 240 | regulators_info[i].status); |
| 241 | col += 12; |
| 242 | print(regulator_win, col, count, "%s", |
| 243 | regulators_info[i].state); |
| 244 | col += 12; |
| 245 | print(regulator_win, col, count, "%s", |
| 246 | regulators_info[i].type); |
| 247 | col += 12; |
| 248 | print(regulator_win, col, count, "%d", |
| 249 | regulators_info[i].microvolts); |
| 250 | col += 12; |
| 251 | print(regulator_win, col, count, "%d", |
| 252 | regulators_info[i].min_microvolts); |
| 253 | col += 12; |
| 254 | print(regulator_win, col, count, "%d", |
| 255 | regulators_info[i].max_microvolts); |
| 256 | |
| 257 | count++; |
| 258 | } |
| 259 | wrefresh(regulator_win); |
| 260 | } |
| 261 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 262 | |
| 263 | void print_clock_header(int level) |
| 264 | { |
| 265 | char lev[NAME_MAX]; |
| 266 | |
| 267 | sprintf(lev, "(Level %d)\n", level); |
| 268 | werase(clock_win); |
| 269 | wattron(clock_win, A_BOLD); |
| 270 | wattron(clock_win, A_STANDOUT); |
| 271 | print(clock_win, 0, 0, "Clock Information"); |
| 272 | wattroff(clock_win, A_STANDOUT); |
| 273 | print(clock_win, 0, 1, "Name"); |
| 274 | print(clock_win, 24, 1, "Flags"); |
| 275 | print(clock_win, 36, 1, "Rate"); |
| 276 | print(clock_win, 48, 1, "Usecount"); |
| 277 | print(clock_win, 60, 1, lev); |
| 278 | wattroff(clock_win, A_BOLD); |
| 279 | wrefresh(clock_win); |
| 280 | } |
| 281 | |
| 282 | void print_sensor_header(void) |
| 283 | { |
| 284 | werase(sensor_win); |
| 285 | wattron(sensor_win, A_BOLD); |
| 286 | wattron(sensor_win, A_STANDOUT); |
| 287 | print(sensor_win, 0, 0, "Sensor Information"); |
| 288 | wattroff(sensor_win, A_STANDOUT); |
| 289 | print(sensor_win, 0, 1, "Name"); |
| 290 | print(sensor_win, 36, 1, "Temperature"); |
| 291 | wattroff(sensor_win, A_BOLD); |
| 292 | wattron(sensor_win, A_BLINK); |
| 293 | print(sensor_win, 0, 2, "Currently Sensor information available" |
| 294 | " only in Dump mode!"); |
| 295 | wattroff(sensor_win, A_BLINK); |
| 296 | wrefresh(sensor_win); |
| 297 | } |
| 298 | |
| 299 | void print_clock_info_line(int line, char *clockname, int flags, int rate, |
| 300 | int usecount, int highlight) |
| 301 | { |
Amit Arora | 29cb757 | 2010-10-05 17:40:29 +0530 | [diff] [blame^] | 302 | if (usecount) |
| 303 | wattron(clock_win, WA_BOLD); |
| 304 | else { |
| 305 | wattroff(clock_win, WA_BOLD); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 306 | wattron(clock_win, WA_DIM); |
Amit Arora | 29cb757 | 2010-10-05 17:40:29 +0530 | [diff] [blame^] | 307 | } |
| 308 | |
| 309 | if (highlight) |
| 310 | wattron(clock_win, WA_REVERSE); |
| 311 | else |
| 312 | wattroff(clock_win, WA_REVERSE); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 313 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 314 | print(clock_win, 0, line + 2, "%s", clockname); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 315 | if (strcmp(clockname, "..")) { |
| 316 | print(clock_win, 24, line + 2, "%d", flags); |
| 317 | print(clock_win, 36, line + 2, "%d", rate); |
| 318 | print(clock_win, 48, line + 2, "%d", usecount); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 319 | } |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 320 | |
| 321 | if (highlight) |
| 322 | wattroff(clock_win, WA_BOLD|WA_STANDOUT); |
| 323 | else |
| 324 | wattroff(clock_win, WA_DIM); |
| 325 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 326 | wrefresh(clock_win); |
| 327 | } |