initial commit
[teletype.git] / python / teletype-rx.py
1 import time
2 import binascii
3 import urllib # for url unquote
4 import threading
5 import pigpio
6
7 GPIO_PIN=23
8 pi = pigpio.pi() 
9 pi.set_mode(GPIO_PIN, pigpio.INPUT)   
10 time_wait=(0.022)
11 in_string=""
12 howdy=0
13
14 binstr_to_ascii = {
15   '00011' : 'A' ,
16   '11001' : 'B' ,
17   '01110' : 'C' ,
18   '01001' : 'D' ,
19   '00001' : 'E' ,
20   '01101' : 'F' ,
21   '11010' : 'G' ,
22   '10100' : 'H' ,
23   '00110' : 'I' ,
24   '01011' : 'J' ,
25   '01111' : 'K' ,
26   '10010' : 'L' ,
27   '11100' : 'M' ,
28   '01100' : 'N' ,
29   '11000' : 'O' ,
30   '10110' : 'P' ,
31   '10111' : 'Q' ,
32   '01010' : 'R' ,
33   '00101' : 'S' ,
34   '10000' : 'T' ,
35   '00111' : 'U' ,
36   '11110' : 'V' ,
37   '10011' : 'W' ,
38   '11101' : 'X' ,
39   '10101' : 'Y' ,
40   '10001' : 'Z' ,
41   #'10111' : '1' ,
42   #'10011' : '2' ,
43   #'00001' : '3' ,
44   #'01011' : '4' ,
45   #'10000' : '5' ,
46   #'10101' : '6' ,
47   #'00111' : '7' ,
48   #'00110' : '8' ,
49   #'11000' : '9' ,
50   #'10110' : '0' ,
51   #'00011' : '-' ,
52   #'11001' : '?' ,
53   #'01110' : ':' ,
54   #'01001' : '$' ,
55   #'01101' : '!' ,
56   #'11010' : '&' ,
57   #'10100' : '#' ,
58   #'01111' : '(' ,
59   #'10010' : ')' ,
60   #'11100' : '.' ,
61   #'01100' : ',' ,
62   #'01010' : '\\' ,
63   #'11101' : '/' ,
64   #'11101' : '"' ,
65   '00100' : ' '
66 }
67
68 def status(gpio, level, tick):
69   global in_string
70   global howdy
71   global binstr_to_ascii
72   if (howdy==0):
73     in_string=""
74     for x in range (0,5):
75       time.sleep(time_wait)
76       in_string += str(pi.read(GPIO_PIN))
77     howdy=1
78     print(in_string)
79     print(binstr_to_ascii[in_string[::-1]])
80
81 cb1 = pi.callback(GPIO_PIN,pigpio.FALLING_EDGE,status)
82 while True:
83   if (cb1.tally() == 0):
84     howdy=0
85   else:
86     string=""
87   cb1.reset_tally()
88   time.sleep(.1)