From 66b6f0bc8b6f44dd60f36a30ac657ed1c8b854d3 Mon Sep 17 00:00:00 2001 From: Fabio Manganiello Date: Sat, 1 Dec 2018 18:55:13 +0100 Subject: [PATCH] Added Wiimote support docs; Added Wiimote connection/disconnection events --- docs/source/backends.rst | 1 + docs/source/conf.py | 1 + docs/source/platypush/backend/wiimote.rst | 6 ++++++ docs/source/platypush/plugins/wiimote.rst | 6 ++++++ docs/source/plugins.rst | 1 + platypush/backend/wiimote.py | 18 +++++------------- platypush/message/event/wiimote.py | 18 ++++++++++++++++++ 7 files changed, 38 insertions(+), 13 deletions(-) create mode 100644 docs/source/platypush/backend/wiimote.rst create mode 100644 docs/source/platypush/plugins/wiimote.rst diff --git a/docs/source/backends.rst b/docs/source/backends.rst index 58e5f4769..941be9e97 100644 --- a/docs/source/backends.rst +++ b/docs/source/backends.rst @@ -30,3 +30,4 @@ Backends platypush/backend/tcp.rst platypush/backend/weather.forecast.rst platypush/backend/websocket.rst + platypush/backend/wiimote.rst diff --git a/docs/source/conf.py b/docs/source/conf.py index dba0170ec..4fd608a01 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -202,6 +202,7 @@ autodoc_mock_imports = ['googlesamples.assistant.grpc.audio_helpers', 'inotify', 'omxplayer', 'plexapi', + 'cwiid', ] sys.path.insert(0, os.path.abspath('../..')) diff --git a/docs/source/platypush/backend/wiimote.rst b/docs/source/platypush/backend/wiimote.rst new file mode 100644 index 000000000..5f93c9c46 --- /dev/null +++ b/docs/source/platypush/backend/wiimote.rst @@ -0,0 +1,6 @@ +``platypush.backend.wiimote`` +============================= + +.. automodule:: platypush.backend.wiimote + :members: + diff --git a/docs/source/platypush/plugins/wiimote.rst b/docs/source/platypush/plugins/wiimote.rst new file mode 100644 index 000000000..dded28722 --- /dev/null +++ b/docs/source/platypush/plugins/wiimote.rst @@ -0,0 +1,6 @@ +``platypush.plugins.wiimote`` +============================= + +.. automodule:: platypush.plugins.wiimote + :members: + diff --git a/docs/source/plugins.rst b/docs/source/plugins.rst index cfcd1a61d..bfa87806f 100644 --- a/docs/source/plugins.rst +++ b/docs/source/plugins.rst @@ -50,3 +50,4 @@ Plugins platypush/plugins/video.omxplayer.rst platypush/plugins/weather.forecast.rst platypush/plugins/websocket.rst + platypush/plugins/wiimote.rst diff --git a/platypush/backend/wiimote.py b/platypush/backend/wiimote.py index 18895d7a9..4946a03cb 100644 --- a/platypush/backend/wiimote.py +++ b/platypush/backend/wiimote.py @@ -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): diff --git a/platypush/message/event/wiimote.py b/platypush/message/event/wiimote.py index 2010422c6..9229338db 100644 --- a/platypush/message/event/wiimote.py +++ b/platypush/message/event/wiimote.py @@ -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: