From patchwork Wed Jun 15 13:50:40 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Daniel Lezcano X-Patchwork-Id: 1925 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 74CBA23DE6 for ; Wed, 15 Jun 2011 13:52:41 +0000 (UTC) Received: from mail-vw0-f52.google.com (mail-vw0-f52.google.com [209.85.212.52]) by fiordland.canonical.com (Postfix) with ESMTP id 44987A1897A for ; Wed, 15 Jun 2011 13:52:41 +0000 (UTC) Received: by vws16 with SMTP id 16so416327vws.11 for ; Wed, 15 Jun 2011 06:52:40 -0700 (PDT) Received: by 10.52.108.101 with SMTP id hj5mr774031vdb.247.1308145960760; Wed, 15 Jun 2011 06:52:40 -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 em2cs126630vdc; Wed, 15 Jun 2011 06:52:40 -0700 (PDT) Received: by 10.216.231.89 with SMTP id k67mr587494weq.113.1308145958911; Wed, 15 Jun 2011 06:52:38 -0700 (PDT) Received: from smtp.smtpout.orange.fr (smtp05.smtpout.orange.fr [80.12.242.127]) by mx.google.com with ESMTP id v73si1391550weq.59.2011.06.15.06.52.38; Wed, 15 Jun 2011 06:52:38 -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 wDsa1g00D1hMfSL03DsdBf; Wed, 15 Jun 2011 15:52:38 +0200 From: Daniel Lezcano To: daniel.lezcano@linaro.org Cc: linaro-dev@lists.linaro.org, patches@linaro.org Subject: [powerdebug 06/22] add sensors display Date: Wed, 15 Jun 2011 15:50:40 +0200 Message-Id: <1308145856-6112-6-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> Add the sensor display. Signed-off-by: Daniel Lezcano --- display.c | 6 +----- powerdebug.c | 33 +++++++++------------------------ sensor.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 29 deletions(-) diff --git a/display.c b/display.c index b417459..c6a68a7 100644 --- a/display.c +++ b/display.c @@ -219,12 +219,8 @@ void print_sensor_header(void) werase(sensor_win); wattron(sensor_win, A_BOLD); print(sensor_win, 0, 0, "Name"); - print(sensor_win, 36, 0, "Temperature"); + print(sensor_win, 36, 0, "Value"); wattroff(sensor_win, A_BOLD); - wattron(sensor_win, A_BLINK); - print(sensor_win, 0, 1, "Currently Sensor information available" - " only in Dump mode!"); - wattroff(sensor_win, A_BLINK); wrefresh(sensor_win); } diff --git a/powerdebug.c b/powerdebug.c index 641673b..24db8c8 100644 --- a/powerdebug.c +++ b/powerdebug.c @@ -174,32 +174,17 @@ int keystroke_callback(bool *enter_hit, bool *findparent_ncurses, options->selectedwindow = TOTAL_FEATURE_WINS - 1; } -#if 0 /* TODO */ - if (options->selectedwindow == REGULATOR) { - - if (keystroke == KEY_DOWN) { - display_next_line(); - *cont = true; - } - - if (keystroke == KEY_UP) { - display_prev_line(); - *cont = true; - } - + if (keystroke == KEY_DOWN) { + display_next_line(options->selectedwindow); + *cont = true; } -#endif - if (options->selectedwindow == CLOCK) { - if (keystroke == KEY_DOWN) { - display_next_line(CLOCK); - *cont = true; - } + if (keystroke == KEY_UP) { + display_prev_line(options->selectedwindow); + *cont = true; + } - if (keystroke == KEY_UP) { - display_prev_line(CLOCK); - *cont = true; - } + if (options->selectedwindow == CLOCK) { #if 0 /* TODO : fix with a new panel applicable for all subsystems */ @@ -299,7 +284,7 @@ int mainloop(struct powerdebug_options *options) } if (options->selectedwindow == SENSOR) - print_sensor_header(); + sensor_display(); FD_ZERO(&readfds); FD_SET(0, &readfds); diff --git a/sensor.c b/sensor.c index f386f0c..9c97e72 100644 --- a/sensor.c +++ b/sensor.c @@ -13,6 +13,15 @@ * - initial API and implementation *******************************************************************************/ +#define _GNU_SOURCE +#include +#undef _GNU_SOURCE +#include +#include +#include +#include +#include + #include "powerdebug.h" #include "sensor.h" #include "tree.h" @@ -193,6 +202,53 @@ static int sensor_filter_cb(const char *name) return 0; } +static int sensor_display_cb(struct tree *t, void *data) +{ + struct sensor_info *sensor = t->private; + int *line = data; + char buf[1024]; + int i; + + if (!strlen(sensor->name)) + return 0; + + sprintf(buf, "%s", sensor->name); + display_print_line(SENSOR, *line, buf, 1, t); + + (*line)++; + + for (i = 0; i < sensor->nrtemps; i++) { + sprintf(buf, " %-35s%.1f °C", sensor->temperatures[i].name, + (float)sensor->temperatures[i].temp / 1000); + display_print_line(SENSOR, *line, buf, 0, t); + (*line)++; + } + + for (i = 0; i < sensor->nrfans; i++) { + sprintf(buf, " %-35s%d rpm", sensor->fans[i].name, + sensor->fans[i].rpms); + display_print_line(SENSOR, *line, buf, 0, t); + (*line)++; + } + + return 0; +} + +int sensor_display(void) +{ + int ret, line = 0; + + display_reset_cursor(SENSOR); + + print_sensor_header(); + + ret = tree_for_each(sensor_tree, sensor_display_cb, &line); + + display_refresh_pad(SENSOR); + + return ret; +} + int sensor_init(void) { sensor_tree = tree_load(SYSFS_SENSOR, sensor_filter_cb);