diff --git a/docs/source/backends.rst b/docs/source/backends.rst index 58e5f476..941be9e9 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 dba0170e..4fd608a0 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 00000000..5f93c9c4 --- /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 00000000..dded2872 --- /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 cfcd1a61..bfa87806 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 18895d7a..4946a03c 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 2010422c..9229338d 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: