Added Module overrides for all Arduino core functions
This commit is contained in:
parent
febeba23e0
commit
59c44d3883
2 changed files with 93 additions and 17 deletions
|
@ -175,8 +175,8 @@ bool Module::ATsendData(uint8_t* data, uint32_t len) {
|
||||||
bool Module::ATgetResponse() {
|
bool Module::ATgetResponse() {
|
||||||
char data[128];
|
char data[128];
|
||||||
char* dataPtr = data;
|
char* dataPtr = data;
|
||||||
uint32_t start = millis();
|
uint32_t start = Module::millis();
|
||||||
while(millis() - start < _ATtimeout) {
|
while(Module::millis() - start < _ATtimeout) {
|
||||||
while(ModuleSerial->available() > 0) {
|
while(ModuleSerial->available() > 0) {
|
||||||
char c = ModuleSerial->read();
|
char c = ModuleSerial->read();
|
||||||
RADIOLIB_VERBOSE_PRINT(c);
|
RADIOLIB_VERBOSE_PRINT(c);
|
||||||
|
@ -218,9 +218,9 @@ int16_t Module::SPIsetRegValue(uint8_t reg, uint8_t value, uint8_t msb, uint8_t
|
||||||
|
|
||||||
// check register value each millisecond until check interval is reached
|
// check register value each millisecond until check interval is reached
|
||||||
// some registers need a bit of time to process the change (e.g. SX127X_REG_OP_MODE)
|
// some registers need a bit of time to process the change (e.g. SX127X_REG_OP_MODE)
|
||||||
uint32_t start = micros();
|
uint32_t start = Module::micros();
|
||||||
uint8_t readValue;
|
uint8_t readValue;
|
||||||
while(micros() - start < (checkInterval * 1000)) {
|
while(Module::micros() - start < (checkInterval * 1000)) {
|
||||||
readValue = SPIreadRegister(reg);
|
readValue = SPIreadRegister(reg);
|
||||||
if(readValue == newValue) {
|
if(readValue == newValue) {
|
||||||
// check passed, we can stop the loop
|
// check passed, we can stop the loop
|
||||||
|
@ -336,7 +336,7 @@ RADIOLIB_PIN_STATUS Module::digitalRead(RADIOLIB_PIN_TYPE pin) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) {
|
void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) {
|
||||||
/// \todo Add tone support for platforms without tone()
|
// TODO add tone support for platforms without tone()
|
||||||
#ifndef RADIOLIB_TONE_UNSUPPORTED
|
#ifndef RADIOLIB_TONE_UNSUPPORTED
|
||||||
if(pin != RADIOLIB_NC) {
|
if(pin != RADIOLIB_NC) {
|
||||||
::tone(pin, value);
|
::tone(pin, value);
|
||||||
|
@ -345,7 +345,7 @@ void Module::tone(RADIOLIB_PIN_TYPE pin, uint16_t value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Module::noTone(RADIOLIB_PIN_TYPE pin) {
|
void Module::noTone(RADIOLIB_PIN_TYPE pin) {
|
||||||
/// \todo Add tone support for platforms without tone()
|
// TODO add tone support for platforms without noTone()
|
||||||
#ifndef RADIOLIB_TONE_UNSUPPORTED
|
#ifndef RADIOLIB_TONE_UNSUPPORTED
|
||||||
if(pin != RADIOLIB_NC) {
|
if(pin != RADIOLIB_NC) {
|
||||||
::noTone(pin);
|
::noTone(pin);
|
||||||
|
@ -353,6 +353,34 @@ void Module::noTone(RADIOLIB_PIN_TYPE pin) {
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Module::attachInterrupt(RADIOLIB_PIN_TYPE interruptNum, void (*userFunc)(void), RADIOLIB_INTERRUPT_STATUS mode) {
|
||||||
|
::attachInterrupt(interruptNum, userFunc, mode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::detachInterrupt(RADIOLIB_PIN_TYPE interruptNum) {
|
||||||
|
::detachInterrupt(interruptNum);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::yield() {
|
||||||
|
::yield();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::delay(uint32_t ms) {
|
||||||
|
::delay(ms);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Module::delayMicroseconds(uint32_t us) {
|
||||||
|
::delayMicroseconds(us);
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Module::millis() {
|
||||||
|
return(::millis());
|
||||||
|
}
|
||||||
|
|
||||||
|
uint32_t Module::micros() {
|
||||||
|
return(::micros());
|
||||||
|
}
|
||||||
|
|
||||||
void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
|
void Module::setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn) {
|
||||||
_useRfSwitch = true;
|
_useRfSwitch = true;
|
||||||
_rxEn = rxEn;
|
_rxEn = rxEn;
|
||||||
|
|
70
src/Module.h
70
src/Module.h
|
@ -4,7 +4,6 @@
|
||||||
#include "TypeDef.h"
|
#include "TypeDef.h"
|
||||||
|
|
||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
//#include <Wire.h>
|
|
||||||
#ifndef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
|
#ifndef RADIOLIB_SOFTWARE_SERIAL_UNSUPPORTED
|
||||||
#include <SoftwareSerial.h>
|
#include <SoftwareSerial.h>
|
||||||
#endif
|
#endif
|
||||||
|
@ -356,6 +355,27 @@ class Module {
|
||||||
*/
|
*/
|
||||||
SPISettings getSpiSettings() const { return(_spiSettings); }
|
SPISettings getSpiSettings() const { return(_spiSettings); }
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state.
|
||||||
|
When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
|
||||||
|
|
||||||
|
\param rxEn RX enable pin.
|
||||||
|
|
||||||
|
\param txEn TX enable pin.
|
||||||
|
*/
|
||||||
|
void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Set RF switch state.
|
||||||
|
|
||||||
|
\param rxPinState Pin state to set on Tx enable pin (usually high to transmit).
|
||||||
|
|
||||||
|
\param txPinState Pin state to set on Rx enable pin (usually high to receive).
|
||||||
|
*/
|
||||||
|
void setRfSwitchState(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState);
|
||||||
|
|
||||||
|
// Arduino core overrides
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Arduino core pinMode override that checks RADIOLIB_NC as alias for unused pin.
|
\brief Arduino core pinMode override that checks RADIOLIB_NC as alias for unused pin.
|
||||||
|
|
||||||
|
@ -400,23 +420,51 @@ class Module {
|
||||||
static void noTone(RADIOLIB_PIN_TYPE pin);
|
static void noTone(RADIOLIB_PIN_TYPE pin);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Some modules contain external RF switch controlled by two pins. This function gives RadioLib control over those two pins to automatically switch Rx and Tx state.
|
\brief Arduino core attachInterrupt override.
|
||||||
When using automatic RF switch control, DO NOT change the pin mode of rxEn or txEn from Arduino sketch!
|
|
||||||
|
|
||||||
\param rxEn RX enable pin.
|
\param interruptNum Interrupt number.
|
||||||
|
|
||||||
\param txEn TX enable pin.
|
\param userFunc Interrupt service routine.
|
||||||
|
|
||||||
|
\param mode Pin hcange direction.
|
||||||
*/
|
*/
|
||||||
void setRfSwitchPins(RADIOLIB_PIN_TYPE rxEn, RADIOLIB_PIN_TYPE txEn);
|
static void attachInterrupt(RADIOLIB_PIN_TYPE interruptNum, void (*userFunc)(void), RADIOLIB_INTERRUPT_STATUS mode);
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
\brief Set RF switch state.
|
\brief Arduino core detachInterrupt override.
|
||||||
|
|
||||||
\param rxPinState Pin state to set on Tx enable pin (usually high to transmit).
|
\param interruptNum Interrupt number.
|
||||||
|
|
||||||
\param txPinState Pin state to set on Rx enable pin (usually high to receive).
|
|
||||||
*/
|
*/
|
||||||
void setRfSwitchState(RADIOLIB_PIN_STATUS rxPinState, RADIOLIB_PIN_STATUS txPinState);
|
static void detachInterrupt(RADIOLIB_PIN_TYPE interruptNum);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Arduino core yield override.
|
||||||
|
*/
|
||||||
|
static void yield();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Arduino core delay override.
|
||||||
|
|
||||||
|
\param ms Delay length in milliseconds.
|
||||||
|
*/
|
||||||
|
static void delay(uint32_t ms);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Arduino core delayMicroseconds override.
|
||||||
|
|
||||||
|
\param us Delay length in microseconds.
|
||||||
|
*/
|
||||||
|
static void delayMicroseconds(uint32_t us);
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Arduino core millis override.
|
||||||
|
*/
|
||||||
|
static uint32_t millis();
|
||||||
|
|
||||||
|
/*!
|
||||||
|
\brief Arduino core micros override.
|
||||||
|
*/
|
||||||
|
static uint32_t micros();
|
||||||
|
|
||||||
#ifndef RADIOLIB_GODMODE
|
#ifndef RADIOLIB_GODMODE
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Add table
Reference in a new issue