acid-drop- Hacking the planet from a LilyGo T-Deck using custom firmware |
git clone git://git.acid.vegas/acid-drop.git |
Log | Files | Refs | Archive | README | LICENSE |
Morse.h (7530B)
1 #if !defined(_RADIOLIB_RADIOLIB_MORSE_H) && !defined(RADIOLIB_EXCLUDE_MORSE) 2 #define _RADIOLIB_RADIOLIB_MORSE_H 3 4 #include "../../TypeDef.h" 5 #include "../PhysicalLayer/PhysicalLayer.h" 6 #include "../AFSK/AFSK.h" 7 8 #define RADIOLIB_MORSE_DOT 0b0 9 #define RADIOLIB_MORSE_DASH 0b1 10 #define RADIOLIB_MORSE_GUARDBIT 0b1 11 #define RADIOLIB_MORSE_UNSUPORTED 0xFF 12 #define RADIOLIB_MORSE_ASCII_OFFSET 32 13 #define RADIOLIB_MORSE_INTER_SYMBOL 0x00 14 #define RADIOLIB_MORSE_CHAR_COMPLETE 0x01 15 #define RADIOLIB_MORSE_WORD_COMPLETE 0x02 16 17 // Morse character table: - using codes defined in ITU-R M.1677-1 18 // - Morse code representation is saved LSb first, using additional bit as guard 19 // - position in array corresponds ASCII code minus RADIOLIB_MORSE_ASCII_OFFSET 20 // - ASCII characters marked RADIOLIB_MORSE_UNSUPORTED do not have ITU-R M.1677-1 equivalent 21 static const uint8_t MorseTable[] RADIOLIB_NONVOLATILE = { 22 0b00, // space 23 0b110101, // ! (unsupported) 24 0b1010010, // " 25 RADIOLIB_MORSE_UNSUPORTED, // # (unsupported) 26 RADIOLIB_MORSE_UNSUPORTED, // $ (unsupported) 27 RADIOLIB_MORSE_UNSUPORTED, // % (unsupported) 28 RADIOLIB_MORSE_UNSUPORTED, // & (unsupported) 29 0b1011110, // ' 30 0b101101, // ( 31 0b1101101, // ) 32 RADIOLIB_MORSE_UNSUPORTED, // * (unsupported) 33 0b101010, // + 34 0b1110011, // , 35 0b1100001, // - 36 0b1101010, // . 37 0b101001, // / 38 0b111111, // 0 39 0b111110, // 1 40 0b111100, // 2 41 0b111000, // 3 42 0b110000, // 4 43 0b100000, // 5 44 0b100001, // 6 45 0b100011, // 7 46 0b100111, // 8 47 0b101111, // 9 48 0b1000111, // : 49 RADIOLIB_MORSE_UNSUPORTED, // ; (unsupported) 50 RADIOLIB_MORSE_UNSUPORTED, // < (unsupported) 51 0b110001, // = 52 RADIOLIB_MORSE_UNSUPORTED, // > (unsupported) 53 0b1001100, // ? 54 0b1010110, // @ 55 0b110, // A 56 0b10001, // B 57 0b10101, // C 58 0b1001, // D 59 0b10, // E 60 0b10100, // F 61 0b1011, // G 62 0b10000, // H 63 0b100, // I 64 0b11110, // J 65 0b1101, // K 66 0b10010, // L 67 0b111, // M 68 0b101, // N 69 0b1111, // O 70 0b10110, // P 71 0b11011, // Q 72 0b1010, // R 73 0b1000, // S 74 0b11, // T 75 0b1100, // U 76 0b11000, // V 77 0b1110, // W 78 0b11001, // X 79 0b11101, // Y 80 0b10011, // Z 81 RADIOLIB_MORSE_UNSUPORTED, // [ (unsupported) 82 RADIOLIB_MORSE_UNSUPORTED, // \ (unsupported) 83 RADIOLIB_MORSE_UNSUPORTED, // ] (unsupported) 84 0b1101000, // ^ (unsupported, used as alias for end of work) 85 0b110101 // _ (unsupported, used as alias for starting signal) 86 }; 87 88 /*! 89 \class MorseClient 90 91 \brief Client for Morse Code communication. The public interface is the same as Arduino Serial. 92 */ 93 class MorseClient { 94 public: 95 /*! 96 \brief Constructor for 2-FSK mode. 97 98 \param phy Pointer to the wireless module providing PhysicalLayer communication. 99 */ 100 explicit MorseClient(PhysicalLayer* phy); 101 102 #if !defined(RADIOLIB_EXCLUDE_AFSK) 103 /*! 104 \brief Constructor for AFSK mode. 105 106 \param audio Pointer to the AFSK instance providing audio. 107 */ 108 explicit MorseClient(AFSKClient* audio); 109 #endif 110 111 // basic methods 112 113 /*! 114 \brief Initialization method. 115 116 \param base Base RF frequency to be used in MHz (in 2-FSK mode), or the tone frequency in Hz (in AFSK mode) 117 118 \param speed Coding speed in words per minute. 119 120 \returns \ref status_codes 121 */ 122 int16_t begin(float base, uint8_t speed = 20); 123 124 /*! 125 \brief Send start signal. 126 127 \returns Number of bytes sent (always 0). 128 */ 129 size_t startSignal(); 130 131 /*! 132 \brief Decode Morse symbol to ASCII. 133 134 \param symbol Morse code symbol, respresented as outlined in MorseTable. 135 136 \param len Symbol length (number of dots and dashes). 137 138 \returns ASCII character matching the symbol, or 0xFF if no match is found. 139 */ 140 static char decode(uint8_t symbol, uint8_t len); 141 142 /*! 143 \brief Read Morse tone on input pin. 144 145 \param symbol Pointer to the symbol buffer. 146 147 \param len Pointer to the length counter. 148 149 \param low Low threshold for decision limit (dot length, pause length etc.), defaults to 0.75. 150 151 \param high High threshold for decision limit (dot length, pause length etc.), defaults to 1.25. 152 153 \returns 0 if not enough symbols were decoded, 1 if inter-character space was detected, 2 if inter-word space was detected. 154 */ 155 #if !defined(RADIOLIB_EXCLUDE_AFSK) 156 int read(byte* symbol, byte* len, float low = 0.75f, float high = 1.25f); 157 #endif 158 159 size_t write(const char* str); 160 size_t write(uint8_t* buff, size_t len); 161 size_t write(uint8_t b); 162 163 size_t print(__FlashStringHelper*); 164 size_t print(const String &); 165 size_t print(const char[]); 166 size_t print(char); 167 size_t print(unsigned char, int = DEC); 168 size_t print(int, int = DEC); 169 size_t print(unsigned int, int = DEC); 170 size_t print(long, int = DEC); 171 size_t print(unsigned long, int = DEC); 172 size_t print(double, int = 2); 173 174 size_t println(void); 175 size_t println(__FlashStringHelper*); 176 size_t println(const String &); 177 size_t println(const char[]); 178 size_t println(char); 179 size_t println(unsigned char, int = DEC); 180 size_t println(int, int = DEC); 181 size_t println(unsigned int, int = DEC); 182 size_t println(long, int = DEC); 183 size_t println(unsigned long, int = DEC); 184 size_t println(double, int = 2); 185 186 #if !defined(RADIOLIB_GODMODE) 187 private: 188 #endif 189 PhysicalLayer* _phy; 190 #if !defined(RADIOLIB_EXCLUDE_AFSK) 191 AFSKClient* _audio; 192 #endif 193 194 uint32_t _base = 0, _baseHz = 0; 195 float _basePeriod = 0.0f; 196 uint16_t _dotLength = 0; 197 uint16_t _dashLength = 0; 198 uint16_t _letterSpace = 0; 199 uint16_t _wordSpace = 0; 200 201 // variables to keep decoding state 202 uint32_t signalCounter = 0; 203 uint32_t signalStart = 0; 204 uint32_t pauseCounter = 0; 205 uint32_t pauseStart = 0; 206 207 size_t printNumber(unsigned long, uint8_t); 208 size_t printFloat(double, uint8_t); 209 210 int16_t transmitDirect(uint32_t freq = 0, uint32_t freqHz = 0); 211 int16_t standby(); 212 }; 213 214 #endif