aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Lezcano <daniel.lezcano@linaro.org>2011-06-15 15:45:12 +0200
committerDaniel Lezcano <daniel.lezcano@linaro.org>2011-06-15 15:45:12 +0200
commit176e69dd96d7bee2effcfb52cd8fbad570c89d0e (patch)
tree389f714ca7e6f05201da19a68771f0bd330858eb
parent156274830b76fc80b27508a6bf9cbc6151c15d48 (diff)
downloadpowerdebug-176e69dd96d7bee2effcfb52cd8fbad570c89d0e.tar.gz
Encapsulate the display (10)
The keystroke callback could be moved to the display code. Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
-rw-r--r--display.c48
-rw-r--r--display.h8
-rw-r--r--powerdebug.c45
3 files changed, 49 insertions, 52 deletions
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;
}