blob: e67dc5e2e77cd999f90cb0b7f8b1fcd80cb8fc1c [file] [log] [blame]
Amit Arora39f29542010-09-14 12:03:22 +05301/*******************************************************************************
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 Arora47fd9182010-08-24 13:26:06 +053017#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
22static WINDOW *header_win;
23static WINDOW *regulator_win;
Amit Arora728e0c92010-09-14 12:06:09 +053024static WINDOW *clock_win;
25static WINDOW *sensor_win;
Amit Arorac93e0712010-10-07 13:51:53 +053026static WINDOW *selected_win;
Amit Arora47fd9182010-08-24 13:26:06 +053027static WINDOW *footer_win;
28
29int maxx, maxy;
30char footer_items[NUM_FOOTER_ITEMS][64];
31
32
33void fini_curses(void) {
34 endwin();
35}
36
Amit Arorac93e0712010-10-07 13:51:53 +053037/* "all" : Kill header and footer windows too ? */
38void killall_windows(int all)
Amit Arora47fd9182010-08-24 13:26:06 +053039{
Amit Arorac93e0712010-10-07 13:51:53 +053040 if (all && header_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053041 delwin(header_win);
42 header_win = NULL;
43 }
44 if (regulator_win) {
45 delwin(regulator_win);
46 regulator_win = NULL;
47 }
Amit Arora728e0c92010-09-14 12:06:09 +053048 if (clock_win) {
49 delwin(clock_win);
50 clock_win = NULL;
51 }
52 if (sensor_win) {
53 delwin(sensor_win);
54 sensor_win = NULL;
55 }
Amit Arorac93e0712010-10-07 13:51:53 +053056 if (all && footer_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053057 delwin(footer_win);
58 footer_win = NULL;
59 }
60}
61
62void init_curses(void)
63{
64 initscr();
65 start_color();
66 keypad(stdscr, TRUE);
67 noecho();
68 cbreak();
69 curs_set(0);
70 nonl();
71 use_default_colors();
72
73 init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
Amit Arora47fd9182010-08-24 13:26:06 +053074 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
Amit Arorac93e0712010-10-07 13:51:53 +053075 //init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
76 init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN);
Amit Arora47fd9182010-08-24 13:26:06 +053077 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
78 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
Amit Arora47fd9182010-08-24 13:26:06 +053079 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
Amit Arora728e0c92010-09-14 12:06:09 +053080 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE);
81 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
Amit Arora47fd9182010-08-24 13:26:06 +053082
83 atexit(fini_curses);
84}
85
86
87void create_windows(void)
88{
89
90 getmaxyx(stdscr, maxy, maxx);
Amit Arorac93e0712010-10-07 13:51:53 +053091 killall_windows(1);
Amit Arora47fd9182010-08-24 13:26:06 +053092
93 header_win = subwin(stdscr, 1, maxx, 0, 0);
Amit Arora728e0c92010-09-14 12:06:09 +053094// regulator_win = subwin(stdscr, maxy/2 - 2, maxx, 1, 0);
95// clock_win = subwin(stdscr, maxy/2 - 2, maxx, maxy/2, 0);
Amit Arora47fd9182010-08-24 13:26:06 +053096
97 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
98
99 strcpy(footer_items[0], " Q (Quit) ");
100 strcpy(footer_items[1], " R (Refresh) ");
101
102 werase(stdscr);
103 refresh();
104
105}
106
Amit Arorac93e0712010-10-07 13:51:53 +0530107void create_selectedwindow(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530108{
Amit Arorac93e0712010-10-07 13:51:53 +0530109 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530110
Amit Arorac93e0712010-10-07 13:51:53 +0530111 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530112
113 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530114
Amit Arorac93e0712010-10-07 13:51:53 +0530115 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530116
Amit Arorac93e0712010-10-07 13:51:53 +0530117 switch (selectedwindow) {
118 case REGULATOR: regulator_win = win;
119 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530120
Amit Arorac93e0712010-10-07 13:51:53 +0530121 case CLOCK: clock_win = win;
122 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530123
Amit Arorac93e0712010-10-07 13:51:53 +0530124 case SENSOR: sensor_win = win;
125 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530126 }
127
Amit Arorac93e0712010-10-07 13:51:53 +0530128 selected_win = win;
129
Amit Arora728e0c92010-09-14 12:06:09 +0530130 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530131}
Amit Arora47fd9182010-08-24 13:26:06 +0530132
133void show_header(void)
134{
135 int i, j = 0;
Amit Arorac93e0712010-10-07 13:51:53 +0530136 //char format[64];
Amit Arora47fd9182010-08-24 13:26:06 +0530137
138 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
139 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
140 werase(header_win);
141
Amit Arorac93e0712010-10-07 13:51:53 +0530142 print(header_win, 0, 0, "PowerDebug %s",
Amit Arora47fd9182010-08-24 13:26:06 +0530143 VERSION);
Amit Arorac93e0712010-10-07 13:51:53 +0530144 //print(header_win, 50, 0, "Refresh Rate %4.2f Secs", ticktime);
Amit Arora47fd9182010-08-24 13:26:06 +0530145
Amit Arorac93e0712010-10-07 13:51:53 +0530146 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
147 if (selectedwindow == i)
148 wattron(header_win, A_REVERSE);
149 else
150 wattroff(header_win, A_REVERSE);
151
152 //sprintf(format, " %%-%ds ", sizeof(win_names[i]) + 2);
153 //sprintf(format, " %%s ");
154
155 print(header_win, i*(maxx / TOTAL_FEATURE_WINS) + 20, 0,
156 " %s ", win_names[i]);
157 }
158 wrefresh(header_win);
159
Amit Arora47fd9182010-08-24 13:26:06 +0530160
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
175void show_regulator_info(int verbose)
176{
Amit Arorac93e0712010-10-07 13:51:53 +0530177 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530178
Amit Arorabf50db92010-10-07 14:09:05 +0530179 (void)verbose;
180
Amit Arora47fd9182010-08-24 13:26:06 +0530181 werase(regulator_win);
182 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530183 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 Arora47fd9182010-08-24 13:26:06 +0530191 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 Arorabf50db92010-10-07 14:09:05 +0530199 if(regulators_info[i].num_users > 0)
200 wattron(regulator_win, WA_BOLD);
201 else
202 wattroff(regulator_win, WA_BOLD);
203
Amit Arora47fd9182010-08-24 13:26:06 +0530204 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 Arora6a943ec2010-10-07 11:49:25 +0530217 regulators_info[i].num_users);
218 col += 12;
219 print(regulator_win, col, count, "%d",
Amit Arora47fd9182010-08-24 13:26:06 +0530220 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 Arora728e0c92010-09-14 12:06:09 +0530233
234void print_clock_header(int level)
235{
236 char lev[NAME_MAX];
237
238 sprintf(lev, "(Level %d)\n", level);
239 werase(clock_win);
240 wattron(clock_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530241 print(clock_win, 0, 0, "Name %s", lev);
242 print(clock_win, 48, 0, "Flags");
243 print(clock_win, 60, 0, "Rate");
244 print(clock_win, 72, 0, "Usecount");
Amit Arora728e0c92010-09-14 12:06:09 +0530245 wattroff(clock_win, A_BOLD);
246 wrefresh(clock_win);
247}
248
249void print_sensor_header(void)
250{
251 werase(sensor_win);
252 wattron(sensor_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530253 print(sensor_win, 0, 0, "Name");
254 print(sensor_win, 36, 0, "Temperature");
Amit Arora728e0c92010-09-14 12:06:09 +0530255 wattroff(sensor_win, A_BOLD);
256 wattron(sensor_win, A_BLINK);
Amit Arorac93e0712010-10-07 13:51:53 +0530257 print(sensor_win, 0, 1, "Currently Sensor information available"
Amit Arora728e0c92010-09-14 12:06:09 +0530258 " only in Dump mode!");
259 wattroff(sensor_win, A_BLINK);
260 wrefresh(sensor_win);
261}
262
263void print_clock_info_line(int line, char *clockname, int flags, int rate,
264 int usecount, int highlight)
265{
Amit Arora29cb7572010-10-05 17:40:29 +0530266 if (usecount)
267 wattron(clock_win, WA_BOLD);
268 else {
269 wattroff(clock_win, WA_BOLD);
Amit Arora24ed7d12010-09-14 12:12:58 +0530270 wattron(clock_win, WA_DIM);
Amit Arora29cb7572010-10-05 17:40:29 +0530271 }
272
273 if (highlight)
274 wattron(clock_win, WA_REVERSE);
275 else
276 wattroff(clock_win, WA_REVERSE);
Amit Arora24ed7d12010-09-14 12:12:58 +0530277
Amit Arorac93e0712010-10-07 13:51:53 +0530278 print(clock_win, 0, line + 1, "%s", clockname);
Amit Arora24ed7d12010-09-14 12:12:58 +0530279 if (strcmp(clockname, "..")) {
Amit Arorac93e0712010-10-07 13:51:53 +0530280 print(clock_win, 48, line + 1, "%d", flags);
281 print(clock_win, 60, line + 1, "%d", rate);
282 print(clock_win, 72, line + 1, "%d", usecount);
Amit Arora728e0c92010-09-14 12:06:09 +0530283 }
Amit Arora24ed7d12010-09-14 12:12:58 +0530284
285 if (highlight)
286 wattroff(clock_win, WA_BOLD|WA_STANDOUT);
287 else
288 wattroff(clock_win, WA_DIM);
289
Amit Arora728e0c92010-09-14 12:06:09 +0530290 wrefresh(clock_win);
291}