commit b8e587a8cbde8b6f9610add121c96a4981db2f00
Author: Thies Pfeiffer <thies.pfeiffer@uni-bielefeld.de>
Date:   Wed Jul 15 10:36:48 2015 +0200

    Added the device server for the SMI REDm systems

diff --git a/DesktopConnector/DesktopConnector.js b/DesktopConnector/DesktopConnector.js
index 6d39b5c..d1085ee 100644
--- a/DesktopConnector/DesktopConnector.js
+++ b/DesktopConnector/DesktopConnector.js
@@ -1,3 +1,24 @@
+/*
+ * Copyright 2015 Thies Pfeiffer and Dimitri Heil
+ * GazeTk is distributed under the terms of the GNU General Public License
+ * 
+ * This file is part of GazeTk.
+ * 
+ * GazeTk is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ * 
+ * GazeTk is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ * 
+ * You should have received a copy of the GNU General Public License
+ * along with GazeTk. If not, see <http://www.gnu.org/licenses/>.
+ */
+ 
+
 var net = require('net');
 var ws = require("nodejs-websocket");
 
diff --git a/DesktopConnector/DeviceServer_SMI_REDm/DeviceServer_REDm.py b/DesktopConnector/DeviceServer_SMI_REDm/DeviceServer_REDm.py
new file mode 100644
index 0000000..008162e
--- /dev/null
+++ b/DesktopConnector/DeviceServer_SMI_REDm/DeviceServer_REDm.py
@@ -0,0 +1,121 @@
+#
+# DeviceServer_REDm.py
+# 
+# This file is part of GazeTk.
+#
+# Copyright 2015 Thies Pfeiffer and Dimitri Heil
+# GazeTk is distributed under the terms of the GNU General Public License
+# 
+# GazeTk is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+# 
+# GazeTk is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with GazeTk. If not, see <http://www.gnu.org/licenses/>.
+#
+
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+from iViewXAPI import  *            #iViewX library
+from iViewXAPIReturnCodes import * 
+from websocket import create_connection
+ws = create_connection("ws://127.0.0.1:6777")
+print "sending: Hi, this is the python server"
+ws.send("TYPE:smi");
+ws.send("Hi, this is the python server")
+print "sent."
+
+
+
+
+# ---------------------------------------------
+#---- connect to iViewX
+# ---------------------------------------------
+
+res = iViewXAPI.iV_SetLogger(c_int(1), c_char_p("iViewXSDK_Python_SimpleExperiment.txt"))
+res = iViewXAPI.iV_Connect(c_char_p('127.0.0.1'), c_int(4444), c_char_p('127.0.0.1'), c_int(5555))
+if res != 1:
+    HandleError(res)
+    exit(0)
+
+res = iViewXAPI.iV_GetSystemInfo(byref(systemData))
+print "iV_GetSystemInfo: " + str(res)
+print "Samplerate: " + str(systemData.samplerate)
+print "iViewX Version: " + str(systemData.iV_MajorVersion) + "." + str(systemData.iV_MinorVersion) + "." + str(systemData.iV_Buildnumber)
+print "iViewX API Version: " + str(systemData.API_MajorVersion) + "." + str(systemData.API_MinorVersion) + "." + str(systemData.API_Buildnumber)
+
+
+# ---------------------------------------------
+#---- configure and start calibration
+# ---------------------------------------------
+
+calibrationData = CCalibration(5, 1, 0, 0, 1, 250, 220, 2, 20, b"")
+
+res = iViewXAPI.iV_SetupCalibration(byref(calibrationData))
+print "iV_SetupCalibration " + str(res)
+
+res = iViewXAPI.iV_Calibrate()
+print "iV_Calibrate " + str(res)
+
+res = iViewXAPI.iV_Validate()
+print "iV_Validate " + str(res)
+res = iViewXAPI.iV_GetAccuracy(byref(accuracyData), 0)
+print "iV_GetAccuracy " + str(res)
+print "deviationXLeft " + str(accuracyData.deviationLX) + " deviationYLeft " + str(accuracyData.deviationLY)
+print "deviationXRight " + str(accuracyData.deviationRX) + " deviationYRight " + str(accuracyData.deviationRY)
+
+
+# ---------------------------------------------
+#---- define the callback functions
+# ---------------------------------------------
+
+def SampleCallback(sample):
+    print " Gaze Data - Timestamp " + str(sample.timestamp) + " Gaze " + str(sample.leftEye.gazeX) + " " + str(sample.leftEye.gazeY) + "\n"
+    print "{\"x\":" + str(sample.leftEye.gazeX) + ",\"y\":" + str(sample.leftEye.gazeY) + "}"
+    ws.send("{\"x\":"+str(sample.leftEye.gazeX)+",\"y\":"+str(sample.leftEye.gazeY)+"}")
+    #ws.send("hi..")
+    return 0
+
+def EventCallback(event):
+    print " Event: " + str(event.positionX) + " " + str(event.positionY) + "\n"
+    return 0
+
+
+CMPFUNC = WINFUNCTYPE(c_int, CSample)
+smp_func = CMPFUNC(SampleCallback)
+sampleCB = False
+
+CMPFUNC = WINFUNCTYPE(c_int, CEvent)
+event_func = CMPFUNC(EventCallback)
+eventCB = False
+
+
+# ---------------------------------------------
+#---- start DataStreaming
+# ---------------------------------------------
+command = 0
+
+while (command != 'q'):
+    command = raw_input("waiting for input - press 's' and 'Enter' to start DataStreaming \n\
+                  - press 'q' and 'Enter' to quit DataStreaming \n")
+    
+    if (command == 's'):
+		res = iViewXAPI.iV_SetSampleCallback(smp_func)
+		sampleCB = True
+		res = iViewXAPI.iV_SetEventCallback(event_func)
+		eventCB = True
+
+
+# ---------------------------------------------
+#---- stop recording and disconnect from iViewX
+# ---------------------------------------------
+
+res = iViewXAPI.iV_Disconnect()
+ws.close()
\ No newline at end of file
diff --git a/DesktopConnector/DeviceServer_SMI_REDm/README.md b/DesktopConnector/DeviceServer_SMI_REDm/README.md
new file mode 100644
index 0000000..5b9588e
--- /dev/null
+++ b/DesktopConnector/DeviceServer_SMI_REDm/README.md
@@ -0,0 +1,36 @@
+DeviceServer_REDm
+=================
+
+[Download](https://opensource.cit-ec.de/projects/gazetk/repository/gazetk)
+
+License
+-------
+DeviceServer_REDm is free and open source software distributed under the terms of the [GNU General Public License](http://www.gnu.org/licenses/).
+
+Description
+-----------
+Welcome to DeviceServer_REDm!
+
+This python-based server connects your SMI REDm eye tracking device with the GazeTk DesktopConnector. 
+
+Requirements
+------------
+- Python 2.7 32bit
+- Python module websocket
+
+Installation
+------------
+1. Install Python 2.7 32bit
+2. Install websocket-client by running the following script from PYTHONDIR/Scripts:
+
+$ pip install websocket-client
+
+Starting DeviceServer_REDm
+--------------------------
+1. Start the REDm application provided with the device.
+2. Make sure you have the iViewXAPI.dlls on your PATH, they come with the REDm installation package.
+3. Start the DeviceServer_REDm:
+
+$ python DeviceServer_REDm.py
+
+
diff --git a/DesktopConnector/DeviceServer_SMI_REDm/iViewXAPI.py b/DesktopConnector/DeviceServer_SMI_REDm/iViewXAPI.py
new file mode 100644
index 0000000..05698ea
--- /dev/null
+++ b/DesktopConnector/DeviceServer_SMI_REDm/iViewXAPI.py
@@ -0,0 +1,117 @@
+# -----------------------------------------------------------------------
+#
+# (c) Copyright 1997-2013, SensoMotoric Instruments GmbH
+# 
+# Permission  is  hereby granted,  free  of  charge,  to any  person  or
+# organization  obtaining  a  copy  of  the  software  and  accompanying
+# documentation  covered  by  this  license  (the  "Software")  to  use,
+# reproduce,  display, distribute, execute,  and transmit  the Software,
+# and  to  prepare derivative  works  of  the  Software, and  to  permit
+# third-parties to whom the Software  is furnished to do so, all subject
+# to the following:
+# 
+# The  copyright notices  in  the Software  and  this entire  statement,
+# including the above license  grant, this restriction and the following
+# disclaimer, must be  included in all copies of  the Software, in whole
+# or  in part, and  all derivative  works of  the Software,  unless such
+# copies   or   derivative   works   are   solely   in   the   form   of
+# machine-executable  object   code  generated  by   a  source  language
+# processor.
+# 
+# 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,   TITLE  AND
+# NON-INFRINGEMENT. IN  NO EVENT SHALL  THE COPYRIGHT HOLDERS  OR ANYONE
+# DISTRIBUTING  THE  SOFTWARE  BE   LIABLE  FOR  ANY  DAMAGES  OR  OTHER
+# LIABILITY, WHETHER  IN CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT
+# OF OR IN CONNECTION WITH THE  SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# -----------------------------------------------------------------------
+# iViewXAPI.py
+#
+# Demonstrates features of iView API 
+# Defines structures 
+# Loads in iViewXAPI.dll
+# This script shows how to set up an experiment with Python 2.7.1 (with ctypes Library) 
+
+
+from ctypes import *
+
+
+#===========================
+#		Struct Definition
+#===========================
+
+class CSystem(Structure):
+	_fields_ = [("samplerate", c_int),
+	("iV_MajorVersion", c_int),
+	("iV_MinorVersion", c_int),
+	("iV_Buildnumber", c_int),
+	("API_MajorVersion", c_int),
+	("API_MinorVersion", c_int),
+	("API_Buildnumber", c_int),
+	("iV_ETDevice", c_int)]
+
+class CCalibration(Structure):
+	_fields_ = [("method", c_int),
+	("visualization", c_int),
+	("displayDevice", c_int),
+	("speed", c_int),
+	("autoAccept", c_int),
+	("foregroundBrightness", c_int),
+	("backgroundBrightness", c_int),
+	("targetShape", c_int),
+	("targetSize", c_int),
+	("targetFilename", c_char * 256)]
+
+class CEye(Structure):
+	_fields_ = [("gazeX", c_double),
+	("gazeY", c_double),
+	("diam", c_double),
+	("eyePositionX", c_double),
+	("eyePositionY", c_double),
+	("eyePositionZ", c_double)]
+
+class CSample(Structure):
+	_fields_ = [("timestamp", c_longlong),
+	("leftEye", CEye),
+	("rightEye", CEye),
+	("planeNumber", c_int)]
+
+class CEvent(Structure):
+	_fields_ = [("eventType", c_char),
+	("eye", c_char),
+	("startTime", c_longlong),
+	("endTime", c_longlong),
+	("duration", c_longlong),
+	("positionX", c_double),
+	("positionY", c_double)]
+
+class CAccuracy(Structure):
+	_fields_ = [("deviationLX",c_double),
+				("deviationLY",c_double),				
+				("deviationRX",c_double),
+				("deviationRY",c_double)]
+				
+				
+#===========================
+#		Loading iViewX.dll 
+#===========================
+
+iViewXAPI = windll.LoadLibrary("iViewXAPI.dll")
+
+
+#===========================
+#		Initializing Structs
+#===========================
+
+systemData = CSystem(0, 0, 0, 0, 0, 0, 0, 0)
+calibrationData = CCalibration(5, 1, 0, 0, 1, 20, 239, 1, 15, b"")
+leftEye = CEye(0,0,0)
+rightEye = CEye(0,0,0)
+sampleData = CSample(0,leftEye,rightEye,0)
+eventData = CEvent('F', 'L', 0, 0, 0, 0, 0)
+accuracyData = CAccuracy(0,0,0,0)
+
+
diff --git a/DesktopConnector/DeviceServer_SMI_REDm/iViewXAPIReturnCodes.py b/DesktopConnector/DeviceServer_SMI_REDm/iViewXAPIReturnCodes.py
new file mode 100644
index 0000000..e4ee4b1
--- /dev/null
+++ b/DesktopConnector/DeviceServer_SMI_REDm/iViewXAPIReturnCodes.py
@@ -0,0 +1,43 @@
+# -----------------------------------------------------------------------
+#
+# (c) Copyright 1997-2013, SensoMotoric Instruments GmbH
+# 
+# Permission  is  hereby granted,  free  of  charge,  to any  person  or
+# organization  obtaining  a  copy  of  the  software  and  accompanying
+# documentation  covered  by  this  license  (the  "Software")  to  use,
+# reproduce,  display, distribute, execute,  and transmit  the Software,
+# and  to  prepare derivative  works  of  the  Software, and  to  permit
+# third-parties to whom the Software  is furnished to do so, all subject
+# to the following:
+# 
+# The  copyright notices  in  the Software  and  this entire  statement,
+# including the above license  grant, this restriction and the following
+# disclaimer, must be  included in all copies of  the Software, in whole
+# or  in part, and  all derivative  works of  the Software,  unless such
+# copies   or   derivative   works   are   solely   in   the   form   of
+# machine-executable  object   code  generated  by   a  source  language
+# processor.
+# 
+# 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,   TITLE  AND
+# NON-INFRINGEMENT. IN  NO EVENT SHALL  THE COPYRIGHT HOLDERS  OR ANYONE
+# DISTRIBUTING  THE  SOFTWARE  BE   LIABLE  FOR  ANY  DAMAGES  OR  OTHER
+# LIABILITY, WHETHER  IN CONTRACT, TORT OR OTHERWISE,  ARISING FROM, OUT
+# OF OR IN CONNECTION WITH THE  SOFTWARE OR THE USE OR OTHER DEALINGS IN
+# THE SOFTWARE.
+#
+# -----------------------------------------------------------------------
+
+def HandleError(ret):
+    if ret == 104:
+         print "Could not establish connection. Check if Eye Tracker is running."
+    elif ret == 105:
+         print "Could not establish connection. Check the communication Ports."
+    elif ret == 123:
+         print "Could not establish connection. Another Process is blocking the communication Ports."
+    elif ret == 201:
+         print "Could not establish connection. Check if Eye Tracker is installed and running."
+    else:
+        print "Return Code is " + ret + ". Refer to the iView X SDK Manual for its meaning."
+	return
\ No newline at end of file
diff --git a/DesktopConnector/DeviceServer_SMI_REDm/startDeviceServer_REDm.bat b/DesktopConnector/DeviceServer_SMI_REDm/startDeviceServer_REDm.bat
new file mode 100644
index 0000000..8edb4fe
--- /dev/null
+++ b/DesktopConnector/DeviceServer_SMI_REDm/startDeviceServer_REDm.bat
@@ -0,0 +1,2 @@
+python DeviceServer_REDm.py
+pause
