aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmit Arora <amit.arora@linaro.org>2010-10-07 13:51:53 +0530
committerAmit Arora <amit.arora@linaro.org>2010-10-07 13:51:53 +0530
commitc93e07180c85ff75949238d681caf88c09da3e5e (patch)
treea06dfc58a93831b7c31dc11fdef46433b48bf6a2
parent6a943ecbcd933e2c40973590db7255e8dd9102ff (diff)
Add Tabs for various features
-rw-r--r--display.c162
-rw-r--r--powerdebug.c111
-rw-r--r--powerdebug.h13
3 files changed, 137 insertions, 149 deletions
diff --git a/display.c b/display.c
index bb5fb69..11bf45e 100644
--- a/display.c
+++ b/display.c
@@ -23,6 +23,7 @@ static WINDOW *header_win;
static WINDOW *regulator_win;
static WINDOW *clock_win;
static WINDOW *sensor_win;
+static WINDOW *selected_win;
static WINDOW *footer_win;
int maxx, maxy;
@@ -33,9 +34,10 @@ void fini_curses(void) {
endwin();
}
-void killall_windows(void)
+/* "all" : Kill header and footer windows too ? */
+void killall_windows(int all)
{
- if (header_win) {
+ if (all && header_win) {
delwin(header_win);
header_win = NULL;
}
@@ -51,7 +53,7 @@ void killall_windows(void)
delwin(sensor_win);
sensor_win = NULL;
}
- if (footer_win) {
+ if (all && footer_win) {
delwin(footer_win);
footer_win = NULL;
}
@@ -70,7 +72,8 @@ void init_curses(void)
init_pair(PT_COLOR_DEFAULT, COLOR_WHITE, COLOR_BLACK);
init_pair(PT_COLOR_ERROR, COLOR_BLACK, COLOR_RED);
- init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
+ //init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_WHITE);
+ init_pair(PT_COLOR_HEADER_BAR, COLOR_BLACK, COLOR_GREEN);
init_pair(PT_COLOR_YELLOW, COLOR_WHITE, COLOR_YELLOW);
init_pair(PT_COLOR_GREEN, COLOR_WHITE, COLOR_GREEN);
init_pair(PT_COLOR_BRIGHT, COLOR_WHITE, COLOR_BLACK);
@@ -85,7 +88,7 @@ void create_windows(void)
{
getmaxyx(stdscr, maxy, maxx);
- killall_windows();
+ killall_windows(1);
header_win = subwin(stdscr, 1, maxx, 0, 0);
// regulator_win = subwin(stdscr, maxy/2 - 2, maxx, 1, 0);
@@ -101,98 +104,59 @@ void create_windows(void)
}
-/*
- * maxrows is the MAXIMUM number of rows we need for this window
- * pshare is the minimum number of rows we should have for this (in %age)
- * maxrows prevails in case of an argument !
- */
-int create_regulator_win(int row, int maxrows, int *pshare)
+void create_selectedwindow(void)
{
- int numrows;
- int idealrows; // Based on pshare provided to us
+ WINDOW *win;
- if (regulator_win) {
- delwin(regulator_win);
- regulator_win = NULL;
- }
+ killall_windows(0);
getmaxyx(stdscr, maxy, maxx);
- idealrows = ((maxy - 2) * (*pshare)) / 100;
- if (maxrows < idealrows) {
- numrows = maxrows;
- *pshare = (numrows * 100) / maxy;
- } else
- numrows = idealrows;
- regulator_win = subwin(stdscr, numrows, maxx, row, 0);
-
- refresh();
-
- return numrows + row;
-}
-
-int create_clock_win(int row, int maxrows, int *pshare)
-{
- int numrows;
- int idealrows;
-
- if (clock_win) {
- delwin(clock_win);
- clock_win = NULL;
- }
-
- getmaxyx(stdscr, maxy, maxx);
- idealrows = ((maxy - 2) * (*pshare)) / 100;
-
- if (maxrows < idealrows)
- numrows = maxrows;
- else
- numrows = idealrows;
- clock_win = subwin(stdscr, numrows, maxx, row, 0);
-
- refresh();
+ win = subwin(stdscr, maxy - 2, maxx, 1, 0);
- return numrows + row;
-}
+ switch (selectedwindow) {
+ case REGULATOR: regulator_win = win;
+ break;
-int create_sensor_win(int row, int maxrows, int *pshare)
-{
- int numrows;
- int idealrows;
+ case CLOCK: clock_win = win;
+ break;
- if (sensor_win) {
- delwin(sensor_win);
- sensor_win = NULL;
+ case SENSOR: sensor_win = win;
+ break;
}
- getmaxyx(stdscr, maxy, maxx);
- idealrows = ((maxy - 2) * (*pshare)) / 100;
-
- if (maxrows < idealrows)
- numrows = maxrows;
- else
- numrows = idealrows;
- sensor_win = subwin(stdscr, numrows, maxx, row, 0);
-
+ selected_win = win;
+
refresh();
-
- return numrows + row;
}
void show_header(void)
{
int i, j = 0;
+ //char format[64];
wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR));
werase(header_win);
- print(header_win, 0, 0, "PowerDebug version %s (C) Linaro",
+ print(header_win, 0, 0, "PowerDebug %s",
VERSION);
- print(header_win, 50, 0, "Refresh Rate %4.2f Secs",
- ticktime);
+ //print(header_win, 50, 0, "Refresh Rate %4.2f Secs", ticktime);
+
+ for (i = 0; i < TOTAL_FEATURE_WINS; i++) {
+ if (selectedwindow == i)
+ wattron(header_win, A_REVERSE);
+ else
+ wattroff(header_win, A_REVERSE);
+
+ //sprintf(format, " %%-%ds ", sizeof(win_names[i]) + 2);
+ //sprintf(format, " %%s ");
+
+ print(header_win, i*(maxx / TOTAL_FEATURE_WINS) + 20, 0,
+ " %s ", win_names[i]);
+ }
+ wrefresh(header_win);
- wrefresh(header_win);
werase(footer_win);
@@ -210,21 +174,18 @@ void show_header(void)
void show_regulator_info(int verbose)
{
- int i, count = 2;
+ int i, count = 1;
werase(regulator_win);
wattron(regulator_win, A_BOLD);
- wattron(regulator_win, A_STANDOUT);
- print(regulator_win, 0, 0, "Regulator Information");
- wattroff(regulator_win, A_STANDOUT);
- print(regulator_win, 0, 1, "Name");
- print(regulator_win, 12, 1, "Status");
- print(regulator_win, 24, 1, "State");
- print(regulator_win, 36, 1, "Type");
- print(regulator_win, 48, 1, "Users");
- print(regulator_win, 60, 1, "Microvolts");
- print(regulator_win, 72, 1, "Min u-volts");
- print(regulator_win, 84, 1, "Max u-volts");
+ print(regulator_win, 0, 0, "Name");
+ print(regulator_win, 12, 0, "Status");
+ print(regulator_win, 24, 0, "State");
+ print(regulator_win, 36, 0, "Type");
+ print(regulator_win, 48, 0, "Users");
+ print(regulator_win, 60, 0, "Microvolts");
+ print(regulator_win, 72, 0, "Min u-volts");
+ print(regulator_win, 84, 0, "Max u-volts");
wattroff(regulator_win, A_BOLD);
for (i=0; i<numregulators; i++) {
@@ -273,14 +234,10 @@ void print_clock_header(int level)
sprintf(lev, "(Level %d)\n", level);
werase(clock_win);
wattron(clock_win, A_BOLD);
- wattron(clock_win, A_STANDOUT);
- print(clock_win, 0, 0, "Clock Information");
- wattroff(clock_win, A_STANDOUT);
- print(clock_win, 0, 1, "Name");
- print(clock_win, 24, 1, "Flags");
- print(clock_win, 36, 1, "Rate");
- print(clock_win, 48, 1, "Usecount");
- print(clock_win, 60, 1, lev);
+ print(clock_win, 0, 0, "Name %s", lev);
+ print(clock_win, 48, 0, "Flags");
+ print(clock_win, 60, 0, "Rate");
+ print(clock_win, 72, 0, "Usecount");
wattroff(clock_win, A_BOLD);
wrefresh(clock_win);
}
@@ -289,14 +246,11 @@ void print_sensor_header(void)
{
werase(sensor_win);
wattron(sensor_win, A_BOLD);
- wattron(sensor_win, A_STANDOUT);
- print(sensor_win, 0, 0, "Sensor Information");
- wattroff(sensor_win, A_STANDOUT);
- print(sensor_win, 0, 1, "Name");
- print(sensor_win, 36, 1, "Temperature");
+ print(sensor_win, 0, 0, "Name");
+ print(sensor_win, 36, 0, "Temperature");
wattroff(sensor_win, A_BOLD);
wattron(sensor_win, A_BLINK);
- print(sensor_win, 0, 2, "Currently Sensor information available"
+ print(sensor_win, 0, 1, "Currently Sensor information available"
" only in Dump mode!");
wattroff(sensor_win, A_BLINK);
wrefresh(sensor_win);
@@ -317,11 +271,11 @@ void print_clock_info_line(int line, char *clockname, int flags, int rate,
else
wattroff(clock_win, WA_REVERSE);
- print(clock_win, 0, line + 2, "%s", clockname);
+ print(clock_win, 0, line + 1, "%s", clockname);
if (strcmp(clockname, "..")) {
- print(clock_win, 24, line + 2, "%d", flags);
- print(clock_win, 36, line + 2, "%d", rate);
- print(clock_win, 48, line + 2, "%d", usecount);
+ print(clock_win, 48, line + 1, "%d", flags);
+ print(clock_win, 60, line + 1, "%d", rate);
+ print(clock_win, 72, line + 1, "%d", usecount);
}
if (highlight)
diff --git a/powerdebug.c b/powerdebug.c
index 87e60bc..8c84932 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -20,8 +20,14 @@
int numregulators;
int dump;
int highlighted_row;
+int selectedwindow = -1;
double ticktime = 10.0; /* in seconds */
+char *win_names[TOTAL_FEATURE_WINS] = {
+ "Regulators",
+ "Clocks",
+ "Sensors" };
+
int init_regulator_ds(void)
{
DIR *regdir;
@@ -228,17 +234,20 @@ exit:
int main(int argc, char **argv)
{
- int c;
- int firsttime = 1;
+ int c, i;
+ int firsttime[TOTAL_FEATURE_WINS];
int enter_hit = 0;
int regulators = 0, sensors = 0, clocks = 0, verbose = 0;
int r_share = 0, s_share = 0, c_share = 0; //%age share of the win size
+ for (i = 0; i < TOTAL_FEATURE_WINS; i++)
+ firsttime[i] = 1;
+
/*
* Options:
- * -r, --regulator : regulator
- * -s, --sensor : sensors
- * -c, --clock : clocks
+ * -r, --regulator : regulator
+ * -s, --sensor : sensors
+ * -c, --clock : clocks
* -t, --time : ticktime
* -d, --dump : dump
* -v, --verbose : verbose
@@ -250,9 +259,9 @@ int main(int argc, char **argv)
while (1) {
int optindex = 0;
static struct option long_options[] = {
- {"regulator", 0, 0, 'r'},
- {"sensor", 0, 0, 's'},
- {"clock", 0, 0, 'c'},
+ {"regulator", 0, 0, 'r'},
+ {"sensor", 0, 0, 's'},
+ {"clock", 0, 0, 'c'},
{"time", 0, 0, 't'},
{"dump", 0, 0, 'd'},
{"verbose", 0, 0, 'v'},
@@ -266,15 +275,18 @@ int main(int argc, char **argv)
break;
switch (c) {
- case 'r':
- regulators = 1;
- break;
- case 's':
- sensors = 1;
- break;
- case 'c':
- clocks = 1;
- break;
+ case 'r':
+ regulators = 1;
+ selectedwindow = REGULATOR;
+ break;
+ case 's':
+ sensors = 1;
+ selectedwindow = SENSOR;
+ break;
+ case 'c':
+ clocks = 1;
+ selectedwindow = CLOCK;
+ break;
case 't':
ticktime = strtod(optarg, NULL);
break;
@@ -300,11 +312,13 @@ int main(int argc, char **argv)
}
}
+ if (!dump && (regulators || clocks || sensors)) {
+ fprintf(stderr, "Option supported only in dump mode (-d)\n");
+ usage(argv);
+ }
- /* Need atleast one option specified */
- if (!regulators && !sensors && !clocks) {
- usage(argv);
- }
+ if (!dump)
+ selectedwindow = REGULATOR;
init_regulator_ds();
@@ -312,10 +326,9 @@ int main(int argc, char **argv)
int key = 0;
struct timeval tval;
fd_set readfds;
- int row = 1;
if (!dump) {
- if(firsttime)
+ if(firsttime[0])
init_curses();
create_windows();
show_header();
@@ -332,29 +345,25 @@ int main(int argc, char **argv)
c_share = 100 - (r_share + s_share);
}
- if (regulators) {
+ if (selectedwindow == REGULATOR) {
read_regulator_info();
if (!dump) {
- int orig_r_share = r_share;
-
- row = create_regulator_win(row,
- numregulators + 2,
- &r_share);
- c_share += (orig_r_share - r_share);
+ create_selectedwindow();
show_regulator_info(verbose);
}
else
print_regulator_info(verbose);
}
- if (clocks) {
- if (firsttime)
+ if (selectedwindow == CLOCK) {
+ if (firsttime[CLOCK]) {
init_clock_details();
+ firsttime[CLOCK] = 0;
+ }
if (!dump) {
int hrow;
- //giv big no. in second arg as of now
- row = create_clock_win(row, 100, &c_share);
+ create_selectedwindow();
hrow = read_and_print_clock_info(verbose,
highlighted_row,
enter_hit);
@@ -364,9 +373,9 @@ int main(int argc, char **argv)
dump_clock_info(verbose);
}
- if (sensors) {
+ if (selectedwindow == SENSOR) {
if (!dump) {
- row = create_sensor_win(row, 100, &s_share);//big no. as of now
+ create_selectedwindow();
print_sensor_header();
}
else
@@ -386,14 +395,36 @@ int main(int argc, char **argv)
if (key) {
char keychar;
- int keystroke = fgetc(stdin);
+ //int keystroke = fgetc(stdin);
+ int keystroke = getch();
if (keystroke == EOF)
exit(0);
- if (keystroke == 9)
- highlighted_row++;
+ if (keystroke == KEY_RIGHT || keystroke == 9)
+ selectedwindow++;
+
+ if (keystroke == KEY_LEFT || keystroke == 353)
+ selectedwindow--;
+
+ if (selectedwindow >= TOTAL_FEATURE_WINS)
+ selectedwindow = 0;
+
+ if (selectedwindow < 0)
+ selectedwindow = TOTAL_FEATURE_WINS - 1;
+
+ if (selectedwindow == CLOCK) {
+ if (keystroke == KEY_DOWN)
+ highlighted_row++;
+ if (keystroke == KEY_UP && highlighted_row > 0)
+ highlighted_row--;
+ }
keychar = toupper(keystroke);
+
+ //killall_windows(1); fini_curses();
+ //printf("key entered %d:%c\n", keystroke, keychar);
+ //exit(1);
+
if (keystroke == 13)
enter_hit = 1;
@@ -402,8 +433,6 @@ int main(int argc, char **argv)
if (keychar == 'R')
ticktime = 3;
}
- if (firsttime)
- firsttime = 0;
}
exit(0);
diff --git a/powerdebug.h b/powerdebug.h
index 6b7f665..6ce68cd 100644
--- a/powerdebug.h
+++ b/powerdebug.h
@@ -26,6 +26,13 @@
#define VERSION "1.0"
#define VALUE_MAX 16
+#define TOTAL_FEATURE_WINS 3 /* Regulator, Clock and Sensor (for now) */
+
+WINDOW windows[TOTAL_FEATURE_WINS];
+extern char *win_names[TOTAL_FEATURE_WINS];
+
+enum {REGULATOR, CLOCK, SENSOR};
+extern int selectedwindow;
struct regulator_info {
char name[NAME_MAX];
@@ -82,10 +89,8 @@ extern void print_clock_info_line(int line, char *clockname, int flags,
extern void init_curses(void);
extern void fini_curses(void);
-extern void killall_windows(void);
+extern void killall_windows(int all);
extern void show_header(void);
extern void create_windows(void);
-extern int create_regulator_win(int row, int numrows, int *pshare);
-extern int create_clock_win(int row, int numrows, int *pshare);
-extern int create_sensor_win(int row, int numrows, int *pshare);
+extern void create_selectedwindow(void);
extern void show_regulator_info(int verbose);