PiPHL/morse_trainer.py

218 lines
3.2 KiB
Python
Raw Normal View History

2017-02-09 23:15:43 +11:00
##################################################
# This is part of PiPHL the RaspberryPi Passive
# Haptic Learning tool
#
# Copyright 2017 Paul Warren <pwarren@pwarren.id.au>
#
# Released under the GNU Public License Version 3.0 or later.
##################################################
import time
2017-02-11 13:56:56 +11:00
import string
import random
2017-02-09 23:15:43 +11:00
from Adafruit_DRV2605 import *
drv = Adafruit_DRV2605(busnum=0)
### setup ###
drv.begin()
# I2C trigger by sending 'go' command
2017-02-11 13:56:56 +11:00
drv.setMode(DRV2605_MODE_INTTRIG)
2017-02-09 23:15:43 +11:00
drv.selectLibrary(1)
2017-02-11 13:56:56 +11:00
##################################################
# Dahs and Dits arrived at by trial and error
# Feel free to find one that works for you!
# see http://www.ti.com/lit/ds/symlink/drv2605.pdf for more info!
##################################################
def dah():
drv.setWaveform(0, 14)
drv.setWaveform(1, 0)
drv.go()
time.sleep(0.32)
2017-02-09 23:15:43 +11:00
def dit():
2017-02-11 13:56:56 +11:00
drv.setWaveform(0, 1)
drv.setWaveform(1, 0)
drv.go()
time.sleep(0.18)
2017-02-09 23:15:43 +11:00
def wait_letter():
2017-02-11 13:56:56 +11:00
time.sleep(0.33)
2017-02-09 23:15:43 +11:00
def wait_word():
2017-02-11 13:56:56 +11:00
time.sleep(0.45)
2017-02-09 23:15:43 +11:00
def a():
2017-02-11 13:56:56 +11:00
dit(); dah();
2017-02-09 23:15:43 +11:00
def b():
2017-02-11 13:56:56 +11:00
dah(); dit(); dit(); dit();
2017-02-09 23:15:43 +11:00
def c():
2017-02-11 13:56:56 +11:00
dah(); dit(); dah(); dit()
2017-02-09 23:15:43 +11:00
def d():
2017-02-11 13:56:56 +11:00
dah(); dit(); dit();
2017-02-09 23:15:43 +11:00
def e():
2017-02-11 13:56:56 +11:00
dit();
2017-02-09 23:15:43 +11:00
def f():
2017-02-11 13:56:56 +11:00
dit(); dit(); dah(); dit();
2017-02-09 23:15:43 +11:00
def g():
2017-02-11 13:56:56 +11:00
dah(); dah(); dit();
2017-02-09 23:15:43 +11:00
def h():
2017-02-11 13:56:56 +11:00
dit(); dit(); dit(); dit();
2017-02-09 23:15:43 +11:00
def i():
2017-02-11 13:56:56 +11:00
dit(); dit();
2017-02-09 23:15:43 +11:00
def j():
2017-02-11 13:56:56 +11:00
dit(); dah(); dah(); dah();
2017-02-09 23:15:43 +11:00
def k():
2017-02-11 13:56:56 +11:00
dah(); dit(); dah();
2017-02-09 23:15:43 +11:00
def l():
2017-02-11 13:56:56 +11:00
dit(); dah(); dit(); dit();
2017-02-09 23:15:43 +11:00
def m():
2017-02-11 13:56:56 +11:00
dah(); dah();
2017-02-09 23:15:43 +11:00
def n():
2017-02-11 13:56:56 +11:00
dah(); dit();
2017-02-09 23:15:43 +11:00
def O():
2017-02-11 13:56:56 +11:00
dah(); dah(); dah();
2017-02-09 23:15:43 +11:00
def p():
2017-02-11 13:56:56 +11:00
dit(); dah(); dah(); dit();
2017-02-09 23:15:43 +11:00
def q():
2017-02-11 13:56:56 +11:00
dah(); dah(); dit(); dah();
2017-02-09 23:15:43 +11:00
def r():
2017-02-11 13:56:56 +11:00
dit(); dah(); dit();
2017-02-09 23:15:43 +11:00
def s():
2017-02-11 13:56:56 +11:00
dit(); dit(); dit();
2017-02-09 23:15:43 +11:00
def t():
2017-02-11 13:56:56 +11:00
dah();
2017-02-09 23:15:43 +11:00
def u():
2017-02-11 13:56:56 +11:00
dit(); dit(); dah();
2017-02-09 23:15:43 +11:00
def v():
2017-02-11 13:56:56 +11:00
dit(); dit(); dit(); dah();
2017-02-09 23:15:43 +11:00
def w():
2017-02-11 13:56:56 +11:00
dit(); dah(); dah();
2017-02-09 23:15:43 +11:00
def x():
2017-02-11 13:56:56 +11:00
dah(); dit(); dit(); dah();
2017-02-09 23:15:43 +11:00
def y():
2017-02-11 13:56:56 +11:00
dah(); dit(); dah(); dah();
2017-02-09 23:15:43 +11:00
def z():
2017-02-11 13:56:56 +11:00
dah(); dah(); dit(); dit();
2017-02-09 23:15:43 +11:00
def m1():
2017-02-11 13:56:56 +11:00
dit(); dah(); dah(); dah(); dah();
2017-02-09 23:15:43 +11:00
def m2():
2017-02-11 13:56:56 +11:00
dit(); dit(); dah(); dah(); dah();
2017-02-09 23:15:43 +11:00
def m3():
2017-02-11 13:56:56 +11:00
dit(); dit(); dit(); dah(); dah();
2017-02-09 23:15:43 +11:00
def m4():
2017-02-11 13:56:56 +11:00
dit(); dit(); dit(); dit(); dah();
2017-02-09 23:15:43 +11:00
def m5():
2017-02-11 13:56:56 +11:00
dit(); dit(); dit(); dit(); dit();
2017-02-09 23:15:43 +11:00
def m6():
2017-02-11 13:56:56 +11:00
dah(); dit(); dit(); dit(); dit();
2017-02-09 23:15:43 +11:00
def m7():
2017-02-11 13:56:56 +11:00
dah(); dah(); dit(); dit(); dit();
2017-02-09 23:15:43 +11:00
def m8():
2017-02-11 13:56:56 +11:00
dah(); dah(); dah(); dit(); dit();
2017-02-09 23:15:43 +11:00
def m9():
2017-02-11 13:56:56 +11:00
dah(); dah(); dah(); dah(); dit();
2017-02-09 23:15:43 +11:00
def m0():
2017-02-11 13:56:56 +11:00
dah(); dah(); dah(); dah(); dah();
def play_morse(alphanum):
gettatr(self, alphanum)()
wait_letter()
def generateSequence(size, chars=string.ascii_lowercase + string.digits):
return random.sample(chars, size)
def main(args, kwargs):
while(1):
# generate sequence
sequence = generateSequence(64)
# play sequence!
for item in sequence:
print item