Skip to content

Commit

Permalink
quick change psychopy/pport --> lsl
Browse files Browse the repository at this point in the history
  • Loading branch information
remrama committed Nov 1, 2023
1 parent 62b23eb commit 56aa27c
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 36 deletions.
4 changes: 2 additions & 2 deletions setup.cfg
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[metadata]
name = smacc
version = 0.0.5
version = 0.0.5.1
author = Remington Mallett
author_email = [email protected]
description = Sleep manipulation and communication clickything
Expand All @@ -23,6 +23,6 @@ classifiers =
python_requires = ==3.8.*
install_requires =
numpy
pylsl
PyQt5
scipy
psychopy
2 changes: 1 addition & 1 deletion smacc/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@

__author__ = "Remington Mallett <[email protected]>"
__version__ = "0.0.5"
__version__ = "0.0.5.1"
49 changes: 16 additions & 33 deletions smacc/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@
import warnings
import webbrowser

try:
from psychopy import parallel
except ModuleNotFoundError:
print("Psychopy not found, no parallel port access.")

from pylsl import StreamInfo, StreamOutlet, local_clock
from PyQt5 import QtWidgets, QtGui, QtCore, QtMultimedia

from smacc import utils
Expand Down Expand Up @@ -133,7 +129,7 @@ def __init__(self, subject_id, session_id):
init_msg = "Opened SMACC v" + VERSION
self.log_info_msg(init_msg)

self.init_pport()
self.init_lsl_stream()

def showErrorPopup(self, short_msg, long_msg=None):
self.log_info_msg("ERROR")
Expand Down Expand Up @@ -167,29 +163,16 @@ def log_info_msg(self, msg):
# self.eventList.addItem(item)
# self.eventList.update()

def init_pport(self):
try:
self.pport = parallel.ParallelPort(address=self.pport_address)
self.pport.setData(0) # clear all pins out to prep for sending
msg = "Parallel port connection succeeded."
except:
self.pport = None
msg = "Parallel port connection failed."
portcode = self.portcodes["TriggerInitialization"]
self.send_to_pport(portcode, msg)

def send_to_pport(self, portcode, port_msg):
def init_lsl_stream(self, stream_id="myuidw43536"):
self.info = StreamInfo("MyMarkerStream", "Markers", 1, 0, "string", stream_id)
self.outlet = StreamOutlet(self.info)

def send_event_marker(self, portcode, port_msg):
"""Wrapper to avoid rewriting if not None a bunch
to make sure the msg also gets logged to output file and gui
"""
if self.pport is not None:
self.pport.setData(0)
self.pport.setData(portcode)
success = "Sent"
else:
success = "Failed"
### Consider re-trying to connect here
log_msg = f"{port_msg} - {success} portcode {portcode}"
self.outlet.push_sample([str(portcode)])
log_msg = f"{port_msg} - portcode {portcode}"
self.log_info_msg(log_msg)

def init_logger(self):
Expand Down Expand Up @@ -399,7 +382,7 @@ def on_cuePlayingChange(self):
portcode = self.portcodes["CueStopped"]
action = "Stopped"
port_msg = f"Cue{action}-{cue_name} - Volume {current_volume}"
self.send_to_pport(portcode, port_msg)
self.send_event_marker(portcode, port_msg)


def recorder_state_change(self, state):
Expand All @@ -418,7 +401,7 @@ def handleDreamReportButton(self):
port_msg = "DreamReportStopped"
# button_label = self.sender().text()
portcode = self.portcodes[port_msg]
self.send_to_pport(portcode, port_msg)
self.send_event_marker(portcode, port_msg)

def handleLightSwitch(self):
# button_label = self.sender().text()
Expand All @@ -427,7 +410,7 @@ def handleLightSwitch(self):
else:
port_msg = "LightsOn"
portcode = self.portcodes[port_msg]
self.send_to_pport(portcode, port_msg)
self.send_event_marker(portcode, port_msg)


# def preload_biocals(self):
Expand All @@ -451,7 +434,7 @@ def handleLightSwitch(self):
# biocal_str = self.biocals_order[current_index]
# portcode = self.portcodes[f"biocals-{biocal_str}"]
# msg = f"BiocalStarted-{biocal_str}"
# self.send_to_pport(portcode, msg)
# self.send_event_marker(portcode, msg)
# else:
# self.biocalsButton.setChecked(False)

Expand Down Expand Up @@ -506,7 +489,7 @@ def handleNoiseButton(self):
else: # not checked
self.noisePlayer.stop()
msg = "NoiseStopped"
self.send_to_pport(self.portcodes[msg], msg)
self.send_event_marker(self.portcodes[msg], msg)

@QtCore.pyqtSlot()
def handleCueButton(self):
Expand All @@ -517,7 +500,7 @@ def handleCueButton(self):
# cue_basename = selected_item.text()
# portcode = self.portcodes[cue_basename]
# port_msg = "CUE+" + cue_basename
# self.send_to_pport(portcode, port_msg)
# self.send_event_marker(portcode, port_msg)
# self.playables[cue_basename].play()
#### play random
n_list_items = self.rightList.count()
Expand All @@ -536,7 +519,7 @@ def handleNoteButton(self):
if ok: # True of OK button was hit, False otherwise (cancel button)
portcode = self.portcodes["Note"]
port_msg = f"Note [{text}]"
self.send_to_pport(portcode, port_msg)
self.send_event_marker(portcode, port_msg)

@QtCore.pyqtSlot()
def handleLeft2RightButton(self):
Expand Down

0 comments on commit 56aa27c

Please sign in to comment.