Skip to content

Wisp Sensor Integrations to Main #186

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

Open
wants to merge 11 commits into
base: main
Choose a base branch
from
Open

Wisp Sensor Integrations to Main #186

wants to merge 11 commits into from

Conversation

drcrockerjr
Copy link
Contributor

This serves as a pull request to merge new Wisp sensor integrations into the main branch. The two sensors are the T6793 CO2 Sensor and the DFRobot Gravity sensor suite. For the DFRobots sensors, it is a modular setup that works with any of the gravity gas sensors. Here is the github with the code library that is used in the DFRobot code:
https://github.com/DFRobot/DFRobot_MultiGasSensor
The Wiki: https://wiki.dfrobot.com/SKU_SEN0465toSEN0476_Gravity_Gas_Sensor_Calibrated_I2C_UART

All code for the T6793 CO2 Sensor is base C with no external dependencies

@drcrockerjr
Copy link
Contributor Author

The sensor integrations have been verified by multiple parties.

@rainewheary
Copy link
Collaborator

Waiting on a new release (4.8) with https://github.com/DFRobot/DFRobot_MultiGasSensor integrated for merge.

@@ -28,5 +28,20 @@ class I2CDevice : public Module{
return false;
};

uint8_t scanI2C(){
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like if we are gonna have this function in here it should be static. It just feels like the specific I2C device has no need to scan but I still think this file would be a good location, thoughts @rainewheary?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd pull it out as a separate function - the class is I2CDevice, and I don't feel great about using it as a namespace for all I2C related actions that aren't device-specific.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This works too


//////////////////////////////////////////////////////////////////////////////////////////////////////
uint8_t Loom_MultiGasSensor::get_gas_i2c(const std::string& gasType) {
static const std::unordered_map<std::string, uint8_t> GAS_ADDRESSES = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We make a new one of these every time, but it seems like it doesn't change, move to a member variable

{"PH3", 0x45}
};

auto it = GAS_ADDRESSES.find(gasType);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not a fan of auto I feel like it just leads to ambiguity

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty conventional - the actual type is some horrible iterator thing.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair feels gross still but okay I guess lowkey would rather a if(contains) and then a [] but this works too

return;
}

const std::vector<std::string> gasTypes = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initialize as member variable

};

if (gasData == nullptr) {
gasData = new std::unordered_map<std::string, float>;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ummmm... there better be a really good reason for this

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't. Don't use new on smart pointers!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Kinda what I thought

}


String queryResult;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely not, use a c-string instead

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to modify the library - there's a huge amount of pointless back-and-forth conversions going on (mainly due to an inadequate API that pervasively exposes Arduino strings all over the place). Very frustrating...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm this is pain, but it may be required String is gross

char output[OUTPUT_SIZE];
char sensorError[OUTPUT_SIZE];

byte data[4];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is this series of writes actually doing

FUNCTION_START;
byte data[4];
Wire.beginTransmission(i2s_addr);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here

@rainewheary rainewheary linked an issue Apr 25, 2025 that may be closed by this pull request
Copy link
Collaborator

@rainewheary rainewheary left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the multigas library, we may be able to fix up a lot of the issues here by taking a sledgehammer scalpel to the api.

};

if (gasData == nullptr) {
gasData = new std::unordered_map<std::string, float>;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There isn't. Don't use new on smart pointers!

uint8_t addr;
bool moduleInitialized = false;
bool needsReinit = false;
std::unordered_map<std::string, float> *gasData = nullptr;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need to have a pointer here, unordered_map already manages it's own allocation. Just hold one directly.

}


String queryResult;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We may need to modify the library - there's a huge amount of pointless back-and-forth conversions going on (mainly due to an inadequate API that pervasively exposes Arduino strings all over the place). Very frustrating...



private:
uint8_t get_gas_i2c(const std::string& gasType);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use camelCase for methods

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Zak/Wisp MultiGas Integration
4 participants