2017-02-08 20:28:57 -04:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_Param/AP_Param.h>
|
|
|
|
#include <AP_Math/AP_Math.h>
|
|
|
|
#include "AP_BattMonitor_SMBus.h"
|
|
|
|
#include <AP_HAL/I2CDevice.h>
|
|
|
|
|
|
|
|
class AP_BattMonitor_SMBus_Maxell : public AP_BattMonitor_SMBus
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
AP_BattMonitor_SMBus_Maxell(AP_BattMonitor &mon, uint8_t instance,
|
|
|
|
AP_BattMonitor::BattMonitor_State &mon_state,
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev);
|
|
|
|
|
|
|
|
// read does nothing, all done in timer
|
|
|
|
void read() override;
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
void timer(void);
|
|
|
|
|
|
|
|
// read word from register
|
|
|
|
// returns true if read was successful, false if failed
|
|
|
|
bool read_word(uint8_t reg, uint16_t& data) const;
|
|
|
|
|
2017-03-29 07:49:10 -03:00
|
|
|
// check if PEC supported with the version value in SpecificationInfo() function
|
|
|
|
// returns true once PEC is confirmed as working or not working
|
|
|
|
bool check_pec_support();
|
2017-02-19 04:50:06 -04:00
|
|
|
|
|
|
|
// read_block - returns number of characters read if successful, zero if unsuccessful
|
|
|
|
uint8_t read_block(uint8_t reg, uint8_t* data, bool append_zero) const;
|
|
|
|
|
|
|
|
// get_PEC - calculate PEC for a read or write from the battery
|
|
|
|
// buff is the data that was read or will be written
|
|
|
|
uint8_t get_PEC(const uint8_t i2c_addr, uint8_t cmd, bool reading, const uint8_t buff[], uint8_t len) const;
|
|
|
|
|
2017-02-08 20:28:57 -04:00
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;
|
2017-03-29 07:49:10 -03:00
|
|
|
uint8_t _pec_confirmed; // count of the number of times PEC has been confirmed as working
|
|
|
|
bool _pec_supported; // true if pec is supported
|
2017-02-08 20:28:57 -04:00
|
|
|
};
|