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)
CONFIGURED_APPS += examples/powermonitor
CONFIGURED_APPS += examples/powermonitor
endif

View File

@ -36,8 +36,8 @@
-include $(TOPDIR)/Make.defs
APPNAME = powermonitor
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 768
PRIORITY = SCHED_PRIORITY_DEFAULT
STACKSIZE = 768
ASRCS =
CSRCS =

View File

@ -33,6 +33,10 @@
*
****************************************************************************/
/******************************************************************************
* Included Files
******************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
@ -48,40 +52,58 @@
#include <nuttx/sensors/ltc4151.h>
//#include <nuttx/board.h>
/******************************************************************************
* 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, &ltc, 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, &ltc, 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;