Skip to content

Commit

Permalink
multiple virtual devices on the same machine
Browse files Browse the repository at this point in the history
  • Loading branch information
rmst committed Jan 14, 2019
1 parent 80a4686 commit 8960266
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ sudo apt install gamepadtool
gamepadtool # to run
```

### Multiple virtual devices on the same machine
Each `yoke` process creates one virtual device. To run multiple processes on the same machine make sure to give them different `--id` numbers (any integer greater than 0).

### Security
The communication between the Linux client and the Android app are unencrypted UDP messages. You should therefore use it in networks you trust. However, if you are not in a trusted environment you can always create one via USB or Bluetooth. Just enable USB or Bluetooth tethering on your Android device and connect your Linux computer. This will create a mini-network for just your Phone and Computer and Yoke will work as usual.

Expand Down
3 changes: 2 additions & 1 deletion bin/yoke
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,13 @@ TYPES = {'gamepad': GamepadService, 'flightgear': FlightgearYokeService, 'rbr':

parser = argparse.ArgumentParser()
parser.add_argument('--name', type=str, default='Yoke', help='virtual device name')
parser.add_argument('--id', type=int, default=1, help='virtual device id (an integer larger than 0 in case there are multiple virtual devices)')
parser.add_argument('--port', type=int, default=0, help='port to listen on')
parser.add_argument('--type', type=str, default='gamepad', help='device type', choices=TYPES.keys())
args = parser.parse_args()

Service = TYPES[args.type]
dev = yoke.Device(args.name, events=Service.events)
dev = yoke.Device(args.id, args.name, events=Service.events)
service = Service(dev, args.port)

try:
Expand Down
10 changes: 5 additions & 5 deletions yoke/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ def get_ip_address():
ABS_EVENTS = [getattr(EVENTS, n) for n in dir(EVENTS) if n.startswith("ABS_")]

class Device:
def __init__(self, name="Yoke", events=GAMEPAD_EVENTS):
self.name = name
def __init__(self, id=1, name="Yoke", events=GAMEPAD_EVENTS):
self.name = name + '-' + str(id)
for fn in glob('/sys/class/input/js*/device/name'):
with open(fn) as f:
fname = f.read().split()[0] # need to split because there seem to be newlines
Expand Down Expand Up @@ -95,11 +95,11 @@ def close(self):
setattr(EVENTS, k, getattr(VjoyConstants, k, None))

class Device:
def __init__(self, name, events=GAMEPAD_EVENTS):
def __init__(self, id=1, name='Yoke', events=GAMEPAD_EVENTS):
super().__init__()
self.device = VjoyDevice(1)
self.name = name + '-' + id
self.device = VjoyDevice(id)
self.events = events
self.name = name
def emit(self, d, v):
if d is not None:
if d in range(1, 8+1):
Expand Down

0 comments on commit 8960266

Please sign in to comment.