actionified, formatted and doxy'd

This commit is contained in:
siddacious 2020-04-08 11:36:24 -07:00
parent 428e115b57
commit 5d60b0d3f0
10 changed files with 387 additions and 341 deletions

32
.github/workflows/githubci.yml vendored Normal file
View File

@ -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 : "DHT sensor library"
run: bash ci/doxy_gen_and_deploy.sh

View File

@ -1,29 +0,0 @@
language: c
sudo: false
cache:
directories:
- ~/arduino_ide
- ~/.arduino15/packages/
git:
depth: false
quiet: true
env:
global:
- ARDUINO_IDE_VERSION="1.8.7"
- PRETTYNAME="DHT sensor library"
before_install:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/install.sh)
install:
- arduino --install-library "Adafruit Unified Sensor"
script:
- build_main_platforms
after_success:
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/library_check.sh)
- source <(curl -SLs https://raw.githubusercontent.com/adafruit/travis-ci-arduino/master/doxy_gen_and_deploy.sh)

View File

@ -164,8 +164,8 @@ float DHT::readHumidity(bool force) {
* @brief Compute Heat Index
* Simplified version that reads temp and humidity from sensor
* @param isFahrenheit
* true if fahrenheit, false if celcius (default
*true)
* true if fahrenheit, false if celcius
*(default true)
* @return float heat index
*/
float DHT::computeHeatIndex(bool isFahrenheit) {

29
DHT.h
View File

@ -3,7 +3,8 @@
*
* This is a library for DHT series of low cost temperature/humidity sensors.
*
* You must have Adafruit Unified Sensor Library library installed to use this class.
* You must have Adafruit Unified Sensor Library library installed to use this
* class.
*
* Adafruit invests time and resources providing this open source code,
* please support Adafruit andopen-source hardware by purchasing products
@ -22,16 +23,21 @@
/* Uncomment to enable printing out nice debug messages. */
//#define DHT_DEBUG
#define DEBUG_PRINTER Serial /**< Define where debug output will be printed. */
#define DEBUG_PRINTER \
Serial /**< Define where debug output will be printed. \
*/
/* Setup debug printing macros. */
#ifdef DHT_DEBUG
#define DEBUG_PRINT(...) { DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) { DEBUG_PRINTER.println(__VA_ARGS__); }
#define DEBUG_PRINT(...) \
{ DEBUG_PRINTER.print(__VA_ARGS__); }
#define DEBUG_PRINTLN(...) \
{ DEBUG_PRINTER.println(__VA_ARGS__); }
#else
#define DEBUG_PRINT(...) {} /**< Debug Print Placeholder if Debug is disabled */
#define DEBUG_PRINTLN(...) {} /**< Debug Print Line Placeholder if Debug is disabled */
#define DEBUG_PRINT(...) \
{} /**< Debug Print Placeholder if Debug is disabled */
#define DEBUG_PRINTLN(...) \
{} /**< Debug Print Line Placeholder if Debug is disabled */
#endif
/* Define types of sensors. */
@ -52,7 +58,8 @@ class DHT {
float convertCtoF(float);
float convertFtoC(float);
float computeHeatIndex(bool isFahrenheit = true);
float computeHeatIndex(float temperature, float percentHumidity, bool isFahrenheit=true);
float computeHeatIndex(float temperature, float percentHumidity,
bool isFahrenheit = true);
float readHumidity(bool force = false);
bool read(bool force = false);
@ -60,8 +67,9 @@ class DHT {
uint8_t data[5];
uint8_t _pin, _type;
#ifdef __AVR
// Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask
// for the digital pin connected to the DHT. Other platforms will use digitalRead.
// Use direct GPIO access on an 8-bit AVR so keep track of the port and
// bitmask for the digital pin connected to the DHT. Other platforms will use
// digitalRead.
uint8_t _bit, _port;
#endif
uint32_t _lastreadtime, _maxcycles;
@ -69,7 +77,6 @@ class DHT {
uint8_t pullTime; // Time (in usec) to pull up data line before reading
uint32_t expectPulse(bool level);
};
/*!

View File

@ -27,19 +27,15 @@
* @param humiditySensorId
* humidity sensor id
*/
DHT_Unified::DHT_Unified(uint8_t pin, uint8_t type, uint8_t count, int32_t tempSensorId, int32_t humiditySensorId):
_dht(pin, type, count),
_type(type),
_temp(this, tempSensorId),
_humidity(this, humiditySensorId)
{}
DHT_Unified::DHT_Unified(uint8_t pin, uint8_t type, uint8_t count,
int32_t tempSensorId, int32_t humiditySensorId)
: _dht(pin, type, count), _type(type), _temp(this, tempSensorId),
_humidity(this, humiditySensorId) {}
/*!
* @brief Setup sensor (calls begin on It)
*/
void DHT_Unified::begin() {
_dht.begin();
}
void DHT_Unified::begin() { _dht.begin(); }
/*!
* @brief Sets sensor name
@ -61,8 +57,9 @@ void DHT_Unified::setName(sensor_t* sensor) {
strncpy(sensor->name, "DHT22", sizeof(sensor->name) - 1);
break;
default:
// TODO: Perhaps this should be an error? However main DHT library doesn't enforce
// restrictions on the sensor type value. Pick a generic name for now.
// TODO: Perhaps this should be an error? However main DHT library doesn't
// enforce restrictions on the sensor type value. Pick a generic name for
// now.
strncpy(sensor->name, "DHT?", sizeof(sensor->name) - 1);
break;
}
@ -102,10 +99,8 @@ void DHT_Unified::setMinDelay(sensor_t* sensor) {
* @param id
* Sensor id
*/
DHT_Unified::Temperature::Temperature(DHT_Unified* parent, int32_t id):
_parent(parent),
_id(id)
{}
DHT_Unified::Temperature::Temperature(DHT_Unified *parent, int32_t id)
: _parent(parent), _id(id) {}
/*!
* @brief Reads the sensor and returns the data as a sensors_event_t
@ -177,10 +172,8 @@ void DHT_Unified::Temperature::getSensor(sensor_t* sensor) {
* @param id
* Sensor id
*/
DHT_Unified::Humidity::Humidity(DHT_Unified* parent, int32_t id):
_parent(parent),
_id(id)
{}
DHT_Unified::Humidity::Humidity(DHT_Unified *parent, int32_t id)
: _parent(parent), _id(id) {}
/*!
* @brief Reads the sensor and returns the data as a sensors_event_t

182
README.md
View File

@ -1,4 +1,4 @@
# Adafruit DHT Humidity & Temperature Sensor Library [![Build Status](https://travis-ci.com/adafruit/DHT-sensor-library.svg?branch=master)](https://travis-ci.com/adafruit/DHT-sensor-library)
# DHT sensor library [![Build Status](https://github.com/adafruit/DHT-sensor-library/workflows/Arduino%20Library%20CI/badge.svg)](https://github.com/adafruit/DHT-sensor-library/actions)
## Description
@ -6,157 +6,53 @@ An Arduino library for the DHT series of low-cost temperature/humidity sensors.
You can find DHT tutorials [here](https://learn.adafruit.com/dht).
## Installation
# Dependencies
* [Adafruit Unified Sensor Driver](https://github.com/adafruit/Adafruit_Sensor)
### First Method
# Contributing
![image](https://user-images.githubusercontent.com/36513474/67982415-773d6a00-fc44-11e9-8741-8185da71e785.png)
Contributions are welcome! Not only youll encourage the development of the library, but youll also learn how to best use the library and probably some C++ too
1. In the Arduino IDE, navigate to Sketch > Include Library > Manage Libraries
1. Then the Library Manager will open and you will find a list of libraries that are already installed or ready for installation.
1. Then search for DHT-sensor using the search bar.
1. Click on the text area and then select the specific version and install it.
Please read our [Code of Conduct](https://github.com/adafruit/DHT-sensor-library/blob/master/CODE_OF_CONDUCT.md>)
before contributing to help this project stay welcoming.
### Second Method
## Documentation and doxygen
Documentation is produced by doxygen. Contributions should include documentation for any new code added.
1. Navigate to the Releases page.
1. Download the latest release.
1. Extract the zip file
1. In the Arduino IDE, navigate to Sketch > Include Library > Add .ZIP Library
Some examples of how to use doxygen can be found in these guide pages:
## Requirements
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen
This library depends on [Adafruit Unified Sensor Library](https://github.com/adafruit/Adafruit_Sensor). To use this library the user must download the required library.
https://learn.adafruit.com/the-well-automated-arduino-library/doxygen-tips
## Features
Written by Adafruit Industries based on work by:
- ### Inexpensive
* T. DiCola
* P. Y. Dragon
* L. Fried
* J. Hoffmann
* M. Kooijman
* J. M. Dana
* S. Conaway
* S. IJskes
* T. Forbes
* B. C
* T. J Myers
* L. Sørup
* per1234
* O. Duffy
* matthiasdanner
* J. Lim
* G. Ambrozio
* chelmi
* adams13x13
* Spacefish
* I. Scheller
* C. Miller
* 7eggert
This library is used with low-cost temperature and humidity sensors, for example, DHT11 and DHT22. This library is free of cost and the only cost is of the sensors.
- ### Compatible
MIT license, check license.txt for more information
All text above must be included in any redistribution
DHT sensor library is compatible with multiple low-cost temperature and humidity sensors like DHT11 and DHT22. A few examples are implemented just to demonstrate how to modify the code for different sensors.
- ### Function calls
Basic functions of the low-cost temperature/humidity sensors have been implemented in this library. There's no need to re-implement these functions from scratch. The user simply has to import the library in the project and can use any of its functions by just calling it.
- ### Give back
The library is free, you dont have to pay for anything. However, if you want to support the development, or just thank the author of the library by purchasing products from Adafruit!
Not only youll encourage the development of the library, but youll also learn how to best use the library and probably some C++ too
- ### MIT License
DHT sensor library is open-source and uses one of the most permissive licenses so you can use it on any project.
- Commercial use
- Modification
- Distribution
- Private use
## Functions
- begin()
- readTemperature()
- convertCtoF()
- convertFtoC()
- readHumidity()
- computeHeatIndex()
- read()
- expectPulse()
## Example
Examples include both a "standalone" DHT example and one that works along with the Adafruit Unified Sensor Library. A Unified sensor library is required even if using the standalone version. You can find other examples from [Github-DHT-sensor-library](https://github.com/adafruit/DHT-sensor-library/tree/master/examples).
```Cpp
#include "DHT.h"
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));
dht.begin();
}
void loop() {
delay(2000);
float h = dht.readHumidity();
float t = dht.readTemperature();
float f = dht.readTemperature(true);
if (isnan(h) || isnan(t) || isnan(f)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}
float hif = dht.computeHeatIndex(f, h);
float hic = dht.computeHeatIndex(t, h, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(F("°C "));
Serial.print(f);
Serial.print(F("°F Heat index: "));
Serial.print(hic);
Serial.print(F("°C "));
Serial.print(hif);
Serial.println(F("°F"));
}
```
## Contributing
If you want to contribute to this project:
- Report bugs and errors
- Ask for enhancements
- Create issues and pull requests
- Tell others about this library
- Contribute new protocols
Please read [CONTRIBUTING.md](https://github.com/adafruit/DHT-sensor-library/blob/master/CONTRIBUTING.md) for details on our code of conduct, and the process for submitting pull requests to us.
## Credits
The author and maintainer of this library is Adafruit <info@adafruit.com>
Based on previous work by:
- T. DiCola
- P. Y. Dragon
- L. Fried
- J. Hoffmann
- M. Kooijman
- J. M. Dana
- S. Conaway
- S. IJskes
- T. Forbes
- B. C
- T. J Myers
- L. Sørup
- per1234
- O. Duffy
- matthiasdanner
- J. Lim
- G. Ambrozio
- chelmi
- adams13x13
- Spacefish
- I. Scheller
- C. Miller
- 7eggert
## License
This library is licensed under [MIT license](https://opensource.org/licenses/MIT).
To install, use the Arduino Library Manager and search for "DHT sensor library" and install the library.

127
code-of-conduct.md Normal file
View File

@ -0,0 +1,127 @@
# Adafruit Community Code of Conduct
## Our Pledge
In the interest of fostering an open and welcoming environment, we as
contributors and leaders pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, gender identity and expression, level or type of
experience, education, socio-economic status, nationality, personal appearance,
race, religion, or sexual identity and orientation.
## Our Standards
We are committed to providing a friendly, safe and welcoming environment for
all.
Examples of behavior that contributes to creating a positive environment
include:
* Be kind and courteous to others
* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Collaborating with other community members
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members
Examples of unacceptable behavior by participants include:
* The use of sexualized language or imagery and sexual attention or advances
* The use of inappropriate images, including in a community member's avatar
* The use of inappropriate language, including in a community member's nickname
* Any spamming, flaming, baiting or other attention-stealing behavior
* Excessive or unwelcome helping; answering outside the scope of the question
asked
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate
The goal of the standards and moderation guidelines outlined here is to build
and maintain a respectful community. We ask that you dont just aim to be
"technically unimpeachable", but rather try to be your best self.
We value many things beyond technical expertise, including collaboration and
supporting others within our community. Providing a positive experience for
other community members can have a much more significant impact than simply
providing the correct answer.
## Our Responsibilities
Project leaders are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.
Project leaders have the right and responsibility to remove, edit, or
reject messages, comments, commits, code, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any community member for other behaviors that they deem
inappropriate, threatening, offensive, or harmful.
## Moderation
Instances of behaviors that violate the Adafruit Community Code of Conduct
may be reported by any member of the community. Community members are
encouraged to report these situations, including situations they witness
involving other community members.
You may report in the following ways:
In any situation, you may send an email to <support@adafruit.com>.
On the Adafruit Discord, you may send an open message from any channel
to all Community Helpers by tagging @community helpers. You may also send an
open message from any channel, or a direct message to @kattni#1507,
@tannewt#4653, @Dan Halbert#1614, @cater#2442, @sommersoft#0222, or
@Andon#8175.
Email and direct message reports will be kept confidential.
In situations on Discord where the issue is particularly egregious, possibly
illegal, requires immediate action, or violates the Discord terms of service,
you should also report the message directly to Discord.
These are the steps for upholding our communitys standards of conduct.
1. Any member of the community may report any situation that violates the
Adafruit Community Code of Conduct. All reports will be reviewed and
investigated.
2. If the behavior is an egregious violation, the community member who
committed the violation may be banned immediately, without warning.
3. Otherwise, moderators will first respond to such behavior with a warning.
4. Moderators follow a soft "three strikes" policy - the community member may
be given another chance, if they are receptive to the warning and change their
behavior.
5. If the community member is unreceptive or unreasonable when warned by a
moderator, or the warning goes unheeded, they may be banned for a first or
second offense. Repeated offenses will result in the community member being
banned.
## Scope
This Code of Conduct and the enforcement policies listed above apply to all
Adafruit Community venues. This includes but is not limited to any community
spaces (both public and private), the entire Adafruit Discord server, and
Adafruit GitHub repositories. Examples of Adafruit Community spaces include
but are not limited to meet-ups, audio chats on the Adafruit Discord, or
interaction at a conference.
This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. As a community
member, you are representing our community, and are expected to behave
accordingly.
## Attribution
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
version 1.4, available at
<https://www.contributor-covenant.org/version/1/4/code-of-conduct.html>,
and the [Rust Code of Conduct](https://www.rust-lang.org/en-US/conduct.html).
For other projects adopting the Adafruit Community Code of
Conduct, please contact the maintainers of those projects for enforcement.
If you wish to use this code of conduct for your own project, consider
explicitly mentioning your moderation policy or making a copy with your
own moderation policy so as to avoid confusion.

View File

@ -1,5 +1,5 @@
name=DHT sensor library
version=1.3.8
version=1.3.9
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors

20
license.txt Normal file
View File

@ -0,0 +1,20 @@
Copyright (c) 2020 Adafruit Industries
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE
OR OTHER DEALINGS IN THE SOFTWARE.