gazetk / DesktopConnector / DeviceServer_SMI_REDm / DeviceServer_REDm.py @ 6b3a8f8f
History | View | Annotate | Download (4.079 KB)
1 |
#
|
---|---|
2 |
# DeviceServer_REDm.py
|
3 |
#
|
4 |
# This file is part of GazeTk.
|
5 |
#
|
6 |
# Copyright 2015 Thies Pfeiffer and Dimitri Heil
|
7 |
# GazeTk is distributed under the terms of the GNU General Public License
|
8 |
#
|
9 |
# GazeTk is free software: you can redistribute it and/or modify
|
10 |
# it under the terms of the GNU General Public License as published by
|
11 |
# the Free Software Foundation, either version 3 of the License, or
|
12 |
# (at your option) any later version.
|
13 |
#
|
14 |
# GazeTk is distributed in the hope that it will be useful,
|
15 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
16 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
17 |
# GNU General Public License for more details.
|
18 |
#
|
19 |
# You should have received a copy of the GNU General Public License
|
20 |
# along with GazeTk. If not, see <http://www.gnu.org/licenses/>.
|
21 |
#
|
22 |
|
23 |
#!/usr/bin/env python
|
24 |
# -*- coding: utf-8 -*-
|
25 |
|
26 |
from iViewXAPI import * #iViewX library |
27 |
from iViewXAPIReturnCodes import * |
28 |
from websocket import create_connection |
29 |
ws = create_connection("ws://127.0.0.1:6777")
|
30 |
print "sending: Hi, this is the python server" |
31 |
ws.send("TYPE:smi");
|
32 |
ws.send("Hi, this is the python server")
|
33 |
print "sent." |
34 |
|
35 |
|
36 |
|
37 |
|
38 |
# ---------------------------------------------
|
39 |
#---- connect to iViewX
|
40 |
# ---------------------------------------------
|
41 |
|
42 |
res = iViewXAPI.iV_SetLogger(c_int(1), c_char_p("iViewXSDK_Python_SimpleExperiment.txt")) |
43 |
res = iViewXAPI.iV_Connect(c_char_p('127.0.0.1'), c_int(4444), c_char_p('127.0.0.1'), c_int(5555)) |
44 |
if res != 1: |
45 |
HandleError(res) |
46 |
exit(0) |
47 |
|
48 |
res = iViewXAPI.iV_GetSystemInfo(byref(systemData)) |
49 |
print "iV_GetSystemInfo: " + str(res) |
50 |
print "Samplerate: " + str(systemData.samplerate) |
51 |
print "iViewX Version: " + str(systemData.iV_MajorVersion) + "." + str(systemData.iV_MinorVersion) + "." + str(systemData.iV_Buildnumber) |
52 |
print "iViewX API Version: " + str(systemData.API_MajorVersion) + "." + str(systemData.API_MinorVersion) + "." + str(systemData.API_Buildnumber) |
53 |
|
54 |
|
55 |
# ---------------------------------------------
|
56 |
#---- configure and start calibration
|
57 |
# ---------------------------------------------
|
58 |
|
59 |
calibrationData = CCalibration(5, 1, 0, 0, 1, 250, 220, 2, 20, b"") |
60 |
|
61 |
res = iViewXAPI.iV_SetupCalibration(byref(calibrationData)) |
62 |
print "iV_SetupCalibration " + str(res) |
63 |
|
64 |
res = iViewXAPI.iV_Calibrate() |
65 |
print "iV_Calibrate " + str(res) |
66 |
|
67 |
res = iViewXAPI.iV_Validate() |
68 |
print "iV_Validate " + str(res) |
69 |
res = iViewXAPI.iV_GetAccuracy(byref(accuracyData), 0)
|
70 |
print "iV_GetAccuracy " + str(res) |
71 |
print "deviationXLeft " + str(accuracyData.deviationLX) + " deviationYLeft " + str(accuracyData.deviationLY) |
72 |
print "deviationXRight " + str(accuracyData.deviationRX) + " deviationYRight " + str(accuracyData.deviationRY) |
73 |
|
74 |
|
75 |
# ---------------------------------------------
|
76 |
#---- define the callback functions
|
77 |
# ---------------------------------------------
|
78 |
|
79 |
def SampleCallback(sample): |
80 |
print " Gaze Data - Timestamp " + str(sample.timestamp) + " Gaze " + str(sample.leftEye.gazeX) + " " + str(sample.leftEye.gazeY) + "\n" |
81 |
print "{\"x\":" + str(sample.leftEye.gazeX) + ",\"y\":" + str(sample.leftEye.gazeY) + "}" |
82 |
ws.send("{\"x\":"+str(sample.leftEye.gazeX)+",\"y\":"+str(sample.leftEye.gazeY)+"}") |
83 |
#ws.send("hi..")
|
84 |
return 0 |
85 |
|
86 |
def EventCallback(event): |
87 |
print " Event: " + str(event.positionX) + " " + str(event.positionY) + "\n" |
88 |
return 0 |
89 |
|
90 |
|
91 |
CMPFUNC = WINFUNCTYPE(c_int, CSample) |
92 |
smp_func = CMPFUNC(SampleCallback) |
93 |
sampleCB = False
|
94 |
|
95 |
CMPFUNC = WINFUNCTYPE(c_int, CEvent) |
96 |
event_func = CMPFUNC(EventCallback) |
97 |
eventCB = False
|
98 |
|
99 |
|
100 |
# ---------------------------------------------
|
101 |
#---- start DataStreaming
|
102 |
# ---------------------------------------------
|
103 |
command = 0
|
104 |
|
105 |
while (command != 'q'): |
106 |
command = raw_input("waiting for input - press 's' and 'Enter' to start DataStreaming \n\ |
107 |
- press 'q' and 'Enter' to quit DataStreaming \n")
|
108 |
|
109 |
if (command == 's'): |
110 |
res = iViewXAPI.iV_SetSampleCallback(smp_func) |
111 |
sampleCB = True
|
112 |
res = iViewXAPI.iV_SetEventCallback(event_func) |
113 |
eventCB = True
|
114 |
|
115 |
|
116 |
# ---------------------------------------------
|
117 |
#---- stop recording and disconnect from iViewX
|
118 |
# ---------------------------------------------
|
119 |
|
120 |
res = iViewXAPI.iV_Disconnect() |
121 |
ws.close() |