blob: ee2869a8382c69c53f1d4f7abd23bd959cc5622b [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 Arora17552782010-12-02 12:23:14 +053018#include "regulator.h"
Amit Aroraed3e5652010-10-27 12:02:53 +053019#include "display.h"
Amit Arora47fd9182010-08-24 13:26:06 +053020
21#define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0)
22#define NUM_FOOTER_ITEMS 5
23
24static WINDOW *header_win;
25static WINDOW *regulator_win;
Amit Arora728e0c92010-09-14 12:06:09 +053026static WINDOW *clock_win;
27static WINDOW *sensor_win;
Amit Arorac93e0712010-10-07 13:51:53 +053028static WINDOW *selected_win;
Amit Arora47fd9182010-08-24 13:26:06 +053029static WINDOW *footer_win;
30
31int maxx, maxy;
32char footer_items[NUM_FOOTER_ITEMS][64];
33
34
35void fini_curses(void) {
36 endwin();
37}
38
Amit Arorac93e0712010-10-07 13:51:53 +053039/* "all" : Kill header and footer windows too ? */
40void killall_windows(int all)
Amit Arora47fd9182010-08-24 13:26:06 +053041{
Amit Arorac93e0712010-10-07 13:51:53 +053042 if (all && header_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053043 delwin(header_win);
44 header_win = NULL;
45 }
46 if (regulator_win) {
47 delwin(regulator_win);
48 regulator_win = NULL;
49 }
Amit Arora728e0c92010-09-14 12:06:09 +053050 if (clock_win) {
51 delwin(clock_win);
52 clock_win = NULL;
53 }
54 if (sensor_win) {
55 delwin(sensor_win);
56 sensor_win = NULL;
57 }
Amit Arorac93e0712010-10-07 13:51:53 +053058 if (all && footer_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053059 delwin(footer_win);
60 footer_win = NULL;
61 }
62}
63
64void init_curses(void)
65{
Amit Arora6e774cd2010-10-28 11:31:24 +053066 initscr();
67 start_color();
68 keypad(stdscr, TRUE);
69 noecho();
70 cbreak();
71 curs_set(0);
72 nonl();
73 use_default_colors();
Amit Arora47fd9182010-08-24 13:26:06 +053074
Amit Arora6e774cd2010-10-28 11:31:24 +053075 init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
76 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
Amit Arora6e774cd2010-10-28 11:31:24 +053077 init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN);
78 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
79 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
80 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
81 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
Amit Arora6e774cd2010-10-28 11:31:24 +053084 atexit(fini_curses);
Amit Arora47fd9182010-08-24 13:26:06 +053085}
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 Arora47fd9182010-08-24 13:26:06 +053095 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
96
97 strcpy(footer_items[0], " Q (Quit) ");
98 strcpy(footer_items[1], " R (Refresh) ");
99
Amit Arora83ae6cb2010-12-02 12:22:19 +0530100 if (selectedwindow == CLOCK)
101 strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', "
102 " '/', 'Esc' ");
103 else
104 strcpy(footer_items[2], " Other Keys: 'Left', 'Right' ");
105
106 strcpy(footer_items[3], "");
107
Amit Arora47fd9182010-08-24 13:26:06 +0530108 werase(stdscr);
109 refresh();
110
111}
112
Amit Arorac93e0712010-10-07 13:51:53 +0530113void create_selectedwindow(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530114{
Amit Arora6e774cd2010-10-28 11:31:24 +0530115 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530116
Amit Arora6e774cd2010-10-28 11:31:24 +0530117 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530118
Amit Arora6e774cd2010-10-28 11:31:24 +0530119 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530120
Amit Arora6e774cd2010-10-28 11:31:24 +0530121 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530122
Amit Arora6e774cd2010-10-28 11:31:24 +0530123 switch (selectedwindow) {
124 case REGULATOR: regulator_win = win;
125 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530126
Amit Arora6e774cd2010-10-28 11:31:24 +0530127 case CLOCK: clock_win = win;
128 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530129
Amit Arora6e774cd2010-10-28 11:31:24 +0530130 case SENSOR: sensor_win = win;
131 break;
132 }
Amit Arora728e0c92010-09-14 12:06:09 +0530133
Amit Arora6e774cd2010-10-28 11:31:24 +0530134 selected_win = win;
135
136 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530137}
Amit Arora47fd9182010-08-24 13:26:06 +0530138
139void show_header(void)
140{
141 int i, j = 0;
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530142 int curr_pointer = 0;
Amit Arora47fd9182010-08-24 13:26:06 +0530143
144 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
145 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
146 werase(header_win);
147
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530148 print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
149 curr_pointer += 20;
Amit Arora47fd9182010-08-24 13:26:06 +0530150
Amit Arora6e774cd2010-10-28 11:31:24 +0530151 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
152 if (selectedwindow == i)
153 wattron(header_win, A_REVERSE);
154 else
155 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530156
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530157 print(header_win, curr_pointer, 0, " %s ", win_names[i]);
158 curr_pointer += strlen(win_names[i]) + 2;
Amit Arora6e774cd2010-10-28 11:31:24 +0530159 }
160 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530161 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 Arora6e774cd2010-10-28 11:31:24 +0530179 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530180
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)
Amit Arora6e774cd2010-10-28 11:31:24 +0530200 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
Amit Aroraac4e8652010-11-09 11:16:53 +0530234void print_clock_header(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530235{
Amit Arora6e774cd2010-10-28 11:31:24 +0530236 werase(clock_win);
237 wattron(clock_win, A_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530238 print(clock_win, 0, 0, "Name");
Amit Arora031263a2010-11-09 11:12:41 +0530239 print(clock_win, 54, 0, "Flags");
240 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530241 print(clock_win, 72, 0, "Usecount");
Amit Arora04f97742010-11-16 11:28:57 +0530242 print(clock_win, 84, 0, "Children");
Amit Arora6e774cd2010-10-28 11:31:24 +0530243 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530244 wrefresh(clock_win);
245}
246
247void print_sensor_header(void)
248{
Amit Arora6e774cd2010-10-28 11:31:24 +0530249 werase(sensor_win);
250 wattron(sensor_win, A_BOLD);
251 print(sensor_win, 0, 0, "Name");
252 print(sensor_win, 36, 0, "Temperature");
253 wattroff(sensor_win, A_BOLD);
254 wattron(sensor_win, A_BLINK);
255 print(sensor_win, 0, 1, "Currently Sensor information available"
256 " only in Dump mode!");
257 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530258 wrefresh(sensor_win);
259}
260
Amit Aroraac4e8652010-11-09 11:16:53 +0530261void print_one_clock(int line, char *str, int bold, int highlight)
Amit Arora728e0c92010-09-14 12:06:09 +0530262{
Amit Arora031263a2010-11-09 11:12:41 +0530263 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530264 wattron(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530265 if (highlight)
266 wattron(clock_win, WA_STANDOUT);
267
Amit Arora031263a2010-11-09 11:12:41 +0530268 print(clock_win, 0, line + 1, "%s", str);
269 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530270 wattroff(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530271 if (highlight)
272 wattroff(clock_win, WA_STANDOUT);
Amit Arora6e774cd2010-10-28 11:31:24 +0530273 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530274}