summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2015-12-21 00:35:33 +0100
committerFlorian Baumann <derflob@derflob.de>2015-12-21 00:39:02 +0100
commit6607b1f84bd9a5b75dfbdb1b1b2e1eabf7339739 (patch)
tree1db1d0664067d9786a5ee68acd733d9ac5ed616c
parenta001684c9b21b1e2ea208a655a23dcdd0d09dca6 (diff)
downloadmFeTAp-6607b1f84bd9a5b75dfbdb1b1b2e1eabf7339739.tar.gz
mFeTAp-6607b1f84bd9a5b75dfbdb1b1b2e1eabf7339739.tar.bz2
add include guard to morse_code.h
-rw-r--r--morse_code.h117
1 files changed, 60 insertions, 57 deletions
diff --git a/morse_code.h b/morse_code.h
index 6018e38..22b1373 100644
--- a/morse_code.h
+++ b/morse_code.h
@@ -1,60 +1,45 @@
-uint16_t morse_code[26] = {
-(1 << 0 | 1 << 2 | 1 << 3 | 1 << 4),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 8),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 10),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6),
-(1 << 0),
-(1 << 0 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8),
-(1 << 0 | 1 << 2 | 1 << 4 | 1 << 6),
-(1 << 0 | 1 << 2),
-(1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 10 | 1 << 11 | 1 << 12),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8),
-(1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6 | 1 << 8),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4),
-//o
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8 | 1 << 9 | 1 << 10),
-(1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 10),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8 | 1 << 10 | 1 << 11 | 1 << 12),
-(1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6),
-(1 << 0 | 1 << 2 | 1 << 4),
-(1 << 0 | 1 << 1 | 1 << 2),
-(1 << 0 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6),
-(1 << 0 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8),
-(1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 8 | 1 << 9 | 1 << 10),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 10 | 1 << 11 | 1 << 12),
-(1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8 | 1 << 10),
+#ifndef __MORSE_CODE_H__
+#define __MORSE_CODE_H__
+
+#define MORSE_INTER_CHAR_UNITS 3
+#define MORSE_INTRA_CHAR_UNITS 1
+#define MORSE_DASH_UNITS 3
+#define MORSE_DOT_UNITS 1
+#define MORSE_INTER_WORD_UNITS 7
+
+uint16_t morse_code[27] = {
+ (1 << 0 | 1 << 2 | 1 << 3 | 1 << 4),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 8),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 10),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6),
+ (1 << 0),
+ (1 << 0 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8),
+ (1 << 0 | 1 << 2 | 1 << 4 | 1 << 6),
+ (1 << 0 | 1 << 2),
+ (1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 10 | 1 << 11 | 1 << 12),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8),
+ (1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6 | 1 << 8),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4),
+ //o
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8 | 1 << 9 | 1 << 10),
+ (1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 10),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8 | 1 << 10 | 1 << 11 | 1 << 12),
+ (1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6),
+ (1 << 0 | 1 << 2 | 1 << 4),
+ (1 << 0 | 1 << 1 | 1 << 2),
+ (1 << 0 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6),
+ (1 << 0 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8),
+ (1 << 0 | 1 << 2 | 1 << 3 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 8 | 1 << 9 | 1 << 10),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 6 | 1 << 7 | 1 << 8 | 1 << 10 | 1 << 11 | 1 << 12),
+ (1 << 0 | 1 << 1 | 1 << 2 | 1 << 4 | 1 << 5 | 1 << 6 | 1 << 8 | 1 << 10),
+ 0,
};
-uint8_t morse_code_len[26] = {
-5,
-9,
-11,
-7,
-1,
-9,
-9,
-7,
-3,
-13,
-9,
-9,
-7,
-5,
-11,
-11,
-13,
-7,
-5,
-3,
-7,
-9,
-9,
-11,
-13,
-11};
+uint8_t morse_code_len[27] = { 5, 9, 11, 7, 1, 9, 9, 7, 3, 13, 9, 9, 7, 5, 11, 11, 13, 7, 5, 3, 7, 9, 9, 11, 13, 11, 4 };
+
uint16_t units_in_str(char *s, uint8_t l);
uint16_t units_in_char(char *s);
uint8_t morse_unit(char *s, uint16_t u);
@@ -71,9 +56,27 @@ uint16_t units_in_str(char *s, uint8_t l) {
}
uint16_t units_in_char(char *s) {
- return morse_code_len[*s - 97];
+ if (*s > 41 && *s < 91) {
+ return morse_code_len[*s - 65];
+ } else if (*s > 97 && *s < 122) {
+ return morse_code_len[*s - 97];
+ } else if (*s == ' ') {
+ return morse_code_len[26];
+ } else {
+ return 0;
+ }
}
uint8_t morse_unit(char *s, uint16_t u) {
- return morse_code[*s - 97] & (1 << u);
+ if (*s > 41 && *s < 91) {
+ return morse_code[*s - 65] & (1 << u);
+ } else if (*s > 97 && *s < 122) {
+ return morse_code[*s - 97] & (1 << u);
+ } else if (*s == ' ') {
+ return 0;
+ } else {
+ return 0;
+ }
}
+
+#endif