Skip to content
Snippets Groups Projects
Commit d36c6b22 authored by Faruk Hammoud's avatar Faruk Hammoud
Browse files

whl

parent 33dc4f36
Branches
No related tags found
No related merge requests found
Showing
with 211 additions and 27 deletions
......@@ -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);
......
from controller.controller import Controller as Controller_
def Controller(*args):
c = Controller_()
return c
\ No newline at end of file
No preview for this file type
No preview for this file type
No preview for this file type
......@@ -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,8 +54,11 @@ class Controller:
self.sio.disconnect()
def getMobile(self,id):
if self.single_mobile:
return self.mobile
else:
if id in self.mobiles:
return self.mobiles['id']
return self.mobiles[id]
else:
return self.create_mobile(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]
......
......@@ -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.')
......
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())
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
# 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)
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
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
File added
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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment