From patchwork Wed Jun 15 13:50:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1937 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 4AA8623DE6 for ; Wed, 15 Jun 2011 13:52:46 +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 1AA71A186F5 for ; Wed, 15 Jun 2011 13:52:46 +0000 (UTC) Received: by mail-vx0-f180.google.com with SMTP id 12so410110vxk.11 for ; Wed, 15 Jun 2011 06:52:45 -0700 (PDT) Received: by 10.52.162.72 with SMTP id xy8mr817737vdb.87.1308145965861; Wed, 15 Jun 2011 06:52:45 -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 em2cs126644vdc; Wed, 15 Jun 2011 06:52:45 -0700 (PDT) Received: by 10.227.104.2 with SMTP id m2mr641058wbo.35.1308145964677; Wed, 15 Jun 2011 06:52:44 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by mx.google.com with ESMTP id fq6si1392955wbb.15.2011.06.15.06.52.44; Wed, 15 Jun 2011 06:52:44 -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 wDsa1g00D1hMfSL03DsjE8; Wed, 15 Jun 2011 15:52:44 +0200 From: Daniel Lezcano To: daniel.lezcano@linaro.org Cc: linaro-dev@lists.linaro.org, patches@linaro.org Subject: [powerdebug 17/22] change the keystroke callback for less test Date: Wed, 15 Jun 2011 15:50:51 +0200 Message-Id: <1308145856-6112-17-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> We can use a switch here to check the key which was stroke. Signed-off-by: Daniel Lezcano --- powerdebug.c | 43 +++++++++++++++++++++++++------------------ 1 files changed, 25 insertions(+), 18 deletions(-) diff --git a/powerdebug.c b/powerdebug.c index fccc08b..0b25860 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -155,35 +155,42 @@ int getoptions(int argc, char *argv[], struct powerdebug_options *options) int keystroke_callback(struct powerdebug_options *options) { - char keychar; int keystroke = getch(); - if (keystroke == EOF) - exit(0); + switch (keystroke) { - if (keystroke == KEY_RIGHT || keystroke == '\t') + case KEY_RIGHT: + case '\t': display_next_panel(); + break; - if (keystroke == KEY_LEFT || keystroke == KEY_BTAB) + case KEY_LEFT: + case KEY_BTAB: display_prev_panel(); + break; - if (keystroke == KEY_DOWN) + case KEY_DOWN: display_next_line(); + break; - if (keystroke == KEY_UP) + case KEY_UP: display_prev_line(); + break; - keychar = toupper(keystroke); - - if (keystroke == '\r') + case '\r': display_select(); + break; - if (keychar == 'Q') + case EOF: + case 'q': + case 'Q': return 1; - if (keychar == 'R') { + case 'r': + case 'R': display_refresh(); options->ticktime = 3; + break; } return 0; @@ -192,21 +199,23 @@ int keystroke_callback(struct powerdebug_options *options) int mainloop(struct powerdebug_options *options) { while (1) { - int key = 0; + int ret; struct timeval tval; fd_set readfds; + display_refresh(); + FD_ZERO(&readfds); FD_SET(0, &readfds); tval.tv_sec = options->ticktime; tval.tv_usec = (options->ticktime - tval.tv_sec) * 1000000; again: - key = select(1, &readfds, NULL, NULL, &tval); - if (!key) + ret = select(1, &readfds, NULL, NULL, &tval); + if (!ret) continue; - if (key < 0) { + if (ret < 0) { if (errno == EINTR) goto again; break; @@ -214,8 +223,6 @@ int mainloop(struct powerdebug_options *options) if (keystroke_callback(options)) break; - - display_refresh(); } return 0;