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 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 65 | initscr(); |
| 66 | start_color(); |
| 67 | keypad(stdscr, TRUE); |
| 68 | noecho(); |
| 69 | cbreak(); |
| 70 | curs_set(0); |
| 71 | nonl(); |
| 72 | use_default_colors(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 73 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 74 | init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK); |
| 75 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 76 | init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN); |
| 77 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW); |
| 78 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN); |
| 79 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK); |
| 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 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 83 | atexit(fini_curses); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 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 | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 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 | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 104 | void create_selectedwindow(void) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 105 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 106 | WINDOW *win; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 107 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 108 | killall_windows(0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 109 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 110 | getmaxyx(stdscr, maxy, maxx); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 111 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 112 | win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 113 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 114 | switch (selectedwindow) { |
| 115 | case REGULATOR: regulator_win = win; |
| 116 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 117 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 118 | case CLOCK: clock_win = win; |
| 119 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 120 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 121 | case SENSOR: sensor_win = win; |
| 122 | break; |
| 123 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 124 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 125 | selected_win = win; |
| 126 | |
| 127 | refresh(); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 128 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 129 | |
| 130 | void show_header(void) |
| 131 | { |
| 132 | int i, j = 0; |
| 133 | |
| 134 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 135 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 136 | werase(header_win); |
| 137 | |
Amit Arora | 97006e5 | 2010-10-28 11:56:08 +0530 | [diff] [blame] | 138 | print(header_win, 0, 0, "PowerDebug %s", VERSION); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 139 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 140 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 141 | if (selectedwindow == i) |
| 142 | wattron(header_win, A_REVERSE); |
| 143 | else |
| 144 | wattroff(header_win, A_REVERSE); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 145 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 146 | print(header_win, i*(maxx / TOTAL_FEATURE_WINS) + 20, 0, |
| 147 | " %s ", win_names[i]); |
| 148 | } |
| 149 | wrefresh(header_win); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 150 | werase(footer_win); |
| 151 | |
| 152 | for (i=0; i<NUM_FOOTER_ITEMS; i++) { |
| 153 | if (strlen(footer_items[i])==0) |
| 154 | continue; |
| 155 | wattron(footer_win, A_REVERSE); |
| 156 | print(footer_win, j, 0, "%s", footer_items[i]); |
| 157 | wattroff(footer_win, A_REVERSE); |
| 158 | j+= strlen(footer_items[i])+1; |
| 159 | } |
| 160 | wrefresh(footer_win); |
| 161 | } |
| 162 | |
| 163 | |
| 164 | void show_regulator_info(int verbose) |
| 165 | { |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 166 | int i, count = 1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 167 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 168 | (void)verbose; |
Amit Arora | bf50db9 | 2010-10-07 14:09:05 +0530 | [diff] [blame] | 169 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 170 | werase(regulator_win); |
| 171 | wattron(regulator_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 172 | print(regulator_win, 0, 0, "Name"); |
| 173 | print(regulator_win, 12, 0, "Status"); |
| 174 | print(regulator_win, 24, 0, "State"); |
| 175 | print(regulator_win, 36, 0, "Type"); |
| 176 | print(regulator_win, 48, 0, "Users"); |
| 177 | print(regulator_win, 60, 0, "Microvolts"); |
| 178 | print(regulator_win, 72, 0, "Min u-volts"); |
| 179 | print(regulator_win, 84, 0, "Max u-volts"); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 180 | wattroff(regulator_win, A_BOLD); |
| 181 | |
| 182 | for (i=0; i<numregulators; i++) { |
| 183 | int col = 0; |
| 184 | |
| 185 | if((i + 2) > (maxy-2)) |
| 186 | break; |
| 187 | |
Amit Arora | bf50db9 | 2010-10-07 14:09:05 +0530 | [diff] [blame] | 188 | if(regulators_info[i].num_users > 0) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 189 | wattron(regulator_win, WA_BOLD); |
| 190 | else |
| 191 | wattroff(regulator_win, WA_BOLD); |
| 192 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 193 | print(regulator_win, col, count, "%s", |
| 194 | regulators_info[i].name); |
| 195 | col += 12; |
| 196 | print(regulator_win, col, count, "%s", |
| 197 | regulators_info[i].status); |
| 198 | col += 12; |
| 199 | print(regulator_win, col, count, "%s", |
| 200 | regulators_info[i].state); |
| 201 | col += 12; |
| 202 | print(regulator_win, col, count, "%s", |
| 203 | regulators_info[i].type); |
| 204 | col += 12; |
| 205 | print(regulator_win, col, count, "%d", |
Amit Arora | 6a943ec | 2010-10-07 11:49:25 +0530 | [diff] [blame] | 206 | regulators_info[i].num_users); |
| 207 | col += 12; |
| 208 | print(regulator_win, col, count, "%d", |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 209 | regulators_info[i].microvolts); |
| 210 | col += 12; |
| 211 | print(regulator_win, col, count, "%d", |
| 212 | regulators_info[i].min_microvolts); |
| 213 | col += 12; |
| 214 | print(regulator_win, col, count, "%d", |
| 215 | regulators_info[i].max_microvolts); |
| 216 | |
| 217 | count++; |
| 218 | } |
| 219 | wrefresh(regulator_win); |
| 220 | } |
| 221 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 222 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame^] | 223 | void print_clock_header(void) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 224 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 225 | werase(clock_win); |
| 226 | wattron(clock_win, A_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame^] | 227 | print(clock_win, 0, 0, "Name"); |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 228 | print(clock_win, 54, 0, "Flags"); |
| 229 | print(clock_win, 64, 0, "Rate"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 230 | print(clock_win, 72, 0, "Usecount"); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame^] | 231 | print(clock_win, 84, 0, "ChildCount"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 232 | wattroff(clock_win, A_BOLD); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 233 | wrefresh(clock_win); |
| 234 | } |
| 235 | |
| 236 | void print_sensor_header(void) |
| 237 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 238 | werase(sensor_win); |
| 239 | wattron(sensor_win, A_BOLD); |
| 240 | print(sensor_win, 0, 0, "Name"); |
| 241 | print(sensor_win, 36, 0, "Temperature"); |
| 242 | wattroff(sensor_win, A_BOLD); |
| 243 | wattron(sensor_win, A_BLINK); |
| 244 | print(sensor_win, 0, 1, "Currently Sensor information available" |
| 245 | " only in Dump mode!"); |
| 246 | wattroff(sensor_win, A_BLINK); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 247 | wrefresh(sensor_win); |
| 248 | } |
| 249 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame^] | 250 | void print_one_clock(int line, char *str, int bold, int highlight) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 251 | { |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 252 | if (bold) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 253 | wattron(clock_win, WA_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame^] | 254 | if (highlight) |
| 255 | wattron(clock_win, WA_STANDOUT); |
| 256 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 257 | print(clock_win, 0, line + 1, "%s", str); |
| 258 | if (bold) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 259 | wattroff(clock_win, WA_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame^] | 260 | if (highlight) |
| 261 | wattroff(clock_win, WA_STANDOUT); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 262 | wrefresh(clock_win); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 263 | } |