blob: d3ec4212267f945a34dd8432df558e8ea28bdb5b [file] [log] [blame]
Amit Arora39f29542010-09-14 12:03:22 +05301/*******************************************************************************
Amit Kucheriac0e17fc2011-01-17 09:35:52 +02002 * Copyright (C) 2010, Linaro Limited.
Amit Arora39f29542010-09-14 12:03:22 +05303 *
4 * This file is part of PowerDebug.
5 *
6 * All rights reserved. This program and the accompanying materials
7 * are made available under the terms of the Eclipse Public License v1.0
8 * which accompanies this distribution, and is available at
9 * http://www.eclipse.org/legal/epl-v10.html
10 *
11 * Contributors:
12 * Amit Arora <amit.arora@linaro.org> (IBM Corporation)
13 * - initial API and implementation
14 *******************************************************************************/
15
Amit Arora47fd9182010-08-24 13:26:06 +053016#include "powerdebug.h"
Amit Arora17552782010-12-02 12:23:14 +053017#include "regulator.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 Kucheriab85e5d52011-01-12 10:55:24 -060076 init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK);
Amit Arora6e774cd2010-10-28 11:31:24 +053077 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
Amit Arora83ae6cb2010-12-02 12:22:19 +053099 if (selectedwindow == CLOCK)
100 strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', "
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600101 " '/', 'Esc' ");
Amit Arora83ae6cb2010-12-02 12:22:19 +0530102 else
103 strcpy(footer_items[2], " Other Keys: 'Left', 'Right' ");
104
105 strcpy(footer_items[3], "");
106
Amit Arora47fd9182010-08-24 13:26:06 +0530107 werase(stdscr);
108 refresh();
109
110}
111
Amit Arorac93e0712010-10-07 13:51:53 +0530112void create_selectedwindow(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530113{
Amit Arora6e774cd2010-10-28 11:31:24 +0530114 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530115
Amit Arora6e774cd2010-10-28 11:31:24 +0530116 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530117
Amit Arora6e774cd2010-10-28 11:31:24 +0530118 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530119
Amit Arora6e774cd2010-10-28 11:31:24 +0530120 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530121
Amit Arora6e774cd2010-10-28 11:31:24 +0530122 switch (selectedwindow) {
123 case REGULATOR: regulator_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600124 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530125
Amit Arora6e774cd2010-10-28 11:31:24 +0530126 case CLOCK: clock_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600127 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530128
Amit Arora6e774cd2010-10-28 11:31:24 +0530129 case SENSOR: sensor_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600130 break;
Amit Arora6e774cd2010-10-28 11:31:24 +0530131 }
Amit Arora728e0c92010-09-14 12:06:09 +0530132
Amit Arora6e774cd2010-10-28 11:31:24 +0530133 selected_win = win;
134
135 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530136}
Amit Arora47fd9182010-08-24 13:26:06 +0530137
138void show_header(void)
139{
140 int i, j = 0;
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530141 int curr_pointer = 0;
Amit Arora47fd9182010-08-24 13:26:06 +0530142
143 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
144 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
145 werase(header_win);
146
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530147 print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
148 curr_pointer += 20;
Amit Arora47fd9182010-08-24 13:26:06 +0530149
Amit Arora6e774cd2010-10-28 11:31:24 +0530150 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
151 if (selectedwindow == i)
152 wattron(header_win, A_REVERSE);
153 else
154 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530155
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530156 print(header_win, curr_pointer, 0, " %s ", win_names[i]);
157 curr_pointer += strlen(win_names[i]) + 2;
Amit Arora6e774cd2010-10-28 11:31:24 +0530158 }
159 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530160 werase(footer_win);
161
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600162 for (i = 0; i < NUM_FOOTER_ITEMS; i++) {
163 if (strlen(footer_items[i]) == 0)
Amit Arora47fd9182010-08-24 13:26:06 +0530164 continue;
165 wattron(footer_win, A_REVERSE);
166 print(footer_win, j, 0, "%s", footer_items[i]);
167 wattroff(footer_win, A_REVERSE);
168 j+= strlen(footer_items[i])+1;
169 }
170 wrefresh(footer_win);
171}
172
173
174void show_regulator_info(int verbose)
175{
Amit Arorac93e0712010-10-07 13:51:53 +0530176 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530177
Amit Arora6e774cd2010-10-28 11:31:24 +0530178 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530179
Amit Arora47fd9182010-08-24 13:26:06 +0530180 werase(regulator_win);
181 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530182 print(regulator_win, 0, 0, "Name");
183 print(regulator_win, 12, 0, "Status");
184 print(regulator_win, 24, 0, "State");
185 print(regulator_win, 36, 0, "Type");
186 print(regulator_win, 48, 0, "Users");
187 print(regulator_win, 60, 0, "Microvolts");
188 print(regulator_win, 72, 0, "Min u-volts");
189 print(regulator_win, 84, 0, "Max u-volts");
Amit Arora47fd9182010-08-24 13:26:06 +0530190 wattroff(regulator_win, A_BOLD);
191
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600192 for (i = 0; i < numregulators; i++) {
Amit Arora47fd9182010-08-24 13:26:06 +0530193 int col = 0;
194
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600195 if ((i + 2) > (maxy-2))
Amit Arora47fd9182010-08-24 13:26:06 +0530196 break;
197
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600198 if (regulators_info[i].num_users > 0)
Amit Arora6e774cd2010-10-28 11:31:24 +0530199 wattron(regulator_win, WA_BOLD);
200 else
201 wattroff(regulator_win, WA_BOLD);
202
Amit Arora47fd9182010-08-24 13:26:06 +0530203 print(regulator_win, col, count, "%s",
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600204 regulators_info[i].name);
Amit Arora47fd9182010-08-24 13:26:06 +0530205 col += 12;
206 print(regulator_win, col, count, "%s",
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600207 regulators_info[i].status);
Amit Arora47fd9182010-08-24 13:26:06 +0530208 col += 12;
209 print(regulator_win, col, count, "%s",
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600210 regulators_info[i].state);
Amit Arora47fd9182010-08-24 13:26:06 +0530211 col += 12;
212 print(regulator_win, col, count, "%s",
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600213 regulators_info[i].type);
Amit Arora47fd9182010-08-24 13:26:06 +0530214 col += 12;
215 print(regulator_win, col, count, "%d",
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600216 regulators_info[i].num_users);
Amit Arora6a943ec2010-10-07 11:49:25 +0530217 col += 12;
218 print(regulator_win, col, count, "%d",
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600219 regulators_info[i].microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530220 col += 12;
221 print(regulator_win, col, count, "%d",
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600222 regulators_info[i].min_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530223 col += 12;
224 print(regulator_win, col, count, "%d",
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600225 regulators_info[i].max_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530226
227 count++;
228 }
229 wrefresh(regulator_win);
230}
231
Amit Arora728e0c92010-09-14 12:06:09 +0530232
Amit Aroraac4e8652010-11-09 11:16:53 +0530233void print_clock_header(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530234{
Amit Arora6e774cd2010-10-28 11:31:24 +0530235 werase(clock_win);
236 wattron(clock_win, A_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530237 print(clock_win, 0, 0, "Name");
Amit Arora031263a2010-11-09 11:12:41 +0530238 print(clock_win, 54, 0, "Flags");
239 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530240 print(clock_win, 72, 0, "Usecount");
Amit Arora04f97742010-11-16 11:28:57 +0530241 print(clock_win, 84, 0, "Children");
Amit Arora6e774cd2010-10-28 11:31:24 +0530242 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530243 wrefresh(clock_win);
244}
245
246void print_sensor_header(void)
247{
Amit Arora6e774cd2010-10-28 11:31:24 +0530248 werase(sensor_win);
249 wattron(sensor_win, A_BOLD);
250 print(sensor_win, 0, 0, "Name");
251 print(sensor_win, 36, 0, "Temperature");
252 wattroff(sensor_win, A_BOLD);
253 wattron(sensor_win, A_BLINK);
254 print(sensor_win, 0, 1, "Currently Sensor information available"
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600255 " only in Dump mode!");
Amit Arora6e774cd2010-10-28 11:31:24 +0530256 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530257 wrefresh(sensor_win);
258}
259
Amit Aroraac4e8652010-11-09 11:16:53 +0530260void print_one_clock(int line, char *str, int bold, int highlight)
Amit Arora728e0c92010-09-14 12:06:09 +0530261{
Amit Arora031263a2010-11-09 11:12:41 +0530262 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530263 wattron(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530264 if (highlight)
265 wattron(clock_win, WA_STANDOUT);
266
Amit Arora031263a2010-11-09 11:12:41 +0530267 print(clock_win, 0, line + 1, "%s", str);
268 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530269 wattroff(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530270 if (highlight)
271 wattroff(clock_win, WA_STANDOUT);
Amit Arora6e774cd2010-10-28 11:31:24 +0530272 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530273}