It works with Volumio, using the same one
You do need to install something like:
and you need to create or adapt the code:
#!/usr/bin/python3
import struct
import time
import subprocess
import os
dev_list_filename = '/proc/bus/input/devices'
while True:
dev_list_file = open(dev_list_filename, 'r')
dev_found = False
infile_path = "/dev/input/"
for line in dev_list_file:
if '=' in line:
tokens = line.split('=')
if 'ZYSD.Ltd HCY RC Consumer Control' in tokens[1]:
dev_found = True
if dev_found and 'Handlers' in tokens[0]:
tokens = tokens[1].split(' ')
infile_path = infile_path + tokens[1]
break
if dev_found:
EVENT_SIZE = struct.calcsize("llHHIllHHIllHHI")
file = open(infile_path, "rb")
event = file.read(EVENT_SIZE)
#print(event)
pressed = -1
while event:
(tv_sec1, tv_usec1, type1, code1, value1, tv_sec2, tv_usec2, type2, code2, value2, tv_sec2, tv_usec3, type3, code3, value3) = struct.unpack("llHHIllHHIllHHI", event)
if pressed == -1:
pressed = value1
print(value1)
# Home => 786979
# Back => 786980
# - => 786666
# + => 786665
if value1 == 786666:
command = 'volumio previous'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif value1 == 786665:
command = 'volumio next'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif value1 == 786979:
command = 'node /data/plugins/user_interface/randomizer/randomAlbum'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif value1 == 786980:
command = 'node /data/plugins/user_interface/randomizer/randomTracks'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif pressed == value1:
pressed = -1
event = file.read(EVENT_SIZE)
else:
dev_list_file.close()
time.sleep(1)
#!/usr/bin/python3
import struct
import time
import subprocess
import os
dev_list_filename = '/proc/bus/input/devices'
while True:
dev_list_file = open(dev_list_filename, 'r')
dev_found = False
infile_path = "/dev/input/"
for line in dev_list_file:
if '=' in line:
tokens = line.split('=')
if 'ZYSD.Ltd HCY RC' in tokens[1]:
dev_found = True
if dev_found and 'Handlers' in tokens[0]:
tokens = tokens[1].split(' ')
infile_path = infile_path + tokens[2]
break
if dev_found:
EVENT_SIZE = struct.calcsize("llHHIllHHIllHHI")
file = open(infile_path, "rb")
event = file.read(EVENT_SIZE)
#print(event)
pressed = -1
while event:
(tv_sec1, tv_usec1, type1, code1, value1, tv_sec2, tv_usec2, type2, code2, value2, tv_sec2, tv_usec3, type3, code3, value3) = struct.unpack("llHHIllHHIllHHI", event)
if pressed == -1:
pressed = value1
print(value1)
# OK => 458792
# ^ => 458834
# v => 458833
# < => 458832
# > => 458831
if value1 == 458832:
command = 'volumio seek minus'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif value1 == 458831:
command = 'volumio seek plus'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif value1 == 458792:
command = 'volumio toggle'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif value1 == 458834:
command = 'sudo systemctl restart oled'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif value1 == 458833:
command = 'sudo systemctl restart oled1'
process = subprocess.Popen(command.split(), stdout=subprocess.PIPE)
elif pressed == value1:
pressed = -1
event = file.read(EVENT_SIZE)
else:
dev_list_file.close()
time.sleep(1)