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

Scd40 driver libhal 2.0 #108

Merged
merged 41 commits into from
Jan 23, 2024
Merged

Conversation

MichaelYKersey
Copy link
Contributor

Scd40 driver: functional readings, config settings are untested

Copy link
Contributor

@kammce kammce left a comment

Choose a reason for hiding this comment

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

This isn't a full review, but some things I spotted when I skimmed through this PR. Great work @MichaelYKersey ! Keep it up :)

science/platform-implementations/scd40.cpp Show resolved Hide resolved

hal::status scd40_nm::set_settings( struct settings setting) {
if(setting.set_temp != 0){
int temp = int(((setting.set_temp*(1<<16)) / 175)) ;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
int temp = int(((setting.set_temp*(1<<16)) / 175)) ;
int temp = int(((setting.set_temp*(1<<16)) / 175)) ;

Give these magic numbers names. 175 isn't some power of two so it must mean something. Fine the term in the datasheet and make a constexpr variables for it. Something like:

// Found on page X in datasheet name "<url to datasheet>"
constexpr std::uint32_t temperature_scalar = 175; 

science/platform-implementations/scd40.cpp Show resolved Hide resolved


//TODO: revise output type
enum addresses {// deal with hal::byte later
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
enum addresses {// deal with hal::byte later
enum class addresses { // deal with hal::byte later

Great work using an enum for all of the addresses. Makes it easier to understand whats what. But its favorable to use an enum class as they get promoted to a type. You can static_cast<> them back to whatever integral repersation you need provided that representation does not truncate the enum value. You can also use hal::value() in <libhal-util/enum.hpp>

Copy link
Contributor Author

@MichaelYKersey MichaelYKersey Jan 20, 2024

Choose a reason for hiding this comment

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

I talked to Corey and Gene to understand what you were saying. While on the topic they recommended using constants (likely in a separate file) for this use case. What are your thoughts on switching the values in the enum to static constants?

Copy link
Contributor

Choose a reason for hiding this comment

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

static constants are great! Sometimes the constructs of an enum work fine too just depends on what you are doing.

science/platform-implementations/scd40.hpp Show resolved Hide resolved
Comment on lines 53 to 55
double set_temp = 4;
double set_alt = 0;
double set_pressure = -1;
Copy link
Contributor

Choose a reason for hiding this comment

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

What do these magic numbers mean? Maybe make some constants or add some comments?

Comment on lines 64 to 69
static hal::result<scd40> create(hal::i2c& p_i2c,hal::steady_clock& p_clock);
hal::status start();
hal::result<scd40_read_data> read();
hal::status stop();
hal::result<scd40_settings> get_settings();
hal::status set_settings( struct settings setting);
Copy link
Contributor

Choose a reason for hiding this comment

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

These APIs should be documented in order to understand how they should be used.

@Viha123 Viha123 merged commit a47c064 into libhal-2.0-port-science Jan 23, 2024
@Viha123 Viha123 deleted the scd40-driver-libhal-2.0 branch January 23, 2024 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants