Skip to content

Commit

Permalink
FF: updated iohub getDeviceNames
Browse files Browse the repository at this point in the history
now returns list of (manufacturer_name, iohub_device_name) pairs.
getDeviceParams now returns data type for list element instead of 'list'
  • Loading branch information
isolver committed Apr 12, 2021
1 parent f629e02 commit 2498b9b
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions psychopy/iohub/util/__init__.py
Expand Up @@ -219,24 +219,30 @@ def getDeviceDefaultConfig(device_name, builder_hides=True):
_iohub2builderInputType = dict(IOHUB_STRING='single', IOHUB_BOOL='bool', IOHUB_FLOAT='single', IOHUB_INT='single',
IOHUB_LIST=('choice','multi'), IOHUB_COLOR='color', IOHUB_IP_ADDRESS_V4='single')

def getDeviceNames(device_name="eyetracker.hw"):
def getDeviceNames(device_name="eyetracker.hw", get_paths=True):
"""
Return a list of iohub eye tracker device names, as would be used as keys to launchHubServer.
Return a list of iohub eye tracker device names, as would be used as keys to launchHubServer. If get_paths is true,
return both device manufacturer name (for display in builder) as well as iohub device name.
Example:
eyetrackers = getDeviceNames()
print(eyetrackers)
Output:
['eyetracker.hw.gazepoint.gp3.EyeTracker', 'eyetracker.hw.sr_research.eyelink.EyeTracker',
'eyetracker.hw.tobii.EyeTracker']
[('GazePoint', 'eyetracker.hw.gazepoint.gp3.EyeTracker'),
('MouseGaze', 'eyetracker.hw.mouse.EyeTracker'),
('SR Research Ltd', 'eyetracker.hw.sr_research.eyelink.EyeTracker'),
('Tobii Technology', 'eyetracker.hw.tobii.EyeTracker')]
"""
names = []
dconfigs = getDeviceDefaultConfig(device_name)
for dcfg in dconfigs:
d_name = tuple(dcfg.keys())[0]
#d_name = d_name[:d_name.rfind('.')]
names.append(d_name)
d_path = tuple(dcfg.keys())[0]
d_config = tuple(dcfg.values())[0]
if get_paths is False:
names.append(d_path)
else:
names.append((d_config.get('manufacturer_name'), d_path))
return names

def getDeviceFile(device_name, file_name):
Expand Down Expand Up @@ -359,7 +365,7 @@ def settings2Params(parent_list, settings):
slabel = slabel+k.replace("_", " ").title()

if isinstance(sconfig_data, dict):
iohub_type, type_constraints =list(sconfig_data.items())[0]
iohub_type, type_constraints = list(sconfig_data.items())[0]
builderValType = _iohub2builderValType[iohub_type]
builderInputType = _iohub2builderInputType[iohub_type]
valid_values = None
Expand All @@ -369,14 +375,15 @@ def settings2Params(parent_list, settings):
builderInputType = builderInputType[0]
else:
builderInputType = builderInputType[1]
builderValType = type(valid_values[0])
if valid_values:
nv = dict(valType=builderValType, inputType=builderInputType, defaultVal=v,
allowedVals=valid_values, hint=shint, label=slabel)
else:
nv = dict(valType=builderValType, inputType=builderInputType, defaultVal=v,
hint=shint, label=slabel)
elif isinstance(sconfig_data, list):
nv = dict(valType='list', inputType='static', defaultVal=v, hint=shint, label=slabel)
nv = dict(valType=type(v), inputType='static', defaultVal=v, hint=shint, label=slabel)
elif sconfig_data in _iohub2builderValType.keys():
nv = dict(valType=_iohub2builderValType[sconfig_data],
inputType=_iohub2builderInputType[sconfig_data], defaultVal=v,
Expand Down

0 comments on commit 2498b9b

Please sign in to comment.