2021-10-07 08:19:01 -03:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <AP_Common/AP_Common.h>
|
|
|
|
#include <AP_HAL/I2CDevice.h>
|
|
|
|
#include "AP_BattMonitor_Backend.h"
|
2021-10-24 21:58:19 -03:00
|
|
|
#include <AP_Param/AP_Param.h>
|
2021-10-07 08:19:01 -03:00
|
|
|
#include <utility>
|
|
|
|
|
2021-10-24 21:58:19 -03:00
|
|
|
#ifndef HAL_BATTMON_INA2XX_ENABLED
|
|
|
|
#define HAL_BATTMON_INA2XX_ENABLED (BOARD_FLASH_SIZE > 1024)
|
|
|
|
#endif
|
2021-10-07 08:19:01 -03:00
|
|
|
|
2021-10-24 21:58:19 -03:00
|
|
|
#if HAL_BATTMON_INA2XX_ENABLED
|
2021-10-07 08:19:01 -03:00
|
|
|
|
2021-10-24 21:58:19 -03:00
|
|
|
class AP_BattMonitor_INA2XX : public AP_BattMonitor_Backend
|
2021-10-07 08:19:01 -03:00
|
|
|
{
|
|
|
|
public:
|
2021-10-24 21:58:19 -03:00
|
|
|
/// Constructor
|
|
|
|
AP_BattMonitor_INA2XX(AP_BattMonitor &mon,
|
|
|
|
AP_BattMonitor::BattMonitor_State &mon_state,
|
|
|
|
AP_BattMonitor_Params ¶ms);
|
2021-10-07 08:19:01 -03:00
|
|
|
|
|
|
|
bool has_cell_voltages() const override { return false; }
|
|
|
|
bool has_temperature() const override { return false; }
|
|
|
|
bool has_current() const override { return true; }
|
|
|
|
bool reset_remaining(float percentage) override { return false; }
|
|
|
|
bool get_cycle_count(uint16_t &cycles) const override { return false; }
|
|
|
|
|
2022-06-20 22:58:58 -03:00
|
|
|
void init(void) override;
|
|
|
|
void read() override;
|
2021-10-24 21:58:19 -03:00
|
|
|
|
|
|
|
static const struct AP_Param::GroupInfo var_info[];
|
|
|
|
|
2021-10-07 08:19:01 -03:00
|
|
|
private:
|
|
|
|
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev;
|
|
|
|
|
2022-06-20 22:58:58 -03:00
|
|
|
void configure(void);
|
2021-10-07 08:19:01 -03:00
|
|
|
bool read_word(const uint8_t reg, int16_t& data) const;
|
|
|
|
bool write_word(const uint8_t reg, const uint16_t data) const;
|
|
|
|
void timer(void);
|
|
|
|
|
2021-10-24 21:58:19 -03:00
|
|
|
AP_Int8 i2c_bus;
|
|
|
|
AP_Int8 i2c_address;
|
2022-06-20 22:58:58 -03:00
|
|
|
bool configured;
|
|
|
|
bool callback_registered;
|
|
|
|
uint32_t failed_reads;
|
|
|
|
uint32_t last_configure_ms;
|
2021-10-24 21:58:19 -03:00
|
|
|
|
2021-10-07 08:19:01 -03:00
|
|
|
struct {
|
|
|
|
uint16_t count;
|
|
|
|
float volt_sum;
|
|
|
|
float current_sum;
|
|
|
|
HAL_Semaphore sem;
|
|
|
|
} accumulate;
|
|
|
|
float current_LSB;
|
|
|
|
float voltage_LSB;
|
|
|
|
};
|
|
|
|
|
2021-10-24 21:58:19 -03:00
|
|
|
#endif // HAL_BATTMON_INA2XX_ENABLED
|