Skip to content

fix pulse timing for new arduino-esp32 library #8

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

Merged
merged 1 commit into from
Mar 16, 2022
Merged
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
20 changes: 9 additions & 11 deletions src/esp32DHT.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -119,34 +119,32 @@ void DHT::_readSensor(DHT* instance) {
if (items) {
instance->_decode(items, rx_size/sizeof(rmt_item32_t));
vRingbufferReturnItem(instance->_ringBuf, static_cast<void*>(items));
rmt_rx_stop(instance->_channel);
pinMode(instance->_pin, OUTPUT);
digitalWrite(instance->_pin, HIGH);
} else {
instance->_status = 1; // timeout error
rmt_rx_stop(instance->_channel);
pinMode(instance->_pin, OUTPUT);
digitalWrite(instance->_pin, HIGH);
}
rmt_rx_stop(instance->_channel);
pinMode(instance->_pin, OUTPUT);
digitalWrite(instance->_pin, HIGH);

// return results
instance->_tryCallback();
}
}

void DHT::_decode(rmt_item32_t* data, int numItems) {
if (numItems < 42) {
uint8_t pulse = data[0].duration0 + data[0].duration1;
if (numItems < 41) {
_status = 5;
} else if (numItems > 42) {
_status = 6;
} else if ((data[0].duration0 + data[0].duration1) < 140 || (data[0].duration0 + data[0].duration1) > 180) {
} else if (pulse < 130 || pulse > 180) {
_status = 2;
} else {
for (uint8_t i = 1; i < numItems - 1; ++i) { // don't include tail
uint8_t pulse = data[i].duration0 + data[i].duration1;
for (uint8_t i = 1; i < 41; ++i) { // don't include tail >40
pulse = data[i].duration0 + data[i].duration1;
if (pulse > 55 && pulse < 145) {
_data[(i - 1) / 8] <<= 1; // shift left
if (pulse > 120) {
if (pulse > 110) {
_data[(i - 1) / 8] |= 1;
}
} else {
Expand Down