Skip to content

Commit

Permalink
AP_BattMonitor: added get_cell_voltage() for scripting
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Oct 23, 2023
1 parent 13d5668 commit b197f11
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
17 changes: 17 additions & 0 deletions libraries/AP_BattMonitor/AP_BattMonitor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,23 @@ const AP_BattMonitor::cells & AP_BattMonitor::get_cell_voltages(const uint8_t in
}
}

// get once cell voltage (for scripting)
bool AP_BattMonitor::get_cell_voltage(uint8_t instance, uint8_t cell, float &voltage) const
{
if (!has_cell_voltages(instance) ||
cell >= AP_BATT_MONITOR_CELLS_MAX) {
return false;
}
const auto &cell_voltages = get_cell_voltages(instance);
const uint16_t voltage_mv = cell_voltages.cells[cell];
if (voltage_mv == 0 || voltage_mv == UINT16_MAX) {
// UINT16_MAX is used as invalid indicator
return false;
}
voltage = voltage_mv*0.001;
return true;
}

// returns true if there is a temperature reading
bool AP_BattMonitor::get_temperature(float &temperature, const uint8_t instance) const
{
Expand Down
3 changes: 3 additions & 0 deletions libraries/AP_BattMonitor/AP_BattMonitor.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ class AP_BattMonitor
const cells &get_cell_voltages() const { return get_cell_voltages(AP_BATT_PRIMARY_INSTANCE); }
const cells &get_cell_voltages(const uint8_t instance) const;

// get once cell voltage (for scripting)
bool get_cell_voltage(uint8_t instance, uint8_t cell, float &voltage) const;

// temperature
bool get_temperature(float &temperature) const { return get_temperature(temperature, AP_BATT_PRIMARY_INSTANCE); }
bool get_temperature(float &temperature, const uint8_t instance) const;
Expand Down

0 comments on commit b197f11

Please sign in to comment.