Skip to content

Commit 919b3f9

Browse files
bbilasMaureenHelm
authored andcommitted
drivers: sensor: ina23x: fix sample fetching
Fix the usage of sensor shell module that calls sensor_sample_fetch function with SENSOR_CHAN_ALL id which is not supported and causes the following error: uart:~$ sensor get INA237 current Failed to read sensor: -134 channel idx=31 current = 0.000000 Fix that by adding support for SENSOR_CHAN_ALL channel id. Signed-off-by: Bartosz Bilas <[email protected]>
1 parent 262b5b1 commit 919b3f9

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

drivers/sensor/ina23x/ina23x.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -159,33 +159,35 @@ static int ina23x_sample_fetch(const struct device *dev,
159159
struct ina23x_data *ina23x = dev->data;
160160
int ret;
161161

162-
switch (chan) {
163-
case SENSOR_CHAN_VOLTAGE:
162+
if (chan != SENSOR_CHAN_ALL &&
163+
chan != SENSOR_CHAN_VOLTAGE &&
164+
chan != SENSOR_CHAN_CURRENT &&
165+
chan != SENSOR_CHAN_POWER) {
166+
return -ENOTSUP;
167+
}
168+
169+
if ((chan == SENSOR_CHAN_ALL) || (chan == SENSOR_CHAN_VOLTAGE)) {
164170
ret = ina23x_reg_read(dev, INA23X_REG_BUS_VOLT, &ina23x->bus_voltage);
165171
if (ret < 0) {
166172
LOG_ERR("Failed to read bus voltage");
167173
return ret;
168174
}
169-
break;
175+
}
170176

171-
case SENSOR_CHAN_CURRENT:
177+
if ((chan == SENSOR_CHAN_ALL) || (chan == SENSOR_CHAN_CURRENT)) {
172178
ret = ina23x_reg_read(dev, INA23X_REG_CURRENT, &ina23x->current);
173179
if (ret < 0) {
174180
LOG_ERR("Failed to read current");
175181
return ret;
176182
}
177-
break;
183+
}
178184

179-
case SENSOR_CHAN_POWER:
185+
if ((chan == SENSOR_CHAN_ALL) || (chan == SENSOR_CHAN_POWER)) {
180186
ret = ina23x_reg_read(dev, INA23X_REG_POWER, &ina23x->power);
181187
if (ret < 0) {
182188
LOG_ERR("Failed to read power");
183189
return ret;
184190
}
185-
break;
186-
187-
default:
188-
return -ENOTSUP;
189191
}
190192

191193
return 0;

0 commit comments

Comments
 (0)