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_INA239.h
Views: 1798
1
#pragma once
2
3
#include <AP_Common/AP_Common.h>
4
#include <AP_HAL/SPIDevice.h>
5
#include "AP_BattMonitor_Backend.h"
6
#include <utility>
7
8
#if AP_BATTERY_INA239_ENABLED
9
10
class AP_BattMonitor_INA239 : public AP_BattMonitor_Backend
11
{
12
public:
13
/// Constructor
14
AP_BattMonitor_INA239(AP_BattMonitor &mon,
15
AP_BattMonitor::BattMonitor_State &mon_state,
16
AP_BattMonitor_Params &params);
17
18
bool has_cell_voltages() const override { return false; }
19
bool has_temperature() const override { return false; }
20
bool has_current() const override { return true; }
21
bool get_cycle_count(uint16_t &cycles) const override { return false; }
22
23
void init(void) override;
24
void read() override;
25
26
static const struct AP_Param::GroupInfo var_info[];
27
28
protected:
29
AP_HAL::OwnPtr<AP_HAL::Device> dev;
30
31
void configure(void);
32
bool read_word(const uint8_t reg, int16_t& data) const;
33
bool write_word(const uint8_t reg, const uint16_t data) const;
34
void timer(void);
35
36
bool configured;
37
bool callback_registered;
38
uint32_t failed_reads;
39
uint32_t last_configure_ms;
40
41
struct {
42
uint16_t count;
43
float volt_sum;
44
float current_sum;
45
HAL_Semaphore sem;
46
} accumulate;
47
float current_LSB;
48
float voltage_LSB;
49
50
AP_Float max_amps;
51
AP_Float rShunt;
52
};
53
54
#endif // AP_BATTERY_INA239_ENABLED
55
56