diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.cpp b/libraries/AP_BattMonitor/AP_BattMonitor.cpp index 1e501af361..390542dbdf 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.cpp +++ b/libraries/AP_BattMonitor/AP_BattMonitor.cpp @@ -384,6 +384,15 @@ bool AP_BattMonitor::overpower_detected(uint8_t instance) const #endif } +bool AP_BattMonitor::has_cell_voltages(const uint8_t instance) const +{ + if (instance < _num_instances && drivers[instance] != nullptr) { + return drivers[instance]->has_cell_voltages(); + } + + return false; +} + // return the current cell voltages, returns the first monitor instances cells if the instance is out of range const AP_BattMonitor::cells & AP_BattMonitor::get_cell_voltages(const uint8_t instance) const { diff --git a/libraries/AP_BattMonitor/AP_BattMonitor.h b/libraries/AP_BattMonitor/AP_BattMonitor.h index 6c16361be2..e3f15aca5f 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor.h @@ -144,7 +144,9 @@ public: bool overpower_detected(uint8_t instance) const; // cell voltages - const cells & get_cell_voltages() { return get_cell_voltages(AP_BATT_PRIMARY_INSTANCE); }; + bool has_cell_voltages() { return has_cell_voltages(AP_BATT_PRIMARY_INSTANCE); } + bool has_cell_voltages(const uint8_t instance) const; + const cells & get_cell_voltages() const { return get_cell_voltages(AP_BATT_PRIMARY_INSTANCE); } const cells & get_cell_voltages(const uint8_t instance) const; // temperature diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_Backend.h b/libraries/AP_BattMonitor/AP_BattMonitor_Backend.h index 25188f064a..b205f37651 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_Backend.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor_Backend.h @@ -37,6 +37,9 @@ public: /// returns true if battery monitor instance provides current info virtual bool has_current() const = 0; + // returns true if battery monitor provides individual cell voltages + virtual bool has_cell_voltages() const { return false; } + /// capacity_remaining_pct - returns the % battery capacity remaining (0 ~ 100) uint8_t capacity_remaining_pct() const; diff --git a/libraries/AP_BattMonitor/AP_BattMonitor_SMBus.h b/libraries/AP_BattMonitor/AP_BattMonitor_SMBus.h index 0c4f0f86bf..de581365cc 100644 --- a/libraries/AP_BattMonitor/AP_BattMonitor_SMBus.h +++ b/libraries/AP_BattMonitor/AP_BattMonitor_SMBus.h @@ -23,8 +23,9 @@ public: // virtual destructor to reduce compiler warnings virtual ~AP_BattMonitor_SMBus() {} - // all smart batteries provide current info + // all smart batteries provide current and individual cell voltages bool has_current() const override { return true; } + bool has_cell_voltages() const override { return true; } protected: