3 import urllib # for url unquote
7 pi = pigpio.pi() # connect to local Pi
9 pi.set_mode(2, pigpio.OUTPUT)
11 gpio8period = 20 # period of 1 bit to achieve 45bps was 20
13 ColumnCurrentPosition = 1
16 # first we map ascii to the possible ascii chars
17 ascii_to_baudot_char = {
97 # then we map limted set to baudot
98 # see http://rabbit.eng.miami.edu/info/baudot.html
183 initialize teletype i/o
185 txbaudot("01000") # cr
187 txbaudot("00010") # lf
194 # establish timer for TTY Motor
196 def motor_start(time_secs=0):
200 global MotorTimerCtr, MotorTimerVal
202 if (not MotorTimerCtr) :
203 gpio.output(PWR_RLY,gpio.LOW)
207 MotorTimerCtr = MotorTimerVal
209 MotorTimerCtr = time_secs
213 turn off motor, turn off data relay
216 gpio.output(PWR_RLY,gpio.HIGH)
218 gpio.output(DATA_RLY,gpio.HIGH)
227 test mapping tables by attempt to print out all possible codes
229 for i in range(0,256):
230 if (ascii_to_baudot_char.has_key(chr(i))): # if first reduce mapping table has key
231 a = ascii_to_baudot_char[chr(i)]
232 if (ascii_to_binstr.has_key(a)): # and 2nd reduce mapping table has key
233 b = ascii_to_binstr[a]
239 transmit one character to the teletype
247 micros = gpio8period*1000
249 wf.append(pigpio.pulse(0, 1<<gpio, 20000))
251 for b in reversed(c):
253 wf.append(pigpio.pulse(1<<gpio, 0, micros))
255 wf.append(pigpio.pulse(0, 1<<gpio, micros))
257 wf.append(pigpio.pulse(1<<gpio, 0, micros))
258 pi.wave_add_generic(wf)
260 wid = pi.wave_create()
263 pi.wave_send_once(wid)
265 while pi.wave_tx_busy():
275 if (ascii_to_baudot_char.has_key(chr(k))):
276 a = ascii_to_baudot_char[chr(k)]
277 if (ascii_to_binstr.has_key(a)): # and 2nd reduce mapping table has key
278 b = ascii_to_binstr[a]
284 def update_column_position():
286 keep track of column position so we can insert cr lf when necessary
288 global ColumnCurrentPosition, ColumnMax
289 ColumnCurrentPosition = ColumnCurrentPosition + 1
290 if ColumnCurrentPosition > ColumnMax:
291 #print "update_column_position(): col 0"
294 ColumnCurrentPosition = 0;
307 Shift down to letters
317 send an ascii character
319 if (ascii_to_baudot_char.has_key(c)):
320 a = ascii_to_baudot_char[c]
321 if (ascii_to_binstr.has_key(a)): # and 2nd reduce mapping table has key
322 b = ascii_to_binstr[a]
324 if (a in needs_shift_up):
329 update_column_position()
333 send an ascii character
339 transmit an ascii string
341 de_uried_str = urllib.unquote(s)
342 for i in range(len(de_uried_str)):
343 tx_ascii_chr(de_uried_str[i])
348 transmit a control code 'lf' = line feed, 'cr' = carriage return, etc.
350 global ColumnCurrentPosition
353 ColumnCurrentPosition = 0
361 txbaudot('11011') # shift up
363 txbaudot('11111') # shift down
364 txbaudot('01000') # cr
365 txbaudot('00100') # space
373 txbaudot('01000') # cr
374 ColumnCurrentPosition = 0
379 update_column_position()
382 tx_str("the quick brown fox jumps over the lazy dog!")