mirror of
https://github.com/meshtastic/firmware.git
synced 2025-08-18 11:13:29 +00:00
INA3221 bugfixes & refinement (#2944)
Reorganized and refactored some INA3221 code Added comments Added missing shunt resistor value (100mΩ) Added INA3221 Channel 1 to getINAVoltage() for device battery monitoring modified: src/Power.cpp modified: src/modules/Telemetry/PowerTelemetry.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.cpp modified: src/modules/Telemetry/Sensor/INA3221Sensor.h modified: src/power.h
This commit is contained in:
parent
5ce6ca25f2
commit
9d4af1146e
@ -52,6 +52,7 @@ static const adc_atten_t atten = ADC_ATTENUATION;
|
|||||||
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
|
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
|
||||||
INA260Sensor ina260Sensor;
|
INA260Sensor ina260Sensor;
|
||||||
INA219Sensor ina219Sensor;
|
INA219Sensor ina219Sensor;
|
||||||
|
INA3221Sensor ina3221Sensor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef HAS_PMU
|
#ifdef HAS_PMU
|
||||||
@ -286,6 +287,9 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
|
||||||
config.power.device_battery_ina_address) {
|
config.power.device_battery_ina_address) {
|
||||||
return ina260Sensor.getBusVoltageMv();
|
return ina260Sensor.getBusVoltageMv();
|
||||||
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
|
||||||
|
config.power.device_battery_ina_address) {
|
||||||
|
return ina3221Sensor.getBusVoltageMv();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -11,11 +11,6 @@
|
|||||||
#include "sleep.h"
|
#include "sleep.h"
|
||||||
#include "target_specific.h"
|
#include "target_specific.h"
|
||||||
|
|
||||||
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
|
|
||||||
#include "Sensor/INA3221Sensor.h"
|
|
||||||
INA3221Sensor ina3221Sensor;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
|
#define FAILED_STATE_SENSOR_READ_MULTIPLIER 10
|
||||||
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
|
#define DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
|
||||||
|
|
||||||
|
@ -13,8 +13,9 @@ int32_t INA3221Sensor::runOnce()
|
|||||||
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
|
||||||
}
|
}
|
||||||
if (!status) {
|
if (!status) {
|
||||||
ina3221.setAddr(INA3221_ADDR42_SDA);
|
ina3221.setAddr(INA3221_ADDR42_SDA); // i2c address 0x42
|
||||||
ina3221.begin();
|
ina3221.begin();
|
||||||
|
ina3221.setShuntRes(100, 100, 100); // 0.1 Ohm shunt resistors
|
||||||
status = true;
|
status = true;
|
||||||
} else {
|
} else {
|
||||||
status = true;
|
status = true;
|
||||||
|
@ -1,16 +1,19 @@
|
|||||||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
#include "../mesh/generated/meshtastic/telemetry.pb.h"
|
||||||
#include "TelemetrySensor.h"
|
#include "TelemetrySensor.h"
|
||||||
|
#include "VoltageSensor.h"
|
||||||
#include <INA3221.h>
|
#include <INA3221.h>
|
||||||
|
|
||||||
class INA3221Sensor : public TelemetrySensor
|
class INA3221Sensor : public TelemetrySensor, VoltageSensor
|
||||||
{
|
{
|
||||||
|
private:
|
||||||
|
INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
|
||||||
|
|
||||||
|
protected:
|
||||||
|
void setup() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
INA3221Sensor();
|
INA3221Sensor();
|
||||||
int32_t runOnce() override;
|
int32_t runOnce() override;
|
||||||
void setup() override;
|
|
||||||
bool getMetrics(meshtastic_Telemetry *measurement) override;
|
bool getMetrics(meshtastic_Telemetry *measurement) override;
|
||||||
virtual uint16_t getBusVoltageMv();
|
virtual uint16_t getBusVoltageMv() override;
|
||||||
|
|
||||||
private:
|
|
||||||
INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
|
|
||||||
};
|
};
|
@ -25,8 +25,10 @@ extern RTC_NOINIT_ATTR uint64_t RTC_reg_b;
|
|||||||
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
|
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
|
||||||
#include "modules/Telemetry/Sensor/INA219Sensor.h"
|
#include "modules/Telemetry/Sensor/INA219Sensor.h"
|
||||||
#include "modules/Telemetry/Sensor/INA260Sensor.h"
|
#include "modules/Telemetry/Sensor/INA260Sensor.h"
|
||||||
|
#include "modules/Telemetry/Sensor/INA3221Sensor.h"
|
||||||
extern INA260Sensor ina260Sensor;
|
extern INA260Sensor ina260Sensor;
|
||||||
extern INA219Sensor ina219Sensor;
|
extern INA219Sensor ina219Sensor;
|
||||||
|
extern INA3221Sensor ina3221Sensor;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class Power : private concurrency::OSThread
|
class Power : private concurrency::OSThread
|
||||||
|
Loading…
Reference in New Issue
Block a user