blob: a3f312bc4cf34ebbeab911cef5a6af85a7c464e4 [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{
Amit Arora6e774cd2010-10-28 11:31:24 +053065 initscr();
66 start_color();
67 keypad(stdscr, TRUE);
68 noecho();
69 cbreak();
70 curs_set(0);
71 nonl();
72 use_default_colors();
Amit Arora47fd9182010-08-24 13:26:06 +053073
Amit Arora6e774cd2010-10-28 11:31:24 +053074 init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
75 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
Amit Arora6e774cd2010-10-28 11:31:24 +053076 init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN);
77 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
78 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
79 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
80 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
Amit Arora6e774cd2010-10-28 11:31:24 +053083 atexit(fini_curses);
Amit Arora47fd9182010-08-24 13:26:06 +053084}
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 Arora47fd9182010-08-24 13:26:06 +053094 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 Arorac93e0712010-10-07 13:51:53 +0530104void create_selectedwindow(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530105{
Amit Arora6e774cd2010-10-28 11:31:24 +0530106 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530107
Amit Arora6e774cd2010-10-28 11:31:24 +0530108 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530109
Amit Arora6e774cd2010-10-28 11:31:24 +0530110 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530111
Amit Arora6e774cd2010-10-28 11:31:24 +0530112 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530113
Amit Arora6e774cd2010-10-28 11:31:24 +0530114 switch (selectedwindow) {
115 case REGULATOR: regulator_win = win;
116 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530117
Amit Arora6e774cd2010-10-28 11:31:24 +0530118 case CLOCK: clock_win = win;
119 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530120
Amit Arora6e774cd2010-10-28 11:31:24 +0530121 case SENSOR: sensor_win = win;
122 break;
123 }
Amit Arora728e0c92010-09-14 12:06:09 +0530124
Amit Arora6e774cd2010-10-28 11:31:24 +0530125 selected_win = win;
126
127 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530128}
Amit Arora47fd9182010-08-24 13:26:06 +0530129
130void show_header(void)
131{
132 int i, j = 0;
133
134 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
135 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
136 werase(header_win);
137
Amit Arora97006e52010-10-28 11:56:08 +0530138 print(header_win, 0, 0, "PowerDebug %s", VERSION);
Amit Arora47fd9182010-08-24 13:26:06 +0530139
Amit Arora6e774cd2010-10-28 11:31:24 +0530140 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
141 if (selectedwindow == i)
142 wattron(header_win, A_REVERSE);
143 else
144 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530145
Amit Arora6e774cd2010-10-28 11:31:24 +0530146 print(header_win, i*(maxx / TOTAL_FEATURE_WINS) + 20, 0,
147 " %s ", win_names[i]);
148 }
149 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530150 werase(footer_win);
151
152 for (i=0; i<NUM_FOOTER_ITEMS; i++) {
153 if (strlen(footer_items[i])==0)
154 continue;
155 wattron(footer_win, A_REVERSE);
156 print(footer_win, j, 0, "%s", footer_items[i]);
157 wattroff(footer_win, A_REVERSE);
158 j+= strlen(footer_items[i])+1;
159 }
160 wrefresh(footer_win);
161}
162
163
164void show_regulator_info(int verbose)
165{
Amit Arorac93e0712010-10-07 13:51:53 +0530166 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530167
Amit Arora6e774cd2010-10-28 11:31:24 +0530168 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530169
Amit Arora47fd9182010-08-24 13:26:06 +0530170 werase(regulator_win);
171 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530172 print(regulator_win, 0, 0, "Name");
173 print(regulator_win, 12, 0, "Status");
174 print(regulator_win, 24, 0, "State");
175 print(regulator_win, 36, 0, "Type");
176 print(regulator_win, 48, 0, "Users");
177 print(regulator_win, 60, 0, "Microvolts");
178 print(regulator_win, 72, 0, "Min u-volts");
179 print(regulator_win, 84, 0, "Max u-volts");
Amit Arora47fd9182010-08-24 13:26:06 +0530180 wattroff(regulator_win, A_BOLD);
181
182 for (i=0; i<numregulators; i++) {
183 int col = 0;
184
185 if((i + 2) > (maxy-2))
186 break;
187
Amit Arorabf50db92010-10-07 14:09:05 +0530188 if(regulators_info[i].num_users > 0)
Amit Arora6e774cd2010-10-28 11:31:24 +0530189 wattron(regulator_win, WA_BOLD);
190 else
191 wattroff(regulator_win, WA_BOLD);
192
Amit Arora47fd9182010-08-24 13:26:06 +0530193 print(regulator_win, col, count, "%s",
194 regulators_info[i].name);
195 col += 12;
196 print(regulator_win, col, count, "%s",
197 regulators_info[i].status);
198 col += 12;
199 print(regulator_win, col, count, "%s",
200 regulators_info[i].state);
201 col += 12;
202 print(regulator_win, col, count, "%s",
203 regulators_info[i].type);
204 col += 12;
205 print(regulator_win, col, count, "%d",
Amit Arora6a943ec2010-10-07 11:49:25 +0530206 regulators_info[i].num_users);
207 col += 12;
208 print(regulator_win, col, count, "%d",
Amit Arora47fd9182010-08-24 13:26:06 +0530209 regulators_info[i].microvolts);
210 col += 12;
211 print(regulator_win, col, count, "%d",
212 regulators_info[i].min_microvolts);
213 col += 12;
214 print(regulator_win, col, count, "%d",
215 regulators_info[i].max_microvolts);
216
217 count++;
218 }
219 wrefresh(regulator_win);
220}
221
Amit Arora728e0c92010-09-14 12:06:09 +0530222
223void print_clock_header(int level)
224{
Amit Arora6e774cd2010-10-28 11:31:24 +0530225 char lev[NAME_MAX];
Amit Arora728e0c92010-09-14 12:06:09 +0530226
Amit Arora6e774cd2010-10-28 11:31:24 +0530227 sprintf(lev, "(Level %d)\n", level);
228 werase(clock_win);
229 wattron(clock_win, A_BOLD);
230 print(clock_win, 0, 0, "Name %s", lev);
Amit Arora031263a2010-11-09 11:12:41 +0530231 print(clock_win, 54, 0, "Flags");
232 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530233 print(clock_win, 72, 0, "Usecount");
234 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530235 wrefresh(clock_win);
236}
237
238void print_sensor_header(void)
239{
Amit Arora6e774cd2010-10-28 11:31:24 +0530240 werase(sensor_win);
241 wattron(sensor_win, A_BOLD);
242 print(sensor_win, 0, 0, "Name");
243 print(sensor_win, 36, 0, "Temperature");
244 wattroff(sensor_win, A_BOLD);
245 wattron(sensor_win, A_BLINK);
246 print(sensor_win, 0, 1, "Currently Sensor information available"
247 " only in Dump mode!");
248 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530249 wrefresh(sensor_win);
250}
251
Amit Arora031263a2010-11-09 11:12:41 +0530252void print_one_clock(int line, char *str, int bold)
Amit Arora728e0c92010-09-14 12:06:09 +0530253{
Amit Arora031263a2010-11-09 11:12:41 +0530254 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530255 wattron(clock_win, WA_BOLD);
Amit Arora031263a2010-11-09 11:12:41 +0530256 print(clock_win, 0, line + 1, "%s", str);
257 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530258 wattroff(clock_win, WA_BOLD);
Amit Arora6e774cd2010-10-28 11:31:24 +0530259 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530260}