-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsender.cpp
106 lines (98 loc) · 2.63 KB
/
sender.cpp
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
#include "sender.hpp"
#include "Arduino.h"
const char* ALPHABET_LETTERS[26][2] = {
"A", ". --- ",
"B", "--- . . . ",
"C", "--- . --- . ",
"D", "--- . . ",
"E", ". ",
"F", ". . --- . ",
"G", "--- --- . ",
"H", ". . . . ",
"I", ". . ",
"J", ". --- --- --- ",
"K", "--- . --- ",
"L", ". --- . . ",
"M", "--- --- ",
"N", "--- . ",
"O", "--- --- --- ",
"P", ". --- --- . ",
"Q", "--- --- . --- ",
"R", ". --- . ",
"S", ". . . ",
"T", "--- ",
"U", ". . --- ",
"V", ". . . --- ",
"W", ". --- --- ",
"X", "--- . . --- ",
"Y", "--- . --- --- ",
"Z", "--- --- . . ",
};
const char* ALPHABET_NUMBERS[10][2] = {
"0", "--- --- --- --- --- ",
"1", ". --- --- --- --- ",
"2", ". . --- --- --- ",
"3", ". . . --- --- ",
"4", ". . . . --- ",
"5", ". . . . . ",
"6", "--- . . . . ",
"7", "--- --- . . . ",
"8", "--- --- --- . . ",
"9", "--- --- --- --- . ",
};
void update_msgs() {
for (int i = 0; i<msg_cnt; i++) {
cw_msg *msg = &msgs[i];
GET_LETTER:
char curr_letter = msg->msg[msg->letter];
// translate to capital letter
if (curr_letter >= 'a' && curr_letter <= 'z') {
curr_letter = curr_letter - 'a' + 'A';
}
// now translate letter to codes
const char* curr_cw;
if (curr_letter >= 'A' && curr_letter <= 'Z') {
// letter found, look up
curr_cw = ALPHABET_LETTERS[curr_letter - 'A'][1];
} else if (curr_letter >= '0' && curr_letter <= '9') {
// number found, look up
curr_cw = ALPHABET_NUMBERS[curr_letter - '0'][1];
} else if (curr_letter == ' ') {
// space found, send 7 pauses
curr_cw = " "; // 3 pauses from letter, 4 more (must be 7)
} else if (curr_letter == '\0') {
// end of word reached, 14 pauses
curr_cw = " @"; // 3 spaces from letter, 11 more spaces, reset word
} else if (curr_letter == '@') {
// control character for immediate reset
curr_cw = "@";
} else {
// never crash, fail silently
curr_cw = " ";
}
char curr_op = curr_cw[msg->phase];
switch (curr_op) {
case '.':
case '-':
msg->state = 1;
msg->phase++;
break;
case ' ':
msg->state = 0;
msg->phase++;
break;
case '\0':
msg->letter++;
msg->phase = 0;
goto GET_LETTER;
case '@':
msg->letter = 0;
msg->phase = 0;
goto GET_LETTER;
default:
msg->letter = 0;
msg->phase = 0;
goto GET_LETTER;
}
}
}