diff mbox

[powerdebug,05/22] assign a pad for each window

Message ID 1308145856-6112-5-git-send-email-daniel.lezcano@linaro.org
State Accepted
Headers show

Commit Message

Daniel Lezcano June 15, 2011, 1:50 p.m. UTC
Create a pad for each pm blocks, so we can use the same code
to scroll the values on the display.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 display.c |  141 ++++++++++++++++++-------------------------------------------
 1 files changed, 41 insertions(+), 100 deletions(-)
diff mbox

Patch

diff --git a/display.c b/display.c
index 3795547..b417459 100644
--- a/display.c
+++ b/display.c
@@ -31,10 +31,6 @@  enum { PT_COLOR_DEFAULT = 1,
 };
 
 static WINDOW *header_win;
-static WINDOW *regulator_win;
-static WINDOW *clock_pad;
-static WINDOW *clock_labels;
-static WINDOW *sensor_win;
 static WINDOW *footer_win;
 
 int maxx, maxy;
@@ -50,6 +46,8 @@  struct rowdata {
 };
 
 struct windata {
+	WINDOW *win;
+	WINDOW *pad;
 	struct rowdata *rowdata;
 	char *name;
 	int nrdata;
@@ -70,6 +68,9 @@  static void display_fini(void)
 
 int display_init(void)
 {
+	int i;
+	size_t array_size = sizeof(windata) / sizeof(windata[0]);
+
 	if (!initscr())
 		return -1;
 
@@ -97,21 +98,17 @@  int display_init(void)
 
 	getmaxyx(stdscr, maxy, maxx);
 
-	regulator_win = subwin(stdscr, maxy - 2, maxx, 1, 0);
-	if (!regulator_win)
-		return -1;
+	for (i = 0; i < array_size; i++) {
 
-	clock_labels = subwin(stdscr, maxy - 2, maxx, 1, 0);
-	if (!clock_labels)
-		return -1;
+		windata[i].win = subwin(stdscr, maxy - 2, maxx, 1, 0);
+		if (!windata[i].win)
+			return -1;
 
-	clock_pad = newpad(maxrows, maxx);
-	if (!clock_pad)
-		return -1;
+		windata[i].pad = newpad(maxrows, maxx);
+		if (!windata[i].pad)
+			return -1;
 
-	sensor_win = subwin(stdscr, maxy - 2, maxx, 1, 0);
-	if (!sensor_win)
-		return -1;
+	}
 
 	header_win = subwin(stdscr, 1, maxx, 0, 0);
 	if (!header_win)
@@ -142,17 +139,9 @@  void create_windows(int selectedwindow)
 
 }
 
-void create_selectedwindow(int selectedwindow)
+void create_selectedwindow(int win)
 {
-	switch (selectedwindow) {
-	case REGULATOR:
-		wrefresh(regulator_win);
-		break;
-
-	case SENSOR:
-		wrefresh(sensor_win);
-		break;
-	}
+	wrefresh(windata[win].win);
 }
 
 void show_header(int selectedwindow)
@@ -192,6 +181,8 @@  void show_header(int selectedwindow)
 
 void print_regulator_header(void)
 {
+	WINDOW *regulator_win = windata[REGULATOR].win;
+
 	werase(regulator_win);
 	wattron(regulator_win, A_BOLD);
 	print(regulator_win, 0, 0, "Name");
@@ -208,73 +199,23 @@  void print_regulator_header(void)
 
 void print_clock_header(void)
 {
-	werase(clock_labels);
-	wattron(clock_labels, A_BOLD);
-	print(clock_labels, 0, 0, "Name");
-	print(clock_labels, 56, 0, "Flags");
-	print(clock_labels, 75, 0, "Rate");
-	print(clock_labels, 88, 0, "Usecount");
-	print(clock_labels, 98, 0, "Children");
-	wattroff(clock_labels, A_BOLD);
-	wrefresh(clock_labels);
+	WINDOW *clock_win = windata[CLOCK].win;
+
+	werase(clock_win);
+	wattron(clock_win, A_BOLD);
+	print(clock_win, 0, 0, "Name");
+	print(clock_win, 56, 0, "Flags");
+	print(clock_win, 75, 0, "Rate");
+	print(clock_win, 88, 0, "Usecount");
+	print(clock_win, 98, 0, "Children");
+	wattroff(clock_win, A_BOLD);
+	wrefresh(clock_win);
 }
 
-#if 0
-void show_regulator_info(struct regulator_info *reg_info, int nr_reg, int verbose)
-{
-	int i, count = 1;
-
-	print_regulator_header();
-
-	wrefresh(regulator_win);
-
-	return;
-
-	(void)verbose;
-
-	for (i = 0; i < nr_reg; i++) {
-		int col = 0;
-
-		if ((i + 2) > (maxy-2))
-			break;
-
-		if (reg_info[i].num_users > 0)
-			wattron(regulator_win, WA_BOLD);
-		else
-			wattroff(regulator_win, WA_BOLD);
-
-		print(regulator_win, col, count, "%s",
-			reg_info[i].name);
-		col += 12;
-		print(regulator_win, col, count, "%s",
-			reg_info[i].status);
-		col += 12;
-		print(regulator_win, col, count, "%s",
-			reg_info[i].state);
-		col += 12;
-		print(regulator_win, col, count, "%s",
-			reg_info[i].type);
-		col += 12;
-		print(regulator_win, col, count, "%d",
-			reg_info[i].num_users);
-		col += 12;
-		print(regulator_win, col, count, "%d",
-			reg_info[i].microvolts);
-		col += 12;
-		print(regulator_win, col, count, "%d",
-			reg_info[i].min_microvolts);
-		col += 12;
-		print(regulator_win, col, count, "%d",
-			reg_info[i].max_microvolts);
-
-		count++;
-	}
-	wrefresh(regulator_win);
-}
-#endif
-
 void print_sensor_header(void)
 {
+	WINDOW *sensor_win = windata[SENSOR].win;
+
 	werase(sensor_win);
 	wattron(sensor_win, A_BOLD);
 	print(sensor_win, 0, 0, "Name");
@@ -289,14 +230,14 @@  void print_sensor_header(void)
 
 int display_refresh_pad(int win)
 {
-	return prefresh(clock_pad, windata[win].scrolling,
+	return prefresh(windata[win].pad, windata[win].scrolling,
 			0, 2, 0, maxy - 2, maxx);
 }
 
-static int inline display_clock_un_select(int win, int line,
+static int inline display_un_select(int win, int line,
 					  bool highlight, bool bold)
 {
-	if (mvwchgat(clock_pad, line, 0, -1,
+	if (mvwchgat(windata[win].pad, line, 0, -1,
 		     highlight ? WA_STANDOUT :
 		     bold ? WA_BOLD: WA_NORMAL, 0, NULL) < 0)
 		return -1;
@@ -306,12 +247,12 @@  static int inline display_clock_un_select(int win, int line,
 
 int display_select(int win, int line)
 {
-	return display_clock_un_select(win, line, true, false);
+	return display_un_select(win, line, true, false);
 }
 
 int display_unselect(int win, int line, bool bold)
 {
-	return display_clock_un_select(win, line, false, bold);
+	return display_un_select(win, line, false, bold);
 }
 
 void *display_get_row_data(int win)
@@ -337,11 +278,11 @@  int display_set_row_data(int win, int line, void *data, int attr)
 	return 0;
 }
 
-int display_reset_cursor(win)
+int display_reset_cursor(int win)
 {
 	windata[win].nrdata = 0;
-	werase(clock_pad);
-	return wmove(clock_pad, 0, 0);
+	werase(windata[win].pad);
+	return wmove(windata[win].pad, 0, 0);
 }
 
 int display_print_line(int win, int line, char *str, int bold, void *data)
@@ -358,12 +299,12 @@  int display_print_line(int win, int line, char *str, int bold, void *data)
 		return -1;
 
 	if (attr)
-		wattron(clock_pad, attr);
+		wattron(windata[win].pad, attr);
 
-	wprintw(clock_pad, "%s\n", str);
+	wprintw(windata[win].pad, "%s\n", str);
 
 	if (attr)
-		wattroff(clock_pad, attr);
+		wattroff(windata[win].pad, attr);
 
 	return 0;
 }