Added Wiimote support docs; Added Wiimote connection/disconnection events

This commit is contained in:
Fabio Manganiello 2018-12-01 18:55:13 +01:00
parent 383a075f39
commit 66b6f0bc8b
7 changed files with 38 additions and 13 deletions

View file

@ -30,3 +30,4 @@ Backends
platypush/backend/tcp.rst
platypush/backend/weather.forecast.rst
platypush/backend/websocket.rst
platypush/backend/wiimote.rst

View file

@ -202,6 +202,7 @@ autodoc_mock_imports = ['googlesamples.assistant.grpc.audio_helpers',
'inotify',
'omxplayer',
'plexapi',
'cwiid',
]
sys.path.insert(0, os.path.abspath('../..'))

View file

@ -0,0 +1,6 @@
``platypush.backend.wiimote``
=============================
.. automodule:: platypush.backend.wiimote
:members:

View file

@ -0,0 +1,6 @@
``platypush.plugins.wiimote``
=============================
.. automodule:: platypush.plugins.wiimote
:members:

View file

@ -50,3 +50,4 @@ Plugins
platypush/plugins/video.omxplayer.rst
platypush/plugins/weather.forecast.rst
platypush/plugins/websocket.rst
platypush/plugins/wiimote.rst

View file

@ -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):

View file

@ -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: