From e74cabf923ec419712477e0522300b098492f218 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Wed, 9 Jan 2019 07:49:19 -0600 Subject: [PATCH] Cosmetic changes from review of last PR. --- drivers/sensors/scd30.c | 10 ++++++++-- drivers/sensors/sgp30.c | 20 +++++++++++++------- drivers/sensors/sps30.c | 34 ++++++++++++++++++++++++---------- include/nuttx/sensors/sps30.h | 2 ++ 4 files changed, 47 insertions(+), 19 deletions(-) diff --git a/drivers/sensors/scd30.c b/drivers/sensors/scd30.c index e7148af3ad..a1e13ce4f4 100644 --- a/drivers/sensors/scd30.c +++ b/drivers/sensors/scd30.c @@ -287,6 +287,7 @@ static int scd30_write_cmd(FAR struct scd30_dev_s *priv, uint16_t cmd, return (ret >= 0) ? OK : ret; #else /* UART mode not implemented yet. */ + return -ENODEV; #endif } @@ -315,6 +316,7 @@ static int scd30_read_words(FAR struct scd30_dev_s *priv, return (ret >= 0) ? OK : ret; #else /* UART mode not implemented yet. */ + return -ENODEV; #endif } @@ -390,7 +392,9 @@ static int scd30_check_data_crc(FAR const struct scd30_word_s *words, while (num_words) { if (scd30_crc_word(scd30_data_word_to_uint16(words)) != words->crc) - return -1; + { + return -1; + } num_words--; words++; @@ -413,7 +417,9 @@ static int scd30_softreset(FAR struct scd30_dev_s *priv) ret = scd30_write_cmd(priv, SCD30_CMD_SOFT_RESET, NULL, 0); if (ret < 0) - return ret; + { + return ret; + } return 0; } diff --git a/drivers/sensors/sgp30.c b/drivers/sensors/sgp30.c index 85108b95ca..dc89eb5878 100644 --- a/drivers/sensors/sgp30.c +++ b/drivers/sensors/sgp30.c @@ -137,17 +137,17 @@ static int sgp30_measure_raw(FAR struct sgp30_dev_s *priv, /* Character driver methods */ #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS -static int sgp30_open(FAR struct file *filep); -static int sgp30_close(FAR struct file *filep); +static int sgp30_open(FAR struct file *filep); +static int sgp30_close(FAR struct file *filep); #endif static ssize_t sgp30_read(FAR struct file *filep, FAR char *buffer, size_t buflen); static ssize_t sgp30_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); -static int sgp30_ioctl(FAR struct file *filep, int cmd, - unsigned long arg); +static int sgp30_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS -static int sgp30_unlink(FAR struct inode *inode); +static int sgp30_unlink(FAR struct inode *inode); #endif /**************************************************************************** @@ -326,10 +326,14 @@ static int sgp30_read_cmd(FAR struct sgp30_dev_s *priv, struct sgp30_cmd_s cmd, msg[0].length = 2; ret = sgp30_do_transfer(priv->i2c, msg, 1); + sgp30_dbg("cmd: 0x%04X delay: %uus ret: %d\n", cmd.address, cmd.read_delay_usec, ret); + if (ret < 0) - return ret; + { + return ret; + } up_udelay(cmd.read_delay_usec + 100); @@ -400,7 +404,9 @@ static int sgp30_check_data_crc(FAR const struct sgp30_word_s *words, while (num_words) { if (sgp30_crc_word(sgp30_data_word_to_uint16(words)) != words->crc) - return -1; + { + return -1; + } num_words--; words++; diff --git a/drivers/sensors/sps30.c b/drivers/sensors/sps30.c index 11f77fba78..63fd644f28 100644 --- a/drivers/sensors/sps30.c +++ b/drivers/sensors/sps30.c @@ -158,17 +158,17 @@ static int sps30_read_dev_info(FAR struct sps30_dev_s *priv, uint16_t cmd, /* Character driver methods */ #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS -static int sps30_open(FAR struct file *filep); -static int sps30_close(FAR struct file *filep); +static int sps30_open(FAR struct file *filep); +static int sps30_close(FAR struct file *filep); #endif static ssize_t sps30_read(FAR struct file *filep, FAR char *buffer, size_t buflen); static ssize_t sps30_write(FAR struct file *filep, FAR const char *buffer, size_t buflen); -static int sps30_ioctl(FAR struct file *filep, int cmd, - unsigned long arg); +static int sps30_ioctl(FAR struct file *filep, int cmd, + unsigned long arg); #ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS -static int sps30_unlink(FAR struct inode *inode); +static int sps30_unlink(FAR struct inode *inode); #endif /**************************************************************************** @@ -281,6 +281,7 @@ static int sps30_write_cmd(FAR struct sps30_dev_s *priv, uint16_t cmd, return (ret >= 0) ? OK : ret; #else /* UART mode not implemented yet. */ + return -ENODEV; #endif } @@ -308,9 +309,13 @@ static int sps30_read_cmd(FAR struct sps30_dev_s *priv, uint16_t cmd, msg[0].length = 2; ret = sps30_do_transfer(priv->i2c, msg, 1); + sps30_dbg("cmd: 0x%04X ret: %d\n", cmd, ret); + if (ret < 0) - return ret; + { + return ret; + } msg[0].frequency = CONFIG_SPS30_I2C_FREQUENCY; msg[0].addr = priv->addr; @@ -325,6 +330,7 @@ static int sps30_read_cmd(FAR struct sps30_dev_s *priv, uint16_t cmd, return (ret >= 0) ? OK : ret; #else /* UART mode not implemented yet. */ + return -ENODEV; #endif } @@ -400,7 +406,9 @@ static int sps30_check_data_crc(FAR const struct sps30_word_s *words, while (num_words) { if (sps30_crc_word(sps30_data_word_to_uint16(words)) != words->crc) - return -1; + { + return -1; + } num_words--; words++; @@ -423,7 +431,9 @@ static int sps30_softreset(FAR struct sps30_dev_s *priv) ret = sps30_write_cmd(priv, SPS30_CMD_SOFT_RESET, NULL, 0); if (ret < 0) - return ret; + { + return ret; + } return 0; } @@ -600,7 +610,9 @@ static int sps30_read_dev_info(FAR struct sps30_dev_s *priv, uint16_t cmd, } if (outlen) - *out = '\0'; + { + *out = '\0'; + } return ret; } @@ -959,7 +971,9 @@ static int sps30_ioctl(FAR struct file *filep, int cmd, unsigned long arg) } if (arg > 0 && arg < 15) - arg = 15; + { + arg = 15; + } sps30_set_command_param(¶m, arg); ret = sps30_write_cmd(priv, SPS30_CMD_SET_AUTO_CLEANING_INTERVAL, diff --git a/include/nuttx/sensors/sps30.h b/include/nuttx/sensors/sps30.h index 2ee6d5a8a6..675fe53bdb 100644 --- a/include/nuttx/sensors/sps30.h +++ b/include/nuttx/sensors/sps30.h @@ -58,6 +58,7 @@ struct sps30_conv_data_s /* Mass Concentrations for particle ranges PM1.0, PM2.5, PM4.0, PM10. * Unit is [µg/m³] (microgram per cubicmeter). */ + float mass_concenration_pm1_0; float mass_concenration_pm2_5; float mass_concenration_pm4_0; @@ -74,6 +75,7 @@ struct sps30_conv_data_s float number_concenration_pm10; /* Typical particle size. Unit is [µm] (micrometer). */ + float typical_particle_size; };