Skip to content

Commit

Permalink
fixed infinite loops which does not works on some chips like esp8266
Browse files Browse the repository at this point in the history
  • Loading branch information
sprilukin committed Jan 3, 2016
1 parent 9f5b3eb commit 6d7d480
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 16 deletions.
22 changes: 10 additions & 12 deletions examples/reciever/reciever.ino
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,15 @@ void setup() {
void loop() {

//blocks until message will not be read
if (bl999_have_message()) {
//read message to info and if check sum correct - output it to serial port
if (bl999_get_message(info)) {
Serial.println("====== Got message: ");
Serial.println(info.channel);
Serial.println(info.powerUUID);
Serial.println(info.battery);
Serial.println(info.temperature);
Serial.println(info.humidity);
}
bl999_wait_rx();

//read message to info and if check sum correct - output it to serial port
if (bl999_get_message(info)) {
Serial.println("====== Got message: ");
Serial.println(info.channel);
Serial.println(info.powerUUID);
Serial.println(info.battery);
Serial.println(info.temperature);
Serial.println(info.humidity);
}

delay(1000);
}
10 changes: 6 additions & 4 deletions lib_bl999.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,17 @@ extern void bl999_rx_stop() {
}

extern void bl999_wait_rx() {
while (bl999_active && !bl999_message_ready)
;
while (bl999_active && !bl999_message_ready) {
delay(BL999_DELAY_ON_WAIT);
}
}

extern boolean bl999_wait_rx_max(unsigned long milliseconds) {
unsigned long start = millis();

while (bl999_active && !bl999_message_ready && ((millis() - start) < milliseconds))
;
while (bl999_active && !bl999_message_ready && ((millis() - start) < milliseconds)) {
delay(BL999_DELAY_ON_WAIT);
}

return bl999_message_ready;
}
Expand Down
7 changes: 7 additions & 0 deletions lib_bl999.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@
//totally we have 36/4 = 9 nibbles
#define BL999_DATA_ARRAY_SIZE BL999_DATA_BITS_AMOUNT / BL999_BITS_PER_PACKET

// == Utility defines ==

//On some microcontrollers infinite loop cause watch dog reset,
//so introducing some small delay in loop
#define BL999_DELAY_ON_WAIT 10


//In this struct result will be stored
typedef struct {
byte channel : 2; // up to 3 channels
Expand Down

0 comments on commit 6d7d480

Please sign in to comment.