Added Wiimote support docs; Added Wiimote connection/disconnection events
This commit is contained in:
parent
383a075f39
commit
66b6f0bc8b
7 changed files with 38 additions and 13 deletions
|
@ -30,3 +30,4 @@ Backends
|
|||
platypush/backend/tcp.rst
|
||||
platypush/backend/weather.forecast.rst
|
||||
platypush/backend/websocket.rst
|
||||
platypush/backend/wiimote.rst
|
||||
|
|
|
@ -202,6 +202,7 @@ autodoc_mock_imports = ['googlesamples.assistant.grpc.audio_helpers',
|
|||
'inotify',
|
||||
'omxplayer',
|
||||
'plexapi',
|
||||
'cwiid',
|
||||
]
|
||||
|
||||
sys.path.insert(0, os.path.abspath('../..'))
|
||||
|
|
6
docs/source/platypush/backend/wiimote.rst
Normal file
6
docs/source/platypush/backend/wiimote.rst
Normal file
|
@ -0,0 +1,6 @@
|
|||
``platypush.backend.wiimote``
|
||||
=============================
|
||||
|
||||
.. automodule:: platypush.backend.wiimote
|
||||
:members:
|
||||
|
6
docs/source/platypush/plugins/wiimote.rst
Normal file
6
docs/source/platypush/plugins/wiimote.rst
Normal file
|
@ -0,0 +1,6 @@
|
|||
``platypush.plugins.wiimote``
|
||||
=============================
|
||||
|
||||
.. automodule:: platypush.plugins.wiimote
|
||||
:members:
|
||||
|
|
@ -50,3 +50,4 @@ Plugins
|
|||
platypush/plugins/video.omxplayer.rst
|
||||
platypush/plugins/weather.forecast.rst
|
||||
platypush/plugins/websocket.rst
|
||||
platypush/plugins/wiimote.rst
|
||||
|
|
|
@ -8,7 +8,9 @@ import time
|
|||
|
||||
from platypush.backend import Backend
|
||||
from platypush.message import Message
|
||||
from platypush.message.event.wiimote import WiimoteEvent
|
||||
from platypush.message.event.wiimote import WiimoteEvent, \
|
||||
WiimoteConnectionEvent, WiimoteDisconnectionEvent
|
||||
|
||||
from platypush.message.request import Request
|
||||
|
||||
|
||||
|
@ -31,25 +33,14 @@ class WiimoteBackend(Backend):
|
|||
_connection_attempts = 0
|
||||
|
||||
|
||||
def msg_callback(self):
|
||||
def _callback(msg_list, timestamp):
|
||||
print(msg_list)
|
||||
|
||||
return _callback
|
||||
|
||||
def get_wiimote(self):
|
||||
if not self._wiimote:
|
||||
self._wiimote = cwiid.Wiimote()
|
||||
self._wiimote.mesg_callback = self.msg_callback()
|
||||
# self._wiimote.enable(cwiid.FLAG_MESG_IFC | cwiid.FLAG_MOTIONPLUS)
|
||||
self._wiimote.enable(cwiid.FLAG_MOTIONPLUS)
|
||||
self._wiimote.rpt_mode = cwiid.RPT_ACC | cwiid.RPT_BTN | cwiid.RPT_MOTIONPLUS
|
||||
|
||||
self.logger.info('WiiMote connected')
|
||||
self._wiimote.led = 1
|
||||
self._wiimote.rumble = True
|
||||
time.sleep(0.5)
|
||||
self._wiimote.rumble = False
|
||||
self.bus.post(WiimoteConnectionEvent())
|
||||
|
||||
return self._wiimote
|
||||
|
||||
|
@ -99,6 +90,7 @@ class WiimoteBackend(Backend):
|
|||
pass
|
||||
|
||||
self._wiimote = None
|
||||
self.bus.post(WiimoteDisconnectionEvent())
|
||||
|
||||
|
||||
def run(self):
|
||||
|
|
|
@ -10,5 +10,23 @@ class WiimoteEvent(Event):
|
|||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class WiimoteConnectionEvent(WiimoteEvent):
|
||||
"""
|
||||
Event triggered upon Wiimote connection
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
class WiimoteDisconnectionEvent(WiimoteEvent):
|
||||
"""
|
||||
Event triggered upon Wiimote disconnection
|
||||
"""
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
# vim:sw=4:ts=4:et:
|
||||
|
||||
|
|
Loading…
Reference in a new issue