mirror of
https://github.com/meshtastic/firmware.git
synced 2025-06-08 06:02:05 +00:00
Merge 6e89d6bcb7
into 46c7d74760
This commit is contained in:
commit
e36cf3a815
153
src/Power.cpp
153
src/Power.cpp
@ -77,6 +77,8 @@ static const uint8_t ext_chrg_detect_value = EXT_CHRG_DETECT_VALUE;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR
|
||||||
|
#include "main.h";
|
||||||
|
uint8_t INA_ADDR_LOCAL;
|
||||||
#if __has_include(<Adafruit_INA219.h>)
|
#if __has_include(<Adafruit_INA219.h>)
|
||||||
INA219Sensor ina219Sensor;
|
INA219Sensor ina219Sensor;
|
||||||
#else
|
#else
|
||||||
@ -461,7 +463,8 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
if (hasINA()) {
|
if (hasINA()) {
|
||||||
// get current flow from INA sensor - negative value means power flowing into the battery
|
// get current flow from INA sensor - negative value means power flowing into the battery
|
||||||
// default assuming BATTERY+ <--> INA_VIN+ <--> SHUNT RESISTOR <--> INA_VIN- <--> LOAD
|
// default assuming BATTERY+ <--> INA_VIN+ <--> SHUNT RESISTOR <--> INA_VIN- <--> LOAD
|
||||||
LOG_DEBUG("Using INA on I2C addr 0x%x for charging detection", config.power.device_battery_ina_address);
|
// LOG_DEBUG("Using INA on I2C addr 0x%x for charging detection", config.power.device_battery_ina_address);
|
||||||
|
LOG_DEBUG("Using INA on I2C addr 0x%x for charging detection", INA_ADDR_LOCAL);
|
||||||
#if defined(INA_CHARGING_DETECTION_INVERT)
|
#if defined(INA_CHARGING_DETECTION_INVERT)
|
||||||
return getINACurrent() > 0;
|
return getINACurrent() > 0;
|
||||||
#else
|
#else
|
||||||
@ -504,61 +507,131 @@ class AnalogBatteryLevel : public HasBatteryLevel
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_STM32WL)
|
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_STM32WL)
|
||||||
|
/*
|
||||||
|
Read Voltage from INA using autodetect of addr first else use addr in config.power.device_battery_ina_address
|
||||||
|
*/
|
||||||
uint16_t getINAVoltage()
|
uint16_t getINAVoltage()
|
||||||
{
|
{
|
||||||
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
|
if (!config.power.device_battery_ina_address) {
|
||||||
return ina219Sensor.getBusVoltageMv();
|
if (ina_found.type != ScanI2C::DeviceType::NONE) {
|
||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
|
switch (ina_found.type) {
|
||||||
config.power.device_battery_ina_address) {
|
case ScanI2C::DeviceType::INA219:
|
||||||
return ina226Sensor.getBusVoltageMv();
|
return ina219Sensor.getBusVoltageMv();
|
||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
|
break;
|
||||||
config.power.device_battery_ina_address) {
|
case ScanI2C::DeviceType::INA226:
|
||||||
return ina260Sensor.getBusVoltageMv();
|
return ina226Sensor.getBusVoltageMv();
|
||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
|
break;
|
||||||
config.power.device_battery_ina_address) {
|
case ScanI2C::DeviceType::INA260:
|
||||||
return ina3221Sensor.getBusVoltageMv();
|
return ina260Sensor.getBusVoltageMv();
|
||||||
|
break;
|
||||||
|
case ScanI2C::DeviceType::INA3221:
|
||||||
|
return ina3221Sensor.getBusVoltageMv();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (config.power.device_battery_ina_address) {
|
||||||
|
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
|
||||||
|
return ina219Sensor.getBusVoltageMv();
|
||||||
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
|
||||||
|
config.power.device_battery_ina_address) {
|
||||||
|
return ina226Sensor.getBusVoltageMv();
|
||||||
|
} 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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Read Current from INA using autodetect of addr first else use addr in config.power.device_battery_ina_address
|
||||||
|
*/
|
||||||
int16_t getINACurrent()
|
int16_t getINACurrent()
|
||||||
{
|
{
|
||||||
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
|
if (!config.power.device_battery_ina_address) {
|
||||||
return ina219Sensor.getCurrentMa();
|
if (ina_found.type != ScanI2C::DeviceType::NONE) {
|
||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
|
switch (ina_found.type) {
|
||||||
config.power.device_battery_ina_address) {
|
case ScanI2C::DeviceType::INA219:
|
||||||
return ina226Sensor.getCurrentMa();
|
return ina219Sensor.getCurrentMa();
|
||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
|
|
||||||
config.power.device_battery_ina_address) {
|
case ScanI2C::DeviceType::INA226:
|
||||||
return ina3221Sensor.getCurrentMa();
|
return ina226Sensor.getCurrentMa();
|
||||||
|
|
||||||
|
case ScanI2C::DeviceType::INA3221:
|
||||||
|
return ina3221Sensor.getCurrentMa();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (config.power.device_battery_ina_address) {
|
||||||
|
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
|
||||||
|
return ina219Sensor.getCurrentMa();
|
||||||
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
|
||||||
|
config.power.device_battery_ina_address) {
|
||||||
|
return ina226Sensor.getCurrentMa();
|
||||||
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
|
||||||
|
config.power.device_battery_ina_address) {
|
||||||
|
return ina3221Sensor.getCurrentMa();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasINA()
|
bool hasINA()
|
||||||
|
/*
|
||||||
|
Use autodetect of addr first else use addr in config.power.device_battery_ina_address
|
||||||
|
Store INA addr in local variable for later use.
|
||||||
|
*/
|
||||||
{
|
{
|
||||||
if (!config.power.device_battery_ina_address) {
|
if (!config.power.device_battery_ina_address) {
|
||||||
return false;
|
if (ina_found.type != ScanI2C::DeviceType::NONE) {
|
||||||
}
|
INA_ADDR_LOCAL = ina_found.address.address;
|
||||||
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
|
switch (ina_found.type) {
|
||||||
if (!ina219Sensor.isInitialized())
|
case ScanI2C::DeviceType::INA219:
|
||||||
return ina219Sensor.runOnce() > 0;
|
if (!ina219Sensor.isInitialized())
|
||||||
return ina219Sensor.isRunning();
|
return ina219Sensor.runOnce() > 0;
|
||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
|
return ina219Sensor.isRunning();
|
||||||
config.power.device_battery_ina_address) {
|
|
||||||
if (!ina226Sensor.isInitialized())
|
case ScanI2C::DeviceType::INA226:
|
||||||
return ina226Sensor.runOnce() > 0;
|
if (!ina226Sensor.isInitialized())
|
||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
|
return ina226Sensor.runOnce() > 0;
|
||||||
config.power.device_battery_ina_address) {
|
return ina226Sensor.isRunning();
|
||||||
if (!ina260Sensor.isInitialized())
|
|
||||||
return ina260Sensor.runOnce() > 0;
|
case ScanI2C::DeviceType::INA260:
|
||||||
return ina260Sensor.isRunning();
|
if (!ina260Sensor.isInitialized())
|
||||||
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
|
return ina260Sensor.runOnce() > 0;
|
||||||
config.power.device_battery_ina_address) {
|
return ina260Sensor.isRunning();
|
||||||
if (!ina3221Sensor.isInitialized())
|
|
||||||
return ina3221Sensor.runOnce() > 0;
|
case ScanI2C::DeviceType::INA3221:
|
||||||
return ina3221Sensor.isRunning();
|
if (!ina3221Sensor.isInitialized())
|
||||||
|
return ina3221Sensor.runOnce() > 0;
|
||||||
|
return ina3221Sensor.isRunning();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (config.power.device_battery_ina_address) {
|
||||||
|
INA_ADDR_LOCAL = config.power.device_battery_ina_address;
|
||||||
|
if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA219].first == config.power.device_battery_ina_address) {
|
||||||
|
if (!ina219Sensor.isInitialized())
|
||||||
|
return ina219Sensor.runOnce() > 0;
|
||||||
|
return ina219Sensor.isRunning();
|
||||||
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA226].first ==
|
||||||
|
config.power.device_battery_ina_address) {
|
||||||
|
if (!ina226Sensor.isInitialized())
|
||||||
|
return ina226Sensor.runOnce() > 0;
|
||||||
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA260].first ==
|
||||||
|
config.power.device_battery_ina_address) {
|
||||||
|
if (!ina260Sensor.isInitialized())
|
||||||
|
return ina260Sensor.runOnce() > 0;
|
||||||
|
return ina260Sensor.isRunning();
|
||||||
|
} else if (nodeTelemetrySensorsMap[meshtastic_TelemetrySensorType_INA3221].first ==
|
||||||
|
config.power.device_battery_ina_address) {
|
||||||
|
if (!ina3221Sensor.isInitialized())
|
||||||
|
return ina3221Sensor.runOnce() > 0;
|
||||||
|
return ina3221Sensor.isRunning();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
INA_ADDR_LOCAL = 0;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -41,6 +41,12 @@ ScanI2C::FoundDevice ScanI2C::firstAccelerometer() const
|
|||||||
return firstOfOrNONE(8, types);
|
return firstOfOrNONE(8, types);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ScanI2C::FoundDevice ScanI2C::firstINA() const
|
||||||
|
{
|
||||||
|
ScanI2C::DeviceType types[] = {INA219, INA226, INA260, INA3221};
|
||||||
|
return firstOfOrNONE(4, types);
|
||||||
|
}
|
||||||
|
|
||||||
ScanI2C::FoundDevice ScanI2C::firstRGBLED() const
|
ScanI2C::FoundDevice ScanI2C::firstRGBLED() const
|
||||||
{
|
{
|
||||||
ScanI2C::DeviceType types[] = {NCP5623, LP5562};
|
ScanI2C::DeviceType types[] = {NCP5623, LP5562};
|
||||||
|
@ -124,6 +124,8 @@ class ScanI2C
|
|||||||
|
|
||||||
FoundDevice firstAccelerometer() const;
|
FoundDevice firstAccelerometer() const;
|
||||||
|
|
||||||
|
FoundDevice firstINA() const;
|
||||||
|
|
||||||
FoundDevice firstRGBLED() const;
|
FoundDevice firstRGBLED() const;
|
||||||
|
|
||||||
virtual FoundDevice find(DeviceType) const;
|
virtual FoundDevice find(DeviceType) const;
|
||||||
|
@ -176,6 +176,9 @@ ScanI2C::DeviceAddress rtc_found = ScanI2C::ADDRESS_NONE;
|
|||||||
ScanI2C::DeviceAddress accelerometer_found = ScanI2C::ADDRESS_NONE;
|
ScanI2C::DeviceAddress accelerometer_found = ScanI2C::ADDRESS_NONE;
|
||||||
// The I2C address of the RGB LED (if found)
|
// The I2C address of the RGB LED (if found)
|
||||||
ScanI2C::FoundDevice rgb_found = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ScanI2C::ADDRESS_NONE);
|
ScanI2C::FoundDevice rgb_found = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ScanI2C::ADDRESS_NONE);
|
||||||
|
// The I2C address of the INA Module (if found)
|
||||||
|
ScanI2C::FoundDevice ina_found = ScanI2C::FoundDevice(ScanI2C::DeviceType::NONE, ScanI2C::ADDRESS_NONE);
|
||||||
|
ScanI2C::DeviceAddress ina_Address = ScanI2C::ADDRESS_NONE;
|
||||||
|
|
||||||
#ifdef T_WATCH_S3
|
#ifdef T_WATCH_S3
|
||||||
Adafruit_DRV2605 drv;
|
Adafruit_DRV2605 drv;
|
||||||
@ -685,6 +688,12 @@ void setup()
|
|||||||
LOG_DEBUG("acc_info = %i", acc_info.type);
|
LOG_DEBUG("acc_info = %i", acc_info.type);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
|
||||||
|
auto ina_Info = i2cScanner->firstINA();
|
||||||
|
// ina_Address = ina_Info.type != ScanI2C::DeviceType::NONE ? ina_Info.address : ina_Address;
|
||||||
|
LOG_DEBUG("ina_info = %i", ina_Info.type);
|
||||||
|
#endif
|
||||||
|
|
||||||
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BME_680, meshtastic_TelemetrySensorType_BME680);
|
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BME_680, meshtastic_TelemetrySensorType_BME680);
|
||||||
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BME_280, meshtastic_TelemetrySensorType_BME280);
|
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BME_280, meshtastic_TelemetrySensorType_BME280);
|
||||||
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BMP_280, meshtastic_TelemetrySensorType_BMP280);
|
scannerToSensorsMap(i2cScanner, ScanI2C::DeviceType::BMP_280, meshtastic_TelemetrySensorType_BMP280);
|
||||||
|
@ -34,6 +34,8 @@ extern uint8_t kb_model;
|
|||||||
extern ScanI2C::DeviceAddress rtc_found;
|
extern ScanI2C::DeviceAddress rtc_found;
|
||||||
extern ScanI2C::DeviceAddress accelerometer_found;
|
extern ScanI2C::DeviceAddress accelerometer_found;
|
||||||
extern ScanI2C::FoundDevice rgb_found;
|
extern ScanI2C::FoundDevice rgb_found;
|
||||||
|
// extern ScanI2C::DeviceAddress ina_Address;
|
||||||
|
extern ScanI2C::FoundDevice ina_found;
|
||||||
|
|
||||||
extern bool eink_found;
|
extern bool eink_found;
|
||||||
extern bool pmu_found;
|
extern bool pmu_found;
|
||||||
|
Loading…
Reference in New Issue
Block a user