You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

84 lines
2.0 KiB

from serialTest import SerialListener
from serialTest import MOVEMENT
import os
import subprocess
#5 - 101 - a d
#4 - xxx
#3 - 104 - 1 2 3 4 5
#2 - 103 - hz
#1 - 102 - w s
#upButton = 1001
class ENTER:
def __init__(self):
self.pin = 1001
self.enter = "xdotool key Return".split()
def __call__(self, data):
print(self.enter)
subprocess.Popen(self.enter)
class AD:
def __init__(self):
self.pin = 101
self.a = "xdotool key a".split()
self.d = "xdotool key d".split()
def __call__(self, data):
if data[2] == MOVEMENT.LEFT:
print(self.a)
subprocess.Popen(self.a)
if data[2] == MOVEMENT.RIGHT:
print(self.d)
subprocess.Popen(self.d)
class WS:
def __init__(self):
self.pin = 101
self.w = "xdotool key w".split()
self.s = "xdotool key s".split()
def __call__(self, data):
if data[2] == MOVEMENT.LEFT:
print(self.s)
subprocess.Popen(self.s)
if data[2] == MOVEMENT.RIGHT:
print(self.w)
subprocess.Popen(self.w)
class MODE:
def __init__(self):
self.pin = 104
self.min_key = 1
self.max_key = 5
self.current_key = 1
def __call__(self, data):
if data[2] == MOVEMENT.LEFT:
self.current_key -= 1
if data[2] == MOVEMENT.RIGHT:
self.current_key += 1
if (self.current_key < self.min_key):
self.current_key = self.min_key
if (self.current_key > self.max_key):
self.current_key = self.max_key
cmd = f"xdotool key {self.current_key}".split()
print(cmd)
subprocess.Popen(cmd)
if __name__ == "__main__":
os.environ['DISPLAY'] = ':0'
binds = {
101: AD(),
104: MODE(),
102: WS(),
1001: ENTER()
}
listener = SerialListener()
for pin in listener.listen():
if pin[0].id in binds:
binds[pin[0].id](pin)