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

RF: Use threshold values from 0 to 1 rather than 255 #11

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion psychopy_bbtk/tpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def _setThreshold(self, threshold, channel):
# enter command mode
self.parent.setMode(0)
# send command to set threshold
self.parent.sendMessage(f"AAO{channel+1} {int(threshold)}")
self.parent.sendMessage(f"AAO{channel+1} {int(threshold * 255)}")
# force a sleep for diode to settle
time.sleep(0.1)
# get 0 or 1 according to light level
Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
from psychopy.tests.test_liaison import TestLiaison, runInLiaison
from .utils import getTestTPadPhotodiode


class TestBBTKLiaison(TestLiaison):
def test_tpad_photodiode(self):
"""
Test that a TPadPhotodiodeGroup can be set up and calibrated via Liaison
"""
runInLiaison(
self.server, self.protocol, "DeviceManager", "addDevice",
"psychopy_bbtk.tpad.TPadPhotodiodeGroup", "diode",
"COM6", "2"
)
# setup a photodiode
diode = getTestTPadPhotodiode()
# find threshold
runInLiaison(
self.server, self.protocol, "DeviceManager", "callDeviceMethod",
"diode", "findThreshold",
"TestTPadPhotodiode", "findThreshold",
"session.win", "1"
)
# find photodiode
runInLiaison(
self.server, self.protocol, "DeviceManager", "callDeviceMethod",
"diode", "findPhotodiode",
"TestTPadPhotodiode", "findPhotodiode",
"session.win", "1"
)
85 changes: 85 additions & 0 deletions tests/test_coder/test_tpad/utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
from psychopy import hardware
from psychopy_bbtk.tpad import TPad, TPadPhotodiodeGroup, TPadButtonGroup, TPadVoiceKey
import pytest

def getTestTPad():
"""
Get the handle of the test suite's TPad object.

Returns
-------
psychopy_bbtk.tpad.TPad
The TPad object for the test suite
"""
# look for any TPad with the correct name
pad = hardware.DeviceManager.getDevice("TestTPad")
# if there isn't one, try setting one up
for profile in hardware.DeviceManager.getAvailableDevices("psychopy_bbtk.tpad.TPad"):
profile['deviceName'] = "TestTPad"
pad = hardware.DeviceManager.addDevice(
**profile
)
return pad
# if we didn't find a device, skip current test
if pad is None:
pytest.skip()

def getTestTPadPhotodiode():
"""
Get the photodiode node of the test suite's TPad.

Returns
-------
psychopy_bbtk.tpad.TPadPhotodiodeGroup
The TPadPhotodiodeGroup object for the test suite
"""
# get TPad
pad = getTestTPad()
# if there is none, skip
if pad is None:
pytest.skip()
# get its photodiode node
for node in pad.nodes:
if isinstance(node,TPadPhotodiodeGroup):
return node
# if it has no photodiode node, try making one
for profile in hardware.DeviceManager.getAvailableDevices("psychopy_bbtk.tpad.TPadPhotodiodeGroup"):
profile['deviceName'] = "TestTPadPhotodiode"
node = hardware.DeviceManager.addDevice(
**profile
)
# we only need one
return node
# if we didn't find a device, skip current test
if pad is None:
pytest.skip()

def getTestTPadButtons():
"""
Get the buttons node of the test suite's TPad.

Returns
-------
psychopy_bbtk.tpad.TPadButtonGroup
The TPadButtonGroup object for the test suite
"""
# get TPad
pad = getTestTPad()
# if there is none, skip
if pad is None:
pytest.skip()
# get its buttons node
for node in pad.nodes:
if isinstance(node,TPadButtonGroup):
return node
# if it has no buttons node, try making one
for profile in hardware.DeviceManager.getAvailableDevices("psychopy_bbtk.tpad.TPadButtonGroup"):
profile['deviceName'] = "TestTPadButtons"
node = hardware.DeviceManager.addDevice(
**profile
)
# we only need one
return node
# if we didn't find a device, skip current test
if pad is None:
pytest.skip()
Loading