From 411e05346030178e640debb5acf75c709d8b8693 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Fri, 28 Jul 2017 09:14:47 -0600 Subject: [PATCH] Review of last PR. Changes to make consistent with NuttX coding standard. --- examples/powermonitor/Make.defs | 2 +- examples/powermonitor/Makefile | 4 +- examples/powermonitor/powermonitor_main.c | 64 +++++++++++++++-------- 3 files changed, 46 insertions(+), 24 deletions(-) diff --git a/examples/powermonitor/Make.defs b/examples/powermonitor/Make.defs index 84d39a1d0..235f34df2 100644 --- a/examples/powermonitor/Make.defs +++ b/examples/powermonitor/Make.defs @@ -35,5 +35,5 @@ ############################################################################ ifeq ($(CONFIG_EXAMPLES_POWERMONITOR),y) -CONFIGURED_APPS += examples/powermonitor + CONFIGURED_APPS += examples/powermonitor endif diff --git a/examples/powermonitor/Makefile b/examples/powermonitor/Makefile index 0b0c3647a..ab7aa15b1 100644 --- a/examples/powermonitor/Makefile +++ b/examples/powermonitor/Makefile @@ -36,8 +36,8 @@ -include $(TOPDIR)/Make.defs APPNAME = powermonitor -PRIORITY = SCHED_PRIORITY_DEFAULT -STACKSIZE = 768 +PRIORITY = SCHED_PRIORITY_DEFAULT +STACKSIZE = 768 ASRCS = CSRCS = diff --git a/examples/powermonitor/powermonitor_main.c b/examples/powermonitor/powermonitor_main.c index 0dca24deb..4767ef35e 100644 --- a/examples/powermonitor/powermonitor_main.c +++ b/examples/powermonitor/powermonitor_main.c @@ -33,6 +33,10 @@ * ****************************************************************************/ +/****************************************************************************** + * Included Files + ******************************************************************************/ + #include #include @@ -48,40 +52,58 @@ #include -//#include +/****************************************************************************** + * Pre-processor Definitions + ******************************************************************************/ #define DECIMAL_PLACES3(x) abs(((int)(((x)-((int)x))*1000))) +/****************************************************************************** + * Public Functions + ******************************************************************************/ + #ifdef CONFIG_BUILD_KERNEL int main(int argc, char *argv[]) #else int powermonitor_main(int argc, char *argv[]) #endif { - char* pwrmntr_dev = "/dev/pwrmntr0"; - - int samples = 1; - if (argc > 1) { - samples = atoi(argv[1]); - } - - int pwrmntr_fd = open(pwrmntr_dev, O_RDONLY); - if (!pwrmntr_fd) { - printf("Failed to open %s: %d\n", pwrmntr_dev, errno); - return 1; - } - + static FAR const char *pwrmntr_dev = "/dev/pwrmntr0"; + float float_current; + float float_voltage; ltc4151_t ltc; + int pwrmntr_fd; + int samples; int sample; - for (sample = 0; sample < samples; ++sample) { - if (read(pwrmntr_fd, <c, sizeof(ltc)) < 0) { - printf("Failed to read from %s: %d\n", pwrmntr_dev, errno); + + samples = 1; + if (argc > 1) + { + samples = atoi(argv[1]); + } + + pwrmntr_fd = open(pwrmntr_dev, O_RDONLY); + if (pwrmntr_fd < 0) + { + printf("Failed to open %s: %d\n", pwrmntr_dev, errno); return 1; } - float float_current = b16tof(ltc.current); - float float_voltage = b16tof(ltc.voltage); - printf("Current: %d.%03dmA - Voltage: %d.%03dV\n", (int)float_current, DECIMAL_PLACES3(float_current), (int)float_voltage, DECIMAL_PLACES3(float_voltage)); - } + + for (sample = 0; sample < samples; ++sample) + { + if (read(pwrmntr_fd, <c, sizeof(ltc)) < 0) + { + printf("Failed to read from %s: %d\n", pwrmntr_dev, errno); + return 1; + } + + float_current = b16tof(ltc.current); + float_voltage = b16tof(ltc.voltage); + + printf("Current: %d.%03dmA - Voltage: %d.%03dV\n", + (int)float_current, DECIMAL_PLACES3(float_current), + (int)float_voltage, DECIMAL_PLACES3(float_voltage)); + } close(pwrmntr_fd); return 0;