Skip to content

Commit

Permalink
actionified, formatted and doxy'd
Browse files Browse the repository at this point in the history
  • Loading branch information
siddacious committed Mar 25, 2020
1 parent 4c90679 commit 312d210
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 119 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/githubci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Arduino Library CI

on: [pull_request, push, repository_dispatch]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- uses: actions/checkout@v2
- uses: actions/checkout@v2
with:
repository: adafruit/ci-arduino
path: ci

- name: pre-install
run: bash ci/actions_install.sh

- name: test platforms
run: python3 ci/build_platform.py main_platforms

- name: clang
run: python3 ci/run-clang-format.py -e "ci/*" -e "bin/*" -r .

- name: doxygen
env:
GH_REPO_TOKEN: ${{ secrets.GH_REPO_TOKEN }}
PRETTYNAME : "Adafruit HTU21D-F Arduino Library"
run: bash ci/doxy_gen_and_deploy.sh
29 changes: 0 additions & 29 deletions .travis.yml

This file was deleted.

138 changes: 67 additions & 71 deletions Adafruit_HTU21DF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
#endif

/**
* Constructor for the HTU21DF driver.
* Constructor for the HTU21DF driver.
*/
Adafruit_HTU21DF::Adafruit_HTU21DF()
{
/* Assign default values to internal tracking variables. */
_last_humidity = 0.0f;
_last_temp = 0.0f;
Adafruit_HTU21DF::Adafruit_HTU21DF() {
/* Assign default values to internal tracking variables. */
_last_humidity = 0.0f;
_last_temp = 0.0f;
}

/**
Expand All @@ -36,28 +35,26 @@ Adafruit_HTU21DF::Adafruit_HTU21DF()
* @return true (1) if the device was successfully initialised, otherwise
* false (0).
*/
boolean Adafruit_HTU21DF::begin(void)
{
Wire.begin();
boolean Adafruit_HTU21DF::begin(void) {
Wire.begin();

reset();
reset();

Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READREG);
Wire.endTransmission();
Wire.requestFrom(HTU21DF_I2CADDR, 1);
return (Wire.read() == 0x2); // after reset should be 0x2
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READREG);
Wire.endTransmission();
Wire.requestFrom(HTU21DF_I2CADDR, 1);
return (Wire.read() == 0x2); // after reset should be 0x2
}

/**
* Sends a 'reset' request to the HTU21DF, followed by a 15ms delay.
*/
void Adafruit_HTU21DF::reset(void)
{
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_RESET);
Wire.endTransmission();
delay(15);
void Adafruit_HTU21DF::reset(void) {
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_RESET);
Wire.endTransmission();
delay(15);
}

/**
Expand All @@ -66,39 +63,38 @@ void Adafruit_HTU21DF::reset(void)
* @return a single-precision (32-bit) float value indicating the measured
* temperature in degrees Celsius.
*/
float Adafruit_HTU21DF::readTemperature(void)
{
// OK lets ready!
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READTEMP);
Wire.endTransmission();
float Adafruit_HTU21DF::readTemperature(void) {
// OK lets ready!
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READTEMP);
Wire.endTransmission();

delay(50); // add delay between request and actual read!
delay(50); // add delay between request and actual read!

uint8_t count = Wire.requestFrom(HTU21DF_I2CADDR, 3);
uint8_t count = Wire.requestFrom(HTU21DF_I2CADDR, 3);

/* Make sure we got 3 bytes back. */
if (count != 3) {
return 0.0f;
}
/* Make sure we got 3 bytes back. */
if (count != 3) {
return 0.0f;
}

/* Read 16 bits of data, dropping the last two status bits. */
uint16_t t = Wire.read();
t <<= 8;
t |= Wire.read() & 0b11111100;
/* Read 16 bits of data, dropping the last two status bits. */
uint16_t t = Wire.read();
t <<= 8;
t |= Wire.read() & 0b11111100;

uint8_t crc = Wire.read();
(void)crc;
uint8_t crc = Wire.read();
(void)crc;

float temp = t;
temp *= 175.72f;
temp /= 65536.0f;
temp -= 46.85f;
float temp = t;
temp *= 175.72f;
temp /= 65536.0f;
temp -= 46.85f;

/* Track the value internally in case we need to access it later. */
_last_temp = temp;
/* Track the value internally in case we need to access it later. */
_last_temp = temp;

return temp;
return temp;
}

