blob: 5ace63956c3fc5bae75650d4626b374a5cf83530 [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 Arora47fd9182010-08-24 13:26:06 +053026static WINDOW *footer_win;
27
28int maxx, maxy;
29char footer_items[NUM_FOOTER_ITEMS][64];
30
31
32void fini_curses(void) {
33 endwin();
34}
35
36void killall_windows(void)
37{
38 if (header_win) {
39 delwin(header_win);
40 header_win = NULL;
41 }
42 if (regulator_win) {
43 delwin(regulator_win);
44 regulator_win = NULL;
45 }
Amit Arora728e0c92010-09-14 12:06:09 +053046 if (clock_win) {
47 delwin(clock_win);
48 clock_win = NULL;
49 }
50 if (sensor_win) {
51 delwin(sensor_win);
52 sensor_win = NULL;
53 }
Amit Arora47fd9182010-08-24 13:26:06 +053054 if (footer_win) {
55 delwin(footer_win);
56 footer_win = NULL;
57 }
58}
59
60void init_curses(void)
61{
62 initscr();
63 start_color();
64 keypad(stdscr, TRUE);
65 noecho();
66 cbreak();
67 curs_set(0);
68 nonl();
69 use_default_colors();
70
71 init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
Amit Arora47fd9182010-08-24 13:26:06 +053072 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
Amit Arora728e0c92010-09-14 12:06:09 +053073 init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
Amit Arora47fd9182010-08-24 13:26:06 +053074 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
75 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
Amit Arora47fd9182010-08-24 13:26:06 +053076 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
Amit Arora728e0c92010-09-14 12:06:09 +053077 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE);
78 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
Amit Arora47fd9182010-08-24 13:26:06 +053079
80 atexit(fini_curses);
81}
82
83
84void create_windows(void)
85{
86
87 getmaxyx(stdscr, maxy, maxx);
88 killall_windows();
89
90 header_win = subwin(stdscr, 1, maxx, 0, 0);
Amit Arora728e0c92010-09-14 12:06:09 +053091// regulator_win = subwin(stdscr, maxy/2 - 2, maxx, 1, 0);
92// clock_win = subwin(stdscr, maxy/2 - 2, maxx, maxy/2, 0);
Amit Arora47fd9182010-08-24 13:26:06 +053093
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 Arora24ed7d12010-09-14 12:12:58 +0530104/*
105 * maxrows is the MAXIMUM number of rows we need for this window
106 * pshare is the minimum number of rows we should have for this (in %age)
107 * maxrows prevails in case of an argument !
108 */
109int create_regulator_win(int row, int maxrows, int *pshare)
Amit Arora728e0c92010-09-14 12:06:09 +0530110{
111 int numrows;
Amit Arora24ed7d12010-09-14 12:12:58 +0530112 int idealrows; // Based on pshare provided to us
Amit Arora728e0c92010-09-14 12:06:09 +0530113
114 if (regulator_win) {
115 delwin(regulator_win);
116 regulator_win = NULL;
117 }
118
119 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530120
121 idealrows = ((maxy - 2) * (*pshare)) / 100;
122 if (maxrows < idealrows) {
Amit Arora728e0c92010-09-14 12:06:09 +0530123 numrows = maxrows;
Amit Arora24ed7d12010-09-14 12:12:58 +0530124 *pshare = (numrows * 100) / maxy;
125 } else
126 numrows = idealrows;
Amit Arora728e0c92010-09-14 12:06:09 +0530127 regulator_win = subwin(stdscr, numrows, maxx, row, 0);
128
129 refresh();
130
131 return numrows + row;
132}
133
Amit Arora24ed7d12010-09-14 12:12:58 +0530134int create_clock_win(int row, int maxrows, int *pshare)
Amit Arora728e0c92010-09-14 12:06:09 +0530135{
136 int numrows;
Amit Arora24ed7d12010-09-14 12:12:58 +0530137 int idealrows;
Amit Arora728e0c92010-09-14 12:06:09 +0530138
139 if (clock_win) {
140 delwin(clock_win);
141 clock_win = NULL;
142 }
143
144 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530145 idealrows = ((maxy - 2) * (*pshare)) / 100;
146
147 if (maxrows < idealrows)
Amit Arora728e0c92010-09-14 12:06:09 +0530148 numrows = maxrows;
149 else
Amit Arora24ed7d12010-09-14 12:12:58 +0530150 numrows = idealrows;
Amit Arora728e0c92010-09-14 12:06:09 +0530151 clock_win = subwin(stdscr, numrows, maxx, row, 0);
152
153 refresh();
154
155 return numrows + row;
156}
157
Amit Arora24ed7d12010-09-14 12:12:58 +0530158int create_sensor_win(int row, int maxrows, int *pshare)
Amit Arora728e0c92010-09-14 12:06:09 +0530159{
160 int numrows;
Amit Arora24ed7d12010-09-14 12:12:58 +0530161 int idealrows;
Amit Arora728e0c92010-09-14 12:06:09 +0530162
163 if (sensor_win) {
164 delwin(sensor_win);
165 sensor_win = NULL;
166 }
167
168 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530169 idealrows = ((maxy - 2) * (*pshare)) / 100;
170
171 if (maxrows < idealrows)
Amit Arora728e0c92010-09-14 12:06:09 +0530172 numrows = maxrows;
173 else
Amit Arora24ed7d12010-09-14 12:12:58 +0530174 numrows = idealrows;
Amit Arora728e0c92010-09-14 12:06:09 +0530175 sensor_win = subwin(stdscr, numrows, maxx, row, 0);
176
177 refresh();
178
179 return numrows + row;
180}
Amit Arora47fd9182010-08-24 13:26:06 +0530181
182void show_header(void)
183{
184 int i, j = 0;
185
186 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
187 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
188 werase(header_win);
189
190 print(header_win, 0, 0, "PowerDebug version %s (C) Linaro",
191 VERSION);
192
193 wrefresh(header_win);
194
195 werase(footer_win);
196
197 for (i=0; i<NUM_FOOTER_ITEMS; i++) {
198 if (strlen(footer_items[i])==0)
199 continue;
200 wattron(footer_win, A_REVERSE);
201 print(footer_win, j, 0, "%s", footer_items[i]);
202 wattroff(footer_win, A_REVERSE);
203 j+= strlen(footer_items[i])+1;
204 }
205 wrefresh(footer_win);
206}
207
208
209void show_regulator_info(int verbose)
210{
211 int i, count = 2;
212
213 werase(regulator_win);
214 wattron(regulator_win, A_BOLD);
215 wattron(regulator_win, A_STANDOUT);
216 print(regulator_win, 0, 0, "Regulator Information");
217 wattroff(regulator_win, A_STANDOUT);
218 print(regulator_win, 0, 1, "Name");
219 print(regulator_win, 12, 1, "Status");
220 print(regulator_win, 24, 1, "State");
221 print(regulator_win, 36, 1, "Type");
222 print(regulator_win, 48, 1, "Microvolts");
223 print(regulator_win, 60, 1, "Min u-volts");
224 print(regulator_win, 72, 1, "Max u-volts");
225 wattroff(regulator_win, A_BOLD);
226
227 for (i=0; i<numregulators; i++) {
228 int col = 0;
229
230 if((i + 2) > (maxy-2))
231 break;
232
233 if(!verbose && !strncmp(regulators_info[i].state, "disabled", 8))
234 continue;
235
236 print(regulator_win, col, count, "%s",
237 regulators_info[i].name);
238 col += 12;
239 print(regulator_win, col, count, "%s",
240 regulators_info[i].status);
241 col += 12;
242 print(regulator_win, col, count, "%s",
243 regulators_info[i].state);
244 col += 12;
245 print(regulator_win, col, count, "%s",
246 regulators_info[i].type);
247 col += 12;
248 print(regulator_win, col, count, "%d",
249 regulators_info[i].microvolts);
250 col += 12;
251 print(regulator_win, col, count, "%d",
252 regulators_info[i].min_microvolts);
253 col += 12;
254 print(regulator_win, col, count, "%d",
255 regulators_info[i].max_microvolts);
256
257 count++;
258 }
259 wrefresh(regulator_win);
260}
261
Amit Arora728e0c92010-09-14 12:06:09 +0530262
263void print_clock_header(int level)
264{
265 char lev[NAME_MAX];
266
267 sprintf(lev, "(Level %d)\n", level);
268 werase(clock_win);
269 wattron(clock_win, A_BOLD);
270 wattron(clock_win, A_STANDOUT);
271 print(clock_win, 0, 0, "Clock Information");
272 wattroff(clock_win, A_STANDOUT);
273 print(clock_win, 0, 1, "Name");
274 print(clock_win, 24, 1, "Flags");
275 print(clock_win, 36, 1, "Rate");
276 print(clock_win, 48, 1, "Usecount");
277 print(clock_win, 60, 1, lev);
278 wattroff(clock_win, A_BOLD);
279 wrefresh(clock_win);
280}
281
282void print_sensor_header(void)
283{
284 werase(sensor_win);
285 wattron(sensor_win, A_BOLD);
286 wattron(sensor_win, A_STANDOUT);
287 print(sensor_win, 0, 0, "Sensor Information");
288 wattroff(sensor_win, A_STANDOUT);
289 print(sensor_win, 0, 1, "Name");
290 print(sensor_win, 36, 1, "Temperature");
291 wattroff(sensor_win, A_BOLD);
292 wattron(sensor_win, A_BLINK);
293 print(sensor_win, 0, 2, "Currently Sensor information available"
294 " only in Dump mode!");
295 wattroff(sensor_win, A_BLINK);
296 wrefresh(sensor_win);
297}
298
299void print_clock_info_line(int line, char *clockname, int flags, int rate,
300 int usecount, int highlight)
301{
Amit Arora29cb7572010-10-05 17:40:29 +0530302 if (usecount)
303 wattron(clock_win, WA_BOLD);
304 else {
305 wattroff(clock_win, WA_BOLD);
Amit Arora24ed7d12010-09-14 12:12:58 +0530306 wattron(clock_win, WA_DIM);
Amit Arora29cb7572010-10-05 17:40:29 +0530307 }
308
309 if (highlight)
310 wattron(clock_win, WA_REVERSE);
311 else
312 wattroff(clock_win, WA_REVERSE);
Amit Arora24ed7d12010-09-14 12:12:58 +0530313
Amit Arora728e0c92010-09-14 12:06:09 +0530314 print(clock_win, 0, line + 2, "%s", clockname);
Amit Arora24ed7d12010-09-14 12:12:58 +0530315 if (strcmp(clockname, "..")) {
316 print(clock_win, 24, line + 2, "%d", flags);
317 print(clock_win, 36, line + 2, "%d", rate);
318 print(clock_win, 48, line + 2, "%d", usecount);
Amit Arora728e0c92010-09-14 12:06:09 +0530319 }
Amit Arora24ed7d12010-09-14 12:12:58 +0530320
321 if (highlight)
322 wattroff(clock_win, WA_BOLD|WA_STANDOUT);
323 else
324 wattroff(clock_win, WA_DIM);
325
Amit Arora728e0c92010-09-14 12:06:09 +0530326 wrefresh(clock_win);
327}