Add the sensor display.

Signed-off-by: Daniel Lezcano <daniel.lezc...@linaro.org>
---
 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 <stdio.h>
+#undef _GNU_SOURCE
+#include <sys/types.h>
+#include <stdbool.h>
+#include <dirent.h>
+#include <string.h>
+#include <stdlib.h>
+
 #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);
-- 
1.7.1


_______________________________________________
linaro-dev mailing list
linaro-dev@lists.linaro.org
http://lists.linaro.org/mailman/listinfo/linaro-dev

Reply via email to