blob: ff2295a5b0d69d5ad67b7278359fc39c4283b470 [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 Arora728e0c92010-09-14 12:06:09 +0530104int create_regulator_win(int row, int maxrows)
105{
106 int numrows;
107
108 if (regulator_win) {
109 delwin(regulator_win);
110 regulator_win = NULL;
111 }
112
113 getmaxyx(stdscr, maxy, maxx);
114 if (maxrows < (maxy/2 - 2))
115 numrows = maxrows;
116 else
117 numrows = maxy/2 - 2;
118 regulator_win = subwin(stdscr, numrows, maxx, row, 0);
119
120 refresh();
121
122 return numrows + row;
123}
124
125int create_clock_win(int row, int maxrows)
126{
127 int numrows;
128
129 if (clock_win) {
130 delwin(clock_win);
131 clock_win = NULL;
132 }
133
134 getmaxyx(stdscr, maxy, maxx);
135 if (maxrows < (maxy/2 - 2))
136 numrows = maxrows;
137 else
138 numrows = maxy/2 - 2;
139 clock_win = subwin(stdscr, numrows, maxx, row, 0);
140
141 refresh();
142
143 return numrows + row;
144}
145
146int create_sensor_win(int row, int maxrows)
147{
148 int numrows;
149
150 if (sensor_win) {
151 delwin(sensor_win);
152 sensor_win = NULL;
153 }
154
155 getmaxyx(stdscr, maxy, maxx);
156 if (maxrows < 4)
157 numrows = maxrows;
158 else
159 numrows = 4;
160 sensor_win = subwin(stdscr, numrows, maxx, row, 0);
161
162 refresh();
163
164 return numrows + row;
165}
Amit Arora47fd9182010-08-24 13:26:06 +0530166
167void show_header(void)
168{
169 int i, j = 0;
170
171 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
172 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
173 werase(header_win);
174
175 print(header_win, 0, 0, "PowerDebug version %s (C) Linaro",
176 VERSION);
177
178 wrefresh(header_win);
179
180 werase(footer_win);
181
182 for (i=0; i<NUM_FOOTER_ITEMS; i++) {
183 if (strlen(footer_items[i])==0)
184 continue;
185 wattron(footer_win, A_REVERSE);
186 print(footer_win, j, 0, "%s", footer_items[i]);
187 wattroff(footer_win, A_REVERSE);
188 j+= strlen(footer_items[i])+1;
189 }
190 wrefresh(footer_win);
191}
192
193
194void show_regulator_info(int verbose)
195{
196 int i, count = 2;
197
198 werase(regulator_win);
199 wattron(regulator_win, A_BOLD);
200 wattron(regulator_win, A_STANDOUT);
201 print(regulator_win, 0, 0, "Regulator Information");
202 wattroff(regulator_win, A_STANDOUT);
203 print(regulator_win, 0, 1, "Name");
204 print(regulator_win, 12, 1, "Status");
205 print(regulator_win, 24, 1, "State");
206 print(regulator_win, 36, 1, "Type");
207 print(regulator_win, 48, 1, "Microvolts");
208 print(regulator_win, 60, 1, "Min u-volts");
209 print(regulator_win, 72, 1, "Max u-volts");
210 wattroff(regulator_win, A_BOLD);
211
212 for (i=0; i<numregulators; i++) {
213 int col = 0;
214
215 if((i + 2) > (maxy-2))
216 break;
217
218 if(!verbose && !strncmp(regulators_info[i].state, "disabled", 8))
219 continue;
220
221 print(regulator_win, col, count, "%s",
222 regulators_info[i].name);
223 col += 12;
224 print(regulator_win, col, count, "%s",
225 regulators_info[i].status);
226 col += 12;
227 print(regulator_win, col, count, "%s",
228 regulators_info[i].state);
229 col += 12;
230 print(regulator_win, col, count, "%s",
231 regulators_info[i].type);
232 col += 12;
233 print(regulator_win, col, count, "%d",
234 regulators_info[i].microvolts);
235 col += 12;
236 print(regulator_win, col, count, "%d",
237 regulators_info[i].min_microvolts);
238 col += 12;
239 print(regulator_win, col, count, "%d",
240 regulators_info[i].max_microvolts);
241
242 count++;
243 }
244 wrefresh(regulator_win);
245}
246
Amit Arora728e0c92010-09-14 12:06:09 +0530247
248void print_clock_header(int level)
249{
250 char lev[NAME_MAX];
251
252 sprintf(lev, "(Level %d)\n", level);
253 werase(clock_win);
254 wattron(clock_win, A_BOLD);
255 wattron(clock_win, A_STANDOUT);
256 print(clock_win, 0, 0, "Clock Information");
257 wattroff(clock_win, A_STANDOUT);
258 print(clock_win, 0, 1, "Name");
259 print(clock_win, 24, 1, "Flags");
260 print(clock_win, 36, 1, "Rate");
261 print(clock_win, 48, 1, "Usecount");
262 print(clock_win, 60, 1, lev);
263 wattroff(clock_win, A_BOLD);
264 wrefresh(clock_win);
265}
266
267void print_sensor_header(void)
268{
269 werase(sensor_win);
270 wattron(sensor_win, A_BOLD);
271 wattron(sensor_win, A_STANDOUT);
272 print(sensor_win, 0, 0, "Sensor Information");
273 wattroff(sensor_win, A_STANDOUT);
274 print(sensor_win, 0, 1, "Name");
275 print(sensor_win, 36, 1, "Temperature");
276 wattroff(sensor_win, A_BOLD);
277 wattron(sensor_win, A_BLINK);
278 print(sensor_win, 0, 2, "Currently Sensor information available"
279 " only in Dump mode!");
280 wattroff(sensor_win, A_BLINK);
281 wrefresh(sensor_win);
282}
283
284void print_clock_info_line(int line, char *clockname, int flags, int rate,
285 int usecount, int highlight)
286{
287 if (highlight) {
288 //wattrset(clock_win, COLOR_PAIR(PT_COLOR_RED));
289 //wbkgd(clock_win, COLOR_PAIR(PT_COLOR_RED));
290 wattron(clock_win, WA_BOLD);
291 }
292 print(clock_win, 0, line + 2, "%s", clockname);
293 print(clock_win, 24, line + 2, "%d", flags);
294 print(clock_win, 36, line + 2, "%d", rate);
295 print(clock_win, 48, line + 2, "%d", usecount);
296 if (highlight) {
297 //use_default_colors();
298 //wattrset(clock_win, COLOR_PAIR(PT_COLOR_DEFAULT));
299 //wbkgd(clock_win, COLOR_PAIR(PT_COLOR_DEFAULT));
300 wattroff(clock_win, WA_BOLD);
301 }
302 wrefresh(clock_win);
303}