AP_BattMonitor: Require all backends to provide init

This commit is contained in:
Michael du Breuil 2017-10-25 20:58:56 -07:00 committed by Andrew Tridgell
parent 3402d07651
commit 0cee2f2896
8 changed files with 14 additions and 7 deletions

View File

@ -101,6 +101,8 @@ public:
/// returns true if battery monitor provides current info /// returns true if battery monitor provides current info
bool has_current() const override; bool has_current() const override;
void init(void) override {}
protected: protected:
AP_HAL::AnalogSource *_volt_pin_analog_source; AP_HAL::AnalogSource *_volt_pin_analog_source;

View File

@ -29,7 +29,7 @@ public:
virtual ~AP_BattMonitor_Backend(void) {} virtual ~AP_BattMonitor_Backend(void) {}
// initialise // initialise
virtual void init() {} virtual void init() = 0;
// read the latest battery voltage // read the latest battery voltage
virtual void read() = 0; virtual void read() = 0;

View File

@ -17,6 +17,10 @@ AP_BattMonitor_SMBus::AP_BattMonitor_SMBus(AP_BattMonitor &mon,
_mon._pack_capacity[_state.instance] = 0; _mon._pack_capacity[_state.instance] = 0;
} }
void AP_BattMonitor_SMBus::init(void) {
_dev->register_periodic_callback(100000, FUNCTOR_BIND_MEMBER(&AP_BattMonitor_SMBus::timer, void));
}
/// read the battery_voltage and current, should be called at 10hz /// read the battery_voltage and current, should be called at 10hz
void AP_BattMonitor_SMBus::read(void) void AP_BattMonitor_SMBus::read(void)
{ {

View File

@ -28,6 +28,8 @@ public:
// all smart batteries are expected to provide current // all smart batteries are expected to provide current
bool has_current() const override { return true; } bool has_current() const override { return true; }
void init(void) override;
protected: protected:
void read(void) override; void read(void) override;
@ -65,6 +67,8 @@ protected:
bool _has_cell_voltages; // smbus backends flag this as true once they have recieved a valid cell voltage report bool _has_cell_voltages; // smbus backends flag this as true once they have recieved a valid cell voltage report
virtual void timer(void) = 0; // timer function to read from the battery
}; };
// include specific implementations // include specific implementations

View File

@ -40,9 +40,7 @@ AP_BattMonitor_SMBus_Maxell::AP_BattMonitor_SMBus_Maxell(AP_BattMonitor &mon,
AP_BattMonitor::BattMonitor_State &mon_state, AP_BattMonitor::BattMonitor_State &mon_state,
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev) AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev)
: AP_BattMonitor_SMBus(mon, mon_state, std::move(dev)) : AP_BattMonitor_SMBus(mon, mon_state, std::move(dev))
{ {}
_dev->register_periodic_callback(100000, FUNCTOR_BIND_MEMBER(&AP_BattMonitor_SMBus_Maxell::timer, void));
}
void AP_BattMonitor_SMBus_Maxell::timer() void AP_BattMonitor_SMBus_Maxell::timer()
{ {

View File

@ -17,7 +17,7 @@ public:
private: private:
void timer(void); void timer(void) override;
// check if PEC supported with the version value in SpecificationInfo() function // check if PEC supported with the version value in SpecificationInfo() function
// returns true once PEC is confirmed as working or not working // returns true once PEC is confirmed as working or not working

View File

@ -33,7 +33,6 @@ AP_BattMonitor_SMBus_Solo::AP_BattMonitor_SMBus_Solo(AP_BattMonitor &mon,
: AP_BattMonitor_SMBus(mon, mon_state, std::move(dev)) : AP_BattMonitor_SMBus(mon, mon_state, std::move(dev))
{ {
_pec_supported = true; _pec_supported = true;
_dev->register_periodic_callback(100000, FUNCTOR_BIND_MEMBER(&AP_BattMonitor_SMBus_Solo::timer, void));
} }
void AP_BattMonitor_SMBus_Solo::timer() void AP_BattMonitor_SMBus_Solo::timer()

View File

@ -17,7 +17,7 @@ public:
private: private:
void timer(void); void timer(void) override;
// read_block - returns number of characters read if successful, zero if unsuccessful // read_block - returns number of characters read if successful, zero if unsuccessful
uint8_t read_block(uint8_t reg, uint8_t* data, uint8_t max_len, bool append_zero) const; uint8_t read_block(uint8_t reg, uint8_t* data, uint8_t max_len, bool append_zero) const;