mirror of
https://github.com/meshcore-dev/MeshCore.git
synced 2026-04-20 22:13:47 +00:00
283 Add support of INA3221 to Promicro telemetry
This commit is contained in:
parent
d072e7b575
commit
b035487101
6 changed files with 214 additions and 3 deletions
|
|
@ -10,7 +10,7 @@ WRAPPER_CLASS radio_driver(radio, board);
|
|||
|
||||
VolatileRTCClock fallback_clock;
|
||||
AutoDiscoverRTCClock rtc_clock(fallback_clock);
|
||||
SensorManager sensors;
|
||||
PromicroSensorManager sensors;
|
||||
|
||||
#ifndef LORA_CR
|
||||
#define LORA_CR 5
|
||||
|
|
@ -74,3 +74,107 @@ mesh::LocalIdentity radio_new_identity() {
|
|||
RadioNoiseListener rng(radio);
|
||||
return mesh::LocalIdentity(&rng); // create new random identity
|
||||
}
|
||||
|
||||
PromicroSensorManager::PromicroSensorManager(){
|
||||
INA_3221 = new INA3221(TELEM_INA3221_ADDRESS, &Wire);
|
||||
}
|
||||
|
||||
PromicroSensorManager::~PromicroSensorManager(){
|
||||
if (INA_3221) {
|
||||
delete INA_3221;
|
||||
INA_3221 = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
bool PromicroSensorManager::begin() {
|
||||
if (INA_3221->begin() ) {
|
||||
Serial.print("Found INA3221 at address ");
|
||||
Serial.print(INA_3221->getAddress());
|
||||
Serial.println();
|
||||
Serial.print(INA_3221->getDieID(), HEX);
|
||||
Serial.print(INA_3221->getManufacturerID(), HEX);
|
||||
Serial.print(INA_3221->getConfiguration(), HEX);
|
||||
Serial.println();
|
||||
|
||||
for(int i = 0; i < 3; i++) {
|
||||
INA_3221->setShuntR(i, TELEM_INA3221_SHUNT_VALUE);
|
||||
}
|
||||
// add INA3221 settings to settings manager
|
||||
settingsManager.addSetting(TELEM_INA3221_SETTING_CH1, true);
|
||||
settingsManager.addSetting(TELEM_INA3221_SETTING_CH2, true);
|
||||
settingsManager.addSetting(TELEM_INA3221_SETTING_CH3, true);
|
||||
INA3221initialized = true;
|
||||
}
|
||||
else {
|
||||
INA3221initialized = false;
|
||||
Serial.print("INA3221 was not found at I2C address ");
|
||||
Serial.print(TELEM_INA3221_ADDRESS, HEX);
|
||||
Serial.println();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool PromicroSensorManager::querySensors(uint8_t requester_permissions, CayenneLPP& telemetry) {
|
||||
// TODO: what is the correct permission here?
|
||||
if (requester_permissions && TELEM_PERM_BASE) {
|
||||
if (INA3221initialized) {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
// add only enabled INA3221 channels to telemetry
|
||||
if (settingsManager.getSettingValue(INA3221_CHANNEL_NAMES[i]) == "true") {
|
||||
|
||||
// TODO: remove when telemetry support gets properly added
|
||||
// Serial.print("CH");
|
||||
// Serial.print(i);
|
||||
// Serial.print(" Voltage: ");
|
||||
// Serial.print(INA_3221->getBusVoltage(i));
|
||||
// Serial.print("V Current: ");
|
||||
// Serial.print(INA_3221->getCurrent(i));
|
||||
// Serial.print("A Power: ");
|
||||
// Serial.print(INA_3221->getPower(i));
|
||||
// Serial.println();
|
||||
|
||||
telemetry.addVoltage(INA3221_CHANNELS[i], INA_3221->getBusVoltage(i));
|
||||
telemetry.addCurrent(INA3221_CHANNELS[i], INA_3221->getCurrent(i));
|
||||
telemetry.addPower(INA3221_CHANNELS[i], INA_3221->getPower(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int PromicroSensorManager::getNumSettings() const {
|
||||
return settingsManager.getSettingCount();
|
||||
}
|
||||
|
||||
const char* PromicroSensorManager::getSettingName(int i) const {
|
||||
return settingsManager.getSettingName(i);
|
||||
}
|
||||
|
||||
const char* PromicroSensorManager::getSettingValue(int i) const {
|
||||
return settingsManager.getSettingValue(i);
|
||||
}
|
||||
|
||||
bool PromicroSensorManager::setSettingValue(const char* name, const char* value) {
|
||||
if (settingsManager.setSettingValue(name, value)) {
|
||||
onSettingsChanged();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void PromicroSensorManager::onSettingsChanged() {
|
||||
if (INA3221initialized) {
|
||||
for(int i = 0; i < 3; i++) {
|
||||
int channelEnabled = INA_3221->getEnableChannel(i);
|
||||
bool settingEnabled = settingsManager.getSettingValue(INA3221_CHANNEL_NAMES[i]) == "true";
|
||||
if (!settingEnabled && channelEnabled) {
|
||||
INA_3221->disableChannel(i);
|
||||
}
|
||||
if (settingEnabled && !channelEnabled) {
|
||||
INA_3221->enableChannel(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue