CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
Ardupilot

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: Ardupilot/ardupilot
Path: blob/master/libraries/AP_BattMonitor/AP_BattMonitor_INA2xx.h
Views: 1798
1
#pragma once
2
3
#include <AP_Common/AP_Common.h>
4
#include <AP_HAL/I2CDevice.h>
5
#include "AP_BattMonitor_Backend.h"
6
#include <AP_Param/AP_Param.h>
7
#include <utility>
8
9
#if AP_BATTERY_INA2XX_ENABLED
10
11
class AP_BattMonitor_INA2XX : public AP_BattMonitor_Backend
12
{
13
public:
14
/// Constructor
15
AP_BattMonitor_INA2XX(AP_BattMonitor &mon,
16
AP_BattMonitor::BattMonitor_State &mon_state,
17
AP_BattMonitor_Params &params);
18
19
bool has_cell_voltages() const override { return false; }
20
bool has_temperature() const override { return has_temp; }
21
bool has_current() const override { return true; }
22
bool get_cycle_count(uint16_t &cycles) const override { return false; }
23
bool get_temperature(float &temperature) const override;
24
25
void init(void) override;
26
void read() override;
27
28
static const struct AP_Param::GroupInfo var_info[];
29
30
private:
31
AP_HAL::OwnPtr<AP_HAL::I2CDevice> dev;
32
33
enum class DevType : uint8_t {
34
UNKNOWN = 0,
35
INA226,
36
INA228,
37
INA238,
38
INA231,
39
};
40
41
static const uint8_t i2c_probe_addresses[];
42
uint8_t i2c_probe_next;
43
44
bool configure(DevType dtype);
45
bool read_word16(const uint8_t reg, int16_t& data) const;
46
bool read_word24(const uint8_t reg, int32_t& data) const;
47
bool write_word(const uint8_t reg, const uint16_t data) const;
48
void timer(void);
49
bool detect_device(void);
50
51
DevType dev_type;
52
uint32_t last_detect_ms;
53
54
AP_Int8 i2c_bus;
55
AP_Int8 i2c_address;
56
AP_Float max_amps;
57
AP_Float rShunt;
58
uint32_t failed_reads;
59
60
struct {
61
uint16_t count;
62
float volt_sum;
63
float current_sum;
64
HAL_Semaphore sem;
65
} accumulate;
66
float current_LSB;
67
float voltage_LSB;
68
69
float temperature;
70
71
bool has_temp;
72
};
73
74
#endif // AP_BATTERY_INA2XX_ENABLED
75
76