Skip to content

Commit 46a3bbb

Browse files
Jeppe Odgaardfabiobaltieri
authored andcommitted
drivers: sensor: ti: tmp11x: fix get ambient offset
The sensor value was accidentally set a second time. Refactor `tmp11x_attr_get` to fix the issue and align more with `tmp11x_attr_set`. Signed-off-by: Jeppe Odgaard <[email protected]>
1 parent a068709 commit 46a3bbb

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

drivers/sensor/ti/tmp11x/tmp11x.c

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -365,31 +365,29 @@ static int tmp11x_attr_get(const struct device *dev, enum sensor_channel chan,
365365
switch (attr) {
366366
case SENSOR_ATTR_CONFIGURATION:
367367
rc = tmp11x_reg_read(dev, TMP11X_REG_CFGR, &data);
368-
if (rc < 0) {
369-
return rc;
368+
369+
if (rc == 0) {
370+
val->val1 = data;
371+
val->val2 = 0;
370372
}
371-
break;
373+
374+
return rc;
375+
372376
case SENSOR_ATTR_OFFSET:
373377
if (!tmp11x_is_offset_supported(dev->data)) {
374378
LOG_ERR("%s: Offset is not supported", dev->name);
375379
return -EINVAL;
376380
}
377381

378382
rc = tmp11x_reg_read(dev, TMP117_REG_TEMP_OFFSET, &data);
379-
if (rc < 0) {
380-
return rc;
383+
if (rc == 0) {
384+
tmp11x_temperature_to_sensor_value(data, val);
381385
}
382386

383-
tmp11x_temperature_to_sensor_value(data, val);
384-
break;
387+
return rc;
385388
default:
386389
return -ENOTSUP;
387390
}
388-
389-
val->val1 = data;
390-
val->val2 = 0;
391-
392-
return 0;
393391
}
394392

395393
static DEVICE_API(sensor, tmp11x_driver_api) = {

0 commit comments

Comments
 (0)