Skip to content

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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
9 changes: 8 additions & 1 deletion keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,16 @@ end KEYWORD2
readTemperature KEYWORD2
readHumidity KEYWORD2

enableDataReady KEYWORD2
disableDataReady KEYWORD2
setOpenDrain KEYWORD2
setPushPull KEYWORD2
setActiveHigh KEYWORD2
setActiveLow KEYWORD2
Comment on lines +21 to +26
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
enableDataReady KEYWORD2
disableDataReady KEYWORD2
setOpenDrain KEYWORD2
setPushPull KEYWORD2
setActiveHigh KEYWORD2
setActiveLow KEYWORD2
enableDataReady KEYWORD2
disableDataReady KEYWORD2
setOpenDrain KEYWORD2
setPushPull KEYWORD2
setActiveHigh KEYWORD2
setActiveLow KEYWORD2

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


#########################################
# Constants
#########################################

FAHRENHEIT LITERAL1
FAHRENHEIT LITERAL1
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
FAHRENHEIT LITERAL1
FAHRENHEIT LITERAL1

CELSIUS LITERAL1
42 changes: 39 additions & 3 deletions src/HTS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand All @@ -39,6 +40,7 @@
#define HTS221_T0_OUT_REG 0x3c
#define HTS221_T1_OUT_REG 0x3e


HTS221Class::HTS221Class(TwoWire& wire) :
_wire(&wire)
{
Expand All @@ -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;
}
Expand All @@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down
9 changes: 8 additions & 1 deletion src/HTS.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

#include <Arduino.h>
#include <Wire.h>

#define HTS221_CTRL3_REG 0x22
enum {
FAHRENHEIT,
CELSIUS
Expand All @@ -38,6 +38,13 @@ class HTS221Class {
float readTemperature(int units = CELSIUS);
float readHumidity();

void enableDataReady(); //Outputs pin3 DREADY
void disableDataReady();
void setOpenDrain();
void setPushPull();
void setActiveHigh();
void setActiveLow();

private:
int i2cRead(uint8_t reg);
int i2cRead16(uint8_t reg) {
Expand Down