blob: 371ea99b1ad03fcbf0bd7a80b4d59d6f06009f2c [file] [log] [blame]
Amit Arora47fd9182010-08-24 13:26:06 +05301#include "powerdebug.h"
2
3#define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0)
4#define NUM_FOOTER_ITEMS 5
5
6static WINDOW *header_win;
7static WINDOW *regulator_win;
8static WINDOW *footer_win;
9
10int maxx, maxy;
11char footer_items[NUM_FOOTER_ITEMS][64];
12
13
14void fini_curses(void) {
15 endwin();
16}
17
18void killall_windows(void)
19{
20 if (header_win) {
21 delwin(header_win);
22 header_win = NULL;
23 }
24 if (regulator_win) {
25 delwin(regulator_win);
26 regulator_win = NULL;
27 }
28 if (footer_win) {
29 delwin(footer_win);
30 footer_win = NULL;
31 }
32}
33
34void init_curses(void)
35{
36 initscr();
37 start_color();
38 keypad(stdscr, TRUE);
39 noecho();
40 cbreak();
41 curs_set(0);
42 nonl();
43 use_default_colors();
44
45 init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
46 init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
47 init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
48 init_pair(PT_COLOR_RED, COLOR_WHITE, COLOR_RED);
49 init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
50 init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
51 init_pair(PT_COLOR_BLUE, COLOR_WHITE, COLOR_BLUE);
52 init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
53
54 atexit(fini_curses);
55}
56
57
58void create_windows(void)
59{
60
61 getmaxyx(stdscr, maxy, maxx);
62 killall_windows();
63
64 header_win = subwin(stdscr, 1, maxx, 0, 0);
65 regulator_win = subwin(stdscr, maxy-3, maxx, 1, 0);
66
67 footer_win = subwin(stdscr, 1, maxx, maxy-1, 0);
68
69 strcpy(footer_items[0], " Q (Quit) ");
70 strcpy(footer_items[1], " R (Refresh) ");
71
72 werase(stdscr);
73 refresh();
74
75}
76
77
78void show_header(void)
79{
80 int i, j = 0;
81
82 wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
83 wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
84 werase(header_win);
85
86 print(header_win, 0, 0, "PowerDebug version %s (C) Linaro",
87 VERSION);
88
89 wrefresh(header_win);
90
91 werase(footer_win);
92
93 for (i=0; i<NUM_FOOTER_ITEMS; i++) {
94 if (strlen(footer_items[i])==0)
95 continue;
96 wattron(footer_win, A_REVERSE);
97 print(footer_win, j, 0, "%s", footer_items[i]);
98 wattroff(footer_win, A_REVERSE);
99 j+= strlen(footer_items[i])+1;
100 }
101 wrefresh(footer_win);
102}
103
104
105void show_regulator_info(int verbose)
106{
107 int i, count = 2;
108
109 werase(regulator_win);
110 wattron(regulator_win, A_BOLD);
111 wattron(regulator_win, A_STANDOUT);
112 print(regulator_win, 0, 0, "Regulator Information");
113 wattroff(regulator_win, A_STANDOUT);
114 print(regulator_win, 0, 1, "Name");
115 print(regulator_win, 12, 1, "Status");
116 print(regulator_win, 24, 1, "State");
117 print(regulator_win, 36, 1, "Type");
118 print(regulator_win, 48, 1, "Microvolts");
119 print(regulator_win, 60, 1, "Min u-volts");
120 print(regulator_win, 72, 1, "Max u-volts");
121 wattroff(regulator_win, A_BOLD);
122
123 for (i=0; i<numregulators; i++) {
124 int col = 0;
125
126 if((i + 2) > (maxy-2))
127 break;
128
129 if(!verbose && !strncmp(regulators_info[i].state, "disabled", 8))
130 continue;
131
132 print(regulator_win, col, count, "%s",
133 regulators_info[i].name);
134 col += 12;
135 print(regulator_win, col, count, "%s",
136 regulators_info[i].status);
137 col += 12;
138 print(regulator_win, col, count, "%s",
139 regulators_info[i].state);
140 col += 12;
141 print(regulator_win, col, count, "%s",
142 regulators_info[i].type);
143 col += 12;
144 print(regulator_win, col, count, "%d",
145 regulators_info[i].microvolts);
146 col += 12;
147 print(regulator_win, col, count, "%d",
148 regulators_info[i].min_microvolts);
149 col += 12;
150 print(regulator_win, col, count, "%d",
151 regulators_info[i].max_microvolts);
152
153 count++;
154 }
155 wrefresh(regulator_win);
156}
157