Path: blob/master/libraries/AP_BattMonitor/AP_BattMonitor_AD7091R5.h
9767 views
#pragma once12#include "AP_BattMonitor_Backend.h"34#ifndef AP_BATTERY_AD7091R5_ENABLED5#define AP_BATTERY_AD7091R5_ENABLED (HAL_PROGRAM_SIZE_LIMIT_KB > 1024)6#endif78#if AP_BATTERY_AD7091R5_ENABLED910#include <AP_HAL/I2CDevice.h>1112#define AD7091R5_NO_OF_CHANNELS 413#define AD7091R5_CONF_CMD 0x0414#define AD7091R5_CHAN_ALL 0x0F15#define AD7091R5_CONF_PDOWN0 0x0016#define AD7091R5_CONF_PDOWN2 0x0217#define AD7091R5_CONF_PDOWN3 0x0318#define AD7091R5_CONF_PDOWN_MASK 0x031920class AP_BattMonitor_AD7091R5 : public AP_BattMonitor_Backend21{22public:23// Constructor24AP_BattMonitor_AD7091R5(AP_BattMonitor &mon,25AP_BattMonitor::BattMonitor_State &mon_state,26AP_BattMonitor_Params ¶ms);2728// Read the battery voltage and current. Should be called at 10hz29void read() override;30void init(void) override;3132// returns true if battery monitor provides consumed energy info33bool has_consumed_energy() const override34{35return has_current();36}3738// returns true if battery monitor provides current info39bool has_current() const override40{41return true;42}4344static const struct AP_Param::GroupInfo var_info[];4546private:47void _read_adc();48bool _initialize();49float _data_to_volt(uint32_t data);5051static struct AnalogData {52uint32_t data;53} _analog_data[AD7091R5_NO_OF_CHANNELS];54static bool _first;55static bool _health;5657HAL_Semaphore sem; // semaphore for access to shared frontend data58AP_HAL::I2CDevice *_dev;59uint8_t volt_buff_pt;60uint8_t curr_buff_pt;6162protected:6364// Parameters65AP_Float _volt_multiplier; // voltage on volt pin multiplied by this to calculate battery voltage66AP_Float _curr_amp_per_volt; // voltage on current pin multiplied by this to calculate current in amps67AP_Float _curr_amp_offset; // offset voltage that is subtracted from current pin before conversion to amps68AP_Float _volt_offset; // offset voltage that is subtracted from voltage pin before conversion69AP_Int8 _volt_pin; // board pin used to measure battery voltage70AP_Int8 _curr_pin; // board pin used to measure battery current71};7273#endif // AP_BATTERY_AD7091R5_ENABLED747576