Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # Direct access to moRFeus via USB HID.
- # Morse code from : https://www.cl.cam.ac.uk/projects/raspberrypi/tutorials/robot/resources/morse_code.py
- # LamaBleu 04/2018
- import usb.core
- import usb.backend.libusb1
- import usb.util
- import sys
- import time
- import string
- from string import whitespace
- interface = 0
- dev = usb.core.find(idVendor=0x10c4, idProduct=0xeac9) ## Outernet Morfeus
- if dev is None:
- print("No device!")
- else:
- print("Successful Connection")
- if dev.is_kernel_driver_active(0) is True:
- dev.detach_kernel_driver(0)
- if dev is None:
- raise ValueError('Device not found')
- dev.set_configuration()
- print "Device Found!"
- dev.set_configuration()
- #set mixercurrent 5
- byte_ints5 = [0x77, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
- #set mixercurrent 0
- byte_ints0 = [0x77, 0x83, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]
- byte_str0 = "".join(chr(n) for n in byte_ints0)
- byte_str5 = "".join(chr(n) for n in byte_ints5)
- time.sleep(3)
- CODE = {' ': ' ',
- "'": '.----.',
- '(': '-.--.-',
- ')': '-.--.-',
- ',': '--..--',
- '-': '-....-',
- '.': '.-.-.-',
- '/': '-..-.',
- '0': '-----',
- '1': '.----',
- '2': '..---',
- '3': '...--',
- '4': '....-',
- '5': '.....',
- '6': '-....',
- '7': '--...',
- '8': '---..',
- '9': '----.',
- ':': '---...',
- ';': '-.-.-.',
- '?': '..--..',
- 'A': '.-',
- 'B': '-...',
- 'C': '-.-.',
- 'D': '-..',
- 'E': '.',
- 'F': '..-.',
- 'G': '--.',
- 'H': '....',
- 'I': '..',
- 'J': '.---',
- 'K': '-.-',
- 'L': '.-..',
- 'M': '--',
- 'N': '-.',
- 'O': '---',
- 'P': '.--.',
- 'Q': '--.-',
- 'R': '.-.',
- 'S': '...',
- 'T': '-',
- 'U': '..-',
- 'V': '...-',
- 'W': '.--',
- 'X': '-..-',
- 'Y': '-.--',
- 'Z': '--..',
- '_': '..--.-'}
- def dot():
- dev.write(1,buffer(byte_str5))
- time.sleep(0.2)
- dev.write(1,buffer(byte_str0))
- time.sleep(0.2)
- def dash():
- dev.write(1,buffer(byte_str5))
- time.sleep(0.5)
- dev.write(1,buffer(byte_str0))
- time.sleep(0.2)
- while True:
- input = raw_input('What would you like to send? ')
- for letter in input:
- for symbol in CODE[letter.upper()]:
- if symbol == '-':
- dash()
- elif symbol == '.':
- dot()
- else:
- time.sleep(0.5)
- time.sleep(0.5)
- usb.util.release_interface(dev, interface)
- usb.util.dispose_resources(dev)
- dev.attach_kernel_driver(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement