diff mbox

[powerdebug,19/22] Encapsulate the display (10)

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

Commit Message

Daniel Lezcano June 15, 2011, 1:50 p.m. UTC
The keystroke callback could be moved to the display code.

Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
---
 display.c    |   48 +++++++++++++++++++++++++++++++++++++++++++++++-
 display.h    |    8 +-------
 powerdebug.c |   45 +--------------------------------------------
 3 files changed, 49 insertions(+), 52 deletions(-)
diff mbox

Patch

diff --git a/display.c b/display.c
index 3c79737..5fad059 100644
--- a/display.c
+++ b/display.c
@@ -21,6 +21,8 @@ 
 #include "regulator.h"
 #include "display.h"
 
+#define TOTAL_FEATURE_WINS 3  /* Regulator, Clock and Sensor (for now) */
+
 #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0)
 
 enum { PT_COLOR_DEFAULT = 1,
@@ -61,7 +63,7 @@  struct windata {
 	int cursor;
 };
 
-struct windata windata[TOTAL_FEATURE_WINS] = {
+struct windata windata[] = {
 	{ .name = "Clocks"     },
 	{ .name = "Regulators" },
 	{ .name = "Sensors"    },
@@ -383,3 +385,47 @@  int display_prev_line(void)
 
 	return cursor;
 }
+
+int display_keystroke(void *data)
+{
+	int *tick = data;
+	int keystroke = getch();
+
+	switch (keystroke) {
+
+	case KEY_RIGHT:
+	case '\t':
+		display_next_panel();
+		break;
+
+	case KEY_LEFT:
+	case KEY_BTAB:
+		display_prev_panel();
+		break;
+
+	case KEY_DOWN:
+		display_next_line();
+		break;
+
+	case KEY_UP:
+		display_prev_line();
+		break;
+
+	case '\r':
+		display_select();
+		break;
+
+	case EOF:
+	case 'q':
+	case 'Q':
+		return 1;
+
+	case 'r':
+	case 'R':
+		display_refresh();
+		*tick = 3;
+		break;
+	}
+
+	return 0;
+}
diff --git a/display.h b/display.h
index 7e6b199..ebd501a 100644
--- a/display.h
+++ b/display.h
@@ -13,8 +13,6 @@ 
  *       - initial API and implementation
  *******************************************************************************/
 
-#define TOTAL_FEATURE_WINS 3  /* Regulator, Clock and Sensor (for now) */
-
 struct display_ops {
 	int (*display)(void);
 	int (*select)(void);
@@ -29,12 +27,8 @@  extern void *display_get_row_data(int window);
 
 extern int display_init(int wdefault);
 extern int display_register(int win, struct display_ops *ops);
-extern int display_next_panel(void);
-extern int display_prev_panel(void);
-extern int display_next_line(void);
-extern int display_prev_line(void);
 extern int display_refresh(void);
-extern int display_select(void);
+extern int display_keystroke(void *data);
 
 /* FIXME */
 extern void print_sensor_header(void);
diff --git a/powerdebug.c b/powerdebug.c
index 5d834c7..065fa31 100644
--- a/powerdebug.c
+++ b/powerdebug.c
@@ -157,49 +157,6 @@  int getoptions(int argc, char *argv[], struct powerdebug_options *options)
 	return 0;
 }
 
-int keystroke_callback(struct powerdebug_options *options)
-{
-	int keystroke = getch();
-
-	switch (keystroke) {
-
-	case KEY_RIGHT:
-	case '\t':
-		display_next_panel();
-		break;
-
-	case KEY_LEFT:
-	case KEY_BTAB:
-		display_prev_panel();
-		break;
-
-	case KEY_DOWN:
-		display_next_line();
-		break;
-
-	case KEY_UP:
-		display_prev_line();
-		break;
-
-	case '\r':
-		display_select();
-		break;
-
-	case EOF:
-	case 'q':
-	case 'Q':
-		return 1;
-
-	case 'r':
-	case 'R':
-		display_refresh();
-		options->ticktime = 3;
-		break;
-	}
-
-	return 0;
-}
-
 int mainloop(struct powerdebug_options *options)
 {
 	while (1) {
@@ -225,7 +182,7 @@  int mainloop(struct powerdebug_options *options)
 			break;
 		}
 
-		if (keystroke_callback(options))
+		if (display_keystroke(&options->ticktime))
 			break;
 	}