blob: 5cdf78a47157e5d033a5238da0a9542cf7fa3ad6 [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;
142
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 Arora97006e52010-10-28 11:56:08 +0530147 print(header_win, 0, 0, "PowerDebug %s", VERSION);
Amit Arora47fd9182010-08-24 13:26:06 +0530148
Amit Arora6e774cd2010-10-28 11:31:24 +0530149 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
150 if (selectedwindow == i)
151 wattron(header_win, A_REVERSE);
152 else
153 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530154
Amit Arora6e774cd2010-10-28 11:31:24 +0530155 print(header_win, i*(maxx / TOTAL_FEATURE_WINS) + 20, 0,
156 " %s ", win_names[i]);
157 }
158 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530159 werase(footer_win);
160
161 for (i=0; i<NUM_FOOTER_ITEMS; i++) {
162 if (strlen(footer_items[i])==0)
163 continue;
164 wattron(footer_win, A_REVERSE);
165 print(footer_win, j, 0, "%s", footer_items[i]);
166 wattroff(footer_win, A_REVERSE);
167 j+= strlen(footer_items[i])+1;
168 }
169 wrefresh(footer_win);
170}
171
172
173void show_regulator_info(int verbose)
174{
Amit Arorac93e0712010-10-07 13:51:53 +0530175 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530176
Amit Arora6e774cd2010-10-28 11:31:24 +0530177 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530178
Amit Arora47fd9182010-08-24 13:26:06 +0530179 werase(regulator_win);
180 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530181 print(regulator_win, 0, 0, "Name");
182 print(regulator_win, 12, 0, "Status");
183 print(regulator_win, 24, 0, "State");
184 print(regulator_win, 36, 0, "Type");
185 print(regulator_win, 48, 0, "Users");
186 print(regulator_win, 60, 0, "Microvolts");
187 print(regulator_win, 72, 0, "Min u-volts");
188 print(regulator_win, 84, 0, "Max u-volts");
Amit Arora47fd9182010-08-24 13:26:06 +0530189 wattroff(regulator_win, A_BOLD);
190
191 for (i=0; i<numregulators; i++) {
192 int col = 0;
193
194 if((i + 2) > (maxy-2))
195 break;
196
Amit Arorabf50db92010-10-07 14:09:05 +0530197 if(regulators_info[i].num_users > 0)
Amit Arora6e774cd2010-10-28 11:31:24 +0530198 wattron(regulator_win, WA_BOLD);
199 else
200 wattroff(regulator_win, WA_BOLD);
201
Amit Arora47fd9182010-08-24 13:26:06 +0530202 print(regulator_win, col, count, "%s",
203 regulators_info[i].name);
204 col += 12;
205 print(regulator_win, col, count, "%s",
206 regulators_info[i].status);
207 col += 12;
208 print(regulator_win, col, count, "%s",
209 regulators_info[i].state);
210 col += 12;
211 print(regulator_win, col, count, "%s",
212 regulators_info[i].type);
213 col += 12;
214 print(regulator_win, col, count, "%d",
Amit Arora6a943ec2010-10-07 11:49:25 +0530215 regulators_info[i].num_users);
216 col += 12;
217 print(regulator_win, col, count, "%d",
Amit Arora47fd9182010-08-24 13:26:06 +0530218 regulators_info[i].microvolts);
219 col += 12;
220 print(regulator_win, col, count, "%d",
221 regulators_info[i].min_microvolts);
222 col += 12;
223 print(regulator_win, col, count, "%d",
224 regulators_info[i].max_microvolts);
225
226 count++;
227 }
228 wrefresh(regulator_win);
229}
230
Amit Arora728e0c92010-09-14 12:06:09 +0530231
Amit Aroraac4e8652010-11-09 11:16:53 +0530232void print_clock_header(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530233{
Amit Arora6e774cd2010-10-28 11:31:24 +0530234 werase(clock_win);
235 wattron(clock_win, A_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530236 print(clock_win, 0, 0, "Name");
Amit Arora031263a2010-11-09 11:12:41 +0530237 print(clock_win, 54, 0, "Flags");
238 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530239 print(clock_win, 72, 0, "Usecount");
Amit Arora04f97742010-11-16 11:28:57 +0530240 print(clock_win, 84, 0, "Children");
Amit Arora6e774cd2010-10-28 11:31:24 +0530241 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530242 wrefresh(clock_win);
243}
244
245void print_sensor_header(void)
246{
Amit Arora6e774cd2010-10-28 11:31:24 +0530247 werase(sensor_win);
248 wattron(sensor_win, A_BOLD);
249 print(sensor_win, 0, 0, "Name");
250 print(sensor_win, 36, 0, "Temperature");
251 wattroff(sensor_win, A_BOLD);
252 wattron(sensor_win, A_BLINK);
253 print(sensor_win, 0, 1, "Currently Sensor information available"
254 " only in Dump mode!");
255 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530256 wrefresh(sensor_win);
257}
258
Amit Aroraac4e8652010-11-09 11:16:53 +0530259void print_one_clock(int line, char *str, int bold, int highlight)
Amit Arora728e0c92010-09-14 12:06:09 +0530260{
Amit Arora031263a2010-11-09 11:12:41 +0530261 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530262 wattron(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530263 if (highlight)
264 wattron(clock_win, WA_STANDOUT);
265
Amit Arora031263a2010-11-09 11:12:41 +0530266 print(clock_win, 0, line + 1, "%s", str);
267 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530268 wattroff(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530269 if (highlight)
270 wattroff(clock_win, WA_STANDOUT);
Amit Arora6e774cd2010-10-28 11:31:24 +0530271 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530272}