Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
multitouch
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Taddeüs Kroes
multitouch
Commits
5d2ed4f0
Commit
5d2ed4f0
authored
Apr 24, 2012
by
Admin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added TUIO server class.
parent
7f609252
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
90 additions
and
0 deletions
+90
-0
src/tuio_server.py
src/tuio_server.py
+90
-0
No files found.
src/tuio_server.py
0 → 100755
View file @
5d2ed4f0
#!/usr/bin/env python
from
OSC
import
OSCServer
from
logger
import
Logger
class
TuioServer2D
(
Logger
):
_tuio_address
=
(
'localhost'
,
3333
)
def
__init__
(
self
,
handler_obj
,
**
kwargs
):
super
(
TuioServer2D
,
self
).
__init__
(
**
kwargs
)
for
handler
in
(
'point_down'
,
'point_up'
,
'point_move'
):
if
not
hasattr
(
handler_obj
,
handler
):
raise
RuntimeError
(
'Handler "%s" is not defined.'
%
handler
)
# OSC server that listens to incoming TUIO events
self
.
server
=
OSCServer
(
self
.
__class__
.
_tuio_address
)
#self.server.addDefaultHandlers()
self
.
server
.
addMsgHandler
(
'/tuio/2Dobj'
,
self
.
_receive
)
self
.
server
.
addMsgHandler
(
'/tuio/2Dcur'
,
self
.
_receive
)
self
.
server
.
addMsgHandler
(
'/tuio/2Dblb'
,
self
.
_receive
)
# List of alive seddion id's
self
.
alive
=
set
()
# List of session id's of points that have generated a 'point_down'
# event
self
.
down
=
set
()
self
.
handler_obj
=
handler_obj
def
_receive
(
self
,
addr
,
tags
,
data
,
source
):
surface
=
addr
[
8
:]
self
.
log
(
'Received message <surface=%s tags="%s" data=%s source=%s>'
\
%
(
surface
,
tags
,
data
,
source
),
2
)
msg_type
=
data
[
0
]
if
msg_type
==
'alive'
:
alive
=
set
(
data
[
1
:])
released
=
self
.
alive
-
alive
self
.
alive
=
alive
self
.
down
-=
released
self
.
down
-=
released
if
released
:
self
.
log
(
'Released %s.'
%
', '
.
join
(
map
(
str
,
released
)),
2
)
for
sid
in
released
:
self
.
handler_obj
.
point_up
(
sid
)
elif
msg_type
==
'set'
:
sid
,
x
,
y
=
data
[
1
:
4
]
if
sid
not
in
self
.
alive
:
raise
ValueError
(
'Point with sid "%d" is not alive.'
%
sid
)
# Check if 'point_down' has already been triggered. If so, trigger
# a 'point_move' event instead
if
sid
in
self
.
down
:
self
.
log
(
'Moved %d to (%s, %s).'
%
(
sid
,
x
,
y
),
2
)
self
.
handler_obj
.
point_move
(
sid
,
x
,
y
)
else
:
self
.
log
(
'Down %d at (%s, %s).'
%
(
sid
,
x
,
y
),
2
)
self
.
handler_obj
.
point_down
(
sid
,
x
,
y
)
self
.
down
.
add
(
sid
)
def
start
(
self
):
self
.
log
(
'Starting OSC server'
)
self
.
server
.
serve_forever
()
def
stop
(
self
):
self
.
log
(
'Stopping OSC server'
)
self
.
server
.
close
()
if
__name__
==
'__main__'
:
import
sys
class
Handler
(
Logger
):
def
point_down
(
self
,
sid
,
x
,
y
):
self
.
log
(
'Point down: sid=%d (%s, %s)'
%
(
sid
,
x
,
y
))
def
point_up
(
self
,
sid
):
self
.
log
(
'Point up: sid=%d'
%
sid
)
def
point_move
(
self
,
sid
,
x
,
y
):
self
.
log
(
'Point move: sid=%d (%s, %s)'
%
(
sid
,
x
,
y
))
v
=
1
if
len
(
sys
.
argv
)
<
2
else
int
(
sys
.
argv
[
1
])
server
=
TuioServer2D
(
Handler
(
verbose
=
v
),
verbose
=
v
)
server
.
start
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment