Line data Source code
1 : #pragma once 2 : 3 : #include "AP_BattMonitor_config.h" 4 : 5 : #if AP_BATTERY_SCRIPTING_ENABLED 6 : 7 : #include "AP_BattMonitor_Backend.h" 8 : 9 : class AP_BattMonitor_Scripting : public AP_BattMonitor_Backend 10 : { 11 : public: 12 : // Inherit constructor 13 : using AP_BattMonitor_Backend::AP_BattMonitor_Backend; 14 : 15 0 : bool has_current() const override { return last_update_us != 0 && !isnan(internal_state.current_amps); } 16 0 : bool has_consumed_energy() const override { return has_current(); } 17 0 : bool has_cell_voltages() const override { return internal_state.cell_count > 0; } 18 0 : bool has_temperature() const override { return last_update_us != 0 && !isnan(internal_state.temperature); } 19 : bool capacity_remaining_pct(uint8_t &percentage) const override; 20 : bool get_cycle_count(uint16_t &cycles) const override; 21 : 22 : void read() override; 23 : 24 : bool handle_scripting(const BattMonitorScript_State &battmon_state) override; 25 : 26 : protected: 27 : BattMonitorScript_State internal_state; 28 : uint32_t last_update_us; 29 : 30 : HAL_Semaphore sem; 31 : }; 32 : 33 : #endif // AP_BATTERY_SCRIPTING_ENABLED