Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenGaze, implementation of blink data and get_sample methods #176

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion pygaze/_eyetracker/opengaze.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
class OpenGazeTracker:

def __init__(self, ip='127.0.0.1', port=4242, logfile='default.tsv', \
debug=False):
debug=False, data_stream=False):

"""The OpenGazeConnection class communicates to the GazePoint
server through a TCP/IP socket. Incoming samples will be written
Expand Down Expand Up @@ -101,7 +101,13 @@ def __init__(self, ip='127.0.0.1', port=4242, logfile='default.tsv', \
'LEYEX', 'LEYEY', 'LEYEZ', 'LPUPILD', 'LPUPILV', \
'REYEX', 'REYEY', 'REYEZ', 'RPUPILD', 'RPUPILV', \
'CX', 'CY', 'CS', \
'BKID', 'BKDUR', 'BKPMIN', \
'USER']
# Boolean to check whenever the user wants to save
# data samples
self.data_stream = data_stream
# List to store Eyetracker data samples
self._data_stream = []
self._n_logvars = len(self._logheader)
self._logfile.write('\t'.join(self._logheader) + '\n')
# The log is consolidated (written to the disk) every N samples.
Expand Down Expand Up @@ -191,7 +197,9 @@ def __init__(self, ip='127.0.0.1', port=4242, logfile='default.tsv', \
self.enable_send_pupil_right(True)
self.enable_send_time(True)
self.enable_send_time_tick(True)
self.enable_send_blink(True)
self.enable_send_user_data(True)



def calibrate(self):
Expand Down Expand Up @@ -319,6 +327,11 @@ def _log_sample(self, sample):
# Find the appropriate index in the line
line[self._logheader.index(varname)] = sample[varname]
self._logfile.write('\t'.join(line) + '\n')
# Store the sample in _data_stream:
# Only if user decided so in the data_stream
# Boolean variable at constructor
if self.data_stream:
self._data_stream.append(line)

def _parse_msg(self, xml):

Expand Down Expand Up @@ -823,6 +836,27 @@ def enable_send_cursor(self, state):
# Return a success Boolean.
return acknowledged and (timeout==False)

def enable_send_blink(self, state):

"""Enable (state=True) or disable (state=False) the inclusion of
Blink tracking, which has been added to the latest release of the
Gazepoint software (V3.0.0). one can access the blink tracking data
by enabling the ENABLE_SEND_BLINK setting which consists of the
following data:
BKID: A a blink counter.
BKDUR: Blink duration for the last blink.
BKPMIN: The average blink rate over the last minute.
"""

# Send the message (returns after the Server acknowledges receipt).
acknowledged, timeout = self._send_message('SET', \
'ENABLE_SEND_BLINK', \
values=[('STATE', int(state))], \
wait_for_acknowledgement=True)

# Return a success Boolean.
return acknowledged and (timeout==False)

def enable_send_user_data(self, state):

"""Enable (state=True) or disable (state=False) the inclusion of
Expand Down Expand Up @@ -1378,4 +1412,17 @@ def get_api_id(self):
return value

# TODO: Get sample method.
# My approach to sample method
def get_sample(self):
"""Gets a sample from the list that stored all samples.
should be used when data_stream = TRUE.
Returns a data vector from the logged data, 1 at a time.
or
returns None if the are none vectors left.
"""
if len(self._data_stream) > 0:
return self._data_stream.pop(0)
else:
return None

# TODO: Write sample method?