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

Utilize ERROR_* codes as return value defined in globals.h #57

Open
harrisonCassar opened this issue Jan 19, 2021 · 0 comments · May be fixed by #59
Open

Utilize ERROR_* codes as return value defined in globals.h #57

harrisonCassar opened this issue Jan 19, 2021 · 0 comments · May be fixed by #59
Assignees
Labels
bite size Smaller-sized issues enhancement New feature or request
Milestone

Comments

@harrisonCassar
Copy link
Contributor

harrisonCassar commented Jan 19, 2021

As I was working to implement #55, I realized that the update method of the LSM6DS33 could better describe the reason for failing through utilizing some of the error codes we already have defined in src/globals.h. Perhaps we might need to add a few more to better express what went wrong for this specific function.

// TODO(harrisoncassar): Update this `update` function to utilize `ERROR_*` enums defined in `globals.h`
bool spartan::LSM6DS33::update() {
if (m_status == STATUS_OFF)
return false; // Should be returning ERROR_INVALID_STATUS
if (hasNewData() == RESULT_FALSE)
//std::cerr << "No new data" << std::endl;
return false;
// set I2C address
if (m_i2c.address(lsm6Address) != mraa::SUCCESS) {
std::cerr << "Unable to set I2C address." << std::endl;
return false;
}
// 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;
}
//record rawacceleration values using data reads for x,y,z respectively
//DATAx0 is the least significant byte, and DATAx1 is the most significant byte
//conversion of raw sensor data into relevant values based on constant offset values
m_temp = ((m_buffer[1] << 8) | m_buffer[0]);
m_gyro.x = ((m_buffer[3] << 8) | m_buffer[2]);
m_gyro.y = ((m_buffer[5] << 8) | m_buffer[4]);
m_gyro.z = ((m_buffer[7] << 8) | m_buffer[6]);
m_accel.x = ((m_buffer[9] << 8) | m_buffer[8]);
m_accel.y = ((m_buffer[11] << 8) | m_buffer[10]);
m_accel.z = ((m_buffer[13] << 8) | m_buffer[12]);
return true;
}

Make sure when you change the return value of this function, its invocations also respect the new return value (and handle all of the possible return values properly).

Related to #56.

@harrisonCassar harrisonCassar added bite size Smaller-sized issues enhancement New feature or request labels Jan 19, 2021
@harrisonCassar harrisonCassar added this to the Winter 2021 milestone Jan 19, 2021
@grantKinsley grantKinsley self-assigned this Jan 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bite size Smaller-sized issues enhancement New feature or request
Projects
None yet
2 participants