forked from supercollider/supercollider
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[hid_updates] draft of uhid device for HID unit tests
- Loading branch information
1 parent
2fcc884
commit 2a7689d
Showing
2 changed files
with
89 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
HIDTest : UnitTest { | ||
classvar <device; | ||
classvar <addr; | ||
*setUpClass { | ||
var sync = CondVar.new; | ||
var cb = {|msg, time, addr, rcvPort| | ||
var devPath=msg[1].asString; | ||
devPath.postln; | ||
HID.findAvailable; | ||
device = HID.openPath(devPath) | ||
}; | ||
Class.initClassTree(HID); | ||
Class.initClassTree(OSCFunc); | ||
super.initClass(); | ||
|
||
addr=NetAddr("127.0.0.1", 57420); | ||
OSCFunc.new(cb, '/device_created'); | ||
|
||
sync.wait({HID.running}); | ||
addr.sendMsg('/test_hidraw_device_path'); | ||
|
||
} | ||
*tearDownClass { | ||
addr.sendMsg('/quit'); | ||
} | ||
test_Meow { | ||
HIDTest.device.path.postln; | ||
this.assertEquals(1,1); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env python | ||
from hidtools.device.base_gamepad import AsusGamepad | ||
|
||
import signal | ||
import sys | ||
import time | ||
import os | ||
|
||
from pythonosc.dispatcher import Dispatcher | ||
from pythonosc.osc_server import BlockingOSCUDPServer | ||
from pythonosc.udp_client import SimpleUDPClient | ||
|
||
class TestGamepad(): | ||
def __init__(self): | ||
print("hidapi test tool") | ||
self.device = AsusGamepad() | ||
self.device.create_kernel_device() | ||
self.client = SimpleUDPClient("127.0.0.1", 57120) | ||
|
||
def quit(self): | ||
print("quitting uhid service") | ||
self.device.destroy() | ||
exit(0) | ||
|
||
def pid(self): | ||
self.client.send_message("/test_hidraw_pid", os.getpid()) | ||
|
||
def device_path(self, osc_path): | ||
try: | ||
print(osc_path) | ||
pathname = self.device.hidraw_nodes[0] | ||
print(pathname) | ||
self.client.send_message("/device_created", pathname) | ||
return pathname | ||
except: | ||
return None | ||
|
||
def default_handler(path, *args): | ||
print(f"DEFAULT {path}: {args}") | ||
|
||
def main(): | ||
device = TestGamepad() | ||
print("main up") | ||
signal.signal(signal.SIGTERM, device.quit) | ||
|
||
dispatcher = Dispatcher() | ||
dispatcher.map("/quit", device.quit) | ||
dispatcher.map("/test_hidraw_device_path", device.device_path) | ||
dispatcher.set_default_handler(default_handler) | ||
|
||
server = BlockingOSCUDPServer(("localhost", 57420), dispatcher) | ||
try: | ||
server.serve_forever() | ||
except KeyboardInterrupt: | ||
device.quit() | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |