Skip to content
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

ESP-NOW strategy support for esp8266 #361

Open
wants to merge 13 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Removing dependency on simply atomic
  • Loading branch information
Strix-CZ committed Aug 11, 2020
commit 975da999db24257f23e70ec9003b563900f4d5e4
12 changes: 7 additions & 5 deletions src/interfaces/ARDUINO/ESPNOWHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,13 +163,15 @@ class ENHelper {
packet[len + 2] = ESP_NOW_MAGIC_HEADER[2] ^ len;
packet[len + 3] = ESP_NOW_MAGIC_HEADER[3] ^ len;

ATOMIC()
{
sendingDone = false;
}
noInterrupts();
{
sendingDone = false;
}
interrupts();

if(esp_now_send(dest_mac, packet, len + ESPNOW_PACKET_HEADER_LENGTH + ESPNOW_PACKET_FOOTER_LENGTH) == 0) {
do { // wait for sending finished interrupt to be called
yield();
yield();
} while(!sendingDone);
}
};
Expand Down
8 changes: 5 additions & 3 deletions src/interfaces/ARDUINO/PacketQueue.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <esp_now.h>
#endif

#include <SimplyAtomic.h> // https://github.com/wizard97/SimplyAtomic
#include <Arduino.h>
#include "PJONDefines.h"

#define ESP_NOW_MAC_LENGTH 6
Expand Down Expand Up @@ -93,7 +93,7 @@ bool PacketQueue::push(const uint8_t *mac_addr, const uint8_t *data, int len)
{
bool isFull;

ATOMIC()
noInterrupts();
{
int firstSpacePlus1 = (firstSpace + 1) % (PJON_MAX_PACKETS + 1);
isFull = firstSpacePlus1 == firstElement;
Expand All @@ -103,6 +103,7 @@ bool PacketQueue::push(const uint8_t *mac_addr, const uint8_t *data, int len)
firstSpace = firstSpacePlus1;
}
}
interrupts();

return !isFull;
}
Expand All @@ -115,11 +116,12 @@ uint16_t PacketQueue::pop(uint8_t *out_mac_address, uint8_t *out_data, uint16_t
{
uint16_t length;

ATOMIC()
noInterrupts();
{
length = queue[firstElement].checkAndGet(out_mac_address, out_data, max_length);
firstElement = (firstElement + 1) % (PJON_MAX_PACKETS + 1);
}
interrupts();

return length;
}
Expand Down