From de24668fa913c4d50149df48716c81bd8316dd1d Mon Sep 17 00:00:00 2001 From: Martin Schaefer <60383462+martsc1@users.noreply.github.com> Date: Thu, 6 Nov 2025 12:03:10 +0100 Subject: [PATCH] Add pupil diameter and blink data methods Added methods to enable sending pupil diameter in mm and blink data in accordance with Gazepoint API 3.0. The older LPUPILD and RPUPILD are deprecated. --- pygaze/_eyetracker/opengaze.py | 45 +++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) diff --git a/pygaze/_eyetracker/opengaze.py b/pygaze/_eyetracker/opengaze.py index 07420bf..9f58966 100644 --- a/pygaze/_eyetracker/opengaze.py +++ b/pygaze/_eyetracker/opengaze.py @@ -101,7 +101,8 @@ 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', \ - 'USER'] + 'LPMM','LPMMV','RPMM','RPMMV','BKID','BKDUR','BKPMIN','USER'] + 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. @@ -192,6 +193,8 @@ def __init__(self, ip='127.0.0.1', port=4242, logfile='default.tsv', \ self.enable_send_time(True) self.enable_send_time_tick(True) self.enable_send_user_data(True) + self.enable_send_blink(True) + self.enable_send_pupilmm(True) def calibrate(self): @@ -838,6 +841,46 @@ def enable_send_user_data(self, state): # Return a success Boolean. return acknowledged and (timeout==False) + + def enable_send_pupilmm(self, state): + + """Enable (state=True) or disable (state=False) the inclusion of + the left and right eye pupil diameter in millimeters in the data + record string. This data consists of the following: + LPMM: The diameter of the left eye pupil in millimeters + LPMMV: The valid flag with value of 1 if the data is valid, and 0 if it is not. + RPMM: The diameter of the right eye pupil in millimeters + RPMMV: The valid flag with value of 1 if the data is valid, and 0 if it is not. + """ + + # Send the message (returns after the Server acknowledges receipt). + acknowledged, timeout = self._send_message('SET', \ + 'ENABLE_SEND_PUPILMM', \ + values=[('STATE', int(state))], \ + wait_for_acknowledgement=True) + + # 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 + the rolling user blink rate (blinks / minute), blink duration and blink ID. + This data consists of the following: + BKID: Each blink is assigned an ID value and incremented by one. The BKID value + equals 0 for every record where no blink has been detected. + BKDUR: The duration of the preceding blink in seconds. + BKPMIN: The number of blinks in the previous 60 second period of time. + """ + + # 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 calibrate_start(self, state):