/**
Expand All @@ -108,37 +104,37 @@ float Adafruit_HTU21DF::readTemperature(void)
* humidity in percent (0..100.0%).
*/
float Adafruit_HTU21DF::readHumidity(void) {
/* Prepare the I2C request. */
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READHUM);
Wire.endTransmission();
/* Prepare the I2C request. */
Wire.beginTransmission(HTU21DF_I2CADDR);
Wire.write(HTU21DF_READHUM);
Wire.endTransmission();

/* Wait a bit for the conversion to complete. */
delay(50);
/* Wait a bit for the conversion to complete. */
delay(50);

/* Read the conversion results. */
uint8_t count = Wire.requestFrom(HTU21DF_I2CADDR, 3);
/* Read the conversion results. */
uint8_t count = Wire.requestFrom(HTU21DF_I2CADDR, 3);

/* Make sure we got 3 bytes back. */
if (count != 3) {
return 0.0f;
}
/* Make sure we got 3 bytes back. */
if (count != 3) {
return 0.0f;
}

/* Read 16 bits of data, dropping the last two status bits. */
uint16_t h = Wire.read();
h <<= 8;
h |= Wire.read() & 0b11111100;
/* Read 16 bits of data, dropping the last two status bits. */
uint16_t h = Wire.read();
h <<= 8;
h |= Wire.read() & 0b11111100;

uint8_t crc = Wire.read();
(void)crc;
uint8_t crc = Wire.read();
(void)crc;

float hum = h;
hum *= 125.0f;
hum /= 65536.0f;
hum -= 6.0f;
float hum = h;
hum *= 125.0f;
hum /= 65536.0f;
hum -= 6.0f;

/* Track the value internally in case we need to access it later. */
_last_humidity = hum;
/* Track the value internally in case we need to access it later. */
_last_humidity = hum;

return hum;
return hum;
}
34 changes: 17 additions & 17 deletions Adafruit_HTU21DF.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,45 @@
#define _ADAFRUIT_HTU21DF_H

#if (ARDUINO >= 100)
#include "Arduino.h"
#include "Arduino.h"
#else
#include "WProgram.h"
#include "WProgram.h"
#endif
#include "Wire.h"

/** Default I2C address for the HTU21D. */
#define HTU21DF_I2CADDR (0x40)
#define HTU21DF_I2CADDR (0x40)

/** Read temperature register. */
#define HTU21DF_READTEMP (0xE3)
#define HTU21DF_READTEMP (0xE3)

/** Read humidity register. */
#define HTU21DF_READHUM (0xE5)
#define HTU21DF_READHUM (0xE5)

/** Write register command. */
#define HTU21DF_WRITEREG (0xE6)
#define HTU21DF_WRITEREG (0xE6)

/** Read register command. */
#define HTU21DF_READREG (0xE7)
#define HTU21DF_READREG (0xE7)

/** Reset command. */
#define HTU21DF_RESET (0xFE)
#define HTU21DF_RESET (0xFE)

/**
* Driver for the Adafruit HTU21DF breakout board.
*/
class Adafruit_HTU21DF {
public:
Adafruit_HTU21DF();
public:
Adafruit_HTU21DF();

boolean begin(void);
float readTemperature(void);
float readHumidity(void);
void reset(void);
boolean begin(void);
float readTemperature(void);
float readHumidity(void);
void reset(void);

private:
boolean readData(void);
float _last_humidity, _last_temp;
private:
boolean readData(void);
float _last_humidity, _last_temp;
};

#endif /* _ADAFRUIT_HTU21DF_H */
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Adafruit HTU21D-F Humidity/Temp Sensor for Arduino [![Build Status](https://travis-ci.org/adafruit/Adafruit_HTU21DF_Library.svg?branch=master)](https://travis-ci.org/adafruit/Adafruit_HTU21DF_Library)
# Adafruit HTU21D-F Humidity/Temp Sensor for Arduino [![Build Status](https://github.com/adafruit/Adafruit_HTU21DF_Library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/Adafruit_HTU21DF_Library/actions)

![sensors_1899-00](https://user-images.githubusercontent.com/181073/46350691-b53d1880-c655-11e8-8415-452aec129b44.jpg)

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit HTU21DF Library
version=1.0.2
version=1.0.3
author=Adafruit
maintainer=Adafruit <[email protected]>
sentence=Arduino library for the HTU21D-F sensors in the Adafruit shop
Expand Down

0 comments on commit 312d210

Please sign in to comment.