Advertisement
Guest User

moRFeus morse code

a guest
Apr 26th, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.71 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3.  
  4. # Direct access to moRFeus via USB HID.
  5. # Morse code from : https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/resources/morse_code.py
  6. # LamaBleu 04/2018
  7.  
  8.  
  9. import usb.core
  10. import usb.backend.libusb1
  11. import usb.util
  12. import sys
  13. import time
  14. import string
  15. from string import whitespace
  16.  
  17.  
  18.  
  19.  
  20. interface = 0
  21. dev = usb.core.find(idVendor=0x10c4, idProduct=0xeac9) ## Outernet Morfeus
  22.  
  23. if dev is None:
  24.     print("No device!")
  25. else:
  26.     print("Successful Connection")
  27.  
  28.  
  29.  
  30. if dev.is_kernel_driver_active(0) is True:
  31.      dev.detach_kernel_driver(0)
  32.   if dev is None:
  33.      raise ValueError('Device not found')
  34.  
  35. dev.set_configuration()
  36. print "Device Found!"
  37. dev.set_configuration()
  38.  
  39.  
  40. #set mixercurrent 5
  41. byte_ints5 = [0x77, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
  42. #set mixercurrent 0
  43. byte_ints0 = [0x77, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
  44. byte_str0 = "".join(chr(n) for n in byte_ints0)
  45. byte_str5 = "".join(chr(n) for n in byte_ints5)
  46.  
  47. time.sleep(3)
  48. CODE = {' ': ' ',
  49.         "'": '.----.',
  50.         '(': '-.--.-',
  51.         ')': '-.--.-',
  52.         ',': '--..--',
  53.         '-': '-....-',
  54.         '.': '.-.-.-',
  55.         '/': '-..-.',
  56.         '0': '-----',
  57.         '1': '.----',
  58.         '2': '..---',
  59.         '3': '...--',
  60.         '4': '....-',
  61.         '5': '.....',
  62.         '6': '-....',
  63.         '7': '--...',
  64.         '8': '---..',
  65.         '9': '----.',
  66.         ':': '---...',
  67.         ';': '-.-.-.',
  68.         '?': '..--..',
  69.         'A': '.-',
  70.         'B': '-...',
  71.         'C': '-.-.',
  72.         'D': '-..',
  73.         'E': '.',
  74.         'F': '..-.',
  75.         'G': '--.',
  76.         'H': '....',
  77.         'I': '..',
  78.         'J': '.---',
  79.         'K': '-.-',
  80.         'L': '.-..',
  81.         'M': '--',
  82.         'N': '-.',
  83.         'O': '---',
  84.         'P': '.--.',
  85.         'Q': '--.-',
  86.         'R': '.-.',
  87.         'S': '...',
  88.         'T': '-',
  89.         'U': '..-',
  90.         'V': '...-',
  91.         'W': '.--',
  92.         'X': '-..-',
  93.         'Y': '-.--',
  94.         'Z': '--..',
  95.         '_': '..--.-'}
  96.  
  97.  
  98. def dot():
  99.     dev.write(1,buffer(byte_str5))
  100.     time.sleep(0.2)
  101.     dev.write(1,buffer(byte_str0))
  102.     time.sleep(0.2)
  103.  
  104. def dash():
  105.     dev.write(1,buffer(byte_str5))
  106.     time.sleep(0.5)
  107.     dev.write(1,buffer(byte_str0))
  108.     time.sleep(0.2)
  109.  
  110. while True:
  111.     input = raw_input('What would you like to send? ')
  112.     for letter in input:
  113.             for symbol in CODE[letter.upper()]:
  114.                 if symbol == '-':
  115.                     dash()
  116.                 elif symbol == '.':
  117.                     dot()
  118.                 else:
  119.                     time.sleep(0.5)
  120.             time.sleep(0.5)
  121. usb.util.release_interface(dev, interface)
  122. usb.util.dispose_resources(dev)
  123. dev.attach_kernel_driver(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement