batteryCheck: improve user notification for low battery events

Signed-off-by: Silvan Fuhrer <silvan@auterion.com>
This commit is contained in:
Silvan Fuhrer 2023-10-04 13:28:04 +02:00 committed by Beat Küng
parent bc19ccdd1f
commit b7f8ee8ee7
1 changed files with 10 additions and 2 deletions

View File

@ -195,6 +195,7 @@ void BatteryChecks::checkAndReport(const Context &context, Report &reporter)
}
if (context.isArmed()) {
// if armed, only allow increase of battery warning severity
if (worst_warning > reporter.failsafeFlags().battery_warning) {
reporter.failsafeFlags().battery_warning = worst_warning;
}
@ -205,16 +206,23 @@ void BatteryChecks::checkAndReport(const Context &context, Report &reporter)
if (reporter.failsafeFlags().battery_warning > battery_status_s::BATTERY_WARNING_NONE
&& reporter.failsafeFlags().battery_warning < battery_status_s::BATTERY_WARNING_FAILED) {
bool critical_or_higher = reporter.failsafeFlags().battery_warning >= battery_status_s::BATTERY_WARNING_CRITICAL;
const bool critical_or_higher = reporter.failsafeFlags().battery_warning >= battery_status_s::BATTERY_WARNING_CRITICAL;
NavModes affected_modes = critical_or_higher ? NavModes::All : NavModes::None;
events::LogLevel log_level = critical_or_higher ? events::Log::Critical : events::Log::Warning;
/* EVENT
* @description
* The battery state of charge of the worst battery is below the warning threshold.
*
* <profile name="dev">
* This check can be configured via <param>BAT_LOW_THR</param>, <param>BAT_CRIT_THR</param> and <param>BAT_EMERGEN_THR</param> parameters.
* </profile>
*/
reporter.armingCheckFailure(affected_modes, health_component_t::battery, events::ID("check_battery_low"), log_level,
"Low battery");
if (reporter.mavlink_log_pub()) {
mavlink_log_emergency(reporter.mavlink_log_pub(), "Preflight Fail: low battery\t");
mavlink_log_emergency(reporter.mavlink_log_pub(), "Low battery level\t");
}
}
}