Skip to content

Commit 8007aad

Browse files
author
Scott Powell
committed
* Promicro: some refactors, minor fixes for INA3221 sensors
1 parent cf1c863 commit 8007aad

File tree

3 files changed

+12
-21
lines changed

3 files changed

+12
-21
lines changed

src/helpers/SensorManager.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,6 @@
88

99
#define TELEM_CHANNEL_SELF 1 // LPP data channel for 'self' device
1010

11-
#define TELEM_INA3221_ADDRESS 0x42 // INA3221 3 channel current, voltage, power sensor I2C address
12-
#define TELEM_INA3221_SHUNT_VALUE 0.100 // most variants will have a 0.1 ohm shunts
13-
#define TELEM_INA3221_SETTING_CH1 "INA3221 Channel 1"
14-
#define TELEM_INA3221_SETTING_CH2 "INA3221 Channel 2"
15-
#define TELEM_INA3221_SETTING_CH3 "INA3221 Channel 3"
16-
1711
class SensorManager {
1812
public:
1913
double node_lat, node_lon; // modify these, if you want to affect Advert location

variants/promicro/target.cpp

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,34 +75,26 @@ mesh::LocalIdentity radio_new_identity() {
7575
return mesh::LocalIdentity(&rng); // create new random identity
7676
}
7777

78-
INA3221 INA_3221(TELEM_INA3221_ADDRESS, &Wire);
78+
static INA3221 INA_3221(TELEM_INA3221_ADDRESS, &Wire);
7979

8080
bool PromicroSensorManager::begin() {
8181
if (INA_3221.begin() ) {
82-
Serial.print("Found INA3221 at address ");
83-
Serial.print(INA_3221.getAddress());
84-
Serial.println();
85-
Serial.print(INA_3221.getDieID(), HEX);
86-
Serial.print(INA_3221.getManufacturerID(), HEX);
87-
Serial.print(INA_3221.getConfiguration(), HEX);
88-
Serial.println();
82+
MESH_DEBUG_PRINTLN("Found INA3221 at address: %02X", INA_3221.getAddress());
83+
MESH_DEBUG_PRINTLN("%04X %04X %04X", INA_3221.getDieID(), INA_3221.getManufacturerID(), INA_3221.getConfiguration());
8984

9085
for(int i = 0; i < 3; i++) {
9186
INA_3221.setShuntR(i, TELEM_INA3221_SHUNT_VALUE);
9287
}
9388
INA3221initialized = true;
94-
}
95-
else {
89+
} else {
9690
INA3221initialized = false;
97-
Serial.print("INA3221 was not found at I2C address ");
98-
Serial.print(TELEM_INA3221_ADDRESS, HEX);
99-
Serial.println();
91+
MESH_DEBUG_PRINTLN("INA3221 was not found at I2C address %02X", TELEM_INA3221_ADDRESS);
10092
}
10193
return true;
10294
}
10395

10496
bool PromicroSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
105-
if (requester_permissions && TELEM_PERM_ENVIRONMENT) {
97+
if (requester_permissions & TELEM_PERM_ENVIRONMENT) {
10698
if (INA3221initialized) {
10799
for(int i = 0; i < 3; i++) {
108100
// add only enabled INA3221 channels to telemetry

variants/promicro/target.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,18 @@ void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
2323
void radio_set_tx_power(uint8_t dbm);
2424
mesh::LocalIdentity radio_new_identity();
2525

26+
#define TELEM_INA3221_ADDRESS 0x42 // INA3221 3 channel current, voltage, power sensor I2C address
27+
#define TELEM_INA3221_SHUNT_VALUE 0.100 // most variants will have a 0.1 ohm shunts
28+
#define TELEM_INA3221_SETTING_CH1 "INA3221-1"
29+
#define TELEM_INA3221_SETTING_CH2 "INA3221-2"
30+
#define TELEM_INA3221_SETTING_CH3 "INA3221-3"
2631

2732
class PromicroSensorManager: public SensorManager {
2833
bool INA3221initialized = false;
2934

3035
// INA3221 channels in telemetry
3136
int INA3221_CHANNELS[NUM_SENSOR_SETTINGS] = {TELEM_CHANNEL_SELF + 1, TELEM_CHANNEL_SELF + 2, TELEM_CHANNEL_SELF+ 3};
32-
char * INA3221_CHANNEL_NAMES[NUM_SENSOR_SETTINGS] = { TELEM_INA3221_SETTING_CH1, TELEM_INA3221_SETTING_CH2, TELEM_INA3221_SETTING_CH3};
37+
const char * INA3221_CHANNEL_NAMES[NUM_SENSOR_SETTINGS] = { TELEM_INA3221_SETTING_CH1, TELEM_INA3221_SETTING_CH2, TELEM_INA3221_SETTING_CH3};
3338
bool INA3221_CHANNEL_ENABLED[NUM_SENSOR_SETTINGS] = {true, true, true};
3439

3540
public:

0 commit comments

Comments
 (0)