Skip to content

Changed rx and tx callbacks to std::function #569

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/LoRa.cpp
Original file line number Diff line number Diff line change
@@ -359,7 +359,7 @@ void LoRaClass::flush()
}

#ifndef ARDUINO_SAMD_MKRWAN1300
void LoRaClass::onReceive(void(*callback)(int))
void LoRaClass::onReceive(std::function<void (int)> callback)
{
_onReceive = callback;

@@ -377,7 +377,7 @@ void LoRaClass::onReceive(void(*callback)(int))
}
}

void LoRaClass::onTxDone(void(*callback)())
void LoRaClass::onTxDone(std::function<void ()> callback)
{
_onTxDone = callback;

9 changes: 5 additions & 4 deletions src/LoRa.h
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@

#include <Arduino.h>
#include <SPI.h>
#include <functional>

#if defined(ARDUINO_SAMD_MKRWAN1300)
#define LORA_DEFAULT_SPI SPI1
@@ -58,8 +59,8 @@ class LoRaClass : public Stream {
virtual void flush();

#ifndef ARDUINO_SAMD_MKRWAN1300
void onReceive(void(*callback)(int));
void onTxDone(void(*callback)());
void onReceive(std::function<void (int)> callback);
void onTxDone(std::function<void ()> callback);

void receive(int size = 0);
#endif
@@ -121,8 +122,8 @@ class LoRaClass : public Stream {
long _frequency;
int _packetIndex;
int _implicitHeaderMode;
void (*_onReceive)(int);
void (*_onTxDone)();
std::function<void (int)> _onReceive;
std::function<void ()> _onTxDone;
};

extern LoRaClass LoRa;