Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect charging status by measuring current flow with configured INA219 battery sensor #5271

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
124 commits
Select commit Hold shift + click to select a range
ab23e9e
INA219 charging detection
nebman Nov 1, 2024
296f581
Update Power.cpp
nebman Nov 2, 2024
b3777d5
Update Power.cpp
nebman Nov 2, 2024
90062a1
move getCurrentMa() to new CurrentSensor class
nebman Nov 7, 2024
f0a6839
INA219 charging detection
nebman Nov 1, 2024
12cd9e1
Update Power.cpp
nebman Nov 2, 2024
06ebcf0
Update Power.cpp
nebman Nov 2, 2024
e54d259
move getCurrentMa() to new CurrentSensor class
nebman Nov 7, 2024
f85ae4e
Merge branch 'use-ina-currentflow-for-charging-detection' of https://…
nebman Nov 7, 2024
1ab93e0
add INA3221 charging detection
nebman Nov 7, 2024
1b02c86
Merge branch 'master' into use-ina-currentflow-for-charging-detection
thebentern Nov 11, 2024
12f5d01
Merge branch 'master' into use-ina-currentflow-for-charging-detection
jp-bennett Nov 13, 2024
9961b23
Merge branch 'master' into use-ina-currentflow-for-charging-detection
jp-bennett Nov 15, 2024
00b90ec
RP2040: Update core; add mDNS support (#5355)
GUVWAF Nov 16, 2024
adb0cdc
Add sudo to apt-get commands for Raspbian Build (#5364)
fifieldt Nov 16, 2024
1969c5e
Typo fix in build_raspbian.yml (#5365)
fifieldt Nov 16, 2024
431c194
Rework some things
thebentern Nov 16, 2024
7192d8a
Trunk
thebentern Nov 16, 2024
4ebb2c1
Separate littlefs bundle
thebentern Nov 16, 2024
09eef88
version tags
thebentern Nov 16, 2024
11ff0fa
Diag
thebentern Nov 16, 2024
0470094
Add littlefswebui
thebentern Nov 17, 2024
1114430
Bug fixed in ExternalNotificationModule (#5375)
gjelsoe Nov 17, 2024
58a206d
Cleanup static files from bad Web UI bundle on 2.5.13 release (#5376)
thebentern Nov 17, 2024
4f4224b
Move some actions to after `startTransmit()` (#5383)
GUVWAF Nov 17, 2024
41379ae
[create-pull-request] automated change (#5380)
github-actions[bot] Nov 17, 2024
3aba46e
Allows all 3 PKI keys to be added to userPrefs.h (#4969) and a tool. …
gjelsoe Nov 17, 2024
810a014
[create-pull-request] automated change (#5388)
github-actions[bot] Nov 18, 2024
03c3845
add smiley emoji (#5391)
jcyrio Nov 19, 2024
0193e57
Anable trace route function on wismeshtap platform (#5389)
DanielCao0 Nov 19, 2024
72010f6
fix 'symbal' typo (#5395)
jcyrio Nov 19, 2024
9136fed
[create-pull-request] automated change (#5399)
github-actions[bot] Nov 19, 2024
d5bc401
/api/v1/fromradio: add OPTIONS handler for CORS. (#5386)
cpatulea Nov 19, 2024
46d2369
Make heart emoji usable (#5403)
jcyrio Nov 20, 2024
4258372
Create a specific hw_model for WisMesh Tap (#5400)
thebentern Nov 20, 2024
3e5a18f
Fix RTC time injection and consolidate position logic (#5396)
thebentern Nov 20, 2024
13d2b62
Update arduino-pico core to fix sporadic hangs (#5406)
GUVWAF Nov 20, 2024
fc35eca
Update platform-raspberrypi also (#5407)
GUVWAF Nov 20, 2024
f1b7956
--web added to device-install(.sh/.bat) (#5405)
gjelsoe Nov 20, 2024
3101f21
add GPS in indicator board (#5411)
Dylanliacc Nov 21, 2024
3e3c3d6
Fixed NMEA sentence issue in CalTopo as well as bug with no printing …
thebentern Nov 21, 2024
2f3d6ed
--web littlefswebui-* typo fix (#5416)
gjelsoe Nov 21, 2024
baad3e5
Temporarily disable MDNS when MQTT is enabled (#5418)
GUVWAF Nov 21, 2024
ede61e0
Check for OkToMqtt flag presence before uplinking to MQTT (#5413)
thebentern Nov 21, 2024
2d10094
Temetry can respond to want-response for LocalStats variant (#5414)
thebentern Nov 21, 2024
d1e9330
Seems like the last DIY board that's not "extra" (#5420)
jp-bennett Nov 22, 2024
c14c7ae
Cherry pick tdeck fixes (#5422)
thebentern Nov 22, 2024
ae8ef29
add canned message and keyboard in indicator board (#5410)
Dylanliacc Nov 23, 2024
513b030
Update build-native.sh (#5415)
madeofstown Nov 23, 2024
636b791
Cleans up visibility in GPS.h (#5426)
charlieh0tel Nov 23, 2024
350a89d
Fix admin key loading from userPrefs.h (#5417)
Mictronics Nov 23, 2024
563aeba
try to detect dfrobot station to tell it apart from an ublox gps. (#5…
caveman99 Nov 23, 2024
cc7440b
Remove BMA-423 and STK8X by default (#5429)
thebentern Nov 23, 2024
86b504f
[create-pull-request] automated change (#5431)
github-actions[bot] Nov 24, 2024
79589df
Support for the ClimateGuard RadSens Geiger-Muller tube (#5425)
jake-b Nov 24, 2024
66e219d
fixes https://github.com/meshtastic/firmware/issues/5434 (#5435)
caveman99 Nov 24, 2024
fe1ed0d
Fix memory leaks by adding missing `free()` calls before early return…
CTassisF Nov 25, 2024
37bb28a
Removing 1.0 legacy boards from releases and completely removing Helt…
thebentern Nov 25, 2024
14c4475
A second round of cleanup on GPS.h. (#5433)
charlieh0tel Nov 25, 2024
5347ee2
enable MQTT with TLS on RPi picow (#5442)
tomasdubec Nov 25, 2024
adb244e
Don't powersave on Wifi (#5443)
thebentern Nov 25, 2024
e746905
Revert "Seems like the last DIY board that's not "extra" (#5420)" (#5…
thebentern Nov 26, 2024
e0eae54
Actually gunzip all the files when building a .deb (#5449)
jp-bennett Nov 26, 2024
603e723
[create-pull-request] automated change (#5457)
github-actions[bot] Nov 26, 2024
cf62c6d
Cleanup i2c scan logs and macro to save some bytes and remain consist…
thebentern Nov 26, 2024
46eb534
Clean up some inline functions (#5454)
thebentern Nov 26, 2024
32f8156
Use isWithinTimespanMs to avoid refererence to NodeDb instance inside…
thebentern Nov 26, 2024
1f89ee5
fix cors for meshtasticd to allow use of cross origin clients (#5463)
liamcottle Nov 27, 2024
ca4bfa1
Remove ATECC crypto chip placeholder code (#5461)
thebentern Nov 27, 2024
6d14c1a
GPS.h cleanups round 3. (#5447)
charlieh0tel Nov 27, 2024
6c6b323
Fix ukrainian fonts (#5468)
panaceya Nov 28, 2024
49f0f7a
fix: Solve the lightsleep crash problem via disable lightsleep for i…
Wvirgil123 Nov 28, 2024
85d23d6
Trunk
thebentern Nov 28, 2024
b4ae5e3
Warnings and log cleanup (#5472)
thebentern Nov 28, 2024
902a0d2
[create-pull-request] automated change (#5475)
github-actions[bot] Nov 29, 2024
c53e614
Adds libusb dev package to Raspbian build steps (#5480)
jp-bennett Nov 29, 2024
a33276f
[create-pull-request] automated change (#5478)
github-actions[bot] Nov 30, 2024
bb5f07f
Portduino fixes (#5479)
jp-bennett Nov 30, 2024
cff0cea
Update arduino-pico core and remove MDNS restriction (#5483)
GUVWAF Nov 30, 2024
b8c84a1
Update xiao_esp32 fully support L67K (#5488)
Dylanliacc Dec 2, 2024
18b1928
Convert userprefs to a json file instead of header file which has to …
thebentern Dec 3, 2024
2bad857
SimRadio: clean-up and emulate collisions (#5487)
GUVWAF Dec 3, 2024
0d7b82d
add nodeId to nodeinfo update log lines and removed redundant nodeinf…
rbrtio Dec 3, 2024
4c26f36
Refact the macro definition of GPS initialization of GPSDEFAULTD_NOT_…
Dylanliacc Dec 3, 2024
e1532e3
Extend Length of Source and Destination Node IDs Logged (#5492)
rbrtio Dec 3, 2024
0f7039f
Added femtofox configs (#5477)
noon92 Dec 3, 2024
97adf21
[Add] LR1110, LR1120 and LR1121 to linux native Portduino (#5496)
markbirss Dec 4, 2024
595af17
[create-pull-request] automated change (#5500)
github-actions[bot] Dec 4, 2024
a0dd632
Fix minor typos in package workflows (#5505)
jp-bennett Dec 4, 2024
4036fe1
Don't use channel index for encrypted packet (#5509)
GUVWAF Dec 5, 2024
b3e5186
Always Announce MDNS meshtastic service (#5503)
broglep Dec 5, 2024
f36aace
fix nodeDB erase loop when free mem returns invalid value (0, -1). (#…
fifieldt Dec 7, 2024
07a1f73
Add heltec capsule back
thebentern Dec 7, 2024
4823ca1
Revert "Add heltec capsule back"
thebentern Dec 7, 2024
985f4a1
Lets try this again minus device ui
thebentern Dec 7, 2024
74015ec
Add popular nrf52 pro micro to the builds (#5523)
thebentern Dec 7, 2024
2b47e75
Add MACAddress to config.yaml (#5506)
jp-bennett Dec 7, 2024
759a975
Configure Seeed Xiao S3 RX enable pin (#5517)
mgranberry Dec 7, 2024
60cdaa6
Create OpenWRT_One_mikroBUS_sx1262.yaml (#5529)
markbirss Dec 8, 2024
88bbc82
tlora_v2_1_16: Unset BUTTON_PIN and BUTTON_NEED_PULLUP (#5535)
ndoo Dec 9, 2024
f781a92
[create-pull-request] automated change (#5530)
github-actions[bot] Dec 9, 2024
c68a28b
Fix detection for some RadSens hardware versions (#5542)
jake-b Dec 10, 2024
ebc2c05
Initialize dmac array to nulls (#5538)
jp-bennett Dec 10, 2024
ea63ee9
Update OpenWRT_One_mikroBUS_sx1262.yaml (#5544)
markbirss Dec 10, 2024
b618bef
Add portduino-buildroot variant (#5540)
vidplace7 Dec 10, 2024
2e3289d
portduino-buildroot: Define c standard (#5547)
vidplace7 Dec 10, 2024
f91d653
Portduino: Move meshtasticd/web out of /usr/share/doc/ (#5548)
vidplace7 Dec 10, 2024
a25ad66
Portduino: fix transitional symlinks (#5550)
vidplace7 Dec 10, 2024
09c1e44
Windows Support - Trunk and Platformio (#5397) (#5518)
fifieldt Dec 12, 2024
e14e665
Synch minor changes from TFT branch (#5520)
fifieldt Dec 12, 2024
ebec5bf
DIO3_TCXO_VOLTAGE in config.yaml can now take an exact voltage (#5558)
jp-bennett Dec 13, 2024
361fd26
Support TLORA_V3.0 (#5563)
caveman99 Dec 14, 2024
64f217a
Create OpenWRT-One-mikroBUS-LR-IOT-CLICK.yaml (#5564)
markbirss Dec 14, 2024
baa56cc
Portduino: fix setting hwId via argument (#5565)
GUVWAF Dec 14, 2024
ecf87fd
INA219 charging detection
nebman Nov 1, 2024
233b608
Update Power.cpp
nebman Nov 2, 2024
0058187
Trunk Fixes
fifieldt Dec 14, 2024
3d57202
Merge branch 'master' into use-ina-currentflow-for-charging-detection
fifieldt Dec 14, 2024
4e4d46d
Merge branch 'master' into use-ina-currentflow-for-charging-detection
fifieldt Dec 15, 2024
91dd7d4
Merge branch 'master' into use-ina-currentflow-for-charging-detection
fifieldt Dec 18, 2024
86e952a
Merge branch 'master' into use-ina-currentflow-for-charging-detection
fifieldt Dec 20, 2024
70ffa37
Merge branch 'master' into use-ina-currentflow-for-charging-detection
fifieldt Dec 21, 2024
bfe5568
Merge branch 'master' into use-ina-currentflow-for-charging-detection
fifieldt Dec 21, 2024
6f5b352
Add INA226 support
fifieldt Dec 22, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,5 @@ lib_deps =
https://github.com/KodinLanewave/[email protected]
mprograms/[email protected]
dfrobot/[email protected]
https://github.com/meshtastic/DFRobot_LarkWeatherStation#4de3a9cadef0f6a5220a8a906cf9775b02b0040d
https://github.com/meshtastic/DFRobot_LarkWeatherStation#4de3a9cadef0f6a5220a8a906cf9775b02b0040d
robtillaart/[email protected]
39 changes: 37 additions & 2 deletions src/Power.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,9 @@ static const uint8_t ext_chrg_detect_value = EXT_CHRG_DETECT_VALUE;
#endif

#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
INA260Sensor ina260Sensor;
INA219Sensor ina219Sensor;
INA226Sensor ina226Sensor;
INA260Sensor ina260Sensor;
INA3221Sensor ina3221Sensor;
#endif

Expand Down Expand Up @@ -413,7 +414,20 @@ class AnalogBatteryLevel : public HasBatteryLevel
#ifdef EXT_CHRG_DETECT
return digitalRead(EXT_CHRG_DETECT) == ext_chrg_detect_value;
#else
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO) && !defined(ARCH_STM32WL) && \
!defined(DISABLE_INA_CHARGING_DETECTION)
if (hasINA()) {
// get current flow from INA sensor - negative value means power flowing into the battery
// 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);
#if defined(INA_CHARGING_DETECTION_INVERT)
return getINACurrent() > 0;
#else
return getINACurrent() < 0;
#endif
}
return isBatteryConnect() && isVbusIn();
#endif
#endif
}

Expand Down Expand Up @@ -450,6 +464,9 @@ class AnalogBatteryLevel : public HasBatteryLevel
{
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();
Expand All @@ -460,6 +477,20 @@ class AnalogBatteryLevel : public HasBatteryLevel
return 0;
}

int16_t getINACurrent()
{
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;
}

bool hasINA()
{
if (!config.power.device_battery_ina_address) {
Expand All @@ -469,6 +500,10 @@ class AnalogBatteryLevel : public HasBatteryLevel
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())
Expand Down Expand Up @@ -1154,4 +1189,4 @@ bool Power::lipoInit()
{
return false;
}
#endif
#endif
6 changes: 5 additions & 1 deletion src/modules/Telemetry/PowerTelemetry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ int32_t PowerTelemetryModule::runOnce()
// therefore, we should only enable the sensor loop if measurement is also enabled
if (ina219Sensor.hasSensor() && !ina219Sensor.isInitialized())
result = ina219Sensor.runOnce();
if (ina226Sensor.hasSensor() && !ina226Sensor.isInitialized())
result = ina226Sensor.runOnce();
if (ina260Sensor.hasSensor() && !ina260Sensor.isInitialized())
result = ina260Sensor.runOnce();
if (ina3221Sensor.hasSensor() && !ina3221Sensor.isInitialized())
Expand Down Expand Up @@ -170,6 +172,8 @@ bool PowerTelemetryModule::getPowerTelemetry(meshtastic_Telemetry *m)
#if HAS_TELEMETRY && !defined(ARCH_PORTDUINO)
if (ina219Sensor.hasSensor())
valid = ina219Sensor.getMetrics(m);
if (ina226Sensor.hasSensor())
valid = ina226Sensor.getMetrics(m);
if (ina260Sensor.hasSensor())
valid = ina260Sensor.getMetrics(m);
if (ina3221Sensor.hasSensor())
Expand Down Expand Up @@ -253,4 +257,4 @@ bool PowerTelemetryModule::sendTelemetry(NodeNum dest, bool phoneOnly)
return false;
}

#endif
#endif
13 changes: 13 additions & 0 deletions src/modules/Telemetry/Sensor/CurrentSensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "configuration.h"

#if !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR

#pragma once

class CurrentSensor
{
public:
virtual int16_t getCurrentMa() = 0;
};

#endif
5 changes: 5 additions & 0 deletions src/modules/Telemetry/Sensor/INA219Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,9 @@ uint16_t INA219Sensor::getBusVoltageMv()
return lround(ina219.getBusVoltage_V() * 1000);
}

int16_t INA219Sensor::getCurrentMa()
{
return lround(ina219.getCurrent_mA());
}

#endif
4 changes: 3 additions & 1 deletion src/modules/Telemetry/Sensor/INA219Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR

#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "CurrentSensor.h"
#include "TelemetrySensor.h"
#include "VoltageSensor.h"
#include <Adafruit_INA219.h>

class INA219Sensor : public TelemetrySensor, VoltageSensor
class INA219Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
{
private:
Adafruit_INA219 ina219;
Expand All @@ -20,6 +21,7 @@ class INA219Sensor : public TelemetrySensor, VoltageSensor
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual uint16_t getBusVoltageMv() override;
virtual int16_t getCurrentMa() override;
};

#endif
58 changes: 58 additions & 0 deletions src/modules/Telemetry/Sensor/INA226Sensor.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#include "configuration.h"

#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR

#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "INA226.h"
#include "INA226Sensor.h"
#include "TelemetrySensor.h"

INA226Sensor::INA226Sensor() : TelemetrySensor(meshtastic_TelemetrySensorType_INA226, "INA226") {}

int32_t INA226Sensor::runOnce()
{
LOG_INFO("Init sensor: %s", sensorName);
if (!hasSensor()) {
return DEFAULT_SENSOR_MINIMUM_WAIT_TIME_BETWEEN_READS;
}

begin(nodeTelemetrySensorsMap[sensorType].second, nodeTelemetrySensorsMap[sensorType].first);

if (!status) {
status = ina226.begin();
}
return initI2CSensor();
}

void INA226Sensor::setup() {}

void INA226Sensor::begin(TwoWire *wire, uint8_t addr)
{
_wire = wire;
_addr = addr;
ina226 = INA226(_addr, _wire);
_wire->begin();
}

bool INA226Sensor::getMetrics(meshtastic_Telemetry *measurement)
{
measurement->variant.environment_metrics.has_voltage = true;
measurement->variant.environment_metrics.has_current = true;

// mV conversion to V
measurement->variant.environment_metrics.voltage = ina226.getBusVoltage() / 1000;
measurement->variant.environment_metrics.current = ina226.getCurrent_mA();
return true;
}

uint16_t INA226Sensor::getBusVoltageMv()
{
return lround(ina226.getBusVoltage());
}

int16_t INA226Sensor::getCurrentMa()
{
return lround(ina226.getCurrent_mA());
}

#endif
30 changes: 30 additions & 0 deletions src/modules/Telemetry/Sensor/INA226Sensor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "configuration.h"

#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR

#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "CurrentSensor.h"
#include "TelemetrySensor.h"
#include "VoltageSensor.h"
#include <INA226.h>

class INA226Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
{
private:
uint8_t _addr = INA_ADDR;
TwoWire *_wire = &Wire;
INA226 ina226 = INA226(_addr, _wire);

protected:
virtual void setup() override;
void begin(TwoWire *wire = &Wire, uint8_t addr = INA_ADDR);

public:
INA226Sensor();
virtual int32_t runOnce() override;
virtual bool getMetrics(meshtastic_Telemetry *measurement) override;
virtual uint16_t getBusVoltageMv() override;
virtual int16_t getCurrentMa() override;
};

#endif
5 changes: 5 additions & 0 deletions src/modules/Telemetry/Sensor/INA3221Sensor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion src/modules/Telemetry/Sensor/INA3221Sensor.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR

#include "../mesh/generated/meshtastic/telemetry.pb.h"
#include "CurrentSensor.h"
#include "TelemetrySensor.h"
#include "VoltageSensor.h"
#include <INA3221.h>

class INA3221Sensor : public TelemetrySensor, VoltageSensor
class INA3221Sensor : public TelemetrySensor, VoltageSensor, CurrentSensor
{
private:
INA3221 ina3221 = INA3221(INA3221_ADDR42_SDA);
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 4 additions & 2 deletions src/power.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ extern RTC_NOINIT_ATTR uint64_t RTC_reg_b;

#if HAS_TELEMETRY && !MESHTASTIC_EXCLUDE_ENVIRONMENTAL_SENSOR && !defined(ARCH_PORTDUINO)
#include "modules/Telemetry/Sensor/INA219Sensor.h"
#include "modules/Telemetry/Sensor/INA226Sensor.h"
#include "modules/Telemetry/Sensor/INA260Sensor.h"
#include "modules/Telemetry/Sensor/INA3221Sensor.h"
extern INA260Sensor ina260Sensor;
extern INA219Sensor ina219Sensor;
extern INA226Sensor ina226Sensor;
extern INA260Sensor ina260Sensor;
extern INA3221Sensor ina3221Sensor;
#endif

Expand Down Expand Up @@ -99,4 +101,4 @@ class Power : private concurrency::OSThread
#endif
};

extern Power *power;
extern Power *power;
Loading