kopia lustrzana https://github.com/meshtastic/firmware
				
				
				
			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.hpull/2948/head
							rodzic
							
								
									5ce6ca25f2
								
							
						
					
					
						commit
						9d4af1146e
					
				| 
						 | 
				
			
			@ -52,6 +52,7 @@ static const adc_atten_t atten = ADC_ATTENUATION;
 | 
			
		|||
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
 | 
			
		||||
INA260Sensor ina260Sensor;
 | 
			
		||||
INA219Sensor ina219Sensor;
 | 
			
		||||
INA3221Sensor ina3221Sensor;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#ifdef HAS_PMU
 | 
			
		||||
| 
						 | 
				
			
			@ -286,6 +287,9 @@ class AnalogBatteryLevel : public HasBatteryLevel
 | 
			
		|||
        } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
 | 
			
		||||
                   config.power.device_battery_ina_address) {
 | 
			
		||||
            return ina260Sensor.getBusVoltageMv();
 | 
			
		||||
        } else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
 | 
			
		||||
                   config.power.device_battery_ina_address) {
 | 
			
		||||
            return ina3221Sensor.getBusVoltageMv();
 | 
			
		||||
        }
 | 
			
		||||
        return 0;
 | 
			
		||||
    }
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -11,11 +11,6 @@
 | 
			
		|||
#include "sleep.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 DISPLAY_RECEIVEID_MEASUREMENTS_ON_SCREEN true
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -13,8 +13,9 @@ int32_t INA3221Sensor::runOnce()
 | 
			
		|||
        return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
 | 
			
		||||
    }
 | 
			
		||||
    if (!status) {
 | 
			
		||||
        ina3221.setAddr(INA3221_ADDR42_SDA);
 | 
			
		||||
        ina3221.setAddr(INA3221_ADDR42_SDA); // i2c address 0x42
 | 
			
		||||
        ina3221.begin();
 | 
			
		||||
        ina3221.setShuntRes(100, 100, 100); // 0.1 Ohm shunt resistors
 | 
			
		||||
        status = true;
 | 
			
		||||
    } else {
 | 
			
		||||
        status = true;
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -1,16 +1,19 @@
 | 
			
		|||
#include "../mesh/generated/meshtastic/telemetry.pb.h"
 | 
			
		||||
#include "TelemetrySensor.h"
 | 
			
		||||
#include "VoltageSensor.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:
 | 
			
		||||
    INA3221Sensor();
 | 
			
		||||
    int32_t runOnce() override;
 | 
			
		||||
    void setup() override;
 | 
			
		||||
    bool getMetrics(meshtastic_Telemetry *measurement) override;
 | 
			
		||||
    virtual uint16_t getBusVoltageMv();
 | 
			
		||||
 | 
			
		||||
  private:
 | 
			
		||||
    INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
 | 
			
		||||
    virtual uint16_t getBusVoltageMv() override;
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -25,8 +25,10 @@ extern RTC_NOINIT_ATTR uint64_t RTC_reg_b;
 | 
			
		|||
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
 | 
			
		||||
#include "modules/Telemetry/Sensor/INA219Sensor.h"
 | 
			
		||||
#include "modules/Telemetry/Sensor/INA260Sensor.h"
 | 
			
		||||
#include "modules/Telemetry/Sensor/INA3221Sensor.h"
 | 
			
		||||
extern INA260Sensor ina260Sensor;
 | 
			
		||||
extern INA219Sensor ina219Sensor;
 | 
			
		||||
extern INA3221Sensor ina3221Sensor;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
class Power : private concurrency::OSThread
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Ładowanie…
	
		Reference in New Issue