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 | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 18 | #include "regulator.h" |
Amit Arora | ed3e565 | 2010-10-27 12:02:53 +0530 | [diff] [blame] | 19 | #include "display.h" |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 20 | |
| 21 | #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0) |
| 22 | #define NUM_FOOTER_ITEMS 5 |
| 23 | |
| 24 | static WINDOW *header_win; |
| 25 | static WINDOW *regulator_win; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 26 | static WINDOW *clock_win; |
| 27 | static WINDOW *sensor_win; |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 28 | static WINDOW *selected_win; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 29 | static WINDOW *footer_win; |
| 30 | |
| 31 | int maxx, maxy; |
| 32 | char footer_items[NUM_FOOTER_ITEMS][64]; |
| 33 | |
| 34 | |
| 35 | void fini_curses(void) { |
| 36 | endwin(); |
| 37 | } |
| 38 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 39 | /* "all" : Kill header and footer windows too ? */ |
| 40 | void killall_windows(int all) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 41 | { |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 42 | if (all && header_win) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 43 | delwin(header_win); |
| 44 | header_win = NULL; |
| 45 | } |
| 46 | if (regulator_win) { |
| 47 | delwin(regulator_win); |
| 48 | regulator_win = NULL; |
| 49 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 50 | if (clock_win) { |
| 51 | delwin(clock_win); |
| 52 | clock_win = NULL; |
| 53 | } |
| 54 | if (sensor_win) { |
| 55 | delwin(sensor_win); |
| 56 | sensor_win = NULL; |
| 57 | } |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 58 | if (all && footer_win) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 59 | delwin(footer_win); |
| 60 | footer_win = NULL; |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | void init_curses(void) |
| 65 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 66 | initscr(); |
| 67 | start_color(); |
| 68 | keypad(stdscr, TRUE); |
| 69 | noecho(); |
| 70 | cbreak(); |
| 71 | curs_set(0); |
| 72 | nonl(); |
| 73 | use_default_colors(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 74 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 75 | init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK); |
| 76 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 77 | init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN); |
| 78 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW); |
| 79 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN); |
| 80 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK); |
| 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 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 84 | atexit(fini_curses); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 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 | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 95 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 96 | |
| 97 | strcpy(footer_items[0], " Q (Quit) "); |
| 98 | strcpy(footer_items[1], " R (Refresh) "); |
| 99 | |
Amit Arora | 83ae6cb | 2010-12-02 12:22:19 +0530 | [diff] [blame] | 100 | if (selectedwindow == CLOCK) |
| 101 | strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', " |
| 102 | " '/', 'Esc' "); |
| 103 | else |
| 104 | strcpy(footer_items[2], " Other Keys: 'Left', 'Right' "); |
| 105 | |
| 106 | strcpy(footer_items[3], ""); |
| 107 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 108 | werase(stdscr); |
| 109 | refresh(); |
| 110 | |
| 111 | } |
| 112 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 113 | void create_selectedwindow(void) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 114 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 115 | WINDOW *win; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 116 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 117 | killall_windows(0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 118 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 119 | getmaxyx(stdscr, maxy, maxx); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 120 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 121 | win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 122 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 123 | switch (selectedwindow) { |
| 124 | case REGULATOR: regulator_win = win; |
| 125 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 126 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 127 | case CLOCK: clock_win = win; |
| 128 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 129 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 130 | case SENSOR: sensor_win = win; |
| 131 | break; |
| 132 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 133 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 134 | selected_win = win; |
| 135 | |
| 136 | refresh(); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 137 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 138 | |
| 139 | void show_header(void) |
| 140 | { |
| 141 | int i, j = 0; |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame^] | 142 | int curr_pointer = 0; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 143 | |
| 144 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 145 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 146 | werase(header_win); |
| 147 | |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame^] | 148 | print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); |
| 149 | curr_pointer += 20; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 150 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 151 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 152 | if (selectedwindow == i) |
| 153 | wattron(header_win, A_REVERSE); |
| 154 | else |
| 155 | wattroff(header_win, A_REVERSE); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 156 | |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame^] | 157 | print(header_win, curr_pointer, 0, " %s ", win_names[i]); |
| 158 | curr_pointer += strlen(win_names[i]) + 2; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 159 | } |
| 160 | wrefresh(header_win); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 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 | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 179 | (void)verbose; |
Amit Arora | bf50db9 | 2010-10-07 14:09:05 +0530 | [diff] [blame] | 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) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 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 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 234 | void print_clock_header(void) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 235 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 236 | werase(clock_win); |
| 237 | wattron(clock_win, A_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 238 | print(clock_win, 0, 0, "Name"); |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 239 | print(clock_win, 54, 0, "Flags"); |
| 240 | print(clock_win, 64, 0, "Rate"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 241 | print(clock_win, 72, 0, "Usecount"); |
Amit Arora | 04f9774 | 2010-11-16 11:28:57 +0530 | [diff] [blame] | 242 | print(clock_win, 84, 0, "Children"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 243 | wattroff(clock_win, A_BOLD); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 244 | wrefresh(clock_win); |
| 245 | } |
| 246 | |
| 247 | void print_sensor_header(void) |
| 248 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 249 | werase(sensor_win); |
| 250 | wattron(sensor_win, A_BOLD); |
| 251 | print(sensor_win, 0, 0, "Name"); |
| 252 | print(sensor_win, 36, 0, "Temperature"); |
| 253 | wattroff(sensor_win, A_BOLD); |
| 254 | wattron(sensor_win, A_BLINK); |
| 255 | print(sensor_win, 0, 1, "Currently Sensor information available" |
| 256 | " only in Dump mode!"); |
| 257 | wattroff(sensor_win, A_BLINK); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 258 | wrefresh(sensor_win); |
| 259 | } |
| 260 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 261 | void print_one_clock(int line, char *str, int bold, int highlight) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 262 | { |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 263 | if (bold) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 264 | wattron(clock_win, WA_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 265 | if (highlight) |
| 266 | wattron(clock_win, WA_STANDOUT); |
| 267 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 268 | print(clock_win, 0, line + 1, "%s", str); |
| 269 | if (bold) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 270 | wattroff(clock_win, WA_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 271 | if (highlight) |
| 272 | wattroff(clock_win, WA_STANDOUT); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 273 | wrefresh(clock_win); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 274 | } |