-
Notifications
You must be signed in to change notification settings - Fork 17
Add interrupt feature #7
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
b8b52a7
5e15f38
d5c376d
8ef580f
3b97655
378645b
339f396
1921fc2
8af9c21
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 | ||||
---|---|---|---|---|---|---|
|
@@ -18,9 +18,16 @@ end KEYWORD2 | |||||
readTemperature KEYWORD2 | ||||||
readHumidity KEYWORD2 | ||||||
|
||||||
enableDataReady KEYWORD2 | ||||||
disableDataReady KEYWORD2 | ||||||
setOpenDrain KEYWORD2 | ||||||
setPushPull KEYWORD2 | ||||||
setActiveHigh KEYWORD2 | ||||||
setActiveLow KEYWORD2 | ||||||
|
||||||
######################################### | ||||||
# Constants | ||||||
######################################### | ||||||
|
||||||
FAHRENHEIT LITERAL1 | ||||||
FAHRENHEIT LITERAL1 | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
CELSIUS LITERAL1 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
#define HTS221_WHO_AM_I_REG 0x0f | ||
#define HTS221_CTRL1_REG 0x20 | ||
#define HTS221_CTRL2_REG 0x21 | ||
#define HTS221_CTRL3_REG 0x22 //Dara Ready (b7 0 active high)(open drain, b6 1)(b2, 1 enable data ready) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove the comment |
||
#define HTS221_STATUS_REG 0x27 | ||
#define HTS221_HUMIDITY_OUT_L_REG 0x28 | ||
#define HTS221_TEMP_OUT_L_REG 0x2a | ||
|
@@ -39,6 +40,7 @@ | |
#define HTS221_T0_OUT_REG 0x3c | ||
#define HTS221_T1_OUT_REG 0x3e | ||
|
||
|
||
HTS221Class::HTS221Class(TwoWire& wire) : | ||
_wire(&wire) | ||
{ | ||
|
@@ -56,8 +58,12 @@ int HTS221Class::begin() | |
|
||
readHTS221Calibration(); | ||
|
||
// turn on the HTS221 and enable Block Data Update | ||
i2cWrite(HTS221_CTRL1_REG, 0x84); | ||
// enable HTS221 | ||
i2cWrite(HTS221_CTRL1_REG, 0x80); | ||
|
||
// Default DREADY configuration | ||
disableDataReady(); | ||
setPushPull(); | ||
|
||
return 1; | ||
} | ||
|
@@ -70,9 +76,39 @@ void HTS221Class::end() | |
_wire->end(); | ||
} | ||
|
||
void HTS221Class::enableDataReady(){ | ||
uint8_t data = i2cRead(HTS221_CTRL3_REG) & 0b11111000; | ||
i2cWrite(HTS221_CTRL3_REG, data | 0b1 << 2); | ||
} | ||
|
||
void HTS221Class::disableDataReady(){ | ||
uint8_t data = i2cRead(HTS221_CTRL3_REG) & 0b11111000; | ||
i2cWrite(HTS221_CTRL3_REG, data | 0b0 << 2); | ||
} | ||
|
||
void HTS221Class::setOpenDrain(){ | ||
uint8_t data = i2cRead(HTS221_CTRL3_REG) & 0b10111100; | ||
i2cWrite(HTS221_CTRL3_REG, data | 0b1 << 6); | ||
} | ||
|
||
void HTS221Class::setPushPull(){ | ||
uint8_t data = i2cRead(HTS221_CTRL3_REG) & 0b10111100; | ||
i2cWrite(HTS221_CTRL3_REG, data); | ||
} | ||
|
||
void HTS221Class::setActiveHigh(){ | ||
uint8_t data = i2cRead(HTS221_CTRL3_REG) & 0b01111111; | ||
i2cWrite(HTS221_CTRL3_REG, data); | ||
} | ||
|
||
void HTS221Class::setActiveLow(){ | ||
uint8_t data = i2cRead(HTS221_CTRL3_REG) & 0b01111111; | ||
i2cWrite(HTS221_CTRL3_REG, data | 0b1 << 7); | ||
} | ||
|
||
Comment on lines
+79
to
+108
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do you need all these methods? where are they used? i think that is better implement only the part we need for the library |
||
float HTS221Class::readTemperature(int units) | ||
{ | ||
// Wait for ONE_SHOT bit to be cleared by the hardware | ||
// Wait for ONE_SHOT bit to be cleared by the hardware | ||
while (i2cRead(HTS221_CTRL2_REG) & 0x01); | ||
|
||
// trigger one shot | ||
|
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.
In order to be recognized by the Arduino IDE, the keyword fields must be separated by a single true tab (not spaces):
https://arduino.github.io/arduino-cli/latest/library-specification/#keywordstxt-format