Review of last PR.  Changes to make consistent with NuttX coding standard.
*
****************************************************************************/
+/******************************************************************************
+ * Included Files
+ ******************************************************************************/
+
#include <nuttx/config.h>
#include <stdint.h>
#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";
+ 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;
- if (argc > 1) {
+ samples = 1;
+ if (argc > 1)
+ {
samples = atoi(argv[1]);
}
- int pwrmntr_fd = open(pwrmntr_dev, O_RDONLY);
- if (!pwrmntr_fd) {
+ pwrmntr_fd = open(pwrmntr_dev, O_RDONLY);
+ if (pwrmntr_fd < 0)
+ {
printf("Failed to open %s: %d\n", pwrmntr_dev, errno);
return 1;
}
- ltc4151_t ltc;
- int sample;
- for (sample = 0; sample < samples; ++sample) {
- if (read(pwrmntr_fd, &ltc, sizeof(ltc)) < 0) {
+ 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 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));
+
+ 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);
