From patchwork Wed Jun 15 13:50:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1942 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id 076EA24B1C for ; Wed, 15 Jun 2011 13:52:49 +0000 (UTC) Received: from mail-vx0-f180.google.com (mail-vx0-f180.google.com [209.85.220.180]) by fiordland.canonical.com (Postfix) with ESMTP id CB322A18972 for ; Wed, 15 Jun 2011 13:52:48 +0000 (UTC) Received: by mail-vx0-f180.google.com with SMTP id 12so410110vxk.11 for ; Wed, 15 Jun 2011 06:52:48 -0700 (PDT) Received: by 10.52.168.65 with SMTP id zu1mr795776vdb.207.1308145968069; Wed, 15 Jun 2011 06:52:48 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.52.183.130 with SMTP id em2cs126647vdc; Wed, 15 Jun 2011 06:52:47 -0700 (PDT) Received: by 10.227.206.133 with SMTP id fu5mr640631wbb.31.1308145965839; Wed, 15 Jun 2011 06:52:45 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by mx.google.com with ESMTP id fs18si1370623wbb.123.2011.06.15.06.52.45; Wed, 15 Jun 2011 06:52:45 -0700 (PDT) Received-SPF: neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) client-ip=80.12.242.127; Authentication-Results: mx.google.com; spf=neutral (google.com: 80.12.242.127 is neither permitted nor denied by best guess record for domain of daniel.lezcano@linaro.org) smtp.mail=daniel.lezcano@linaro.org Received: from monster.dhcp.lxc ([92.134.76.78]) by mwinf5d28 with ME id wDsa1g00D1hMfSL03DskEJ; Wed, 15 Jun 2011 15:52:45 +0200 From: Daniel Lezcano To: daniel.lezcano@linaro.org Cc: linaro-dev@lists.linaro.org, patches@linaro.org Subject: [powerdebug 19/22] Encapsulate the display (10) Date: Wed, 15 Jun 2011 15:50:53 +0200 Message-Id: <1308145856-6112-19-git-send-email-daniel.lezcano@linaro.org> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1308145856-6112-1-git-send-email-daniel.lezcano@linaro.org> References: <1308145856-6112-1-git-send-email-daniel.lezcano@linaro.org> The keystroke callback could be moved to the display code. Signed-off-by: Daniel Lezcano --- display.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- display.h | 8 +------- powerdebug.c | 45 +-------------------------------------------- 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; }