forked from APLPi/GPIO
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Morse.dyalog
44 lines (35 loc) · 1.79 KB
/
Morse.dyalog
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
:Namespace Morse
⍝ Requires GPIO Utility
⍝∇:require =/Files
rate←200÷1000 ⍝ length of "dit" = 200ms ("dah" will be 3x this)
gpio_pin←18 ⍝ Use GPIO pin 18
∇ Init filename;t
⍝ Read MorseCode.txt file (actual name passed as argument)
t←⎕FMT #.Files.GetText filename ⍝ Read file into matrix
Chars←t[;1],' ' ⍝ Chars are in column 1 (and add space)
Codes←(↓0 1↓t)~¨' ' ⍝ Codes are everything from column 1
Codes,←⊂' ' ⍝ Space is as a double long pause
∇
∇ Display message;direction;value;folder;m;didah;is;index;output;duration
⍝ Output Morse code using LED connected to GPIO pin
is←{(⍕⍵)⎕NREPLACE ⍺ 0} ⍝ Write to offset 0 of a file
index←Chars⍳message ⍝ Look message up in Chars
:If ∨/m←index>⍴Chars ⍝ Any chars not found?
('UNSUPPORTED CHARS: ',m/message)⎕SIGNAL 11
:Else ⋄ output←∊Codes[index],¨',' ⍝ one long string, w/"," between symbols
:EndIf
folder←'/sys/class/gpio/gpio',⍕gpio_pin
⎕SH'gpio export ',⍕gpio_pin, ' out' ⍝ Exports pin
direction←(folder,'/direction')⎕NTIE 0 ⍝ Open the
value←(folder,'/value')⎕NTIE 0 ⍝ GPIO files
:For didah :In output
duration←(1 3 3 7)['.-, '⍳didah]
value is didah∊'.-' ⍝ Turn light on if dit or dah
⎕DL duration×rate ⍝ Wait
value is 0 ⍝ Turn off
⎕DL rate ⍝ Inter-didah pause
:EndFor
⎕NUNTIE direction value
⎕SH'gpio unexport ',⍕gpio_pin
∇
:EndNamespace