-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmorse.ino
134 lines (125 loc) · 2.58 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
/**************************************************************************************
* This module takes care of sending a morse message about each 60 seconds when there
* is no GPS fix.
*
* Based on the code of: Thomas S. Knutsen <[email protected]>
* https://github.com/la3pna/si5351_beacon/blob/master/si5351_beacon.ino
*
**************************************************************************************/
struct t_mtab {
char c, pat;
} ;
struct t_mtab morsetab[] = {
{'.', 106},
{',', 115},
{'?', 76},
{'/', 41},
{'A', 6},
{'B', 17},
{'C', 21},
{'D', 9},
{'E', 2},
{'F', 20},
{'G', 11},
{'H', 16},
{'I', 4},
{'J', 30},
{'K', 13},
{'L', 18},
{'M', 7},
{'N', 5},
{'O', 15},
{'P', 22},
{'Q', 27},
{'R', 10},
{'S', 8},
{'T', 3},
{'U', 12},
{'V', 24},
{'W', 14},
{'X', 25},
{'Y', 29},
{'Z', 19},
{'1', 62},
{'2', 60},
{'3', 56},
{'4', 48},
{'5', 32},
{'6', 33},
{'7', 35},
{'8', 39},
{'9', 47},
{'0', 63}
} ;
#define N_MORSE (sizeof(morsetab)/sizeof(morsetab[0]))
#define SPEED (MORSE_SPEED)
#define DOTLEN (1200/SPEED)
#define DASHLEN (3*(1200/SPEED))
//******************************************************
// Send a dash
//******************************************************
void dash()
{
si5351.output_enable(SI5351_CLK0, 1);
delay(DASHLEN);
si5351.output_enable(SI5351_CLK0, 0);
delay(DOTLEN) ;
}
//******************************************************
// Send a dit
//******************************************************
void dit()
{
si5351.output_enable(SI5351_CLK0, 1);
delay(DOTLEN);
si5351.output_enable(SI5351_CLK0, 0);
delay(DOTLEN);
}
//******************************************************
// Process a character in Morse
//******************************************************
void send(char c)
{
int i ;
if (c == ' ')
{
delay(7 * DOTLEN) ;
return ;
}
for (i = 0; i < N_MORSE; i++)
{
if (morsetab[i].c == c)
{
unsigned char p = morsetab[i].pat ;
while (p != 1)
{
if (p & 1)
dash() ;
else
dit() ;
p = p / 2 ;
}
delay(2 * DOTLEN) ;
return ;
}
}
}
//******************************************************
// Send *str in Morse
//******************************************************
void send_morse_msg(const char *str)
{
#if defined(DEVMODE)
Serial.print(F("Sending Morse: "));
Serial.print(str);
#endif
while (*str)
{
send(*str++) ;
wdt_reset();
}
#if defined(DEVMODE)
Serial.println(F(" <<-- Done!"));
#endif
Serial.print(str);
}