diff --git a/controllerPackage/build/lib/controller/__init__.py b/controllerPackage/build/lib/controller/__init__.py index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..88ecaddf5b64e9176d0478df247565b08f8e3f19 100644 --- a/controllerPackage/build/lib/controller/__init__.py +++ b/controllerPackage/build/lib/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/build/lib/controller/controller.py b/controllerPackage/build/lib/controller/controller.py new file mode 100644 index 0000000000000000000000000000000000000000..9a55122199222688b1c1be3ad6cc5d64dce32232 --- /dev/null +++ b/controllerPackage/build/lib/controller/controller.py @@ -0,0 +1,81 @@ +import socketio +from controller.mobile import Mobile +import json + +class Controller: + + 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() + + @sio.event + def connect(): + print("I'm connected!") + + @sio.event + def connect_error(): + print("The connection failed!") + + @sio.event + def disconnect(): + print("I'm disconnected!") + + @sio.event(namespace='/'+code) + def message(data): + print('I received a message!') + + @sio.event(namespace='/'+code) + def multicast(data): + #print('Multicast received!') + self.handle(data) + + @sio.on('my message',namespace='/'+code) + def on_message(data): + print('I received a message!') + + self.sio = sio + self.connect() + + def connect(self): + self.sio.connect('http://controller.viarezo.fr',namespaces=['/'+self.code]) + self.sio.emit('code', {'code': self.code}) + + def disconnect(self): + self.sio.disconnect() + + def getMobile(self,id): + if self.single_mobile: + return self.mobile + else: + if id in self.mobiles: + return self.mobiles[id] + else: + return self.create_mobile(id) + + def handle(self,data): + mobile = self.getMobile(data['id']) + mobile.handle(data) + + def getMobiles(self): + return self.mobiles + + def create_mobile(self,id): + self.mobiles[id] = Mobile(id) + print("New Mobile connected!") + return self.mobiles[id] + + + + + + diff --git a/controllerPackage/build/lib/controller/mobile.py b/controllerPackage/build/lib/controller/mobile.py new file mode 100644 index 0000000000000000000000000000000000000000..b3f85a261bb5948d51bc6e63c114694adf56bb13 --- /dev/null +++ b/controllerPackage/build/lib/controller/mobile.py @@ -0,0 +1,123 @@ +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): + 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.') + + def on_right_swipe(self): + if self.help: + print('[RIGHT SWIPE DETECTED] You can overwrite on_right_swipe to handle it.') + + def on_up_swipe(self): + if self.help: + print('[UP SWIPE DETECTED] You can overwrite on_up_swipe to handle it.') + + def on_down_swipe(self): + if self.help: + print('[DOWN SWIPE DETECTED] You can overwrite on_down_swipe to handle it.') + \ No newline at end of file diff --git a/controllerPackage/controller.egg-info/PKG-INFO b/controllerPackage/controller.egg-info/PKG-INFO index 65490206a585c76689a3de7bdcc84830a44facd7..958904c2d2deb62c516c2cd7ca4f82ae5ebaa2b7 100644 --- a/controllerPackage/controller.egg-info/PKG-INFO +++ b/controllerPackage/controller.egg-info/PKG-INFO @@ -1,6 +1,6 @@ Metadata-Version: 2.1 Name: controller -Version: 0.0.1 +Version: 0.0.2 Summary: Enables connection to ControllerApp Home-page: https://gitlab.viarezo.fr/2019hammoudf/controller Author: Faruk Hammoud diff --git a/controllerPackage/controller.egg-info/SOURCES.txt b/controllerPackage/controller.egg-info/SOURCES.txt index c481a408d79e664c594d0de2b2bdcdac9a18664d..38ed9585a390d36d19cf6ab5b720a4d85062d517 100644 --- a/controllerPackage/controller.egg-info/SOURCES.txt +++ b/controllerPackage/controller.egg-info/SOURCES.txt @@ -1,6 +1,8 @@ README.md setup.py controller/__init__.py +controller/controller.py +controller/mobile.py controller.egg-info/PKG-INFO controller.egg-info/SOURCES.txt controller.egg-info/dependency_links.txt diff --git a/controllerPackage/dist/controller-0.0.2-py3-none-any.whl b/controllerPackage/dist/controller-0.0.2-py3-none-any.whl new file mode 100644 index 0000000000000000000000000000000000000000..60573c94d441b1c6fc2bb358ba8e65d954035d5b Binary files /dev/null and b/controllerPackage/dist/controller-0.0.2-py3-none-any.whl differ diff --git a/controllerPackage/setup.py b/controllerPackage/setup.py index 073bbdb500a8e014c59210ea0710110db61d4852..ffad5b038f4a89d5b597d23319a0fd542d355be8 100644 --- a/controllerPackage/setup.py +++ b/controllerPackage/setup.py @@ -5,7 +5,7 @@ with open("README.md", "r") as fh: setuptools.setup( name="controller", - version="0.0.1", + version="0.0.2", author="Faruk Hammoud", author_email="farukhammoud@student-cs.fr", description="Enables connection to ControllerApp", diff --git a/controllerSite/LICENSE b/controllerSite/LICENSE deleted file mode 100644 index 335ea9d070ad1c319906aeff798584ded23c7387..0000000000000000000000000000000000000000 --- a/controllerSite/LICENSE +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 3328c642479e9cb5b296288ef4707074cf2be14c..0000000000000000000000000000000000000000 --- a/controllerSite/README.md +++ /dev/null @@ -1,4 +0,0 @@ -# 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/__init__.py b/controllerSite/__init__.py new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/controllerSite/controllerSite.py b/controllerSite/controllerSite.py index f72720133c80ac0d336facdb1f78ee55c3f2de6f..a54f101d5d879d6fad1a73ae9abbc9067046626a 100644 --- a/controllerSite/controllerSite.py +++ b/controllerSite/controllerSite.py @@ -1,40 +1,25 @@ -import os -from flask import Flask, flash, request, jsonify, redirect, url_for, render_template +from flask import Flask, request, jsonify, render_template from flask_socketio import SocketIO, emit from flask_bootstrap import Bootstrap -from werkzeug.utils import secure_filename app = Flask(__name__) -socketio = SocketIO(app) -clients = {} - -queue = [] - app.secret_key = 'super secret key' -app.config['UPLOAD_FOLDER'] = 'upload' -ALLOWED_EXTENSIONS = {'txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'} +socketio = SocketIO(app) Bootstrap(app) -def remove_id(id): - queue.remove(id) - @app.route('/') def index(): return render_template('index.html') -def allowed_file(filename): - return '.' in filename and \ - filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS - @app.route('/multicast/<string:code>', methods=['GET', 'POST']) def multicast(code): if request.method == 'POST': content = request.json if not 'id' in content: - print('[PROBLEM]',content) + #print('[PROBLEM]',content) return jsonify({}) else: - print(code,content['id']) + #print(code,content['id']) with app.app_context(): socketio.emit('multicast', request.get_json(), broadcast = True,namespace='/'+code) return jsonify({"code":code,"id":content['id']}) @@ -42,12 +27,9 @@ def multicast(code): <!doctype html> <title>Use a HTTP POST Request</title> ''' -def confirmReception(): - print('Message Received.') @socketio.on('code') def handle_code(json, methods=['GET', 'POST']): - print('code received: ' + str(json)) socketio.emit('message', json,namespace='/a1b2c3') if __name__ == '__main__': diff --git a/controllerSite/controller_site.egg-info/PKG-INFO b/controllerSite/controller_site.egg-info/PKG-INFO deleted file mode 100644 index fc3c69f3dcc28ba6971fb1f1cdb34658b41e841d..0000000000000000000000000000000000000000 --- a/controllerSite/controller_site.egg-info/PKG-INFO +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 604c09344191e3f4e822aed4a1ab40275d1edd4d..0000000000000000000000000000000000000000 --- a/controllerSite/controller_site.egg-info/SOURCES.txt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/controllerSite/controller_site.egg-info/dependency_links.txt +++ /dev/null @@ -1 +0,0 @@ - diff --git a/controllerSite/controller_site.egg-info/top_level.txt b/controllerSite/controller_site.egg-info/top_level.txt deleted file mode 100644 index 8b137891791fe96927ad78e64b0aad7bded08bdc..0000000000000000000000000000000000000000 --- a/controllerSite/controller_site.egg-info/top_level.txt +++ /dev/null @@ -1 +0,0 @@ - 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 deleted file mode 100644 index b94a69a5c783dcf3b8598e964c6c11bc29299392..0000000000000000000000000000000000000000 Binary files a/controllerSite/dist/controller_site-0.0.1-py3-none-any.whl and /dev/null differ diff --git a/controllerSite/setup.py b/controllerSite/setup.py deleted file mode 100644 index 5c612f934173d4a4cf24c94cf06e7bbbc49e191a..0000000000000000000000000000000000000000 --- a/controllerSite/setup.py +++ /dev/null @@ -1,22 +0,0 @@ -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