From patchwork Wed Jun 15 13:50:42 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1930 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 B1DF823DE6 for ; Wed, 15 Jun 2011 13:52:42 +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 81937A18976 for ; Wed, 15 Jun 2011 13:52:42 +0000 (UTC) Received: by mail-vx0-f180.google.com with SMTP id 12so410110vxk.11 for ; Wed, 15 Jun 2011 06:52:42 -0700 (PDT) Received: by 10.52.162.72 with SMTP id xy8mr817636vdb.87.1308145962153; 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 em2cs126634vdc; Wed, 15 Jun 2011 06:52:41 -0700 (PDT) Received: by 10.227.2.144 with SMTP id 16mr674444wbj.9.1308145960014; 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 fr1si1389327wbb.36.2011.06.15.06.52.39; 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 wDsa1g00D1hMfSL03DseCT; 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 08/22] Encapsulate the display (1) Date: Wed, 15 Jun 2011 15:50:42 +0200 Message-Id: <1308145856-6112-8-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 some corner cases for the footer display we have the same display feature for all the pm blocks. Signed-off-by: Daniel Lezcano --- display.c | 104 +++++++++++++++++++++++---------------------------------- display.h | 2 +- powerdebug.c | 9 ++--- powerdebug.h | 20 ++--------- 4 files changed, 49 insertions(+), 86 deletions(-) diff --git a/display.c b/display.c index c6a68a7..fa7d93a 100644 --- a/display.c +++ b/display.c @@ -18,7 +18,6 @@ #include "display.h" #define print(w, x, y, fmt, args...) do { mvwprintw(w, y, x, fmt, ##args); } while (0) -#define NUM_FOOTER_ITEMS 5 enum { PT_COLOR_DEFAULT = 1, PT_COLOR_HEADER_BAR, @@ -38,7 +37,8 @@ int maxx, maxy; /* Number of lines in the virtual window */ static const int maxrows = 1024; -static char footer_items[NUM_FOOTER_ITEMS][64]; +#define footer_label " Q (Quit) R (Refresh) Other Keys: 'Left', " \ + "'Right' , 'Up', 'Down', 'enter', , 'Esc'" struct rowdata { int attr; @@ -66,7 +66,39 @@ static void display_fini(void) endwin(); } -int display_init(void) +static int show_header_footer(int win) +{ + int i; + int curr_pointer = 0; + + wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); + wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); + werase(header_win); + + print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); + curr_pointer += 20; + + for (i = 0; i < TOTAL_FEATURE_WINS; i++) { + if (win == i) + wattron(header_win, A_REVERSE); + else + wattroff(header_win, A_REVERSE); + + print(header_win, curr_pointer, 0, " %s ", windata[i].name); + curr_pointer += strlen(windata[i].name) + 2; + } + wrefresh(header_win); + werase(footer_win); + + wattron(footer_win, A_REVERSE); + print(footer_win, 0, 0, "%s", footer_label); + wattroff(footer_win, A_REVERSE); + wrefresh(footer_win); + + return 0; +} + +int display_init(int wdefault) { int i; size_t array_size = sizeof(windata) / sizeof(windata[0]); @@ -118,65 +150,7 @@ int display_init(void) if (!footer_win) return -1; - return 0; -} - -void create_windows(int selectedwindow) -{ - strcpy(footer_items[0], " Q (Quit) "); - strcpy(footer_items[1], " R (Refresh) "); - - if (selectedwindow == CLOCK) - strcpy(footer_items[2], " Other Keys: 'Left', 'Right', 'Up', 'Down', 'enter', " - " '/', 'Esc' "); - else - strcpy(footer_items[2], " Other Keys: 'Left', 'Right' "); - - strcpy(footer_items[3], ""); - - werase(stdscr); - refresh(); - -} - -void create_selectedwindow(int win) -{ - wrefresh(windata[win].win); -} - -void show_header(int selectedwindow) -{ - int i, j = 0; - int curr_pointer = 0; - - wattrset(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); - wbkgd(header_win, COLOR_PAIR(PT_COLOR_HEADER_BAR)); - werase(header_win); - - print(header_win, curr_pointer, 0, "PowerDebug %s", VERSION); - curr_pointer += 20; - - for (i = 0; i < TOTAL_FEATURE_WINS; i++) { - if (selectedwindow == i) - wattron(header_win, A_REVERSE); - else - wattroff(header_win, A_REVERSE); - - print(header_win, curr_pointer, 0, " %s ", windata[i].name); - curr_pointer += strlen(windata[i].name) + 2; - } - wrefresh(header_win); - werase(footer_win); - - for (i = 0; i < NUM_FOOTER_ITEMS; i++) { - if (strlen(footer_items[i]) == 0) - continue; - wattron(footer_win, A_REVERSE); - print(footer_win, j, 0, "%s", footer_items[i]); - wattroff(footer_win, A_REVERSE); - j+= strlen(footer_items[i])+1; - } - wrefresh(footer_win); + return show_header_footer(wdefault); } void print_regulator_header(void) @@ -195,6 +169,8 @@ void print_regulator_header(void) print(regulator_win, 84, 0, "Max u-volts"); wattroff(regulator_win, A_BOLD); wrefresh(regulator_win); + + show_header_footer(REGULATOR); } void print_clock_header(void) @@ -210,6 +186,8 @@ void print_clock_header(void) print(clock_win, 98, 0, "Children"); wattroff(clock_win, A_BOLD); wrefresh(clock_win); + + show_header_footer(CLOCK); } void print_sensor_header(void) @@ -222,6 +200,8 @@ void print_sensor_header(void) print(sensor_win, 36, 0, "Value"); wattroff(sensor_win, A_BOLD); wrefresh(sensor_win); + + show_header_footer(SENSOR); } int display_refresh_pad(int win) diff --git a/display.h b/display.h index 047d674..0b407fb 100644 --- a/display.h +++ b/display.h @@ -13,4 +13,4 @@ * - initial API and implementation *******************************************************************************/ -extern int display_init(void); +extern int display_init(int wdefault); diff --git a/powerdebug.c b/powerdebug.c index 0eee7c5..4d94829 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -258,11 +258,8 @@ int mainloop(struct powerdebug_options *options) struct timeval tval; fd_set readfds; - if (options->selectedwindow != CLOCK || !cont) { - create_windows(options->selectedwindow); - show_header(options->selectedwindow); - create_selectedwindow(options->selectedwindow); - } + /* if (options->selectedwindow != CLOCK || !cont) */ + /* show_header(options->selectedwindow); */ if (options->selectedwindow == REGULATOR) regulator_display(); @@ -328,7 +325,7 @@ static int powerdebug_dump(struct powerdebug_options *options) static int powerdebug_display(struct powerdebug_options *options) { - if (display_init()) { + if (display_init(options->selectedwindow)) { printf("failed to initialize display\n"); return -1; } diff --git a/powerdebug.h b/powerdebug.h index 7175839..712acb2 100644 --- a/powerdebug.h +++ b/powerdebug.h @@ -28,13 +28,7 @@ enum {CLOCK, REGULATOR, SENSOR}; enum {CLOCK_SELECTED = 1, REFRESH_WINDOW}; -extern int read_and_dump_clock_info(char *clk); extern void find_parents_for_clock(char *clkname, int complete); -extern int read_and_print_clock_info(void); -extern int print_clock_info(int hrow, int selected); -extern void print_string_val(char *name, char *val); -extern void print_clock_header(void); - extern int display_print_line(int window, int line, char *str, int bold, void *data); @@ -45,16 +39,8 @@ extern int display_prev_line(int window); extern void *display_get_row_data(int window); extern int clock_toggle_expanded(void); -extern int display_clock_select(int window, int line); -extern int display_clock_unselect(int window, int line, bool bold); - -extern void get_sensor_info(char *path, char *name, char *sensor, int verbose); -extern int sensor_dump(void); +extern int regulator_display(void); extern void print_sensor_header(void); +extern void print_clock_header(void); +extern void print_regulator_header(void); -extern void killall_windows(int all); -extern void show_header(int selectedwindow); -extern void create_windows(int selectedwindow); -extern void create_selectedwindow(int selectedwindow); - -extern int regulator_display(void);