Unverified Commit ee8193f3 authored by Gus Grubba's avatar Gus Grubba Committed by GitHub

Merge pull request #8233 from mavlink/pr-low-battery-warning-timer

Add a timer in between low battery warning messages.
parents 7e9b1e85 19522759
......@@ -300,6 +300,7 @@ Vehicle::Vehicle(LinkInterface* link,
// Start csv logger
connect(&_csvLogTimer, &QTimer::timeout, this, &Vehicle::_writeCsvLine);
_csvLogTimer.start(1000);
_lastBatteryAnnouncement.start();
}
// Disconnected Vehicle for offline editing
......@@ -1126,7 +1127,7 @@ void Vehicle::_handleAttitudeQuaternion(mavlink_message_t& message)
// if repr_offset is valid, rotate attitude and rates
if (repr_offset.norm() >= 0.5f) {
quat = quat * repr_offset;
rates = repr_offset * rates;
rates = repr_offset * rates;
}
float roll, pitch, yaw;
......@@ -1550,12 +1551,16 @@ void Vehicle::_handleSysStatus(mavlink_message_t& message)
}
_battery1FactGroup.percentRemaining()->setRawValue(sysStatus.battery_remaining);
//-- Low battery warning
if (sysStatus.battery_remaining > 0) {
if (sysStatus.battery_remaining < _settingsManager->appSettings()->batteryPercentRemainingAnnounce()->rawValue().toInt() &&
sysStatus.battery_remaining < _lastAnnouncedLowBatteryPercent) {
int warnThreshold = _settingsManager->appSettings()->batteryPercentRemainingAnnounce()->rawValue().toInt();
if (sysStatus.battery_remaining < warnThreshold &&
sysStatus.battery_remaining < _lastAnnouncedLowBatteryPercent &&
_lastBatteryAnnouncement.elapsed() > (sysStatus.battery_remaining < warnThreshold * 0.5 ? 15000 : 30000)) {
_say(tr("%1 low battery: %2 percent remaining").arg(_vehicleIdSpeech()).arg(sysStatus.battery_remaining));
_lastBatteryAnnouncement.start();
_lastAnnouncedLowBatteryPercent = sysStatus.battery_remaining;
}
_lastAnnouncedLowBatteryPercent = sysStatus.battery_remaining;
}
if (_onboardControlSensorsPresent != sysStatus.onboard_control_sensors_present) {
......@@ -1656,12 +1661,13 @@ void Vehicle::_updateArmed(bool armed)
if (_armed != armed) {
_armed = armed;
emit armedChanged(_armed);
// We are transitioning to the armed state, begin tracking trajectory points for the map
if (_armed) {
_trajectoryPoints->start();
_flightTimerStart();
_clearCameraTriggerPoints();
// Reset battery warning
_lastAnnouncedLowBatteryPercent = 100;
} else {
_trajectoryPoints->stop();
_flightTimerStop();
......
......@@ -1507,7 +1507,8 @@ private:
QString _gitHash;
quint64 _uid;
int _lastAnnouncedLowBatteryPercent;
QTime _lastBatteryAnnouncement;
int _lastAnnouncedLowBatteryPercent;
SharedLinkInterfacePointer _priorityLink; // We always keep a reference to the priority link to manage shutdown ordering
bool _priorityLinkCommanded;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment