From 8fdbb36827ca489df157984c4a8b444a7300a6e4 Mon Sep 17 00:00:00 2001 From: Jonathan Challinger Date: Wed, 6 Jan 2016 17:11:12 -0800 Subject: [PATCH] AP_BattMonitor: add is_powering_off --- libraries/AP_BattMonitor/AP_BattMonitor.cpp | 4 ++++ libraries/AP_BattMonitor/AP_BattMonitor.h | 4 ++++ libraries/AP_BattMonitor/AP_BattMonitor_SMBus_PX4.cpp | 1 + 3 files changed, 9 insertions(+) diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.cpp b/libraries/AP_BattMonitor/AP_BattMonitor.cpp index 35647883e8..b2d5c508ba 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor.cpp @@ -194,6 +194,10 @@ bool AP_BattMonitor::healthy(uint8_t instance) const { return instance < AP_BATT_MONITOR_MAX_INSTANCES && _BattMonitor_STATE(instance).healthy; } +bool AP_BattMonitor::is_powering_off(uint8_t instance) const { + return instance < AP_BATT_MONITOR_MAX_INSTANCES && _BattMonitor_STATE(instance).is_powering_off; +} + /// has_current - returns true if battery monitor instance provides current info bool AP_BattMonitor::has_current(uint8_t instance) const { diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.h b/libraries/AP_BattMonitor/AP_BattMonitor.h index ab9721b873..04a817f4cb 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor.h @@ -48,6 +48,7 @@ public: struct BattMonitor_State { uint8_t instance; // the instance number of this monitor bool healthy; // battery monitor is communicating correctly + bool is_powering_off; // true if the battery is about to power off float voltage; // voltage in volts float current_amps; // current in amperes float current_total_mah; // total current draw since start-up @@ -70,6 +71,9 @@ public: bool healthy(uint8_t instance) const; bool healthy() const { return healthy(AP_BATT_PRIMARY_INSTANCE); } + bool is_powering_off(uint8_t instance) const; + bool is_powering_off() const { return is_powering_off(AP_BATT_PRIMARY_INSTANCE); } + /// has_current - returns true if battery monitor instance provides current info bool has_current(uint8_t instance) const; bool has_current() const { return has_current(AP_BATT_PRIMARY_INSTANCE); } diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_PX4.cpp b/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_PX4.cpp index f47745b657..6a79a0ee90 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_PX4.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor_SMBus_PX4.cpp @@ -69,6 +69,7 @@ void AP_BattMonitor_SMBus_PX4::read() _state.last_time_micros = AP_HAL::micros(); _state.current_total_mah = batt_status.discharged_mah; _state.healthy = true; + _state.is_powering_off = batt_status.is_powering_off; // read capacity if ((_batt_fd >= 0) && !_capacity_updated) {