Skip to content

Commit

Permalink
[DHT] reoreder interrupt handling
Browse files Browse the repository at this point in the history
  • Loading branch information
uzi18 committed Nov 16, 2019
1 parent 88c6887 commit 54bcf2c
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/_P005_DHT.ino
Original file line number Diff line number Diff line change
Expand Up @@ -172,15 +172,12 @@ bool P005_do_plugin_read(struct EventStruct *event) {
delayMicroseconds(20);
break;
}

if(!P005_waitState(0)) {P005_log(event, P005_error_no_reading); return false; }
if(!P005_waitState(1)) {P005_log(event, P005_error_no_reading); return false; }

noInterrupts();
if(!P005_waitState(0)) {
interrupts();
P005_log(event, P005_error_no_reading);
return false;
}
if(!P005_waitState(0)) {interrupts(); P005_log(event, P005_error_no_reading); return false; }
if(!P005_waitState(1)) {interrupts(); P005_log(event, P005_error_no_reading); return false; }
if(!P005_waitState(0)) {interrupts(); P005_log(event, P005_error_no_reading); return false; }

bool readingAborted = false;
byte dht_dat[5];
for (i = 0; i < 5 && !readingAborted; i++)
Expand Down

3 comments on commit 54bcf2c

@v-a-d-e-r
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this right 2x the same?
if(!P005_waitState(0)) {interrupts(); P005_log(event, P005_error_no_reading); return false; } <==
if(!P005_waitState(1)) {interrupts(); P005_log(event, P005_error_no_reading); return false; }
if(!P005_waitState(0)) {interrupts(); P005_log(event, P005_error_no_reading); return false; } <==

@TD-er
Copy link
Member

@TD-er TD-er commented on 54bcf2c Nov 19, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the interrupts are disabled before trying, so they must be re-enabled when we return.
It doesn't look pretty, but I guess using a function call for it would include more CPU cycles.

@v-a-d-e-r
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, ok, thanks. It looks a bit curious... ;-)

Please sign in to comment.