Joycon: call input hooks in a different thread
This commit is contained in:
parent
6e30040d81
commit
1f98a9bf46
1 changed files with 8 additions and 6 deletions
|
@ -1,5 +1,5 @@
|
||||||
import threading
|
|
||||||
import time
|
import time
|
||||||
|
from threading import Thread
|
||||||
from typing import Optional, Tuple
|
from typing import Optional, Tuple
|
||||||
|
|
||||||
import hid
|
import hid
|
||||||
|
@ -47,9 +47,7 @@ class JoyCon:
|
||||||
self._setup_sensors()
|
self._setup_sensors()
|
||||||
|
|
||||||
# start talking with the joycon in a daemon thread
|
# start talking with the joycon in a daemon thread
|
||||||
self._update_input_report_thread = threading.Thread(target=self._update_input_report)
|
Thread(target=self._update_input_report, daemon=True).start()
|
||||||
self._update_input_report_thread.setDaemon(True)
|
|
||||||
self._update_input_report_thread.start()
|
|
||||||
|
|
||||||
def _open(self, vendor_id, product_id, serial):
|
def _open(self, vendor_id, product_id, serial):
|
||||||
try:
|
try:
|
||||||
|
@ -125,12 +123,16 @@ class JoyCon:
|
||||||
|
|
||||||
self._input_report = report
|
self._input_report = report
|
||||||
|
|
||||||
for callback in self._input_hooks:
|
# Call input hooks in a different thread
|
||||||
callback(self)
|
Thread(target=self._input_hook_caller, daemon=True).start()
|
||||||
except OSError:
|
except OSError:
|
||||||
print('connection closed')
|
print('connection closed')
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
def _input_hook_caller(self):
|
||||||
|
for callback in self._input_hooks:
|
||||||
|
callback(self)
|
||||||
|
|
||||||
def _read_joycon_data(self):
|
def _read_joycon_data(self):
|
||||||
color_data = self._spi_flash_read(0x6050, 6)
|
color_data = self._spi_flash_read(0x6050, 6)
|
||||||
self.color_body = tuple(color_data[:3])
|
self.color_body = tuple(color_data[:3])
|
||||||
|
|
Loading…
Reference in a new issue