[POWERDEBUG] display error on module pads

Message ID 1398157637-22242-1-git-send-email-sanjay.rawat@linaro.org
State New
Headers show

Commit Message

Sanjay Singh Rawat April 22, 2014, 9:07 a.m.
- Currently errors are displayed on stdout. This patch put the
error on subscreens.
- bug 1298171

Signed-off-by: Sanjay Singh Rawat <sanjay.rawat@linaro.org>
---
Not doing for clock window, as clock is the base window. Test exits
if the clock files are not found.
---
 display.c   |    9 +++++++++
 display.h   |    2 +-
 gpio.c      |   17 ++++++++++++++++-
 regulator.c |   20 +++++++++++++++++++-
 sensor.c    |   19 ++++++++++++++++++-
 5 files changed, 63 insertions(+), 4 deletions(-)

Patch

diff --git a/display.c b/display.c
index c0afe03..0000ee9 100644
--- a/display.c
+++ b/display.c
@@ -270,6 +270,15 @@  int display_reset_cursor(int win)
 	return wmove(windata[win].pad, 0, 0);
 }
 
+void display_message(int win, char *buf)
+{
+	display_reset_cursor(win);
+	wattron(windata[win].pad, WA_BOLD);
+	wprintw(windata[win].pad, "%s\n", buf);
+	wattroff(windata[win].pad, WA_BOLD);
+	display_refresh_pad(win);
+}
+
 int display_print_line(int win, int line, char *str, int bold, void *data)
 {
 	int attr = 0;
diff --git a/display.h b/display.h
index b28d26e..95cb846 100644
--- a/display.h
+++ b/display.h
@@ -25,7 +25,7 @@  struct display_ops {
 
 extern int display_print_line(int window, int line, char *str,
 			      int bold, void *data);
-
+extern void display_message(int window, char *buf);
 extern int display_refresh_pad(int window);
 extern int display_reset_cursor(int window);
 extern void *display_get_row_data(int window);
diff --git a/gpio.c b/gpio.c
index 7cc16f7..aa002ce 100644
--- a/gpio.c
+++ b/gpio.c
@@ -45,6 +45,7 @@  struct gpio_info {
 } *gpios_info;
 
 static struct tree *gpio_tree = NULL;
+static bool gpio_error = false;
 
 static struct gpio_info *gpio_alloc(void)
 {
@@ -258,6 +259,11 @@  static int gpio_print_info(struct tree *tree)
 
 static int gpio_display(bool refresh)
 {
+	if (gpio_error) {
+		display_message(GPIO, "error: path " SYSFS_GPIO " not found");
+		return -2;
+	}
+
 	if (refresh && read_gpio_info(gpio_tree))
 		return -1;
 
@@ -319,6 +325,15 @@  static struct display_ops gpio_ops = {
  */
 int gpio_init(void)
 {
+	int ret = 0;
+
+	ret = display_register(GPIO, &gpio_ops);
+	if (!ret)
+		printf("error: gpio display register failed");
+
+	if (access(SYSFS_GPIO, F_OK))
+		gpio_error = true; /* set the flag */
+
 	gpio_tree = tree_load(SYSFS_GPIO, gpio_filter_cb, false);
 	if (!gpio_tree)
 		return -1;
@@ -326,5 +341,5 @@  int gpio_init(void)
 	if (fill_gpio_tree())
 		return -1;
 
-	return display_register(GPIO, &gpio_ops);
+	return ret;
 }
diff --git a/regulator.c b/regulator.c
index 9cd89fd..8cf9288 100644
--- a/regulator.c
+++ b/regulator.c
@@ -28,6 +28,8 @@ 
 #include <dirent.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
+
 #include "display.h"
 #include "powerdebug.h"
 #include "tree.h"
@@ -68,6 +70,7 @@  static struct regulator_data regdata[] = {
 };
 
 static struct tree *reg_tree;
+static bool regulator_error = false;
 
 static struct regulator_info *regulator_alloc(void)
 {
@@ -220,6 +223,12 @@  static int regulator_print_info(struct tree *tree)
 
 static int regulator_display(bool refresh)
 {
+	if (regulator_error) {
+		display_message(REGULATOR,
+			"error: path " SYSFS_REGULATOR " not found");
+		return -2;
+	}
+
 	if (refresh && read_regulator_info(reg_tree))
 		return -1;
 
@@ -255,6 +264,15 @@  static struct display_ops regulator_ops = {
 
 int regulator_init(void)
 {
+	int ret = 0;
+
+	ret = display_register(REGULATOR, &regulator_ops);
+	if (!ret)
+		printf("error: regulator display register failed");
+
+	if (access(SYSFS_REGULATOR, F_OK))
+		regulator_error = true; /* set the flag */
+
 	reg_tree = tree_load(SYSFS_REGULATOR, regulator_filter_cb, false);
 	if (!reg_tree)
 		return -1;
@@ -262,5 +280,5 @@  int regulator_init(void)
 	if (fill_regulator_tree())
 		return -1;
 
-	return display_register(REGULATOR, &regulator_ops);
+	return ret;
 }
diff --git a/sensor.c b/sensor.c
index 0645d25..e4174eb 100644
--- a/sensor.c
+++ b/sensor.c
@@ -21,6 +21,7 @@ 
 #include <dirent.h>
 #include <string.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #include "powerdebug.h"
 #include "display.h"
@@ -31,6 +32,7 @@ 
 #define SYSFS_SENSOR "/sys/class/hwmon"
 
 static struct tree *sensor_tree;
+static bool sensor_error = false;
 
 struct temp_info {
 	char name[NAME_MAX];
@@ -272,6 +274,12 @@  static int sensor_print_info(struct tree *tree)
 
 static int sensor_display(bool refresh)
 {
+	if (sensor_error) {
+		display_message(SENSOR,
+			"error: path " SYSFS_SENSOR " not found");
+		return -2;
+	}
+
 	if (refresh && read_sensor_info(sensor_tree))
 		return -1;
 
@@ -284,6 +292,15 @@  static struct display_ops sensor_ops = {
 
 int sensor_init(void)
 {
+	int ret = 0;
+
+	ret = display_register(SENSOR, &sensor_ops);
+	if (!ret)
+		printf("error: sensor display register failed");
+
+	if (access(SYSFS_SENSOR, F_OK))
+		sensor_error = true; /* set the flag */
+
 	sensor_tree = tree_load(SYSFS_SENSOR, sensor_filter_cb, false);
 	if (!sensor_tree)
 		return -1;
@@ -291,5 +308,5 @@  int sensor_init(void)
 	if (fill_sensor_tree())
 		return -1;
 
-	return display_register(SENSOR, &sensor_ops);
+	return ret;
 }