battery: pass connected flag in by setter

This commit is contained in:
Matthias Grob
2021-12-01 17:04:12 +01:00
parent 38d23f5345
commit 39641494da
10 changed files with 40 additions and 37 deletions
+6 -6
View File
@@ -83,11 +83,11 @@ INA226::INA226(const I2CSPIDriverConfig &config, int battery_index) :
_power_lsb = 25 * _current_lsb;
// We need to publish immediately, to guarantee that the first instance of the driver publishes to uORB instance 0
_battery.setConnected(false);
_battery.updateBatteryStatus(
hrt_absolute_time(),
0.0,
0.0,
false
0.0
);
}
@@ -228,11 +228,11 @@ INA226::collect()
_bus_voltage = _power = _current = _shunt = 0;
}
_battery.setConnected(success);
_battery.updateBatteryStatus(
hrt_absolute_time(),
(float) _bus_voltage * INA226_VSCALE,
(float) _current * _current_lsb,
success
(float) _current * _current_lsb
);
perf_end(_sample_perf);
@@ -296,11 +296,11 @@ INA226::RunImpl()
ScheduleDelayed(INA226_CONVERSION_INTERVAL);
} else {
_battery.setConnected(false);
_battery.updateBatteryStatus(
hrt_absolute_time(),
0.0f,
0.0f,
false
0.0f
);
if (init() != PX4_OK) {
+6 -6
View File
@@ -85,11 +85,11 @@ INA228::INA228(const I2CSPIDriverConfig &config, int battery_index) :
_power_lsb = 3.2f * _current_lsb;
// We need to publish immediately, to guarantee that the first instance of the driver publishes to uORB instance 0
_battery.setConnected(false);
_battery.updateBatteryStatus(
hrt_absolute_time(),
0.0,
0.0,
false
0.0
);
}
@@ -309,11 +309,11 @@ INA228::collect()
_bus_voltage = _power = _current = _shunt = 0;
}
_battery.setConnected(success);
_battery.updateBatteryStatus(
hrt_absolute_time(),
(float) _bus_voltage * INA228_VSCALE,
(float) _current * _current_lsb,
success
(float) _current * _current_lsb
);
perf_end(_sample_perf);
@@ -377,11 +377,11 @@ INA228::RunImpl()
ScheduleDelayed(INA228_CONVERSION_INTERVAL);
} else {
_battery.setConnected(false);
_battery.updateBatteryStatus(
hrt_absolute_time(),
0.0f,
0.0f,
false
0.0f
);
if (init() != PX4_OK) {
+6 -6
View File
@@ -68,11 +68,11 @@ INA238::INA238(const I2CSPIDriverConfig &config, int battery_index) :
_current_lsb = _max_current / INA238_DN_MAX;
// We need to publish immediately, to guarantee that the first instance of the driver publishes to uORB instance 0
_battery.setConnected(false);
_battery.updateBatteryStatus(
hrt_absolute_time(),
0.0,
0.0,
false
0.0
);
}
@@ -196,11 +196,11 @@ int INA238::collect()
bus_voltage = current = 0;
}
_battery.setConnected(success);
_battery.updateBatteryStatus(
hrt_absolute_time(),
(float) bus_voltage * INA238_VSCALE,
(float) current * _current_lsb,
success
(float) current * _current_lsb
);
perf_end(_sample_perf);
@@ -255,11 +255,11 @@ void INA238::RunImpl()
ScheduleDelayed(INA238_CONVERSION_INTERVAL);
} else {
_battery.setConnected(false);
_battery.updateBatteryStatus(
hrt_absolute_time(),
0.0f,
0.0f,
false
0.0f
);
if (init() != PX4_OK) {
+7 -6
View File
@@ -71,11 +71,11 @@ VOXLPM::init()
int ret = PX4_ERROR;
if (_ch_type == VOXLPM_CH_TYPE_VBATT) {
_battery.setConnected(false);
_battery.updateBatteryStatus(
hrt_absolute_time(),
0.0,
0.0,
false
0.0
);
}
@@ -343,10 +343,11 @@ VOXLPM::measure()
if (ret == PX4_OK) {
switch (_ch_type) {
case VOXLPM_CH_TYPE_VBATT: {
_battery.setConnected(true);
_battery.updateBatteryStatus(tnow,
_voltage,
_amperage,
true);
_amperage);
}
// fallthrough
@@ -369,10 +370,10 @@ VOXLPM::measure()
switch (_ch_type) {
case VOXLPM_CH_TYPE_VBATT: {
_battery.setConnected(true);
_battery.updateBatteryStatus(tnow,
0.0,
0.0,
true);
0.0);
}
break;