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 | |
Daniel Lezcano | eeb1376 | 2011-03-26 22:06:17 +0100 | [diff] [blame] | 23 | enum { PT_COLOR_DEFAULT = 1, |
| 24 | PT_COLOR_HEADER_BAR, |
| 25 | PT_COLOR_ERROR, |
| 26 | PT_COLOR_RED, |
| 27 | PT_COLOR_YELLOW, |
| 28 | PT_COLOR_GREEN, |
| 29 | PT_COLOR_BRIGHT, |
| 30 | PT_COLOR_BLUE, |
| 31 | }; |
| 32 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 33 | static WINDOW *header_win; |
| 34 | static WINDOW *regulator_win; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 35 | static WINDOW *clock_win; |
| 36 | static WINDOW *sensor_win; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 37 | static WINDOW *footer_win; |
| 38 | |
| 39 | int maxx, maxy; |
Daniel Lezcano | 68500e8 | 2011-06-08 23:30:00 +0200 | [diff] [blame] | 40 | static char footer_items[NUM_FOOTER_ITEMS][64]; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 41 | |
Daniel Lezcano | d5a2c6d | 2011-03-23 14:37:38 +0100 | [diff] [blame] | 42 | static char *win_names[TOTAL_FEATURE_WINS] = { |
| 43 | "Clocks", |
| 44 | "Regulators", |
| 45 | "Sensors" |
| 46 | }; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 47 | |
Daniel Lezcano | 3abd8b1 | 2011-03-26 22:06:15 +0100 | [diff] [blame] | 48 | static void display_fini(void) |
| 49 | { |
| 50 | endwin(); |
| 51 | } |
| 52 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 53 | int display_init(void) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 54 | { |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 55 | if (!initscr()) |
| 56 | return -1; |
| 57 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 58 | start_color(); |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 59 | use_default_colors(); |
| 60 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 61 | keypad(stdscr, TRUE); |
| 62 | noecho(); |
| 63 | cbreak(); |
| 64 | curs_set(0); |
| 65 | nonl(); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 66 | |
Daniel Lezcano | ca17a72 | 2011-03-26 22:06:16 +0100 | [diff] [blame] | 67 | if (init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK) || |
| 68 | init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED) || |
| 69 | init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK) || |
| 70 | init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW) || |
| 71 | init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN) || |
| 72 | init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK) || |
| 73 | init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE) || |
| 74 | init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED)) |
| 75 | return -1; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 76 | |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame^] | 77 | if (atexit(display_fini)) |
| 78 | return -1; |
| 79 | |
| 80 | getmaxyx(stdscr, maxy, maxx); |
| 81 | |
| 82 | regulator_win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 83 | if (!regulator_win) |
| 84 | return -1; |
| 85 | |
| 86 | clock_win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 87 | if (!clock_win) |
| 88 | return -1; |
| 89 | |
| 90 | sensor_win = subwin(stdscr, maxy - 2, maxx, 1, 0); |
| 91 | if (!sensor_win) |
| 92 | return -1; |
| 93 | |
| 94 | header_win = subwin(stdscr, 1, maxx, 0, 0); |
| 95 | if (!header_win) |
| 96 | return -1; |
| 97 | |
| 98 | footer_win = subwin(stdscr, 1, maxx, maxy-1, 0); |
| 99 | if (!footer_win) |
| 100 | return -1; |
| 101 | |
| 102 | return 0; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 103 | } |
| 104 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 105 | void create_windows(int selectedwindow) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 106 | { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 107 | strcpy(footer_items[0], " Q (Quit) "); |
| 108 | strcpy(footer_items[1], " R (Refresh) "); |
| 109 | |
Amit Arora | 83ae6cb | 2010-12-02 12:22:19 +0530 | [diff] [blame] | 110 | if (selectedwindow == CLOCK) |
| 111 | strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', " |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 112 | " '/', 'Esc' "); |
Amit Arora | 83ae6cb | 2010-12-02 12:22:19 +0530 | [diff] [blame] | 113 | else |
| 114 | strcpy(footer_items[2], " Other Keys: 'Left', 'Right' "); |
| 115 | |
| 116 | strcpy(footer_items[3], ""); |
| 117 | |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 118 | werase(stdscr); |
| 119 | refresh(); |
| 120 | |
| 121 | } |
| 122 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 123 | void create_selectedwindow(int selectedwindow) |
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 | switch (selectedwindow) { |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame^] | 126 | case REGULATOR: |
| 127 | wrefresh(regulator_win); |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 128 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 129 | |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame^] | 130 | case CLOCK: |
| 131 | wrefresh(clock_win); |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 132 | break; |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 133 | |
Daniel Lezcano | 1c25df9 | 2011-06-08 23:30:00 +0200 | [diff] [blame^] | 134 | case SENSOR: |
| 135 | wrefresh(sensor_win); |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 136 | break; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 137 | } |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 138 | } |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 139 | |
Daniel Lezcano | 558a6d5 | 2011-03-23 14:37:41 +0100 | [diff] [blame] | 140 | void show_header(int selectedwindow) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 141 | { |
| 142 | int i, j = 0; |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 143 | int curr_pointer = 0; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 144 | |
| 145 | wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 146 | wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); |
| 147 | werase(header_win); |
| 148 | |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 149 | print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); |
| 150 | curr_pointer += 20; |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 151 | |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 152 | for (i = 0; i < TOTAL_FEATURE_WINS; i++) { |
| 153 | if (selectedwindow == i) |
| 154 | wattron(header_win, A_REVERSE); |
| 155 | else |
| 156 | wattroff(header_win, A_REVERSE); |
Amit Arora | c93e071 | 2010-10-07 13:51:53 +0530 | [diff] [blame] | 157 | |
Amit Kucheria | 0a4d019 | 2011-01-12 04:54:37 +0530 | [diff] [blame] | 158 | print(header_win, curr_pointer, 0, " %s ", win_names[i]); |
| 159 | curr_pointer += strlen(win_names[i]) + 2; |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 160 | } |
| 161 | wrefresh(header_win); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 162 | werase(footer_win); |
| 163 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 164 | for (i = 0; i < NUM_FOOTER_ITEMS; i++) { |
| 165 | if (strlen(footer_items[i]) == 0) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 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 | |
Daniel Lezcano | 833b63a | 2011-03-26 22:06:00 +0100 | [diff] [blame] | 176 | void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 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 | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 180 | (void)verbose; |
Amit Arora | bf50db9 | 2010-10-07 14:09:05 +0530 | [diff] [blame] | 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 | |
Daniel Lezcano | 833b63a | 2011-03-26 22:06:00 +0100 | [diff] [blame] | 194 | for (i = 0; i < nr_reg; i++) { |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 195 | int col = 0; |
| 196 | |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 197 | if ((i + 2) > (maxy-2)) |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 198 | break; |
| 199 | |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 200 | if (reg_info[i].num_users > 0) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 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", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 206 | reg_info[i].name); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 207 | col += 12; |
| 208 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 209 | reg_info[i].status); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 210 | col += 12; |
| 211 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 212 | reg_info[i].state); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 213 | col += 12; |
| 214 | print(regulator_win, col, count, "%s", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 215 | reg_info[i].type); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 216 | col += 12; |
| 217 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 218 | reg_info[i].num_users); |
Amit Arora | 6a943ec | 2010-10-07 11:49:25 +0530 | [diff] [blame] | 219 | col += 12; |
| 220 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 221 | reg_info[i].microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 222 | col += 12; |
| 223 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 224 | reg_info[i].min_microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 225 | col += 12; |
| 226 | print(regulator_win, col, count, "%d", |
Daniel Lezcano | 3bd64f0 | 2011-03-26 22:05:56 +0100 | [diff] [blame] | 227 | reg_info[i].max_microvolts); |
Amit Arora | 47fd918 | 2010-08-24 13:26:06 +0530 | [diff] [blame] | 228 | |
| 229 | count++; |
| 230 | } |
| 231 | wrefresh(regulator_win); |
| 232 | } |
| 233 | |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 234 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 235 | void print_clock_header(void) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 236 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 237 | werase(clock_win); |
| 238 | wattron(clock_win, A_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 239 | print(clock_win, 0, 0, "Name"); |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 240 | print(clock_win, 54, 0, "Flags"); |
| 241 | print(clock_win, 64, 0, "Rate"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 242 | print(clock_win, 72, 0, "Usecount"); |
Amit Arora | 04f9774 | 2010-11-16 11:28:57 +0530 | [diff] [blame] | 243 | print(clock_win, 84, 0, "Children"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 244 | wattroff(clock_win, A_BOLD); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 245 | wrefresh(clock_win); |
| 246 | } |
| 247 | |
| 248 | void print_sensor_header(void) |
| 249 | { |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 250 | werase(sensor_win); |
| 251 | wattron(sensor_win, A_BOLD); |
| 252 | print(sensor_win, 0, 0, "Name"); |
| 253 | print(sensor_win, 36, 0, "Temperature"); |
| 254 | wattroff(sensor_win, A_BOLD); |
| 255 | wattron(sensor_win, A_BLINK); |
| 256 | print(sensor_win, 0, 1, "Currently Sensor information available" |
Amit Kucheria | a0adae4 | 2011-01-12 10:54:23 -0600 | [diff] [blame] | 257 | " only in Dump mode!"); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 258 | wattroff(sensor_win, A_BLINK); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 259 | wrefresh(sensor_win); |
| 260 | } |
| 261 | |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 262 | void print_one_clock(int line, char *str, int bold, int highlight) |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 263 | { |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 264 | if (bold) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 265 | wattron(clock_win, WA_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 266 | if (highlight) |
| 267 | wattron(clock_win, WA_STANDOUT); |
| 268 | |
Amit Arora | 031263a | 2010-11-09 11:12:41 +0530 | [diff] [blame] | 269 | print(clock_win, 0, line + 1, "%s", str); |
| 270 | if (bold) |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 271 | wattroff(clock_win, WA_BOLD); |
Amit Arora | ac4e865 | 2010-11-09 11:16:53 +0530 | [diff] [blame] | 272 | if (highlight) |
| 273 | wattroff(clock_win, WA_STANDOUT); |
Amit Arora | 6e774cd | 2010-10-28 11:31:24 +0530 | [diff] [blame] | 274 | wrefresh(clock_win); |
Amit Arora | 728e0c9 | 2010-09-14 12:06:09 +0530 | [diff] [blame] | 275 | } |