From patchwork Wed Jun 15 13:50:43 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1931 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 26CCE24B1C for ; Wed, 15 Jun 2011 13:52:43 +0000 (UTC) Received: from mail-qy0-f180.google.com (mail-qy0-f180.google.com [209.85.216.180]) by fiordland.canonical.com (Postfix) with ESMTP id EAFF8A18976 for ; Wed, 15 Jun 2011 13:52:42 +0000 (UTC) Received: by mail-qy0-f180.google.com with SMTP id 10so261357qyk.11 for ; Wed, 15 Jun 2011 06:52:42 -0700 (PDT) Received: by 10.52.112.106 with SMTP id ip10mr794029vdb.127.1308145962604; Wed, 15 Jun 2011 06:52:42 -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 em2cs126635vdc; Wed, 15 Jun 2011 06:52:42 -0700 (PDT) Received: by 10.216.237.96 with SMTP id x74mr2195718weq.53.1308145960655; Wed, 15 Jun 2011 06:52:40 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by mx.google.com with ESMTP id o4si1394443wbh.9.2011.06.15.06.52.40; Wed, 15 Jun 2011 06:52:40 -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 wDsa1g00D1hMfSL03DsfCc; Wed, 15 Jun 2011 15:52:39 +0200 From: Daniel Lezcano To: daniel.lezcano@linaro.org Cc: linaro-dev@lists.linaro.org, patches@linaro.org Subject: [powerdebug 09/22] Encapsulate the display (2) Date: Wed, 15 Jun 2011 15:50:43 +0200 Message-Id: <1308145856-6112-9-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> Remove the specific cases in the mainloop and encapsulate the display functions. Signed-off-by: Daniel Lezcano --- display.c | 56 ++++++++++++++++++++++++++++++++++++++------------------ display.h | 6 ++++++ powerdebug.c | 26 +++++++++----------------- powerdebug.h | 2 -- 4 files changed, 53 insertions(+), 37 deletions(-) diff --git a/display.c b/display.c index fa7d93a..384714b 100644 --- a/display.c +++ b/display.c @@ -31,6 +31,7 @@ enum { PT_COLOR_DEFAULT = 1, static WINDOW *header_win; static WINDOW *footer_win; +static int current_win; int maxx, maxy; @@ -103,6 +104,8 @@ int display_init(int wdefault) int i; size_t array_size = sizeof(windata) / sizeof(windata[0]); + current_win = wdefault; + if (!initscr()) return -1; @@ -204,6 +207,23 @@ void print_sensor_header(void) show_header_footer(SENSOR); } +int display_next_panel(void) +{ + current_win++; + current_win %= TOTAL_FEATURE_WINS; + + return current_win; +} + +int display_prev_panel(void) +{ + current_win--; + if (current_win < 0) + current_win = TOTAL_FEATURE_WINS - 1; + + return current_win; +} + int display_refresh_pad(int win) { return prefresh(windata[win].pad, windata[win].scrolling, @@ -285,50 +305,50 @@ int display_print_line(int win, int line, char *str, int bold, void *data) return 0; } -int display_next_line(int win) +int display_next_line(void) { - int cursor = windata[win].cursor; - int nrdata = windata[win].nrdata; - int scrolling = windata[win].scrolling; - struct rowdata *rowdata = windata[win].rowdata; + int cursor = windata[current_win].cursor; + int nrdata = windata[current_win].nrdata; + int scrolling = windata[current_win].scrolling; + struct rowdata *rowdata = windata[current_win].rowdata; if (cursor >= nrdata) return cursor; - display_unselect(win, cursor, rowdata[cursor].attr); + display_unselect(current_win, cursor, rowdata[cursor].attr); if (cursor < nrdata - 1) { if (cursor >= (maxy - 4 + scrolling)) scrolling++; cursor++; } - display_select(win, cursor); + display_select(current_win, cursor); - windata[win].scrolling = scrolling; - windata[win].cursor = cursor; + windata[current_win].scrolling = scrolling; + windata[current_win].cursor = cursor; return cursor; } -int display_prev_line(int win) +int display_prev_line(void) { - int cursor = windata[win].cursor; - int nrdata = windata[win].nrdata; - int scrolling = windata[win].scrolling; - struct rowdata *rowdata = windata[win].rowdata; + int cursor = windata[current_win].cursor; + int nrdata = windata[current_win].nrdata; + int scrolling = windata[current_win].scrolling; + struct rowdata *rowdata = windata[current_win].rowdata; if (cursor >= nrdata) return cursor; - display_unselect(win, cursor, rowdata[cursor].attr); + display_unselect(current_win, cursor, rowdata[cursor].attr); if (cursor > 0) { if (cursor <= scrolling) scrolling--; cursor--; } - display_select(win, cursor); + display_select(current_win, cursor); - windata[win].scrolling = scrolling; - windata[win].cursor = cursor; + windata[current_win].scrolling = scrolling; + windata[current_win].cursor = cursor; return cursor; } diff --git a/display.h b/display.h index 0b407fb..9c0e38a 100644 --- a/display.h +++ b/display.h @@ -14,3 +14,9 @@ *******************************************************************************/ extern int display_init(int wdefault); + +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); diff --git a/powerdebug.c b/powerdebug.c index 4d94829..e702011 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -164,24 +164,19 @@ int keystroke_callback(bool *enter_hit, bool *findparent_ncurses, if (keystroke == EOF) exit(0); - if (keystroke == KEY_RIGHT || keystroke == '\t') { - options->selectedwindow++; - options->selectedwindow %= TOTAL_FEATURE_WINS; - } + if (keystroke == KEY_RIGHT || keystroke == '\t') + options->selectedwindow = display_next_panel(); - if (keystroke == KEY_LEFT || keystroke == KEY_BTAB) { - options->selectedwindow--; - if (options->selectedwindow < 0) - options->selectedwindow = TOTAL_FEATURE_WINS - 1; - } + if (keystroke == KEY_LEFT || keystroke == KEY_BTAB) + options->selectedwindow = display_prev_panel(); if (keystroke == KEY_DOWN) { - display_next_line(options->selectedwindow); + display_next_line(); *cont = true; } if (keystroke == KEY_UP) { - display_prev_line(options->selectedwindow); + display_prev_line(); *cont = true; } @@ -258,12 +253,12 @@ int mainloop(struct powerdebug_options *options) struct timeval tval; fd_set readfds; - /* if (options->selectedwindow != CLOCK || !cont) */ - /* show_header(options->selectedwindow); */ - if (options->selectedwindow == REGULATOR) regulator_display(); + if (options->selectedwindow == SENSOR) + sensor_display(); + if (options->selectedwindow == CLOCK) { if (!cont) { @@ -281,9 +276,6 @@ int mainloop(struct powerdebug_options *options) } else cont = false; } - if (options->selectedwindow == SENSOR) - sensor_display(); - FD_ZERO(&readfds); FD_SET(0, &readfds); tval.tv_sec = options->ticktime; diff --git a/powerdebug.h b/powerdebug.h index 712acb2..df39a8a 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -34,8 +34,6 @@ extern int display_print_line(int window, int line, char *str, extern int display_refresh_pad(int window); extern int display_reset_cursor(int window); -extern int display_next_line(int window); -extern int display_prev_line(int window); extern void *display_get_row_data(int window); extern int clock_toggle_expanded(void);