mirror of
https://github.com/meshtastic/firmware.git
synced 2025-09-08 04:28:47 +00:00
add INA3221 charging detection
This commit is contained in:
parent
f85ae4ee83
commit
1ab93e04d5
@ -476,6 +476,9 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
int16_t getINACurrent() {
|
int16_t getINACurrent() {
|
||||||
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
|
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
|
||||||
return ina219Sensor.getCurrentMa();
|
return ina219Sensor.getCurrentMa();
|
||||||
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
|
||||||
|
config.power.device_battery_ina_address) {
|
||||||
|
return ina3221Sensor.getCurrentMa();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -102,4 +102,9 @@ uint16_t INA3221Sensor::getBusVoltageMv()
|
|||||||
return lround(ina3221.getVoltage(BAT_CH) * 1000);
|
return lround(ina3221.getVoltage(BAT_CH) * 1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int16_t INA3221Sensor::getCurrentMa()
|
||||||
|
{
|
||||||
|
return lround(ina3221.getCurrent(BAT_CH));
|
||||||
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -5,9 +5,10 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
#include "VoltageSensor.h"
|
#include "VoltageSensor.h"
|
||||||
|
#include "CurrentSensor.h"
|
||||||
#include <INA3221.h>
|
#include <INA3221.h>
|
||||||
|
|
||||||
class INA3221Sensor : public TelemetrySensor, VoltageSensor
|
class INA3221Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
|
INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
|
||||||
@ -35,6 +36,7 @@ class INA3221Sensor : public TelemetrySensor, VoltageSensor
|
|||||||
int32_t runOnce() override;
|
int32_t runOnce() override;
|
||||||
bool getMetrics(meshtastic_Telemetry *measurement) override;
|
bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||||
virtual uint16_t getBusVoltageMv() override;
|
virtual uint16_t getBusVoltageMv() override;
|
||||||
|
virtual int16_t getCurrentMa() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct _INA3221Measurement {
|
struct _INA3221Measurement {
|
||||||
|
Loading…
Reference in New Issue
Block a user