[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
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -62,7 +62,7 @@ void setup() {
// base frequency: 434.0 MHz
// speed: 20 words per minute
state = morse.begin(434.0);
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));

View file

@ -52,7 +52,7 @@ void setup() {
// (RF69, CC1101, Si4432 etc.), use the basic begin() method
// int state = radio.begin();
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
Serial.print(F("failed, code "));
@ -65,7 +65,7 @@ void setup() {
// AFSK tone frequency: 400 MHz
// speed: 20 words per minute
state = morse.begin(400);
if(state == ERR_NONE) {
if(state == RADIOLIB_ERR_NONE) {
Serial.println(F("success!"));
} else {
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) {
Module* mod = _phy->getMod();
// check unprintable ASCII characters and boundaries
if((b < ' ') || (b == 0x60) || (b > 'z')) {
return(0);
@ -57,35 +59,35 @@ size_t MorseClient::write(uint8_t b) {
if(b == ' ') {
RADIOLIB_DEBUG_PRINTLN(F("space"));
standby();
Module::delay(4 * _dotLength);
mod->delay(4 * _dotLength);
return(1);
}
// 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
if(code == MORSE_UNSUPORTED) {
if(code == RADIOLIB_MORSE_UNSUPORTED) {
return(0);
}
// iterate through codeword until guard bit is reached
while(code > MORSE_GUARDBIT) {
while(code > RADIOLIB_MORSE_GUARDBIT) {
// send dot or dash
if (code & MORSE_DASH) {
if (code & RADIOLIB_MORSE_DASH) {
RADIOLIB_DEBUG_PRINT('-');
transmitDirect(_base, _baseHz);
Module::delay(3 * _dotLength);
mod->delay(3 * _dotLength);
} else {
RADIOLIB_DEBUG_PRINT('.');
transmitDirect(_base, _baseHz);
Module::delay(_dotLength);
mod->delay(_dotLength);
}
// symbol space
standby();
Module::delay(_dotLength);
mod->delay(_dotLength);
// move onto the next bit
code >>= 1;
@ -93,7 +95,7 @@ size_t MorseClient::write(uint8_t b) {
// letter space
standby();
Module::delay(2 * _dotLength);
mod->delay(2 * _dotLength);
RADIOLIB_DEBUG_PRINTLN();
return(1);
@ -103,7 +105,7 @@ size_t MorseClient::print(__FlashStringHelper* fstr) {
PGM_P p = reinterpret_cast<PGM_P>(fstr);
size_t n = 0;
while(true) {
char c = RADIOLIB_PROGMEM_READ_BYTE(p++);
char c = RADIOLIB_NONVOLATILE_READ_BYTE(p++);
if(c == '\0') {
break;
}

View file

@ -1,84 +1,84 @@
#if !defined(_RADIOLIB_MORSE_H) && !defined(RADIOLIB_EXCLUDE_MORSE)
#define _RADIOLIB_MORSE_H
#if !defined(_RADIOLIB_RADIOLIB_MORSE_H) && !defined(RADIOLIB_EXCLUDE_MORSE)
#define _RADIOLIB_RADIOLIB_MORSE_H
#include "../../TypeDef.h"
#include "../PhysicalLayer/PhysicalLayer.h"
#include "../AFSK/AFSK.h"
#define MORSE_DOT 0b0
#define MORSE_DASH 0b1
#define MORSE_GUARDBIT 0b1
#define MORSE_UNSUPORTED 0xFF
#define RADIOLIB_MORSE_DOT 0b0
#define RADIOLIB_MORSE_DASH 0b1
#define RADIOLIB_MORSE_GUARDBIT 0b1
#define RADIOLIB_MORSE_UNSUPORTED 0xFF
// Morse character table: - using codes defined in ITU-R M.1677-1
// - Morse code representation is saved LSb first, using additional bit as guard
// - position in array corresponds ASCII code minus MORSE_ASCII_OFFSET
// - ASCII characters marked MORSE_UNSUPORTED do not have ITU-R M.1677-1 equivalent
static const uint8_t MorseTable[] RADIOLIB_PROGMEM = {
0b00, // space
0b110101, // ! (unsupported)
0b1010010, // "
MORSE_UNSUPORTED, // # (unsupported)
MORSE_UNSUPORTED, // $ (unsupported)
MORSE_UNSUPORTED, // % (unsupported)
MORSE_UNSUPORTED, // & (unsupported)
0b1011110, // '
0b101101, // (
0b1101101, // )
MORSE_UNSUPORTED, // * (unsupported)
0b101010, // +
0b1110011, // ,
0b1100001, // -
0b1101010, // .
0b101001, // /
0b111111, // 0
0b111110, // 1
0b111100, // 2
0b111000, // 3
0b110000, // 4
0b100000, // 5
0b100001, // 6
0b100011, // 7
0b100111, // 8
0b101111, // 9
0b1000111, // :
MORSE_UNSUPORTED, // ; (unsupported)
MORSE_UNSUPORTED, // < (unsupported)
0b110001, // =
MORSE_UNSUPORTED, // > (unsupported)
0b1001100, // ?
0b1010110, // @
0b110, // A
0b10001, // B
0b10101, // C
0b1001, // D
0b10, // E
0b10100, // F
0b1011, // G
0b10000, // H
0b100, // I
0b11110, // J
0b1101, // K
0b10010, // L
0b111, // M
0b101, // N
0b1111, // O
0b10110, // P
0b11011, // Q
0b1010, // R
0b1000, // S
0b11, // T
0b1100, // U
0b11000, // V
0b1110, // W
0b11001, // X
0b11101, // Y
0b10011, // Z
MORSE_UNSUPORTED, // [ (unsupported)
MORSE_UNSUPORTED, // \ (unsupported)
MORSE_UNSUPORTED, // ] (unsupported)
0b1101000, // ^ (unsupported, used as alias for end of work)
0b110101 // _ (unsupported, used as alias for starting signal)
// - position in array corresponds ASCII code minus RADIOLIB_MORSE_ASCII_OFFSET
// - ASCII characters marked RADIOLIB_MORSE_UNSUPORTED do not have ITU-R M.1677-1 equivalent
static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = {
0b00, // space
0b110101, // ! (unsupported)
0b1010010, // "
RADIOLIB_MORSE_UNSUPORTED, // # (unsupported)
RADIOLIB_MORSE_UNSUPORTED, // $ (unsupported)
RADIOLIB_MORSE_UNSUPORTED, // % (unsupported)
RADIOLIB_MORSE_UNSUPORTED, // & (unsupported)
0b1011110, // '
0b101101, // (
0b1101101, // )
RADIOLIB_MORSE_UNSUPORTED, // * (unsupported)
0b101010, // +
0b1110011, // ,
0b1100001, // -
0b1101010, // .
0b101001, // /
0b111111, // 0
0b111110, // 1
0b111100, // 2
0b111000, // 3
0b110000, // 4
0b100000, // 5
0b100001, // 6
0b100011, // 7
0b100111, // 8
0b101111, // 9
0b1000111, // :
RADIOLIB_MORSE_UNSUPORTED, // ; (unsupported)
RADIOLIB_MORSE_UNSUPORTED, // < (unsupported)
0b110001, // =
RADIOLIB_MORSE_UNSUPORTED, // > (unsupported)
0b1001100, // ?
0b1010110, // @
0b110, // A
0b10001, // B
0b10101, // C
0b1001, // D
0b10, // E
0b10100, // F
0b1011, // G
0b10000, // H
0b100, // I
0b11110, // J
0b1101, // K
0b10010, // L
0b111, // M
0b101, // N
0b1111, // O
0b10110, // P
0b11011, // Q
0b1010, // R
0b1000, // S
0b11, // T
0b1100, // U
0b11000, // V
0b1110, // W
0b11001, // X
0b11101, // Y
0b10011, // Z
RADIOLIB_MORSE_UNSUPORTED, // [ (unsupported)
RADIOLIB_MORSE_UNSUPORTED, // \ (unsupported)
RADIOLIB_MORSE_UNSUPORTED, // ] (unsupported)
0b1101000, // ^ (unsupported, used as alias for end of work)
0b110101 // _ (unsupported, used as alias for starting signal)
};
/*!
@ -151,7 +151,7 @@ class MorseClient {
size_t println(unsigned long, int = DEC);
size_t println(double, int = 2);
#ifndef RADIOLIB_GODMODE
#if !defined(RADIOLIB_GODMODE)
private:
#endif
PhysicalLayer* _phy;