Review of last PR. Changes to make consistent with NuttX coding standard.

This commit is contained in:
Gregory Nutt 2017-07-28 09:14:47 -06:00
parent b28cea29ed
commit 411e053460
3 changed files with 46 additions and 24 deletions

View File

@ -35,5 +35,5 @@
############################################################################ ############################################################################
ifeq ($(CONFIG_EXAMPLES_POWERMONITOR),y) ifeq ($(CONFIG_EXAMPLES_POWERMONITOR),y)
CONFIGURED_APPS += examples/powermonitor CONFIGURED_APPS += examples/powermonitor
endif endif

View File

@ -33,6 +33,10 @@
* *
****************************************************************************/ ****************************************************************************/
/******************************************************************************
* Included Files
******************************************************************************/
#include <nuttx/config.h> #include <nuttx/config.h>
#include <stdint.h> #include <stdint.h>
@ -48,39 +52,57 @@
#include <nuttx/sensors/ltc4151.h> #include <nuttx/sensors/ltc4151.h>
//#include <nuttx/board.h> /******************************************************************************
* Pre-processor Definitions
******************************************************************************/
#define DECIMAL_PLACES3(x) abs(((int)(((x)-((int)x))*1000))) #define DECIMAL_PLACES3(x) abs(((int)(((x)-((int)x))*1000)))
/******************************************************************************
* Public Functions
******************************************************************************/
#ifdef CONFIG_BUILD_KERNEL #ifdef CONFIG_BUILD_KERNEL
int main(int argc, char *argv[]) int main(int argc, char *argv[])
#else #else
int powermonitor_main(int argc, char *argv[]) int powermonitor_main(int argc, char *argv[])
#endif #endif
{ {
char* pwrmntr_dev = "/dev/pwrmntr0"; static FAR const char *pwrmntr_dev = "/dev/pwrmntr0";
float float_current;
float float_voltage;
ltc4151_t ltc;
int pwrmntr_fd;
int samples;
int sample;
int samples = 1; samples = 1;
if (argc > 1) { if (argc > 1)
{
samples = atoi(argv[1]); samples = atoi(argv[1]);
} }
int pwrmntr_fd = open(pwrmntr_dev, O_RDONLY); pwrmntr_fd = open(pwrmntr_dev, O_RDONLY);
if (!pwrmntr_fd) { if (pwrmntr_fd < 0)
{
printf("Failed to open %s: %d\n", pwrmntr_dev, errno); printf("Failed to open %s: %d\n", pwrmntr_dev, errno);
return 1; return 1;
} }
ltc4151_t ltc; for (sample = 0; sample < samples; ++sample)
int sample; {
for (sample = 0; sample < samples; ++sample) { if (read(pwrmntr_fd, &ltc, sizeof(ltc)) < 0)
if (read(pwrmntr_fd, &ltc, sizeof(ltc)) < 0) { {
printf("Failed to read from %s: %d\n", pwrmntr_dev, errno); printf("Failed to read from %s: %d\n", pwrmntr_dev, errno);
return 1; return 1;
} }
float float_current = b16tof(ltc.current);
float float_voltage = b16tof(ltc.voltage); float_current = b16tof(ltc.current);
printf("Current: %d.%03dmA - Voltage: %d.%03dV\n", (int)float_current, DECIMAL_PLACES3(float_current), (int)float_voltage, DECIMAL_PLACES3(float_voltage)); 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); close(pwrmntr_fd);