summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Baumann <derflob@derflob.de>2015-12-20 20:08:55 +0100
committerFlorian Baumann <derflob@derflob.de>2015-12-20 20:08:55 +0100
commita001684c9b21b1e2ea208a655a23dcdd0d09dca6 (patch)
tree1809213e3cb618beb08c8dfda92d408c55dc36a4
parent15dbf2675ff6a627c93429d4baffb8d881f54f22 (diff)
downloadmFeTAp-a001684c9b21b1e2ea208a655a23dcdd0d09dca6.tar.gz
mFeTAp-a001684c9b21b1e2ea208a655a23dcdd0d09dca6.tar.bz2
morse code file{, generator}
-rw-r--r--morse_code.h79
-rwxr-xr-xmorse_code.py50
2 files changed, 129 insertions, 0 deletions
diff --git a/morse_code.h b/morse_code.h
new file mode 100644
index 0000000..6018e38
--- /dev/null
+++ b/morse_code.h
@@ -0,0 +1,79 @@
+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),
+};
+
+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};
+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);
+
+uint16_t units_in_str(char *s, uint8_t l) {
+ uint16_t len = 0;
+ for (uint8_t i = 0; i < l; i++) {
+ len += units_in_char(s + i);
+ len += 3;
+ }
+ len += 4;
+
+ return len;
+}
+
+uint16_t units_in_char(char *s) {
+ return morse_code_len[*s - 97];
+}
+
+uint8_t morse_unit(char *s, uint16_t u) {
+ return morse_code[*s - 97] & (1 << u);
+}
diff --git a/morse_code.py b/morse_code.py
new file mode 100755
index 0000000..2804407
--- /dev/null
+++ b/morse_code.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+template = {
+ 'a': (1, 3),
+ 'b': (3, 1, 1, 1),
+ 'c': (3, 1, 3, 1),
+ 'd': (3, 1, 1),
+ 'e': (1,),
+ 'f': (1, 1, 3, 1),
+ 'g': (3, 3, 1),
+ 'h': (1, 1, 1, 1),
+ 'i': (1, 1),
+ 'j': (1, 3, 3, 3),
+ 'k': (3, 1, 3),
+ 'l': (1, 3, 1, 1),
+ 'm': (3, 3),
+ 'n': (3, 1),
+ 'o': (3, 3, 3),
+ 'p': (1, 3, 3, 1),
+ 'q': (3, 3, 1, 3),
+ 'r': (1, 3, 1),
+ 's': (1, 1, 1),
+ 't': (3,),
+ 'u': (1, 1, 3),
+ 'v': (1, 1, 1, 3),
+ 'w': (1, 3, 3),
+ 'x': (3, 1, 1, 3),
+ 'y': (3, 1, 3, 3),
+ 'z': (3, 3, 1, 1),
+}
+
+out = "uint16_t morse_code[26] = {\n"
+
+for c, v in sorted(template.items(), key=lambda i: i[0]):
+ i = 0
+ m = []
+ for l in v:
+ for j in range(l):
+ m.append("1 << {}".format(i))
+ i += 1
+ i += 1
+ ch = " | ".join(m)
+ out += "({}),\n".format(ch)
+
+out += "};\n\nuint8_t morse_code_len[26] = {\n"
+out += ",\n".join([str(sum(v) + len(v) - 1) for (k, v) in sorted(template.items(), key=lambda i: i[0])])
+out += "};"
+
+with open("/home/flob/Source/mFeTAp/morse_code.h", "w") as f:
+ f.write(out)