samples: sensor: bq274xx: Read all gauge channel individually.

Read all the remaining gauge channel individually.

Signed-off-by: NavinSankar Velliangiri <navin@linumiz.com>
This commit is contained in:
NavinSankar Velliangiri 2020-09-24 20:48:41 +05:30 committed by Maureen Helm
parent 4c0b32405d
commit a7135bca17

View file

@ -48,79 +48,155 @@ static void do_main(const struct device *dev)
printk("Voltage: %d.%06dV\n", voltage.val1, voltage.val2);
status = sensor_sample_fetch_chan(dev,
SENSOR_CHAN_GAUGE_AVG_CURRENT);
if (status < 0) {
printk("Unable to fetch the Average current\n");
return;
}
status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_AVG_CURRENT,
&current);
if (status < 0) {
printk("Unable to get the current value\n");
return;
}
bq274xx_show_values("Avg Current in Amps", current);
status = sensor_channel_get(
dev, SENSOR_CHAN_GAUGE_STDBY_CURRENT, &current_standby);
status = sensor_sample_fetch_chan(dev,
SENSOR_CHAN_GAUGE_STDBY_CURRENT);
if (status < 0) {
printk("Unable to get the current value\n");
printk("Unable to fetch Standby Current\n");
return;
}
bq274xx_show_values("Standby Current in Amps", current_standby);
status = sensor_channel_get(dev,
SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT,
&current_max_load);
SENSOR_CHAN_GAUGE_STDBY_CURRENT,
&current_standby);
if (status < 0) {
printk("Unable to get the current value\n");
return;
}
bq274xx_show_values("Standby Current in Amps", current_standby);
status = sensor_sample_fetch_chan(dev,
SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT);
if (status < 0) {
printk("Unable to fetch Max Load Current\n");
return;
}
status = sensor_channel_get(dev,
SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT,
&current_max_load);
if (status < 0) {
printk("Unable to get the current value\n");
return;
}
bq274xx_show_values("Max Load Current in Amps",
current_max_load);
status = sensor_sample_fetch_chan(dev,
SENSOR_CHAN_GAUGE_STATE_OF_CHARGE);
if (status < 0) {
printk("Unable to fetch State of Charge\n");
return;
}
status = sensor_channel_get(dev,
SENSOR_CHAN_GAUGE_STATE_OF_CHARGE,
&state_of_charge);
if (status < 0) {
printk("Unable to get state of charge\n");
return;
}
printk("State of charge: %d%%\n", state_of_charge.val1);
status = sensor_sample_fetch_chan(dev,
SENSOR_CHAN_GAUGE_STATE_OF_HEALTH);
if (status < 0) {
printk("Failed to fetch State of Health\n");
return;
}
status = sensor_channel_get(dev,
SENSOR_CHAN_GAUGE_STATE_OF_HEALTH,
&state_of_health);
if (status < 0) {
printk("Unable to get state of charge\n");
return;
}
printk("State of health: %d%%\n", state_of_health.val1);
status = sensor_sample_fetch_chan(dev,
SENSOR_CHAN_GAUGE_AVG_POWER);
if (status < 0) {
printk("Unable to fetch Avg Power\n");
return;
}
status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_AVG_POWER,
&avg_power);
if (status < 0) {
printk("Unable to get avg power\n");
return;
}
bq274xx_show_values("Avg Power in Watt", avg_power);
status = sensor_channel_get(
dev, SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY,
&full_charge_capacity);
status = sensor_sample_fetch_chan(dev,
SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY);
if (status < 0) {
printk("Failed to fetch Full Charge Capacity\n");
return;
}
status = sensor_channel_get(dev,
SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY,
&full_charge_capacity);
if (status < 0) {
printk("Unable to get full charge capacity\n");
return;
}
printk("Full charge capacity: %d.%06dAh\n",
full_charge_capacity.val1, full_charge_capacity.val2);
status = sensor_channel_get(
dev, SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY,
&remaining_charge_capacity);
status = sensor_sample_fetch_chan(dev,
SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY);
if (status < 0) {
printk("Unable to fetch Remaining Charge Capacity\n");
return;
}
status = sensor_channel_get(dev,
SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY,
&remaining_charge_capacity);
if (status < 0) {
printk("Unable to get remaining charge capacity\n");
return;
}
printk("Remaining charge capacity: %d.%06dAh\n",
remaining_charge_capacity.val1,
remaining_charge_capacity.val2);
status = sensor_sample_fetch_chan(dev, SENSOR_CHAN_GAUGE_TEMP);
if (status < 0) {
printk("Failed to fetch Gauge Temp\n");
return;
}
status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_TEMP,
&int_temp);
if (status < 0) {
printk("Unable to read internal temperature\n");
return;
}
printk("Gauge Temperature: %d.%06d C\n", int_temp.val1,