From 2b444c310d6dc1d7d5ada7502d3c6ad942919782 Mon Sep 17 00:00:00 2001 From: Nathael Pajani Date: Wed, 14 Sep 2016 01:22:00 +0200 Subject: [PATCH] Set sensor as not present upon I2C communication errors --- extdrv/tmp101_temp_sensor.c | 34 +++++++++++++++++++--------------- extdrv/tsl256x_light_sensor.c | 3 +++ extdrv/veml6070_uv_sensor.c | 3 +++ 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/extdrv/tmp101_temp_sensor.c b/extdrv/tmp101_temp_sensor.c index 3d1313e..47e13d9 100644 --- a/extdrv/tmp101_temp_sensor.c +++ b/extdrv/tmp101_temp_sensor.c @@ -119,16 +119,18 @@ int tmp101_sensor_read(struct tmp101_sensor_config* conf, uint16_t* raw, int* de conf->last_accessed_register = TMP_REG_TEMPERATURE; } - if (ret == 2) { - if (raw != NULL) { - *raw = byte_swap_16(temp); - } - if (deci_degrees != NULL) { - *deci_degrees = tmp101_convert_to_deci_degrees(byte_swap_16(temp)); - } - return 0; + if (ret != 2) { + conf->probe_ok = 0; + return ret; } - return ret; + + if (raw != NULL) { + *raw = byte_swap_16(temp); + } + if (deci_degrees != NULL) { + *deci_degrees = tmp101_convert_to_deci_degrees(byte_swap_16(temp)); + } + return 0; } @@ -163,10 +165,11 @@ int tmp101_sensor_config(struct tmp101_sensor_config* conf) msleep(1); ret = i2c_write(conf->bus_num, cmd, 3, NULL); conf->last_accessed_register = TMP_REG_CONFIG; - if (ret == 3) { - return 0; /* Config success */ + if (ret != 3) { + conf->probe_ok = 0; + return ret; } - return ret; + return 0; /* Config success */ } /* Start a conversion when the sensor is in shutdown mode. */ @@ -183,10 +186,11 @@ int tmp101_sensor_start_conversion(struct tmp101_sensor_config* conf) cmd[2] |= TMP_ONE_SHOT_TRIGGER; ret = i2c_write(conf->bus_num, cmd, 3, NULL); conf->last_accessed_register = TMP_REG_CONFIG; - if (ret == 3) { - return 0; /* Conversion start success */ + if (ret != 3) { + conf->probe_ok = 0; + return ret; } - return ret; + return 0; /* Conversion start success */ } diff --git a/extdrv/tsl256x_light_sensor.c b/extdrv/tsl256x_light_sensor.c index b08dc46..967613b 100644 --- a/extdrv/tsl256x_light_sensor.c +++ b/extdrv/tsl256x_light_sensor.c @@ -83,6 +83,7 @@ int tsl256x_read_id(struct tsl256x_sensor_config* conf) } ret = i2c_read(conf->bus_num, cmd_buf, ID_BUF_SIZE, ctrl_buf, &id, 1); if (ret != 1) { + conf->probe_ok = 0; return ret; } return id; @@ -114,6 +115,7 @@ int tsl256x_sensor_read(struct tsl256x_sensor_config* conf, uint16_t* comb, uint ret = i2c_read(conf->bus_num, cmd_buf, READ_BUF_SIZE, ctrl_buf, data, 4); if (ret != 4) { + conf->probe_ok = 0; return ret; } comb_raw = (data[0] & 0xFF) | ((data[1] << 8) & 0xFF00); @@ -159,6 +161,7 @@ int tsl256x_configure(struct tsl256x_sensor_config* conf) } ret = i2c_write(conf->bus_num, cmd_buf, CONF_BUF_SIZE, NULL); if (ret != CONF_BUF_SIZE) { + conf->probe_ok = 0; return -EIO; } return 0; diff --git a/extdrv/veml6070_uv_sensor.c b/extdrv/veml6070_uv_sensor.c index 5f019a3..abb6337 100644 --- a/extdrv/veml6070_uv_sensor.c +++ b/extdrv/veml6070_uv_sensor.c @@ -73,6 +73,7 @@ int veml6070_sensor_read(struct veml6070_sensor_config* conf, uint16_t* uv_raw) cmd_buf = ((conf->addr + 2) | I2C_READ_BIT); ret = i2c_read(conf->bus_num, &cmd_buf, 1, NULL, &data, 1); if (ret != 1) { + conf->probe_ok = 0; return ret; } *uv_raw = ((uint16_t)data << 8) & 0xFF00; @@ -81,6 +82,7 @@ int veml6070_sensor_read(struct veml6070_sensor_config* conf, uint16_t* uv_raw) cmd_buf = (conf->addr | I2C_READ_BIT); ret = i2c_read(conf->bus_num, &cmd_buf, 1, NULL, &data, 1); if (ret != 1) { + conf->probe_ok = 0; return ret; } *uv_raw |= (uint16_t)data & 0x00FF; @@ -113,6 +115,7 @@ int veml6070_configure(struct veml6070_sensor_config* conf) msleep(1); ret = i2c_write(conf->bus_num, cmd_buf, CONF_BUF_SIZE, NULL); if (ret != CONF_BUF_SIZE) { + conf->probe_ok = 0; return -EIO; } return 0; -- 2.43.0