blob: b39636746f9272407a4e2b7275866a3f0c495d12 [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"
Amit Aroraed3e5652010-10-27 12:02:53 +053018#include "display.h"
Amit Arora47fd9182010-08-24 13:26:06 +053019
20#define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0)
21#define NUM_FOOTER_ITEMS 5
22
23static WINDOW *header_win;
24static WINDOW *regulator_win;
Amit Arora728e0c92010-09-14 12:06:09 +053025static WINDOW *clock_win;
26static WINDOW *sensor_win;
Amit Arorac93e0712010-10-07 13:51:53 +053027static WINDOW *selected_win;
Amit Arora47fd9182010-08-24 13:26:06 +053028static WINDOW *footer_win;
29
30int maxx, maxy;
31char footer_items[NUM_FOOTER_ITEMS][64];
32
33
34void fini_curses(void) {
35 endwin();
36}
37
Amit Arorac93e0712010-10-07 13:51:53 +053038/* "all" : Kill header and footer windows too ? */
39void killall_windows(int all)
Amit Arora47fd9182010-08-24 13:26:06 +053040{
Amit Arorac93e0712010-10-07 13:51:53 +053041 if (all && header_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053042 delwin(header_win);
43 header_win = NULL;
44 }
45 if (regulator_win) {
46 delwin(regulator_win);
47 regulator_win = NULL;
48 }
Amit Arora728e0c92010-09-14 12:06:09 +053049 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 Arorac93e0712010-10-07 13:51:53 +053057 if (all && footer_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053058 delwin(footer_win);
59 footer_win = NULL;
60 }
61}
62
63void init_curses(void)
64{
65 initscr();
66 start_color();
67 keypad(stdscr, TRUE);
68 noecho();
69 cbreak();
70 curs_set(0);
71 nonl();
72 use_default_colors();
73
74 init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
Amit Arora47fd9182010-08-24 13:26:06 +053075 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
Amit Arorac93e0712010-10-07 13:51:53 +053076 //init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
77 init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN);
Amit Arora47fd9182010-08-24 13:26:06 +053078 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
79 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
Amit Arora47fd9182010-08-24 13:26:06 +053080 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
Amit Arora728e0c92010-09-14 12:06:09 +053081 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE);
82 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
Amit Arora47fd9182010-08-24 13:26:06 +053083
84 atexit(fini_curses);
85}
86
87
88void create_windows(void)
89{
90
91 getmaxyx(stdscr, maxy, maxx);
Amit Arorac93e0712010-10-07 13:51:53 +053092 killall_windows(1);
Amit Arora47fd9182010-08-24 13:26:06 +053093
94 header_win = subwin(stdscr, 1, maxx, 0, 0);
Amit Arora728e0c92010-09-14 12:06:09 +053095// regulator_win = subwin(stdscr, maxy/2 - 2, maxx, 1, 0);
96// clock_win = subwin(stdscr, maxy/2 - 2, maxx, maxy/2, 0);
Amit Arora47fd9182010-08-24 13:26:06 +053097
98 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
99
100 strcpy(footer_items[0], " Q (Quit) ");
101 strcpy(footer_items[1], " R (Refresh) ");
102
103 werase(stdscr);
104 refresh();
105
106}
107
Amit Arorac93e0712010-10-07 13:51:53 +0530108void create_selectedwindow(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530109{
Amit Arorac93e0712010-10-07 13:51:53 +0530110 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530111
Amit Arorac93e0712010-10-07 13:51:53 +0530112 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530113
114 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530115
Amit Arorac93e0712010-10-07 13:51:53 +0530116 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530117
Amit Arorac93e0712010-10-07 13:51:53 +0530118 switch (selectedwindow) {
119 case REGULATOR: regulator_win = win;
120 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530121
Amit Arorac93e0712010-10-07 13:51:53 +0530122 case CLOCK: clock_win = win;
123 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530124
Amit Arorac93e0712010-10-07 13:51:53 +0530125 case SENSOR: sensor_win = win;
126 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530127 }
128
Amit Arorac93e0712010-10-07 13:51:53 +0530129 selected_win = win;
130
Amit Arora728e0c92010-09-14 12:06:09 +0530131 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530132}
Amit Arora47fd9182010-08-24 13:26:06 +0530133
134void show_header(void)
135{
136 int i, j = 0;
Amit Arorac93e0712010-10-07 13:51:53 +0530137 //char format[64];
Amit Arora47fd9182010-08-24 13:26:06 +0530138
139 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
140 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
141 werase(header_win);
142
Amit Arorac93e0712010-10-07 13:51:53 +0530143 print(header_win, 0, 0, "PowerDebug %s",
Amit Arora47fd9182010-08-24 13:26:06 +0530144 VERSION);
Amit Arorac93e0712010-10-07 13:51:53 +0530145 //print(header_win, 50, 0, "Refresh Rate %4.2f Secs", ticktime);
Amit Arora47fd9182010-08-24 13:26:06 +0530146
Amit Arorac93e0712010-10-07 13:51:53 +0530147 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
148 if (selectedwindow == i)
149 wattron(header_win, A_REVERSE);
150 else
151 wattroff(header_win, A_REVERSE);
152
153 //sprintf(format, " %%-%ds ", sizeof(win_names[i]) + 2);
154 //sprintf(format, " %%s ");
155
156 print(header_win, i*(maxx / TOTAL_FEATURE_WINS) + 20, 0,
157 " %s ", win_names[i]);
158 }
159 wrefresh(header_win);
160
Amit Arora47fd9182010-08-24 13:26:06 +0530161
162 werase(footer_win);
163
164 for (i=0; i<NUM_FOOTER_ITEMS; i++) {
165 if (strlen(footer_items[i])==0)
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
176void show_regulator_info(int verbose)
177{
Amit Arorac93e0712010-10-07 13:51:53 +0530178 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530179
Amit Arorabf50db92010-10-07 14:09:05 +0530180 (void)verbose;
181
Amit Arora47fd9182010-08-24 13:26:06 +0530182 werase(regulator_win);
183 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530184 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 Arora47fd9182010-08-24 13:26:06 +0530192 wattroff(regulator_win, A_BOLD);
193
194 for (i=0; i<numregulators; i++) {
195 int col = 0;
196
197 if((i + 2) > (maxy-2))
198 break;
199
Amit Arorabf50db92010-10-07 14:09:05 +0530200 if(regulators_info[i].num_users > 0)
201 wattron(regulator_win, WA_BOLD);
202 else
203 wattroff(regulator_win, WA_BOLD);
204
Amit Arora47fd9182010-08-24 13:26:06 +0530205 print(regulator_win, col, count, "%s",
206 regulators_info[i].name);
207 col += 12;
208 print(regulator_win, col, count, "%s",
209 regulators_info[i].status);
210 col += 12;
211 print(regulator_win, col, count, "%s",
212 regulators_info[i].state);
213 col += 12;
214 print(regulator_win, col, count, "%s",
215 regulators_info[i].type);
216 col += 12;
217 print(regulator_win, col, count, "%d",
Amit Arora6a943ec2010-10-07 11:49:25 +0530218 regulators_info[i].num_users);
219 col += 12;
220 print(regulator_win, col, count, "%d",
Amit Arora47fd9182010-08-24 13:26:06 +0530221 regulators_info[i].microvolts);
222 col += 12;
223 print(regulator_win, col, count, "%d",
224 regulators_info[i].min_microvolts);
225 col += 12;
226 print(regulator_win, col, count, "%d",
227 regulators_info[i].max_microvolts);
228
229 count++;
230 }
231 wrefresh(regulator_win);
232}
233
Amit Arora728e0c92010-09-14 12:06:09 +0530234
235void print_clock_header(int level)
236{
237 char lev[NAME_MAX];
238
239 sprintf(lev, "(Level %d)\n", level);
240 werase(clock_win);
241 wattron(clock_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530242 print(clock_win, 0, 0, "Name %s", lev);
243 print(clock_win, 48, 0, "Flags");
244 print(clock_win, 60, 0, "Rate");
245 print(clock_win, 72, 0, "Usecount");
Amit Arora728e0c92010-09-14 12:06:09 +0530246 wattroff(clock_win, A_BOLD);
247 wrefresh(clock_win);
248}
249
250void print_sensor_header(void)
251{
252 werase(sensor_win);
253 wattron(sensor_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530254 print(sensor_win, 0, 0, "Name");
255 print(sensor_win, 36, 0, "Temperature");
Amit Arora728e0c92010-09-14 12:06:09 +0530256 wattroff(sensor_win, A_BOLD);
257 wattron(sensor_win, A_BLINK);
Amit Arorac93e0712010-10-07 13:51:53 +0530258 print(sensor_win, 0, 1, "Currently Sensor information available"
Amit Arora728e0c92010-09-14 12:06:09 +0530259 " only in Dump mode!");
260 wattroff(sensor_win, A_BLINK);
261 wrefresh(sensor_win);
262}
263
264void print_clock_info_line(int line, char *clockname, int flags, int rate,
265 int usecount, int highlight)
266{
Amit Arora29cb7572010-10-05 17:40:29 +0530267 if (usecount)
268 wattron(clock_win, WA_BOLD);
269 else {
270 wattroff(clock_win, WA_BOLD);
Amit Arora24ed7d12010-09-14 12:12:58 +0530271 wattron(clock_win, WA_DIM);
Amit Arora29cb7572010-10-05 17:40:29 +0530272 }
273
274 if (highlight)
275 wattron(clock_win, WA_REVERSE);
276 else
277 wattroff(clock_win, WA_REVERSE);
Amit Arora24ed7d12010-09-14 12:12:58 +0530278
Amit Arorac93e0712010-10-07 13:51:53 +0530279 print(clock_win, 0, line + 1, "%s", clockname);
Amit Arora24ed7d12010-09-14 12:12:58 +0530280 if (strcmp(clockname, "..")) {
Amit Arora67b03312010-10-07 14:09:17 +0530281 double drate = 0.0;
282 char unit[8];
283
Amit Arorac93e0712010-10-07 13:51:53 +0530284 print(clock_win, 48, line + 1, "%d", flags);
Amit Arora67b03312010-10-07 14:09:17 +0530285 if (rate > 1000 && rate < 1000000) {
286 drate = (double)rate/1000.0;
287 strcpy(unit, "KHz");
288 } else if (rate > 1000000) {
289 drate = (double)rate/1000000.0;
290 strcpy(unit, "MHz");
291 } else {
292 drate = (double)rate;
293 strcpy(unit, " Hz");
294 }
295 print(clock_win, 60, line + 1, "%6.2f %s", drate, unit);
Amit Arorac93e0712010-10-07 13:51:53 +0530296 print(clock_win, 72, line + 1, "%d", usecount);
Amit Arora728e0c92010-09-14 12:06:09 +0530297 }
Amit Arora24ed7d12010-09-14 12:12:58 +0530298
299 if (highlight)
300 wattroff(clock_win, WA_BOLD|WA_STANDOUT);
301 else
302 wattroff(clock_win, WA_DIM);
303
Amit Arora728e0c92010-09-14 12:06:09 +0530304 wrefresh(clock_win);
305}