[POWERDEBUG] Pressing "R" to refresh does not update regulator and sensor values

Message ID 1377003019-13435-1-git-send-email-shaojie.sun@linaro.com
State New
Headers show

Commit Message

sunshaojie Aug. 20, 2013, 12:50 p.m.
Fix this bug, and read regulator and sensor datas again when "R"
key pressed.

Signed-off-by: Shaojie Sun <shaojie.sun@linaro.com>
---
 regulator.c |   43 ++++++++++++++++++++++++++++---------------
 sensor.c    |   17 +++++++++++++++--
 2 files changed, 43 insertions(+), 17 deletions(-)

Patch

diff --git a/regulator.c b/regulator.c
index 68c686f..9cd89fd 100644
--- a/regulator.c
+++ b/regulator.c
@@ -160,21 +160,6 @@  static int regulator_print_header(void)
 
 }
 
-static int regulator_display(bool refresh)
-{
-	int ret, line = 0;
-
-	display_reset_cursor(REGULATOR);
-
-	regulator_print_header();
-
-	ret = tree_for_each(reg_tree, regulator_display_cb, &line);
-
-	display_refresh_pad(REGULATOR);
-
-	return ret;
-}
-
 static int regulator_filter_cb(const char *name)
 {
 	/* let's ignore some directories in order to avoid to be
@@ -213,6 +198,34 @@  static inline int read_regulator_cb(struct tree *t, void *data)
 	return 0;
 }
 
+static int read_regulator_info(struct tree *tree)
+{
+	return tree_for_each(tree, read_regulator_cb, NULL);
+}
+
+static int regulator_print_info(struct tree *tree)
+{
+	int ret, line = 0;
+
+	display_reset_cursor(REGULATOR);
+
+	regulator_print_header();
+
+	ret = tree_for_each(tree, regulator_display_cb, &line);
+
+	display_refresh_pad(REGULATOR);
+
+	return ret;
+}
+
+static int regulator_display(bool refresh)
+{
+	if (refresh && read_regulator_info(reg_tree))
+		return -1;
+
+	return regulator_print_info(reg_tree);
+}
+
 static int fill_regulator_cb(struct tree *t, void *data)
 {
 	struct regulator_info *reg;
diff --git a/sensor.c b/sensor.c
index bd8c354..0645d25 100644
--- a/sensor.c
+++ b/sensor.c
@@ -161,6 +161,11 @@  static int read_sensor_cb(struct tree *tree, void *data)
 	return 0;
 }
 
+static int read_sensor_info(struct tree *tree)
+{
+	return tree_for_each(tree, read_sensor_cb, NULL);
+}
+
 static int fill_sensor_cb(struct tree *t, void *data)
 {
 	struct sensor_info *sensor;
@@ -250,7 +255,7 @@  static int sensor_print_header(void)
 	return ret;
 }
 
-static int sensor_display(bool refresh)
+static int sensor_print_info(struct tree *tree)
 {
 	int ret, line = 0;
 
@@ -258,13 +263,21 @@  static int sensor_display(bool refresh)
 
 	sensor_print_header();
 
-	ret = tree_for_each(sensor_tree, sensor_display_cb, &line);
+	ret = tree_for_each(tree, sensor_display_cb, &line);
 
 	display_refresh_pad(SENSOR);
 
 	return ret;
 }
 
+static int sensor_display(bool refresh)
+{
+	if (refresh && read_sensor_info(sensor_tree))
+		return -1;
+
+	return sensor_print_info(sensor_tree);
+}
+
 static struct display_ops sensor_ops = {
 	.display = sensor_display,
 };