Compare commits

...

6 Commits

Author SHA1 Message Date
nebman
1ab93e04d5 add INA3221 charging detection 2024-11-07 17:03:12 +01:00
nebman
f85ae4ee83 Merge branch 'use-ina-currentflow-for-charging-detection' of https://github.com/nebman/meshtastic-firmware into use-ina-currentflow-for-charging-detection 2024-11-07 12:57:58 +01:00
nebman
90062a13c4 move getCurrentMa() to new CurrentSensor class 2024-11-07 10:56:27 +01:00
nebman
b3777d5dff Update Power.cpp
fix disabled case
2024-11-02 01:37:07 +01:00
nebman
296f581c68 Update Power.cpp
added comments and 2 extra defines to disable and swap detection direction
2024-11-02 01:17:27 +01:00
nebman
ab23e9e034 INA219 charging detection
minimal implementation: if there is a configured INA219 sensor for battery monitoring we can take the current flow across the shunt resistor to know if we are charging the battery - negative milliamps indicate charging
2024-11-02 00:46:26 +01:00
3 changed files with 11 additions and 1 deletions

View File

@ -476,6 +476,9 @@ class AnalogBatteryLevel : public HasBatteryLevel
int16_t getINACurrent() {
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
return ina219Sensor.getCurrentMa();
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
config.power.device_battery_ina_address) {
return ina3221Sensor.getCurrentMa();
}
return 0;
}

View File

@ -102,4 +102,9 @@ uint16_t INA3221Sensor::getBusVoltageMv()
return lround(ina3221.getVoltage(BAT_CH) * 1000);
}
int16_t INA3221Sensor::getCurrentMa()
{
return lround(ina3221.getCurrent(BAT_CH));
}
#endif

View File

@ -5,9 +5,10 @@
#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "TelemetrySensor.h"
#include "VoltageSensor.h"
#include "CurrentSensor.h"
#include <INA3221.h>
class INA3221Sensor : public TelemetrySensor, VoltageSensor
class INA3221Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
{
private:
INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
@ -35,6 +36,7 @@ class INA3221Sensor : public TelemetrySensor, VoltageSensor
int32_t runOnce() override;
bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual uint16_t getBusVoltageMv() override;
virtual int16_t getCurrentMa() override;
};
struct _INA3221Measurement {