diff --git a/controllerApp/Net.pde b/controllerApp/Net.pde index f20e91a17596a5b166a980d7186b6f0f3848e2d0..68777d30434cafe5aa96b07be9c1d5c69ec4e898 100644 --- a/controllerApp/Net.pde +++ b/controllerApp/Net.pde @@ -41,20 +41,20 @@ class Net jsonParam.put("d", d); sendPost(); } - public void sendAccelerometer(float x, float y,float z){ + public void sendAccelerometer(float ax, float ay,float az){ jsonParam = new JSONObject(); jsonParam.put("evnType", "Accelerometer"); - jsonParam.put("x", y); - jsonParam.put("y", x); - jsonParam.put("z", z); + jsonParam.put("ax", ay); + jsonParam.put("ay", ax); + jsonParam.put("az", az); sendPost(); } - public void sendGyroscope(float x, float y,float z){ + public void sendGyroscope(float gx, float gy,float gz){ jsonParam = new JSONObject(); jsonParam.put("evnType", "Gyroscope"); - jsonParam.put("x", y); - jsonParam.put("y", x); - jsonParam.put("z", z); + jsonParam.put("gx", gx); + jsonParam.put("gy", gy); + jsonParam.put("gz", gz); sendPost(); } public void sendDoubleTap(float x, float y){ @@ -66,7 +66,7 @@ class Net } public void sendFlick(float x, float y,float px, float py,float v){ jsonParam = new JSONObject(); - jsonParam.put("evnType", "Double Tap"); + jsonParam.put("evnType", "Flick"); jsonParam.put("x", y); jsonParam.put("y", x); jsonParam.put("px", px); diff --git a/controllerPackage/controller/__init__.py b/controllerPackage/controller/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..88ecaddf5b64e9176d0478df247565b08f8e3f19 100644 --- a/controllerPackage/controller/__init__.py +++ b/controllerPackage/controller/__init__.py @@ -0,0 +1,4 @@ +from controller.controller import Controller as Controller_ +def Controller(*args): + c = Controller_() + return c \ No newline at end of file diff --git a/controllerPackage/controller/__pycache__/__init__.cpython-37.pyc b/controllerPackage/controller/__pycache__/__init__.cpython-37.pyc index cb3e5e1d5605fed7aa518990e74ec4720e312506..276b01bc680971d39bcbf8ee4716ba2195832032 100644 Binary files a/controllerPackage/controller/__pycache__/__init__.cpython-37.pyc and b/controllerPackage/controller/__pycache__/__init__.cpython-37.pyc differ diff --git a/controllerPackage/controller/__pycache__/controller.cpython-37.pyc b/controllerPackage/controller/__pycache__/controller.cpython-37.pyc index 090dd2effdbbff823ae93e605673e6c3e5d79af7..d55901fbc43f7cf94cebcd9427a17d7526ff5a66 100644 Binary files a/controllerPackage/controller/__pycache__/controller.cpython-37.pyc and b/controllerPackage/controller/__pycache__/controller.cpython-37.pyc differ diff --git a/controllerPackage/controller/__pycache__/mobile.cpython-37.pyc b/controllerPackage/controller/__pycache__/mobile.cpython-37.pyc index 34e2be9c24f843ecfdad2392e5acabeda68dd515..c7e68533618099ffeb6886ebbd11b1af8b7fa96f 100644 Binary files a/controllerPackage/controller/__pycache__/mobile.cpython-37.pyc and b/controllerPackage/controller/__pycache__/mobile.cpython-37.pyc differ diff --git a/controllerPackage/controller/controller.py b/controllerPackage/controller/controller.py index cf533c8ebcda39ff135f205cc24ca4418e9a0410..9a55122199222688b1c1be3ad6cc5d64dce32232 100644 --- a/controllerPackage/controller/controller.py +++ b/controllerPackage/controller/controller.py @@ -4,9 +4,16 @@ import json class Controller: - def __init__(self,code = 'a1b2c3'): + def __init__(self,code = 'a1b2c3',single_mobile = True): + # Room Code self.code = code + self.single_mobile = single_mobile + + if single_mobile: + self.mobile = Mobile('') + else: + self.mobiles = {} # Socket IO Communication Protocol Definition sio = socketio.Client() @@ -29,7 +36,7 @@ class Controller: @sio.event(namespace='/'+code) def multicast(data): - print('Multicast received!') + #print('Multicast received!') self.handle(data) @sio.on('my message',namespace='/'+code) @@ -37,10 +44,9 @@ class Controller: print('I received a message!') self.sio = sio - self.mobiles = {} # id:MOBILE + self.connect() def connect(self): - global code self.sio.connect('http://controller.viarezo.fr',namespaces=['/'+self.code]) self.sio.emit('code', {'code': self.code}) @@ -48,10 +54,13 @@ class Controller: self.sio.disconnect() def getMobile(self,id): - if id in self.mobiles: - return self.mobiles['id'] + if self.single_mobile: + return self.mobile else: - return self.create_mobile(id) + if id in self.mobiles: + return self.mobiles[id] + else: + return self.create_mobile(id) def handle(self,data): mobile = self.getMobile(data['id']) @@ -61,8 +70,10 @@ class Controller: return self.mobiles def create_mobile(self,id): - self.mobiles['id'] = Mobile(id) - return self.mobiles['id'] + self.mobiles[id] = Mobile(id) + print("New Mobile connected!") + return self.mobiles[id] + diff --git a/controllerPackage/controller/mobile.py b/controllerPackage/controller/mobile.py index ff39ff4a1c308fbf314fb7e3541ce6a9e4474d33..b3f85a261bb5948d51bc6e63c114694adf56bb13 100644 --- a/controllerPackage/controller/mobile.py +++ b/controllerPackage/controller/mobile.py @@ -3,13 +3,108 @@ class Mobile: def __init__(self,id,help=False): self.id = id self.help = help + self.gx, self.gy, self.gz = 0, 0, 0 + self.ax, self.ay, self.az = 0, 0 ,0 + self.angle = 0 def handle(self,data): - if not self.id == data['id']: - print('Its not my problem') - else: - print('ill handle it!') - print(data) + try: + evnType = data['evnType'] + + if evnType == 'Tap': + x = data['x'] + y = data['y'] + self.onTap(x,y) + + elif evnType == 'Long Press': + x = data['x'] + y = data['y'] + self.onLongPress(x,y) + + elif evnType == 'Rotation': + x = data['x'] + y = data['y'] + angle = data['angle'] + self.angle += angle + self.onRotation(x,y,angle) + + elif evnType == 'Pinch': + x = data['x'] + y = data['y'] + d = data['d'] + self.onPinch(x,y,d) + + elif evnType == 'Gyroscope': + gx = data['gx'] + gy = data['gy'] + gz = data['gz'] + self.setGyroscope(gx,gy,gz) + + elif evnType == 'Accelerometer': + ax = data['ax'] + ay = data['ay'] + az = data['az'] + self.setAccelerometer(ax,ay,az) + + elif evnType == 'Double Tap': + x = data['x'] + y = data['y'] + self.onDoubleTap(x,y) + + elif evnType == 'Flick': + x = data['x'] + y = data['y'] + px = data['px'] + py = data['py'] + v = data['v'] + self.onFlick(x,y,px,py,v) + + except BaseException as e: + print(data,e) + + def getGyroscope(self): + return self.gx, self.gy, self.gz + + def setGyroscope(self,gx,gy,gz): + self.gx, self.gy, self.gz = gx, gy, gz + + def getAccelerometer(self): + return self.ax, self.ay, self.az + + def setAccelerometer(self,ax,ay,az): + self.ax, self.ay, self.az = ax, ay, az + + def getAngle(self): + return self.angle + + def setAngle(self,angle): + self.angle = angle + + + def onTap(self,x,y): + if self.help: + print('[TAP DETECTED] You can overwrite onTap(x,y) to handle it.') + + def onDoubleTap(self,x,y): + if self.help: + print('[DOUBLE TAP DETECTED] You can overwrite onDoubleTap(x,y) to handle it.') + + def onFlick(self,x,y,px,py,v): + if self.help: + print('[FLICK DETECTED] You can overwrite onFlick(x,y,px,py,v) to handle it.') + + def onLongPress(self,x,y): + if self.help: + print('[LONGPRESS DETECTED] You can overwrite onLongPress(x,y) to handle it.') + + def onRotation(self,x,y,angle): + if self.help: + print('[ROTATION DETECTED] You can overwrite onRotation(x,y,angle) to handle it.') + + def onPinch(self,x,y,d): + if self.help: + print('[PINCH DETECTED] You can overwrite onPinch(x,y,d) to handle it.') + def on_left_swipe(self): if self.help: print('[LEFT SWIPE DETECTED] You can overwrite on_left_swipe to handle it.') diff --git a/controllerPackage/test.py b/controllerPackage/test.py index c7045e2516c61908a045e899288e77cce91c2c4e..c18a2bb814a025a270c15121f3f18aca1f8752a1 100644 --- a/controllerPackage/test.py +++ b/controllerPackage/test.py @@ -1,8 +1,10 @@ -from controller.controller import Controller -from time import sleep +from controller import Controller c = Controller('a1b2c3') -c.connect() -print('luckly..') + +while(True): + print(c.mobile.getAngle()) + + diff --git a/controllerSite/LICENSE b/controllerSite/LICENSE new file mode 100644 index 0000000000000000000000000000000000000000..335ea9d070ad1c319906aeff798584ded23c7387 --- /dev/null +++ b/controllerSite/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2018 The Python Packaging Authority + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/controllerSite/README.md b/controllerSite/README.md new file mode 100644 index 0000000000000000000000000000000000000000..3328c642479e9cb5b296288ef4707074cf2be14c --- /dev/null +++ b/controllerSite/README.md @@ -0,0 +1,4 @@ +# ControllerSite + +Controller is both an Android App and a Python Package that enables you to connect your Python Code to a so-called "Controller". +[Gitlab Viarezo](https://gitlab.viarezo.fr/2019hammoudf/controller) diff --git a/controllerSite/controller_site.egg-info/PKG-INFO b/controllerSite/controller_site.egg-info/PKG-INFO new file mode 100644 index 0000000000000000000000000000000000000000..fc3c69f3dcc28ba6971fb1f1cdb34658b41e841d --- /dev/null +++ b/controllerSite/controller_site.egg-info/PKG-INFO @@ -0,0 +1,19 @@ +Metadata-Version: 2.1 +Name: controller-site +Version: 0.0.1 +Summary: Enables connection to ControllerApp +Home-page: https://gitlab.viarezo.fr/2019hammoudf/controller +Author: Faruk Hammoud +Author-email: farukhammoud@student-cs.fr +License: UNKNOWN +Description: # ControllerSite + + Controller is both an Android App and a Python Package that enables you to connect your Python Code to a so-called "Controller". + [Gitlab Viarezo](https://gitlab.viarezo.fr/2019hammoudf/controller) + +Platform: UNKNOWN +Classifier: Programming Language :: Python :: 3 +Classifier: License :: OSI Approved :: MIT License +Classifier: Operating System :: OS Independent +Requires-Python: >=3.6 +Description-Content-Type: text/markdown diff --git a/controllerSite/controller_site.egg-info/SOURCES.txt b/controllerSite/controller_site.egg-info/SOURCES.txt new file mode 100644 index 0000000000000000000000000000000000000000..604c09344191e3f4e822aed4a1ab40275d1edd4d --- /dev/null +++ b/controllerSite/controller_site.egg-info/SOURCES.txt @@ -0,0 +1,6 @@ +README.md +setup.py +controller_site.egg-info/PKG-INFO +controller_site.egg-info/SOURCES.txt +controller_site.egg-info/dependency_links.txt +controller_site.egg-info/top_level.txt \ No newline at end of file diff --git a/controllerSite/controller_site.egg-info/dependency_links.txt b/controllerSite/controller_site.egg-info/dependency_links.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/controllerSite/controller_site.egg-info/dependency_links.txt @@ -0,0 +1 @@ + diff --git a/controllerSite/controller_site.egg-info/top_level.txt b/controllerSite/controller_site.egg-info/top_level.txt new file mode 100644 index 0000000000000000000000000000000000000000..8b137891791fe96927ad78e64b0aad7bded08bdc --- /dev/null +++ b/controllerSite/controller_site.egg-info/top_level.txt @@ -0,0 +1 @@ + diff --git a/controllerSite/dist/controller_site-0.0.1-py3-none-any.whl b/controllerSite/dist/controller_site-0.0.1-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..b94a69a5c783dcf3b8598e964c6c11bc29299392 Binary files /dev/null and b/controllerSite/dist/controller_site-0.0.1-py3-none-any.whl differ diff --git a/controllerSite/setup.py b/controllerSite/setup.py new file mode 100644 index 0000000000000000000000000000000000000000..5c612f934173d4a4cf24c94cf06e7bbbc49e191a --- /dev/null +++ b/controllerSite/setup.py @@ -0,0 +1,22 @@ +import setuptools + +with open("README.md", "r") as fh: + long_description = fh.read() + +setuptools.setup( + name="controller_site", + version="0.0.1", + author="Faruk Hammoud", + author_email="farukhammoud@student-cs.fr", + description="Enables connection to ControllerApp", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://gitlab.viarezo.fr/2019hammoudf/controller", + packages=setuptools.find_packages(), + classifiers=[ + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + ], + python_requires='>=3.6', +) \ No newline at end of file