Created
November 18, 2017 01:40
-
-
Save NejcZupec/70367af061d089a4c3c495b870323150 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from time import sleep | |
import sys | |
import serial | |
commands = { | |
'on': b'0', | |
'volume_down': b'1', | |
'volume_up': b'2', | |
'mute': b'3', | |
'channel_dvd': b'4', | |
'channel_tv': b'5', | |
'channel_game': b'6', | |
'channel_mp3': b'7', | |
} | |
def figure_out_serial(): | |
devs = os.listdir('/dev/') | |
try: | |
device_name = [file_ for file_ in devs if 'ttyUSB' in file_][0] | |
except IndexError: | |
print("USB serial not found") | |
return | |
return '/dev/' + device_name | |
def main(): | |
key = sys.argv[1] | |
if not key: | |
print('key was not specified. The command was not sent.') | |
return | |
serial_name = figure_out_serial() | |
print('Serial name: {}'.format(serial_name)) | |
ser = serial.Serial(serial_name) | |
command = commands[key] | |
ser.write(command) | |
print('Command "{}" was sent to Hi-Fi system.'.format(key)) | |
sleep(1) | |
ser.close() | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment