Revision b8e587a8

View differences:

DesktopConnector/DesktopConnector.js
1
/*
2
 * Copyright 2015 Thies Pfeiffer and Dimitri Heil
3
 * GazeTk is distributed under the terms of the GNU General Public License
4
 * 
5
 * This file is part of GazeTk.
6
 * 
7
 * GazeTk is free software: you can redistribute it and/or modify
8
 * it under the terms of the GNU General Public License as published by
9
 * the Free Software Foundation, either version 3 of the License, or
10
 * (at your option) any later version.
11
 * 
12
 * GazeTk is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
 * GNU General Public License for more details.
16
 * 
17
 * You should have received a copy of the GNU General Public License
18
 * along with GazeTk. If not, see <http://www.gnu.org/licenses/>.
19
 */
20
 
21

  
1 22
var net = require('net');
2 23
var ws = require("nodejs-websocket");
3 24

  
DesktopConnector/DeviceServer_SMI_REDm/DeviceServer_REDm.py
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()
DesktopConnector/DeviceServer_SMI_REDm/README.md
1
DeviceServer_REDm
2
=================
3

  
4
[Download](https://opensource.cit-ec.de/projects/gazetk/repository/gazetk)
5

  
6
License
7
-------
8
DeviceServer_REDm is free and open source software distributed under the terms of the [GNU General Public License](http://www.gnu.org/licenses/).
9

  
10
Description
11
-----------
12
Welcome to DeviceServer_REDm!
13

  
14
This python-based server connects your SMI REDm eye tracking device with the GazeTk DesktopConnector. 
15

  
16
Requirements
17
------------
18
- Python 2.7 32bit
19
- Python module websocket
20

  
21
Installation
22
------------
23
1. Install Python 2.7 32bit
24
2. Install websocket-client by running the following script from PYTHONDIR/Scripts:
25

  
26
$ pip install websocket-client
27

  
28
Starting DeviceServer_REDm
29
--------------------------
30
1. Start the REDm application provided with the device.
31
2. Make sure you have the iViewXAPI.dlls on your PATH, they come with the REDm installation package.
32
3. Start the DeviceServer_REDm:
33

  
34
$ python DeviceServer_REDm.py
35

  
36

  
DesktopConnector/DeviceServer_SMI_REDm/iViewXAPI.py
1
# -----------------------------------------------------------------------
2
#
3
# (c) Copyright 1997-2013, SensoMotoric Instruments GmbH
4
# 
5
# Permission  is  hereby granted,  free  of  charge,  to any  person  or
6
# organization  obtaining  a  copy  of  the  software  and  accompanying
7
# documentation  covered  by  this  license  (the  "Software")  to  use,
8
# reproduce,  display, distribute, execute,  and transmit  the Software,
9
# and  to  prepare derivative  works  of  the  Software, and  to  permit
10
# third-parties to whom the Software  is furnished to do so, all subject
11
# to the following:
12
# 
13
# The  copyright notices  in  the Software  and  this entire  statement,
14
# including the above license  grant, this restriction and the following
15
# disclaimer, must be  included in all copies of  the Software, in whole
16
# or  in part, and  all derivative  works of  the Software,  unless such
17
# copies   or   derivative   works   are   solely   in   the   form   of
18
# machine-executable  object   code  generated  by   a  source  language
19
# processor.
20
# 
21
# THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
22
# EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
23
# MERCHANTABILITY,   FITNESS  FOR  A   PARTICULAR  PURPOSE,   TITLE  AND
24
# NON-INFRINGEMENT. IN  NO EVENT SHALL  THE COPYRIGHT HOLDERS  OR ANYONE
25
# DISTRIBUTING  THE  SOFTWARE  BE   LIABLE  FOR  ANY  DAMAGES  OR  OTHER
26
# LIABILITY, WHETHER  IN CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT
27
# OF OR IN CONNECTION WITH THE  SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
# THE SOFTWARE.
29
#
30
# -----------------------------------------------------------------------
31
# iViewXAPI.py
32
#
33
# Demonstrates features of iView API 
34
# Defines structures 
35
# Loads in iViewXAPI.dll
36
# This script shows how to set up an experiment with Python 2.7.1 (with ctypes Library) 
37

  
38

  
39
from ctypes import *
40

  
41

  
42
#===========================
43
#		Struct Definition
44
#===========================
45

  
46
class CSystem(Structure):
47
	_fields_ = [("samplerate", c_int),
48
	("iV_MajorVersion", c_int),
49
	("iV_MinorVersion", c_int),
50
	("iV_Buildnumber", c_int),
51
	("API_MajorVersion", c_int),
52
	("API_MinorVersion", c_int),
53
	("API_Buildnumber", c_int),
54
	("iV_ETDevice", c_int)]
55

  
56
class CCalibration(Structure):
57
	_fields_ = [("method", c_int),
58
	("visualization", c_int),
59
	("displayDevice", c_int),
60
	("speed", c_int),
61
	("autoAccept", c_int),
62
	("foregroundBrightness", c_int),
63
	("backgroundBrightness", c_int),
64
	("targetShape", c_int),
65
	("targetSize", c_int),
66
	("targetFilename", c_char * 256)]
67

  
68
class CEye(Structure):
69
	_fields_ = [("gazeX", c_double),
70
	("gazeY", c_double),
71
	("diam", c_double),
72
	("eyePositionX", c_double),
73
	("eyePositionY", c_double),
74
	("eyePositionZ", c_double)]
75

  
76
class CSample(Structure):
77
	_fields_ = [("timestamp", c_longlong),
78
	("leftEye", CEye),
79
	("rightEye", CEye),
80
	("planeNumber", c_int)]
81

  
82
class CEvent(Structure):
83
	_fields_ = [("eventType", c_char),
84
	("eye", c_char),
85
	("startTime", c_longlong),
86
	("endTime", c_longlong),
87
	("duration", c_longlong),
88
	("positionX", c_double),
89
	("positionY", c_double)]
90

  
91
class CAccuracy(Structure):
92
	_fields_ = [("deviationLX",c_double),
93
				("deviationLY",c_double),				
94
				("deviationRX",c_double),
95
				("deviationRY",c_double)]
96
				
97
				
98
#===========================
99
#		Loading iViewX.dll 
100
#===========================
101

  
102
iViewXAPI = windll.LoadLibrary("iViewXAPI.dll")
103

  
104

  
105
#===========================
106
#		Initializing Structs
107
#===========================
108

  
109
systemData = CSystem(0, 0, 0, 0, 0, 0, 0, 0)
110
calibrationData = CCalibration(5, 1, 0, 0, 1, 20, 239, 1, 15, b"")
111
leftEye = CEye(0,0,0)
112
rightEye = CEye(0,0,0)
113
sampleData = CSample(0,leftEye,rightEye,0)
114
eventData = CEvent('F', 'L', 0, 0, 0, 0, 0)
115
accuracyData = CAccuracy(0,0,0,0)
116

  
117

  
DesktopConnector/DeviceServer_SMI_REDm/iViewXAPIReturnCodes.py
1
# -----------------------------------------------------------------------
2
#
3
# (c) Copyright 1997-2013, SensoMotoric Instruments GmbH
4
# 
5
# Permission  is  hereby granted,  free  of  charge,  to any  person  or
6
# organization  obtaining  a  copy  of  the  software  and  accompanying
7
# documentation  covered  by  this  license  (the  "Software")  to  use,
8
# reproduce,  display, distribute, execute,  and transmit  the Software,
9
# and  to  prepare derivative  works  of  the  Software, and  to  permit
10
# third-parties to whom the Software  is furnished to do so, all subject
11
# to the following:
12
# 
13
# The  copyright notices  in  the Software  and  this entire  statement,
14
# including the above license  grant, this restriction and the following
15
# disclaimer, must be  included in all copies of  the Software, in whole
16
# or  in part, and  all derivative  works of  the Software,  unless such
17
# copies   or   derivative   works   are   solely   in   the   form   of
18
# machine-executable  object   code  generated  by   a  source  language
19
# processor.
20
# 
21
# THE  SOFTWARE IS  PROVIDED  "AS  IS", WITHOUT  WARRANTY  OF ANY  KIND,
22
# EXPRESS OR  IMPLIED, INCLUDING  BUT NOT LIMITED  TO THE  WARRANTIES OF
23
# MERCHANTABILITY,   FITNESS  FOR  A   PARTICULAR  PURPOSE,   TITLE  AND
24
# NON-INFRINGEMENT. IN  NO EVENT SHALL  THE COPYRIGHT HOLDERS  OR ANYONE
25
# DISTRIBUTING  THE  SOFTWARE  BE   LIABLE  FOR  ANY  DAMAGES  OR  OTHER
26
# LIABILITY, WHETHER  IN CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT
27
# OF OR IN CONNECTION WITH THE  SOFTWARE OR THE USE OR OTHER DEALINGS IN
28
# THE SOFTWARE.
29
#
30
# -----------------------------------------------------------------------
31

  
32
def HandleError(ret):
33
    if ret == 104:
34
         print "Could not establish connection. Check if Eye Tracker is running."
35
    elif ret == 105:
36
         print "Could not establish connection. Check the communication Ports."
37
    elif ret == 123:
38
         print "Could not establish connection. Another Process is blocking the communication Ports."
39
    elif ret == 201:
40
         print "Could not establish connection. Check if Eye Tracker is installed and running."
41
    else:
42
        print "Return Code is " + ret + ". Refer to the iView X SDK Manual for its meaning."
43
	return
DesktopConnector/DeviceServer_SMI_REDm/startDeviceServer_REDm.bat
1
python DeviceServer_REDm.py
2
pause

Also available in: Unified diff