Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/libraries/AP_BattMonitor/AP_BattMonitor_AD7091R5.h
Views: 1798
#pragma once12#include "AP_BattMonitor_Backend.h"34#ifndef AP_BATTERY_AD7091R5_ENABLED5#define AP_BATTERY_AD7091R5_ENABLED (BOARD_FLASH_SIZE > 1024)6#endif78#if AP_BATTERY_AD7091R5_ENABLED910#include <AP_HAL/utility/OwnPtr.h>11#include <AP_HAL/I2CDevice.h>1213#define AD7091R5_NO_OF_CHANNELS 414#define AD7091R5_CONF_CMD 0x0415#define AD7091R5_CHAN_ALL 0x0F16#define AD7091R5_CONF_PDOWN0 0x0017#define AD7091R5_CONF_PDOWN2 0x0218#define AD7091R5_CONF_PDOWN3 0x0319#define AD7091R5_CONF_PDOWN_MASK 0x032021class AP_BattMonitor_AD7091R5 : public AP_BattMonitor_Backend22{23public:24// Constructor25AP_BattMonitor_AD7091R5(AP_BattMonitor &mon,26AP_BattMonitor::BattMonitor_State &mon_state,27AP_BattMonitor_Params ¶ms);2829// Read the battery voltage and current. Should be called at 10hz30void read() override;31void init(void) override;3233// returns true if battery monitor provides consumed energy info34bool has_consumed_energy() const override35{36return has_current();37}3839// returns true if battery monitor provides current info40bool has_current() const override41{42return true;43}4445static const struct AP_Param::GroupInfo var_info[];4647private:48void _read_adc();49bool _initialize();50float _data_to_volt(uint32_t data);5152static struct AnalogData {53uint32_t data;54} _analog_data[AD7091R5_NO_OF_CHANNELS];55static bool _first;56static bool _health;5758HAL_Semaphore sem; // semaphore for access to shared frontend data59AP_HAL::OwnPtr<AP_HAL::I2CDevice> _dev;60uint8_t volt_buff_pt;61uint8_t curr_buff_pt;6263protected:6465// Parameters66AP_Float _volt_multiplier; // voltage on volt pin multiplied by this to calculate battery voltage67AP_Float _curr_amp_per_volt; // voltage on current pin multiplied by this to calculate current in amps68AP_Float _curr_amp_offset; // offset voltage that is subtracted from current pin before conversion to amps69AP_Float _volt_offset; // offset voltage that is subtracted from voltage pin before conversion70AP_Int8 _volt_pin; // board pin used to measure battery voltage71AP_Int8 _curr_pin; // board pin used to measure battery current72};7374#endif // AP_BATTERY_AD7091R5_ENABLED757677