Statistics
| Branch: | Revision:

gazetk / DesktopConnector / DeviceServer_MyGaze / DeviceServer_MyGaze.py @ 6b3a8f8f

History | View | Annotate | Download (4.148 KB)

1 908a231e Thies Pfeiffer
#
2
# DeviceServer_MyGaze.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
from myGazeAPI import  *                                    # myGaze library
24
25
from websocket import create_connection
26
ws = create_connection("ws://127.0.0.1:6777")
27
print "sending: Hi, this is the python server"
28
ws.send("TYPE:mygaze");
29
ws.send("Hi, this is the mygaze python server")
30
print "sent."
31
32
33
# ---------------------------------------------------------------------------- 
34
# ---- connect to myGazeAPI eyetracking-server 
35
# ---------------------------------------------------------------------------- 
36
37
res = myGazeAPI.iV_Connect()
38
if res != 1:
39
    print "Could not connect " + str(res) 
40
    exit(0)
41
42
        
43
# ---------------------------------------------------------------------------- 
44
# ---- read out system information 
45
# ---------------------------------------------------------------------------- 
46
47
res = myGazeAPI.iV_GetSystemInfo(byref(systemData))
48
print "myGaze eyetracking-server Version: " + str(systemData.iV_MajorVersion) + "." + str(systemData.iV_MinorVersion) + "." + str(systemData.iV_Buildnumber)
49
print "myGaze API Version: " + str(systemData.API_MajorVersion) + "." + str(systemData.API_MinorVersion) + "." + str(systemData.API_Buildnumber)
50
51
52
# ---------------------------------------------------------------------------- 
53
# ---- start the calibration and validation process 
54
# ---------------------------------------------------------------------------- 
55
56
# see the User Manual for detailed information due to setting up calibration 
57
calibrationData = CCalibration(5, 1, 0, 0, 1, 250, 220, 2, 20, b"")
58
res = myGazeAPI.iV_SetupCalibration(byref(calibrationData))
59
print "iV_SetupCalibration " + str(res)
60
61
# start the calibration process 
62
res = myGazeAPI.iV_Calibrate()
63
print "iV_Calibrate " + str(res)
64
65
# start the validation process 
66
res = myGazeAPI.iV_Validate()
67
print "iV_Validate " + str(res)
68
69
# read out the accuracy values 
70
res = myGazeAPI.iV_GetAccuracy(byref(accuracyData))
71
print "iV_GetAccuracy " + str(res)
72
print "accuracy left X: " + str(accuracyData.deviationLX) + " left Y: " + str(accuracyData.deviationLY)
73
print "accuracy right X: " + str(accuracyData.deviationRX) + " left Y: " + str(accuracyData.deviationRY)
74
75
# show tracking monitor 
76
res = myGazeAPI.iV_ShowTrackingMonitor()
77
print "iV_ShowTrackingMonitor " + str(res)
78
79
80
# ---------------------------------------------------------------------------- 
81
# ---- accessing eye tracking data stream 
82
# ---------------------------------------------------------------------------- 
83
84
# output samples
85
a = 0;
86
while a < 1000:
87
88
    # get gaze data sample
89
    res = myGazeAPI.iV_GetSample(byref(sampleData))
90
    if res == 1:
91
       # a = a + 1
92
        #print "Gaze Data - GazeX: " + str(sampleData.leftEye.gazeX) + " GazeY: " + str(sampleData.leftEye.gazeY) 
93
        ws.send("{\"x\":"+str(sampleData.leftEye.gazeX)+",\"y\":"+str(sampleData.leftEye.gazeY)+"}")
94
        #ws.send("{\"x\":"+str(sampleData.rightEye.gazeX)+",\"y\":"+str(sampleData.rightEye.gazeY)+"}")
95
    # get gaze data sample
96
    res = myGazeAPI.iV_GetEvent(byref(eventData))
97
    #if res == 1:
98
        #print "Fixation " + str(eventData.eye) + " - X: " + str(eventData.positionX) + " Y: " + str(eventData.positionY) 
99
100
                
101
# ---------------------------------------------------------------------------- 
102
# ---- disconnect from myGaze eyetracking server 
103
# ---------------------------------------------------------------------------- 
104
105
res = myGazeAPI.iV_Disconnect()
106
ws.close()
107
#end of the trial 
108
#window.close()
109
#core.quit()
110