[Pager] Added option to invert frequencies (#7)

This commit is contained in:
jgromes 2022-11-27 20:47:01 +01:00
parent b9a7116113
commit f51229ef9a
2 changed files with 22 additions and 7 deletions

View file

@ -19,7 +19,7 @@ PagerClient::PagerClient(PhysicalLayer* phy) {
_readBitInstance = _phy;
}
int16_t PagerClient::begin(float base, uint16_t speed, uint16_t shift) {
int16_t PagerClient::begin(float base, uint16_t speed, bool invert, uint16_t shift) {
// calculate duration of 1 bit in us
_speed = (float)speed/1000.0f;
_bitDuration = (uint32_t)1000000/speed;
@ -34,6 +34,7 @@ int16_t PagerClient::begin(float base, uint16_t speed, uint16_t shift) {
// calculate raw frequency shift
_shiftHz = shift;
_shift = _shiftHz/step;
inv = invert;
// initialize BCH encoder
encoderInit();
@ -433,14 +434,23 @@ void PagerClient::write(uint32_t codeWord) {
for(int8_t i = 31; i >= 0; i--) {
uint32_t mask = (uint32_t)0x01 << i;
uint32_t start = mod->micros();
// figure out the shift direction - start by assuming the bit is 0
int16_t change = _shift;
// now check if it's actually 1
if(codeWord & mask) {
// send 1
_phy->transmitDirect(_baseRaw + _shift);
} else {
// send 0
_phy->transmitDirect(_baseRaw - _shift);
change = -_shift;
}
// finally, check if inversion is enabled
if(inv) {
change = -change;
}
// now transmit the shifted frequency
_phy->transmitDirect(_baseRaw + change);
// this is pretty silly, while(mod->micros() ... ) would be enough
// but for some reason, MegaCore throws a linker error on it
// "relocation truncated to fit: R_AVR_7_PCREL against `no symbol'"

View file

@ -84,9 +84,13 @@ class PagerClient {
\param speed Bit rate to use in bps. Common POCSAG decoders can receive 512, 1200 and 2400 bps.
\param invert Enable frequency inversion. Disabled by default (high frequency is digital 0).
\param shift Set custom frequency shift, defaults to 4500 Hz.
\returns \ref status_codes
*/
int16_t begin(float base, uint16_t speed, uint16_t shift = RADIOLIB_PAGER_FREQ_SHIFT_HZ);
int16_t begin(float base, uint16_t speed, bool invert = false, uint16_t shift = RADIOLIB_PAGER_FREQ_SHIFT_HZ);
/*!
\brief Method to send a tone-only alert to a destination pager.
@ -201,6 +205,7 @@ class PagerClient {
uint32_t _readBatchPos;
uint32_t _filterAddr;
uint32_t _filterMask;
bool inv = false;
// BCH encoder
int32_t _bchAlphaTo[RADIOLIB_PAGER_BCH_N + 1];