blob: b439814db09127aadc8513e0e110050baafe9a97 [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
Daniel Lezcanod5a2c6d2011-03-23 14:37:38 +010033static char *win_names[TOTAL_FEATURE_WINS] = {
34 "Clocks",
35 "Regulators",
36 "Sensors"
37};
Amit Arora47fd9182010-08-24 13:26:06 +053038
39void fini_curses(void) {
40 endwin();
41}
42
Amit Arorac93e0712010-10-07 13:51:53 +053043/* "all" : Kill header and footer windows too ? */
44void killall_windows(int all)
Amit Arora47fd9182010-08-24 13:26:06 +053045{
Amit Arorac93e0712010-10-07 13:51:53 +053046 if (all && header_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053047 delwin(header_win);
48 header_win = NULL;
49 }
50 if (regulator_win) {
51 delwin(regulator_win);
52 regulator_win = NULL;
53 }
Amit Arora728e0c92010-09-14 12:06:09 +053054 if (clock_win) {
55 delwin(clock_win);
56 clock_win = NULL;
57 }
58 if (sensor_win) {
59 delwin(sensor_win);
60 sensor_win = NULL;
61 }
Amit Arorac93e0712010-10-07 13:51:53 +053062 if (all && footer_win) {
Amit Arora47fd9182010-08-24 13:26:06 +053063 delwin(footer_win);
64 footer_win = NULL;
65 }
66}
67
68void init_curses(void)
69{
Amit Arora6e774cd2010-10-28 11:31:24 +053070 initscr();
71 start_color();
72 keypad(stdscr, TRUE);
73 noecho();
74 cbreak();
75 curs_set(0);
76 nonl();
77 use_default_colors();
Amit Arora47fd9182010-08-24 13:26:06 +053078
Amit Arora6e774cd2010-10-28 11:31:24 +053079 init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
80 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
Amit Kucheriab85e5d52011-01-12 10:55:24 -060081 init_pair(PT_COLOR_HEADER_BAR, COLOR_WHITE, COLOR_BLACK);
Amit Arora6e774cd2010-10-28 11:31:24 +053082 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
83 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
84 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
85 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE);
86 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
Amit Arora47fd9182010-08-24 13:26:06 +053087
Amit Arora6e774cd2010-10-28 11:31:24 +053088 atexit(fini_curses);
Amit Arora47fd9182010-08-24 13:26:06 +053089}
90
91
Daniel Lezcano558a6d52011-03-23 14:37:41 +010092void create_windows(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +053093{
94
95 getmaxyx(stdscr, maxy, maxx);
Amit Arorac93e0712010-10-07 13:51:53 +053096 killall_windows(1);
Amit Arora47fd9182010-08-24 13:26:06 +053097
98 header_win = subwin(stdscr, 1, maxx, 0, 0);
Amit Arora47fd9182010-08-24 13:26:06 +053099 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
100
101 strcpy(footer_items[0], " Q (Quit) ");
102 strcpy(footer_items[1], " R (Refresh) ");
103
Amit Arora83ae6cb2010-12-02 12:22:19 +0530104 if (selectedwindow == CLOCK)
105 strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', "
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600106 " '/', 'Esc' ");
Amit Arora83ae6cb2010-12-02 12:22:19 +0530107 else
108 strcpy(footer_items[2], " Other Keys: 'Left', 'Right' ");
109
110 strcpy(footer_items[3], "");
111
Amit Arora47fd9182010-08-24 13:26:06 +0530112 werase(stdscr);
113 refresh();
114
115}
116
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100117void create_selectedwindow(int selectedwindow)
Amit Arora728e0c92010-09-14 12:06:09 +0530118{
Amit Arora6e774cd2010-10-28 11:31:24 +0530119 WINDOW *win;
Amit Arora728e0c92010-09-14 12:06:09 +0530120
Amit Arora6e774cd2010-10-28 11:31:24 +0530121 killall_windows(0);
Amit Arora728e0c92010-09-14 12:06:09 +0530122
Amit Arora6e774cd2010-10-28 11:31:24 +0530123 getmaxyx(stdscr, maxy, maxx);
Amit Arora24ed7d12010-09-14 12:12:58 +0530124
Amit Arora6e774cd2010-10-28 11:31:24 +0530125 win = subwin(stdscr, maxy - 2, maxx, 1, 0);
Amit Arora728e0c92010-09-14 12:06:09 +0530126
Amit Arora6e774cd2010-10-28 11:31:24 +0530127 switch (selectedwindow) {
128 case REGULATOR: regulator_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600129 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530130
Amit Arora6e774cd2010-10-28 11:31:24 +0530131 case CLOCK: clock_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600132 break;
Amit Arora728e0c92010-09-14 12:06:09 +0530133
Amit Arora6e774cd2010-10-28 11:31:24 +0530134 case SENSOR: sensor_win = win;
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600135 break;
Amit Arora6e774cd2010-10-28 11:31:24 +0530136 }
Amit Arora728e0c92010-09-14 12:06:09 +0530137
Amit Arora6e774cd2010-10-28 11:31:24 +0530138 selected_win = win;
139
140 refresh();
Amit Arora728e0c92010-09-14 12:06:09 +0530141}
Amit Arora47fd9182010-08-24 13:26:06 +0530142
Daniel Lezcano558a6d52011-03-23 14:37:41 +0100143void show_header(int selectedwindow)
Amit Arora47fd9182010-08-24 13:26:06 +0530144{
145 int i, j = 0;
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530146 int curr_pointer = 0;
Amit Arora47fd9182010-08-24 13:26:06 +0530147
148 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
149 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
150 werase(header_win);
151
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530152 print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION);
153 curr_pointer += 20;
Amit Arora47fd9182010-08-24 13:26:06 +0530154
Amit Arora6e774cd2010-10-28 11:31:24 +0530155 for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
156 if (selectedwindow == i)
157 wattron(header_win, A_REVERSE);
158 else
159 wattroff(header_win, A_REVERSE);
Amit Arorac93e0712010-10-07 13:51:53 +0530160
Amit Kucheria0a4d0192011-01-12 04:54:37 +0530161 print(header_win, curr_pointer, 0, " %s ", win_names[i]);
162 curr_pointer += strlen(win_names[i]) + 2;
Amit Arora6e774cd2010-10-28 11:31:24 +0530163 }
164 wrefresh(header_win);
Amit Arora47fd9182010-08-24 13:26:06 +0530165 werase(footer_win);
166
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600167 for (i = 0; i < NUM_FOOTER_ITEMS; i++) {
168 if (strlen(footer_items[i]) == 0)
Amit Arora47fd9182010-08-24 13:26:06 +0530169 continue;
170 wattron(footer_win, A_REVERSE);
171 print(footer_win, j, 0, "%s", footer_items[i]);
172 wattroff(footer_win, A_REVERSE);
173 j+= strlen(footer_items[i])+1;
174 }
175 wrefresh(footer_win);
176}
177
178
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100179void show_regulator_info(struct regulator_info *reg_info, int verbose)
Amit Arora47fd9182010-08-24 13:26:06 +0530180{
Amit Arorac93e0712010-10-07 13:51:53 +0530181 int i, count = 1;
Amit Arora47fd9182010-08-24 13:26:06 +0530182
Amit Arora6e774cd2010-10-28 11:31:24 +0530183 (void)verbose;
Amit Arorabf50db92010-10-07 14:09:05 +0530184
Amit Arora47fd9182010-08-24 13:26:06 +0530185 werase(regulator_win);
186 wattron(regulator_win, A_BOLD);
Amit Arorac93e0712010-10-07 13:51:53 +0530187 print(regulator_win, 0, 0, "Name");
188 print(regulator_win, 12, 0, "Status");
189 print(regulator_win, 24, 0, "State");
190 print(regulator_win, 36, 0, "Type");
191 print(regulator_win, 48, 0, "Users");
192 print(regulator_win, 60, 0, "Microvolts");
193 print(regulator_win, 72, 0, "Min u-volts");
194 print(regulator_win, 84, 0, "Max u-volts");
Amit Arora47fd9182010-08-24 13:26:06 +0530195 wattroff(regulator_win, A_BOLD);
196
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600197 for (i = 0; i < numregulators; i++) {
Amit Arora47fd9182010-08-24 13:26:06 +0530198 int col = 0;
199
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600200 if ((i + 2) > (maxy-2))
Amit Arora47fd9182010-08-24 13:26:06 +0530201 break;
202
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100203 if (reg_info[i].num_users > 0)
Amit Arora6e774cd2010-10-28 11:31:24 +0530204 wattron(regulator_win, WA_BOLD);
205 else
206 wattroff(regulator_win, WA_BOLD);
207
Amit Arora47fd9182010-08-24 13:26:06 +0530208 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100209 reg_info[i].name);
Amit Arora47fd9182010-08-24 13:26:06 +0530210 col += 12;
211 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100212 reg_info[i].status);
Amit Arora47fd9182010-08-24 13:26:06 +0530213 col += 12;
214 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100215 reg_info[i].state);
Amit Arora47fd9182010-08-24 13:26:06 +0530216 col += 12;
217 print(regulator_win, col, count, "%s",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100218 reg_info[i].type);
Amit Arora47fd9182010-08-24 13:26:06 +0530219 col += 12;
220 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100221 reg_info[i].num_users);
Amit Arora6a943ec2010-10-07 11:49:25 +0530222 col += 12;
223 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100224 reg_info[i].microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530225 col += 12;
226 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100227 reg_info[i].min_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530228 col += 12;
229 print(regulator_win, col, count, "%d",
Daniel Lezcano3bd64f02011-03-26 22:05:56 +0100230 reg_info[i].max_microvolts);
Amit Arora47fd9182010-08-24 13:26:06 +0530231
232 count++;
233 }
234 wrefresh(regulator_win);
235}
236
Amit Arora728e0c92010-09-14 12:06:09 +0530237
Amit Aroraac4e8652010-11-09 11:16:53 +0530238void print_clock_header(void)
Amit Arora728e0c92010-09-14 12:06:09 +0530239{
Amit Arora6e774cd2010-10-28 11:31:24 +0530240 werase(clock_win);
241 wattron(clock_win, A_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530242 print(clock_win, 0, 0, "Name");
Amit Arora031263a2010-11-09 11:12:41 +0530243 print(clock_win, 54, 0, "Flags");
244 print(clock_win, 64, 0, "Rate");
Amit Arora6e774cd2010-10-28 11:31:24 +0530245 print(clock_win, 72, 0, "Usecount");
Amit Arora04f97742010-11-16 11:28:57 +0530246 print(clock_win, 84, 0, "Children");
Amit Arora6e774cd2010-10-28 11:31:24 +0530247 wattroff(clock_win, A_BOLD);
Amit Arora728e0c92010-09-14 12:06:09 +0530248 wrefresh(clock_win);
249}
250
251void print_sensor_header(void)
252{
Amit Arora6e774cd2010-10-28 11:31:24 +0530253 werase(sensor_win);
254 wattron(sensor_win, A_BOLD);
255 print(sensor_win, 0, 0, "Name");
256 print(sensor_win, 36, 0, "Temperature");
257 wattroff(sensor_win, A_BOLD);
258 wattron(sensor_win, A_BLINK);
259 print(sensor_win, 0, 1, "Currently Sensor information available"
Amit Kucheriaa0adae42011-01-12 10:54:23 -0600260 " only in Dump mode!");
Amit Arora6e774cd2010-10-28 11:31:24 +0530261 wattroff(sensor_win, A_BLINK);
Amit Arora728e0c92010-09-14 12:06:09 +0530262 wrefresh(sensor_win);
263}
264
Amit Aroraac4e8652010-11-09 11:16:53 +0530265void print_one_clock(int line, char *str, int bold, int highlight)
Amit Arora728e0c92010-09-14 12:06:09 +0530266{
Amit Arora031263a2010-11-09 11:12:41 +0530267 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530268 wattron(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530269 if (highlight)
270 wattron(clock_win, WA_STANDOUT);
271
Amit Arora031263a2010-11-09 11:12:41 +0530272 print(clock_win, 0, line + 1, "%s", str);
273 if (bold)
Amit Arora6e774cd2010-10-28 11:31:24 +0530274 wattroff(clock_win, WA_BOLD);
Amit Aroraac4e8652010-11-09 11:16:53 +0530275 if (highlight)
276 wattroff(clock_win, WA_STANDOUT);
Amit Arora6e774cd2010-10-28 11:31:24 +0530277 wrefresh(clock_win);
Amit Arora728e0c92010-09-14 12:06:09 +0530278}