-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmorse.ino
148 lines (132 loc) · 4.54 KB
/
morse.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
/*
Ham radio repeater controller
Copyright (C) 2012 Sebastien Van Cauwenberghe ON4SEB
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "timer.h"
timer_t morseTimer;
String morseStr; // Pointer to the morse string
int strCounter; // Morse string index
unsigned int morseFreq;
// Constants
// Thanks to KB8OJH
#define MORSE_NONE 1
PROGMEM prog_uchar morse_ascii[] = {
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
0x73, MORSE_NONE, 0x55, 0x32, /* , _ . / */
0x3F, 0x2F, 0x27, 0x23, /* 0 1 2 3 */
0x21, 0x20, 0x30, 0x38, /* 4 5 6 7 */
0x3C, 0x37, MORSE_NONE, MORSE_NONE, /* 8 9 _ _ */
MORSE_NONE, 0x31, MORSE_NONE, 0x4C, /* _ = _ ? */
MORSE_NONE, 0x05, 0x18, 0x1A, /* _ A B C */
0x0C, 0x02, 0x12, 0x0E, /* D E F G */
0x10, 0x04, 0x17, 0x0D, /* H I J K */
0x14, 0x07, 0x06, 0x0F, /* L M N O */
0x16, 0x1D, 0x0A, 0x08, /* P Q R S */
0x03, 0x09, 0x11, 0x0B, /* T U V W */
0x19, 0x1B, 0x1C, MORSE_NONE, /* X Y Z _ */
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
MORSE_NONE, 0x05, 0x18, 0x1A, /* _ A B C */
0x0C, 0x02, 0x12, 0x0E, /* D E F G */
0x10, 0x04, 0x17, 0x0D, /* H I J K */
0x14, 0x07, 0x06, 0x0F, /* L M N O */
0x16, 0x1D, 0x0A, 0x08, /* P Q R S */
0x03, 0x09, 0x11, 0x0B, /* T U V W */
0x19, 0x1B, 0x1C, MORSE_NONE, /* X Y Z _ */
MORSE_NONE, MORSE_NONE, MORSE_NONE, MORSE_NONE,
};
// Send morse command
void sendMorse (String message, unsigned int freq)
{
if (! morseActive) // If no morse is being sent do it otherwise drop
{
morseActive = true;
morseStr = message;
morseFreq = freq;
strCounter = 0;
debugPrint ("Sending Morse message : "+message);
}
else
{
debugPrint ("Dropped Morse message : "+message);
}
}
// Morse generation task
void morseGenerator()
{
static bool newChar = true;
static char currentChar = 0;
static char symCounter = 0;
if (newChar && morseActive) // Find first one
{
currentChar = pgm_read_byte_near(morse_ascii + morseStr[strCounter]);
strCounter++;
if (strCounter >= morseStr.length()+1) // If end of string stop sending
{
morseActive = false;
currentChar = 0;
}
while (!(currentChar & 0x80) && (symCounter < 8)) // Shift to find first one
{
currentChar <<= 1;
symCounter ++;
}
currentChar <<= 1; // Shift one to get the first element of the morse symbol
symCounter ++;
newChar = false;
}
if (TimerElapsed(morseTimer) && morseActive) // Generate symbols for every character
{
if (symCounter < 8)
{
if (currentChar & 0x80) // Decode the higher bit
morseDash();
else
morseDot();
currentChar <<= 1;
symCounter ++;
}
else
{
symCounter = 0;
newChar = true;
currentChar = 0x0C;
UpdateTimer(morseTimer,MORSE_LETTER_SPC);
}
}
}
void morseDash()
{
if (TimerElapsed(morseTimer))
{
startBeep (morseFreq, MORSE_DASH);
UpdateTimer(morseTimer,MORSE_DASH+MORSE_SYM_SPC);
}
}
void morseDot()
{
if (TimerElapsed(morseTimer))
{
startBeep (morseFreq, MORSE_DOT);
UpdateTimer(morseTimer,MORSE_DOT+MORSE_SYM_SPC);
}
}