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_SMBus_Rotoye.cpp
Views: 1798
1
#include "AP_BattMonitor_config.h"
2
3
#if AP_BATTERY_SMBUS_ROTOYE_ENABLED
4
5
#include "AP_BattMonitor_SMBus_Rotoye.h"
6
7
#include <AP_HAL/AP_HAL.h>
8
9
// Specific to Rotoye Batmon
10
#define BATTMONITOR_SMBUS_TEMP_EXT 0x48
11
12
// return the maximum of the internal and external temperature sensors
13
void AP_BattMonitor_SMBus_Rotoye::read_temp(void) {
14
uint16_t t_int = 0;
15
uint16_t t_ext = 0;
16
17
/* Both internal and external values will always be sent by Batmon.
18
If no external thermistor is used, a zero-value is sent. */
19
const bool have_temp_internal = read_word(BATTMONITOR_SMBUS_TEMP, t_int);
20
const bool have_temp_external = read_word(BATTMONITOR_SMBUS_TEMP_EXT, t_ext);
21
22
if (!have_temp_internal && !have_temp_external) {
23
_has_temperature = (AP_HAL::millis() - _state.temperature_time) <= AP_BATT_MONITOR_TIMEOUT;
24
return;
25
}
26
27
_has_temperature = true;
28
29
_state.temperature_time = AP_HAL::millis();
30
_state.temperature = KELVIN_TO_C(0.1f * float(MAX(t_int, t_ext)));
31
}
32
33
#endif // AP_BATTERY_SMBUS_ROTOYE_ENABLED
34
35