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

Improve return values of LSM6DS33 class's methods by utilizing global error codes #59

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Software/src/globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ namespace spartan {
ERROR_DATAFORMAT,
ERROR_READ,
ERROR_POLL,
ERROR_INVALID_STATUS
ERROR_INVALID_STATUS,
grantKinsley marked this conversation as resolved.
Show resolved Hide resolved
ERROR_NO_NEW_DATA
};

// sensor status types
Expand Down
10 changes: 5 additions & 5 deletions Software/src/sensors/lsm6ds33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,24 +196,24 @@ int spartan::LSM6DS33::powerOff() {
// Polling functions

// TODO(harrisoncassar): Update this `update` function to utilize `ERROR_*` enums defined in `globals.h`
bool spartan::LSM6DS33::update() {
int spartan::LSM6DS33::update() {
if (m_status == STATUS_OFF)
return false; // Should be returning ERROR_INVALID_STATUS
return ERROR_INVALID_STATUS; // Should be returning ERROR_INVALID_STATUS
grantKinsley marked this conversation as resolved.
Show resolved Hide resolved

if (hasNewData() == RESULT_FALSE)
//std::cerr << "No new data" << std::endl;
return false;
return ERROR_NO_NEW_DATA;
Copy link
Member

Choose a reason for hiding this comment

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

I think this should also be returning RESULT_FALSE; having no new data is not necessarily an error.

Copy link
Author

Choose a reason for hiding this comment

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

That makes sense. I'll also get rid of the ERROR_NO_NEW_DATA code since I made it for the sole purpose of reflecting that there was no new data.


// set I2C address
if (m_i2c.address(lsm6Address) != mraa::SUCCESS) {
std::cerr << "Unable to set I2C address." << std::endl;
return false;
return ERROR_ADDR;
}

// read temp,x,y,z (14 bytes) into buffer
if (m_i2c.readBytesReg(lsm6ds33::OUT_TEMP_L, m_buffer, lsm6ds33::BUFFER_SIZE) == -1) {
std::cerr << "Unable to read data bytes starting from LSM6DS33_OUT_TEMP_L." << std::endl;
return false;
return ERROR_READ;
}

//record rawacceleration values using data reads for x,y,z respectively
Expand Down
4 changes: 2 additions & 2 deletions Software/src/sensors/lsm6ds33.h
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,8 @@ namespace spartan {
int pollData(MasterDataPacket &dp) override;
// returns RESULT_FALSE if no new data, RESULT_SUCCESS if member data was updated with latest reading,
// ERROR in the case of an error
int hasNewData();
virtual bool update();
int hasNewData();
grantKinsley marked this conversation as resolved.
Show resolved Hide resolved
virtual int update();

bool writeReg(uint8_t* buffer, unsigned short size);

Expand Down