[EXT] Implemented direct transmit (#646)

This commit is contained in:
jgromes 2023-07-07 20:48:51 +02:00
parent 01917ad0c2
commit b139767559
2 changed files with 83 additions and 6 deletions

View file

@ -1,15 +1,47 @@
#include "ExternalRadio.h" #include "ExternalRadio.h"
#if defined(RADIOLIB_BUILD_ARDUINO) #if defined(RADIOLIB_BUILD_ARDUINO)
ExternalRadio::ExternalRadio() : PhysicalLayer(1, 0) { ExternalRadio::ExternalRadio(uint32_t pin) : PhysicalLayer(1, 0) {
mod = new Module(RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC); mod = new Module(RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, pin);
mod->hal->pinMode(pin, mod->hal->GpioModeOutput);
this->prevFrf = 0;
} }
#endif #endif
ExternalRadio::ExternalRadio(RadioLibHal *hal) : PhysicalLayer(1, 0) { ExternalRadio::ExternalRadio(RadioLibHal *hal, uint32_t pin) : PhysicalLayer(1, 0) {
mod = new Module(hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC); mod = new Module(hal, RADIOLIB_NC, RADIOLIB_NC, RADIOLIB_NC, pin);
mod->hal->pinMode(pin, mod->hal->GpioModeOutput);
this->prevFrf = 0;
} }
Module* ExternalRadio::getMod() { Module* ExternalRadio::getMod() {
return(mod); return(mod);
}
int16_t ExternalRadio::setFrequencyDeviation(float freqDev) {
(void)freqDev;
return(RADIOLIB_ERR_NONE);
}
int16_t ExternalRadio::setDataShaping(uint8_t sh) {
(void)sh;
return(RADIOLIB_ERR_NONE);
}
int16_t ExternalRadio::setEncoding(uint8_t encoding) {
(void)encoding;
return(RADIOLIB_ERR_NONE);
}
int16_t ExternalRadio::transmitDirect(uint32_t frf) {
if(frf != this->prevFrf) {
uint32_t val = this->mod->hal->GpioLevelLow;
if(frf > this->prevFrf) {
val = this->mod->hal->GpioLevelHigh;
}
this->prevFrf = frf;
this->mod->hal->digitalWrite(this->mod->getGpio(), val);
}
return(RADIOLIB_ERR_NONE);
} }

View file

@ -12,13 +12,58 @@
class ExternalRadio: public PhysicalLayer { class ExternalRadio: public PhysicalLayer {
public: public:
#if defined(RADIOLIB_BUILD_ARDUINO) #if defined(RADIOLIB_BUILD_ARDUINO)
ExternalRadio(); /*!
\brief Default constructor.
\param pin Output pin when using direct transmission, defaults to unused pin.
*/
ExternalRadio(uint32_t pin = RADIOLIB_NC);
#endif #endif
ExternalRadio(RadioLibHal *hal);
/*!
\brief Default constructor.
\param hal Pointer to the hardware abstraction layer to use.
\param pin Output pin when using direct transmission, defaults to unused pin.
*/
ExternalRadio(RadioLibHal *hal, uint32_t pin = RADIOLIB_NC);
/*!
\brief Method to retrieve pointer to the underlying Module instance.
\returns Pointer to the Module instance.
*/
Module* getMod(); Module* getMod();
/*!
\brief Dummy implementation overriding PhysicalLayer.
\param freqDev Ignored.
\returns \ref status_codes
*/
int16_t setFrequencyDeviation(float freqDev) override;
/*!
\brief Dummy implementation overriding PhysicalLayer.
\param sh Ignored.
\returns \ref status_codes
*/
int16_t setDataShaping(uint8_t sh) override;
/*!
\brief Dummy implementation overriding PhysicalLayer.
\param encoding Ignored.
\returns \ref status_codes
*/
int16_t setEncoding(uint8_t encoding) override;
/*!
\brief Direct transmission to drive external radio.
\param frf "Frequency" to control the output pin. If the frequency is higher than the one sent previously,
the output pin will be set to logic high. Otherwise it will be set to logic low.
\returns \ref status_codes
*/
int16_t transmitDirect(uint32_t frf = 0);
private: private:
Module* mod; Module* mod;
uint32_t prevFrf;
}; };
#endif #endif