-
Notifications
You must be signed in to change notification settings - Fork 5
Read Temperature fixes and version bump. #9
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -99,7 +99,7 @@ imu_status_t LIS3DH::readRegisterRegion(uint8_t *outputPointer , uint8_t offset, | |
| } | ||
| else //OK, all worked, keep going | ||
| { | ||
| // request 6 bytes from slave device | ||
| // request length bytes from slave device | ||
| Wire.requestFrom(I2CAddress, length); | ||
| while ( (Wire.available()) && (i < length)) // slave may send less than requested | ||
| { | ||
|
|
@@ -158,7 +158,6 @@ imu_status_t LIS3DH::readRegister(uint8_t* outputPointer, uint8_t offset) { | |
| imu_status_t LIS3DH::readRegisterInt16( int16_t* outputPointer, uint8_t offset ) | ||
| { | ||
| { | ||
| //offset |= 0x80; //turn auto-increment bit on | ||
| uint8_t myBuffer[2]; | ||
| imu_status_t returnError = readRegisterRegion(myBuffer, offset, 2); //Does memory transfer | ||
| int16_t output = (int16_t)myBuffer[0] | int16_t(myBuffer[1] << 8); | ||
|
|
@@ -485,41 +484,23 @@ void LIS3DH::temperatureEnable(bool command){ | |
| } | ||
| } | ||
|
|
||
| // Only in low power we have 8bit. Otherwise 10bit | ||
| #ifdef LOW_POWER | ||
| // 8bits in all modes | ||
| int8_t LIS3DH::readTemperature(){ | ||
| uint8_t r; | ||
|
|
||
| temperatureEnable(1); // Although temperature is enabled, it must | ||
| // re-run to re-apply settings. Otherwise | ||
| // the temperature report is always the same. | ||
|
|
||
| // do we have data? | ||
| readRegister(&r, LIS3DH_STATUS_REG_AUX); | ||
| // check if we have data | ||
| if ( ( r & 0x04 ) == 0x04 ) { | ||
| readRegister(&r, LIS3DH_OUT_ADC3_H); // here are the data | ||
| return (int8_t) r; | ||
|
Comment on lines
491
to
499
|
||
| } | ||
| // we don't have data. Return deep freezing for error. | ||
| return 0xFF; | ||
| } | ||
|
Comment on lines
495
to
503
|
||
| #else | ||
| // 10 bit value, UNTESTED | ||
| int16_t LIS3DH::readTemperature(){ | ||
| int16_t r; | ||
|
|
||
| temperatureEnable(1); // Read comment above | ||
|
|
||
| // do we have data? | ||
| readRegisterInt16(&r, LIS3DH_STATUS_REG_AUX); | ||
| if ( ( r & 0x04 ) == 0x04 ) { | ||
| readRegisterInt16(&r, LIS3DH_OUT_ADC3_L); | ||
| return (int16_t) r; | ||
| } | ||
| // we don't have data. Return deep freezing for error. | ||
| return 0xFFFF; | ||
| } | ||
| #endif | ||
|
|
||
| // disconnect pullup on SDO/SA for lower power consumption | ||
| void LIS3DH::disconnectPullUp(bool command){ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,12 +15,6 @@ Distributed as-is; no warranty is given. | |
| #ifndef __LIS3DH_IMU_H__ | ||
| #define __LIS3DH_IMU_H__ | ||
|
|
||
| // Temperature works only if I define LOW_POWER here (!). | ||
| // Tested with arduino, not with platformio | ||
| #if !defined LOW_POWER & !defined NORMAL_MODE & !defined HIGH_RESOLUTION | ||
| #define LOW_POWER | ||
| #endif | ||
|
|
||
| #include "stdint.h" | ||
|
|
||
| #if defined(ARDUINO) && ARDUINO >= 100 | ||
|
Comment on lines
15
to
20
|
||
|
|
@@ -125,11 +119,7 @@ class LIS3DH | |
| float axisAccel( axis_t _axis); | ||
| uint8_t readClick(); | ||
| uint8_t readAxisEvents(); | ||
| #ifdef LOW_POWER | ||
| int8_t readTemperature(); | ||
| #else | ||
| int16_t readTemperature(); | ||
| #endif | ||
|
|
||
| void temperatureEnable(bool command); | ||
|
|
||
|
|
@@ -170,7 +160,7 @@ class LIS3DH | |
| #define LIS3DH_CTRL_REG2 0x21 | ||
| #define LIS3DH_CTRL_REG3 0x22 | ||
| #define LIS3DH_CTRL_REG4 0x23 | ||
| #define LIS3DH_CTRL_REG5 0x24 //not included | ||
| #define LIS3DH_CTRL_REG5 0x24 | ||
| #define LIS3DH_CTRL_REG6 0x25 | ||
| #define LIS3DH_REFERENCE 0x26 | ||
| #define LIS3DH_STATUS_REG2 0x27 | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since
LIS3DH::readTemperature()now returnsint8_t, the explicit cast to(int8_t)here is redundant. Dropping it makes the example a bit clearer and ensures the printed value reflects the API directly.