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

Scd4x 3x issue #658

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

Scd4x 3x issue #658

wants to merge 9 commits into from

Conversation

tyeth
Copy link
Contributor

@tyeth tyeth commented Nov 8, 2024

This adds a metro s3 debug target, and changes the SCD4x to use a single read for all datapoints at once like the SCD30.
Also noticed the alreadyRead condition needed a fix.
Lastly, to get a reliable first read on the SCD4x, I pass in the sensor period to the Begin setup call, allowing the driver to set it's first read to be five seconds time (after init).

@tyeth tyeth marked this pull request as ready for review November 8, 2024 15:50
@tyeth tyeth requested a review from brentru November 15, 2024 15:16
@tyeth
Copy link
Contributor Author

tyeth commented Nov 15, 2024

@brentru this is ready for review

Copy link
Member

@brentru brentru left a comment

Choose a reason for hiding this comment

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

The changes to the driver(s) look good.

I am confused why you changed functions within I2c.* and I2c_Driver.h. Are these necessary for this PR, and if so, can you explain why they need to be changed?

Comment on lines +1332 to +1333
ulong (WipperSnapper_I2C_Driver::*getPeriodPrvFunc)(),
void (WipperSnapper_I2C_Driver::*setPeriodPrvFunc)(ulong),
Copy link
Member

Choose a reason for hiding this comment

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

What's the reasoning for the function header to change from long to ulong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous poll period (periodPrv) is stored in the backing field as a long, and initially is set to 24hours ago (negative), but the logic check was shortcutting due to the unsigned long getter and setter methods (achieving the initial read change that introduced it).
Now that I've got a driver that wants update to only be called 5seconds after driver init/begin, which uses the sensor poll period taken away from millis +5secs, we need a way of the previous poll period getter+setter taking negative numbers.

Copy link
Member

@brentru brentru Nov 15, 2024

Choose a reason for hiding this comment

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

This makes sense to me as millis() returns a ulong and you want to prevent it from underflowing.

Would we want to change everything within I2C.cpp/I2C_Driver to ulong while we're at it?

If we are going to change something, let's ensure we have matching function signatures everywhere.

Choose a reason for hiding this comment

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

Be careful that you don't make a change that breaks backward compatibility. Could code that uses the current data type break if the type is re-defined?

src/components/i2c/WipperSnapper_I2C.cpp Show resolved Hide resolved
sensors_event_t _temperature; ///< Temperature
sensors_event_t _humidity; ///< Relative Humidity
sensors_event_t _CO2; ///< CO2
float _temperature; ///< Temperature
Copy link
Member

Choose a reason for hiding this comment

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

Why are we moving away from sensors_event_t types here?

bool readSensorMeasurements() {
uint16_t error;
/*******************************************************************************/
bool sensorReady() {
Copy link
Member

Choose a reason for hiding this comment

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

Change function to something that reflects its returning a bool, like IsSensorReady()

Copy link
Member

Choose a reason for hiding this comment

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

the rest of this function incl. the fall-thru makes logical sense, it's much better than it was before

/*******************************************************************************/
bool readSensorData() {
// dont read sensor more than once per second
if (alreadyRecentlyRead()) {
Copy link
Member

Choose a reason for hiding this comment

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

Okay so alreadyRecentlyRead() returning true assets that the sensor is read > 1x per second? Maybe change the function's name to reflect this?

// Check if data is ready
error = _scd->getDataReadyFlag(isDataReady);
if (error || !isDataReady)
if (!sensorReady()) {
Copy link
Member

Choose a reason for hiding this comment

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

Change to something that reflects the boolean, IsSensorReady()

Comment on lines 191 to 194
uint16_t _co2 = 0; ///< SCD4x co2 reading
float _temperature = 20.0f; ///< SCD4x temperature reading
float _humidity = 50.0f; ///< SCD4x humidity reading
ulong _lastRead = 0; ///< Last time the sensor was read
Copy link
Member

Choose a reason for hiding this comment

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

What's the reason for the default values being defined here, why do they need to be 0, 20.0, 50.0, 0?

If they do need to be pre-defined before the function runs, let's do it in the constructor instead of here.

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.

3 participants