Amit Arora | 39f2954 | 2010-09-14 12:03:22 +0530 | [diff] [blame] | 1 | /******************************************************************************* |
Amit Kucheria | c0e17fc | 2011-01-17 09:35:52 +0200 | [diff] [blame] | 2 | * Copyright (C) 2010, Linaro Limited. |
Amit Arora | 39f2954 | 2010-09-14 12:03:22 +0530 | [diff] [blame] | 3 | * |
| 4 | * This file is part of PowerDebug. |
| 5 | * |
| 6 | * All rights reserved. This program and the accompanying materials |
| 7 | * are made available under the terms of the Eclipse Public License v1.0 |
| 8 | * which accompanies this distribution, and is available at |
| 9 | * http://www.eclipse.org/legal/epl-v10.html |
| 10 | * |
| 11 | * Contributors: |
| 12 | * Amit Arora <amit.arora@linaro.org> (IBM Corporation) |
| 13 | * - initial API and implementation |
| 14 | *******************************************************************************/ |
| 15 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 16 | #include "powerdebug.h" |
Amit Arora | 1755278 | 2010-12-02 12:23:14 +0530 | [diff] [blame] | 17 | #include "regulator.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 Kucheria | b85e5d5 | 2011-01-12 10:55:24 -0600 | [diff] [blame] | 76 | init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 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 | |
Amit Arora | 83ae6cb | 2010-12-02 12:22:19 +0530 | [diff] [blame] | 99 | if (selectedwindow == CLOCK) |
| 100 | strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', " |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 101 | " '/', 'Esc' "); |
Amit Arora | 83ae6cb | 2010-12-02 12:22:19 +0530 | [diff] [blame] | 102 | else |
| 103 | strcpy(footer_items[2], " Other Keys: 'Left', 'Right' "); |
| 104 | |
| 105 | strcpy(footer_items[3], ""); |
| 106 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 107 | werase(stdscr); |
| 108 | refresh(); |
| 109 | |
| 110 | } |
| 111 | |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 112 | void create_selectedwindow(void) |
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 | WINDOW *win; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 115 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 116 | killall_windows(0); |
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 | getmaxyx(stdscr, maxy, maxx); |
Amit Arora | 24ed7d1 | 2010-09-14 12:12:58 +0530 | [diff] [blame] | 119 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 120 | win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 121 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 122 | switch (selectedwindow) { |
| 123 | case REGULATOR: regulator_win = win; |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 124 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 125 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 126 | case CLOCK: clock_win = win; |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 127 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 128 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 129 | case SENSOR: sensor_win = win; |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 130 | break; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 131 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 132 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 133 | selected_win = win; |
| 134 | |
| 135 | refresh(); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 136 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 137 | |
| 138 | void show_header(void) |
| 139 | { |
| 140 | int i, j = 0; |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 141 | int curr_pointer = 0; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 142 | |
| 143 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 144 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 145 | werase(header_win); |
| 146 | |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 147 | print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); |
| 148 | curr_pointer += 20; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 149 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 150 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 151 | if (selectedwindow == i) |
| 152 | wattron(header_win, A_REVERSE); |
| 153 | else |
| 154 | wattroff(header_win, A_REVERSE); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 155 | |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 156 | print(header_win, curr_pointer, 0, " %s ", win_names[i]); |
| 157 | curr_pointer += strlen(win_names[i]) + 2; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 158 | } |
| 159 | wrefresh(header_win); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 160 | werase(footer_win); |
| 161 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 162 | for (i = 0; i < NUM_FOOTER_ITEMS; i++) { |
| 163 | if (strlen(footer_items[i]) == 0) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 164 | continue; |
| 165 | wattron(footer_win, A_REVERSE); |
| 166 | print(footer_win, j, 0, "%s", footer_items[i]); |
| 167 | wattroff(footer_win, A_REVERSE); |
| 168 | j+= strlen(footer_items[i])+1; |
| 169 | } |
| 170 | wrefresh(footer_win); |
| 171 | } |
| 172 | |
| 173 | |
| 174 | void show_regulator_info(int verbose) |
| 175 | { |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 176 | int i, count = 1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 177 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 178 | (void)verbose; |
Amit Arora | bf50db9 | 2010-10-07 14:09:05 +0530 | [diff] [blame] | 179 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 180 | werase(regulator_win); |
| 181 | wattron(regulator_win, A_BOLD); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 182 | print(regulator_win, 0, 0, "Name"); |
| 183 | print(regulator_win, 12, 0, "Status"); |
| 184 | print(regulator_win, 24, 0, "State"); |
| 185 | print(regulator_win, 36, 0, "Type"); |
| 186 | print(regulator_win, 48, 0, "Users"); |
| 187 | print(regulator_win, 60, 0, "Microvolts"); |
| 188 | print(regulator_win, 72, 0, "Min u-volts"); |
| 189 | print(regulator_win, 84, 0, "Max u-volts"); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 190 | wattroff(regulator_win, A_BOLD); |
| 191 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 192 | for (i = 0; i < numregulators; i++) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 193 | int col = 0; |
| 194 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 195 | if ((i + 2) > (maxy-2)) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 196 | break; |
| 197 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 198 | if (regulators_info[i].num_users > 0) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 199 | wattron(regulator_win, WA_BOLD); |
| 200 | else |
| 201 | wattroff(regulator_win, WA_BOLD); |
| 202 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 203 | print(regulator_win, col, count, "%s", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 204 | regulators_info[i].name); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 205 | col += 12; |
| 206 | print(regulator_win, col, count, "%s", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 207 | regulators_info[i].status); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 208 | col += 12; |
| 209 | print(regulator_win, col, count, "%s", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 210 | regulators_info[i].state); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 211 | col += 12; |
| 212 | print(regulator_win, col, count, "%s", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 213 | regulators_info[i].type); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 214 | col += 12; |
| 215 | print(regulator_win, col, count, "%d", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 216 | regulators_info[i].num_users); |
Amit Arora | 6a943ec | 2010-10-07 11:49:25 +0530 | [diff] [blame] | 217 | col += 12; |
| 218 | print(regulator_win, col, count, "%d", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 219 | regulators_info[i].microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 220 | col += 12; |
| 221 | print(regulator_win, col, count, "%d", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 222 | regulators_info[i].min_microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 223 | col += 12; |
| 224 | print(regulator_win, col, count, "%d", |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 225 | regulators_info[i].max_microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 226 | |
| 227 | count++; |
| 228 | } |
| 229 | wrefresh(regulator_win); |
| 230 | } |
| 231 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 232 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 233 | void print_clock_header(void) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 234 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 235 | werase(clock_win); |
| 236 | wattron(clock_win, A_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 237 | print(clock_win, 0, 0, "Name"); |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 238 | print(clock_win, 54, 0, "Flags"); |
| 239 | print(clock_win, 64, 0, "Rate"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 240 | print(clock_win, 72, 0, "Usecount"); |
Amit Arora | 04f9774 | 2010-11-16 11:28:57 +0530 | [diff] [blame] | 241 | print(clock_win, 84, 0, "Children"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 242 | wattroff(clock_win, A_BOLD); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 243 | wrefresh(clock_win); |
| 244 | } |
| 245 | |
| 246 | void print_sensor_header(void) |
| 247 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 248 | werase(sensor_win); |
| 249 | wattron(sensor_win, A_BOLD); |
| 250 | print(sensor_win, 0, 0, "Name"); |
| 251 | print(sensor_win, 36, 0, "Temperature"); |
| 252 | wattroff(sensor_win, A_BOLD); |
| 253 | wattron(sensor_win, A_BLINK); |
| 254 | print(sensor_win, 0, 1, "Currently Sensor information available" |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 255 | " only in Dump mode!"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 256 | wattroff(sensor_win, A_BLINK); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 257 | wrefresh(sensor_win); |
| 258 | } |
| 259 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 260 | void print_one_clock(int line, char *str, int bold, int highlight) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 261 | { |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 262 | if (bold) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 263 | wattron(clock_win, WA_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 264 | if (highlight) |
| 265 | wattron(clock_win, WA_STANDOUT); |
| 266 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 267 | print(clock_win, 0, line + 1, "%s", str); |
| 268 | if (bold) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 269 | wattroff(clock_win, WA_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 270 | if (highlight) |
| 271 | wattroff(clock_win, WA_STANDOUT); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 272 | wrefresh(clock_win); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 273 | } |