[Morse] Update to 5.0.0

This commit is contained in:
jgromes 2021-11-14 11:39:51 +01:00
parent d7701c3ec7
commit d0670fd997
4 changed files with 90 additions and 88 deletions

View file

@ -49,7 +49,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method // (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin(); // int state = radio.begin();
if(state == ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));
@ -62,7 +62,7 @@ void setup() {
// base frequency: 434.0 MHz // base frequency: 434.0 MHz
// speed: 20 words per minute // speed: 20 words per minute
state = morse.begin(434.0); state = morse.begin(434.0);
if(state == ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));

View file

@ -52,7 +52,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method // (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin(); // int state = radio.begin();
if(state == ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));
@ -65,7 +65,7 @@ void setup() {
// AFSK tone frequency: 400 MHz // AFSK tone frequency: 400 MHz
// speed: 20 words per minute // speed: 20 words per minute
state = morse.begin(400); state = morse.begin(400);
if(state == ERR_NONE) { if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!")); Serial.println(F("success!"));
} else { } else {
Serial.print(F("failed, code ")); Serial.print(F("failed, code "));

View file

@ -48,6 +48,8 @@ size_t MorseClient::write(uint8_t* buff, size_t len) {
} }
size_t MorseClient::write(uint8_t b) { size_t MorseClient::write(uint8_t b) {
Module* mod = _phy->getMod();
// check unprintable ASCII characters and boundaries // check unprintable ASCII characters and boundaries
if((b < ' ') || (b == 0x60) || (b > 'z')) { if((b < ' ') || (b == 0x60) || (b > 'z')) {
return(0); return(0);
@ -57,35 +59,35 @@ size_t MorseClient::write(uint8_t b) {
if(b == ' ') { if(b == ' ') {
RADIOLIB_DEBUG_PRINTLN(F("space")); RADIOLIB_DEBUG_PRINTLN(F("space"));
standby(); standby();
Module::delay(4 * _dotLength); mod->delay(4 * _dotLength);
return(1); return(1);
} }
// get morse code from lookup table // get morse code from lookup table
uint8_t code = RADIOLIB_PROGMEM_READ_BYTE(&MorseTable[(uint8_t)(toupper(b) - 32)]); uint8_t code = RADIOLIB_NONVOLATILE_READ_BYTE(&MorseTable[(uint8_t)(toupper(b) - 32)]);
// check unsupported characters // check unsupported characters
if(code == MORSE_UNSUPORTED) { if(code == RADIOLIB_MORSE_UNSUPORTED) {
return(0); return(0);
} }
// iterate through codeword until guard bit is reached // iterate through codeword until guard bit is reached
while(code > MORSE_GUARDBIT) { while(code > RADIOLIB_MORSE_GUARDBIT) {
// send dot or dash // send dot or dash
if (code & MORSE_DASH) { if (code & RADIOLIB_MORSE_DASH) {
RADIOLIB_DEBUG_PRINT('-'); RADIOLIB_DEBUG_PRINT('-');
transmitDirect(_base, _baseHz); transmitDirect(_base, _baseHz);
Module::delay(3 * _dotLength); mod->delay(3 * _dotLength);
} else { } else {
RADIOLIB_DEBUG_PRINT('.'); RADIOLIB_DEBUG_PRINT('.');
transmitDirect(_base, _baseHz); transmitDirect(_base, _baseHz);
Module::delay(_dotLength); mod->delay(_dotLength);
} }
// symbol space // symbol space
standby(); standby();
Module::delay(_dotLength); mod->delay(_dotLength);
// move onto the next bit // move onto the next bit
code >>= 1; code >>= 1;
@ -93,7 +95,7 @@ size_t MorseClient::write(uint8_t b) {
// letter space // letter space
standby(); standby();
Module::delay(2 * _dotLength); mod->delay(2 * _dotLength);
RADIOLIB_DEBUG_PRINTLN(); RADIOLIB_DEBUG_PRINTLN();
return(1); return(1);
@ -103,7 +105,7 @@ size_t MorseClient::print(__FlashStringHelper* fstr) {
PGM_P p = reinterpret_cast<PGM_P>(fstr); PGM_P p = reinterpret_cast<PGM_P>(fstr);
size_t n = 0; size_t n = 0;
while(true) { while(true) {
char c = RADIOLIB_PROGMEM_READ_BYTE(p++); char c = RADIOLIB_NONVOLATILE_READ_BYTE(p++);
if(c == '\0') { if(c == '\0') {
break; break;
} }

View file

@ -1,31 +1,31 @@
#if !defined(_RADIOLIB_MORSE_H) && !defined(RADIOLIB_EXCLUDE_MORSE) #if !defined(_RADIOLIB_RADIOLIB_MORSE_H) && !defined(RADIOLIB_EXCLUDE_MORSE)
#define _RADIOLIB_MORSE_H #define _RADIOLIB_RADIOLIB_MORSE_H
#include "../../TypeDef.h" #include "../../TypeDef.h"
#include "../PhysicalLayer/PhysicalLayer.h" #include "../PhysicalLayer/PhysicalLayer.h"
#include "../AFSK/AFSK.h" #include "../AFSK/AFSK.h"
#define MORSE_DOT 0b0 #define RADIOLIB_MORSE_DOT 0b0
#define MORSE_DASH 0b1 #define RADIOLIB_MORSE_DASH 0b1
#define MORSE_GUARDBIT 0b1 #define RADIOLIB_MORSE_GUARDBIT 0b1
#define MORSE_UNSUPORTED 0xFF #define RADIOLIB_MORSE_UNSUPORTED 0xFF
// Morse character table: - using codes defined in ITU-R M.1677-1 // Morse character table: - using codes defined in ITU-R M.1677-1
// - Morse code representation is saved LSb first, using additional bit as guard // - Morse code representation is saved LSb first, using additional bit as guard
// - position in array corresponds ASCII code minus MORSE_ASCII_OFFSET // - position in array corresponds ASCII code minus RADIOLIB_MORSE_ASCII_OFFSET
// - ASCII characters marked MORSE_UNSUPORTED do not have ITU-R M.1677-1 equivalent // - ASCII characters marked RADIOLIB_MORSE_UNSUPORTED do not have ITU-R M.1677-1 equivalent
static const uint8_t MorseTable[] RADIOLIB_PROGMEM = { static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = {
0b00, // space 0b00, // space
0b110101, // ! (unsupported) 0b110101, // ! (unsupported)
0b1010010, // " 0b1010010, // "
MORSE_UNSUPORTED, // # (unsupported) RADIOLIB_MORSE_UNSUPORTED, // # (unsupported)
MORSE_UNSUPORTED, // $ (unsupported) RADIOLIB_MORSE_UNSUPORTED, // $ (unsupported)
MORSE_UNSUPORTED, // % (unsupported) RADIOLIB_MORSE_UNSUPORTED, // % (unsupported)
MORSE_UNSUPORTED, // & (unsupported) RADIOLIB_MORSE_UNSUPORTED, // & (unsupported)
0b1011110, // ' 0b1011110, // '
0b101101, // ( 0b101101, // (
0b1101101, // ) 0b1101101, // )
MORSE_UNSUPORTED, // * (unsupported) RADIOLIB_MORSE_UNSUPORTED, // * (unsupported)
0b101010, // + 0b101010, // +
0b1110011, // , 0b1110011, // ,
0b1100001, // - 0b1100001, // -
@ -42,10 +42,10 @@ static const uint8_t MorseTable[] RADIOLIB_PROGMEM = {
0b100111, // 8 0b100111, // 8
0b101111, // 9 0b101111, // 9
0b1000111, // : 0b1000111, // :
MORSE_UNSUPORTED, // ; (unsupported) RADIOLIB_MORSE_UNSUPORTED, // ; (unsupported)
MORSE_UNSUPORTED, // < (unsupported) RADIOLIB_MORSE_UNSUPORTED, // < (unsupported)
0b110001, // = 0b110001, // =
MORSE_UNSUPORTED, // > (unsupported) RADIOLIB_MORSE_UNSUPORTED, // > (unsupported)
0b1001100, // ? 0b1001100, // ?
0b1010110, // @ 0b1010110, // @
0b110, // A 0b110, // A
@ -74,9 +74,9 @@ static const uint8_t MorseTable[] RADIOLIB_PROGMEM = {
0b11001, // X 0b11001, // X
0b11101, // Y 0b11101, // Y
0b10011, // Z 0b10011, // Z
MORSE_UNSUPORTED, // [ (unsupported) RADIOLIB_MORSE_UNSUPORTED, // [ (unsupported)
MORSE_UNSUPORTED, // \ (unsupported) RADIOLIB_MORSE_UNSUPORTED, // \ (unsupported)
MORSE_UNSUPORTED, // ] (unsupported) RADIOLIB_MORSE_UNSUPORTED, // ] (unsupported)
0b1101000, // ^ (unsupported, used as alias for end of work) 0b1101000, // ^ (unsupported, used as alias for end of work)
0b110101 // _ (unsupported, used as alias for starting signal) 0b110101 // _ (unsupported, used as alias for starting signal)
}; };
@ -151,7 +151,7 @@ class MorseClient {
size_t println(unsigned long, int = DEC); size_t println(unsigned long, int = DEC);
size_t println(double, int = 2); size_t println(double, int = 2);
#ifndef RADIOLIB_GODMODE #if !defined(RADIOLIB_GODMODE)
private: private:
#endif #endif
PhysicalLayer* _phy; PhysicalLayer* _phy;