Example #1
0
def main():
    global IN_GAME
    if IN_GAME:
        s.move()
        head_coords = c.coords(s.segments[-1].instance)
        x1, y1, x2, y2 = head_coords
        insample = pylsl.vectorf()
        inlet_list = []
        while inlet.samples_available():
            inlet.pull_sample(insample)
            inlet_list.append(list(insample))
        for i in range(len(inlet_list)):
            s.change_direction(inlet_list[i])
        if x2 > WIDTH or x1 < 0 or y1 < 0 or y2 > HEIGHT:
            IN_GAME = False
        elif head_coords == c.coords(BLOCK):
            s.add_segment()
            c.delete(BLOCK)
            create_block()
        else:
            for index in range(len(s.segments)-1):
                 if head_coords == c.coords(s.segments[index].instance):
                    IN_GAME = False
        root.after(100, main)
    else:
        c.create_text(WIDTH/2, HEIGHT/2, text="GAME OVER!", font="Arial 20", fill="red")
Example #2
0
def Ni_data_collection():
    streams = pylsl.resolve_stream()
    info = pylsl.stream_info('Force', 'Data', 1, 1000, 'float32')
    outlet = pylsl.stream_outlet(info)

    with nidaqmx.Task() as task:
        task.ai_channels.add_ai_voltage_chan("Dev1/ai0")
        while True:
            sample = pylsl.vectorf([task.read()])
            outlet.push_sample(sample)
            time.sleep(0.01)
Example #3
0
    def replay(self, live=True):

        if len(self.__outlets) == 0:
            raise "Configuration missing."

        if len(self.__events) == 0:
            return

        # (1) get the current time
        delta = time.time() - self.__events[0][0]

        # (2) Loop over messages
        for m in self.__events:
            # (3) Wait until the time is right. and send.
            time_to_wait = m[0] + delta - time.time()
            if time_to_wait > 0 and live:
                time.sleep(time_to_wait)

            samples = pylsl.vectorf(m[2])
            self.__outlets[m[1]].push_sample(samples)
Example #4
0
    def startReadAndProcess(self):
        if self.stream is None:
            print("No stream to read... aborting")
            return
        # create a new inlet to read from the stream
        self.inlet = StreamInlet(self.stream)
        self.outlet = pylsl.stream_outlet(self.outputInfo)
        mustStop = False
        outputEveryNSample = self.inputRate / self.outputRate
        samp = 0
        while not mustStop:
            samp += 1
            np.roll(self.buff, -1, 0)
            self.buff[self.bufferSize -
                      1, :], timestamp = self.inlet.pull_sample()
            if samp % outputEveryNSample == 0:
                #pdb.set_trace()
                values = self.processBuffer(self.freqBand)
                self.outlet.push_sample(
                    pylsl.vectorf(self.processBuffer(self.freqBand)))

        self.inlet = None
Example #5
0
import sys; sys.path.append('..')  # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program)
import pylsl

# first resolve an EEG stream on the lab network
print("looking for an EEG stream...")
streams = pylsl.resolve_stream('type','EEG')

# create a new inlet to read from the stream
inlet = pylsl.stream_inlet(streams[0])

sample = pylsl.vectorf()
while True:
	# get a new sample (you can also omit the timestamp part if you're not interested in it)
	timestamp = inlet.pull_sample(sample)	
	print(timestamp, list(sample))
Example #6
0
    '..'
)  # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program)
import pylsl
import random
import time

# first create a new stream info (here we set the name to BioSemi, the content-type to EEG, 8 channels, 100 Hz, and float-valued data)
# The last value would be the serial number of the device or some other more or less locally unique identifier for the stream as far as available (you could also omit it but interrupted connections wouldn't auto-recover).
info = pylsl.stream_info('BioSemi', 'EEG', 8, 100, pylsl.cf_float32,
                         'dsffwerwer')

# next make an outlet
outlet = pylsl.stream_outlet(info)

print("now sending data...")
while True:
    # make a new random 8-channel sample; this is converted into a pylsl.vectorf (the data type that is expected by push_sample)
    mysample = pylsl.vectorf([
        random.random(),
        random.random(),
        random.random(),
        random.random(),
        random.random(),
        random.random(),
        random.random(),
        random.random()
    ])
    # now send it and wait for a bit
    outlet.push_sample(mysample)
    time.sleep(0.01)
Example #7
0
import sys; sys.path.append('..')  # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program)
import pylsl
import random
import time

# first create a new stream info (here we set the name to BioSemi, the content-type to EEG, 8 channels, 100 Hz, and float-valued data)
# The last value would be the serial number of the device or some other more or less locally unique identifier for the stream as far as available (you could also omit it but interrupted connections wouldn't auto-recover).
info = pylsl.stream_info('BioSemi','EEG',8,100,pylsl.cf_float32,'dsffwerwer');

# append some meta-data
info.desc().append_child_value("manufacturer","BioSemi")
channels = info.desc().append_child("channels")
for c in ["C3","C4","Cz","FPz","POz","CPz","O1","O2"]:
	channels.append_child("channel").append_child_value("name",c).append_child_value("unit","microvolts").append_child_value("type","EEG")

# next make an outlet; we set the outgoing buffer size to 360 seconds (max.) and the transmission chunk size to 32 samples
outlet = pylsl.stream_outlet(info,360,32)

print("now sending data...")
while True:
	# make a new random 8-channel sample; this is converted into a pylsl.vectorf (the data type that is expected by push_sample)
	mysample = pylsl.vectorf([random.random(),random.random(),random.random(),random.random(),random.random(),random.random(),random.random(),random.random()])
    # get a time stamp in seconds (we might modify this time stamp based on the true age of the sample, e.g. if it came from a measurement device, in case we can determine it)
	now = pylsl.local_clock()
	# now send it and wait for a bit
	outlet.push_sample(mysample,now)
	time.sleep(0.01)
Example #8
0
import sys
sys.path.append(
    '..'
)  # make sure that pylsl is found (note: in a normal program you would bundle pylsl with the program)
import pylsl

# first resolve an EEG stream on the lab network
print("looking for an EEG stream...")
streams = pylsl.resolve_stream('type', 'EEG')

# create a new inlet to read from the stream
inlet = pylsl.stream_inlet(streams[0])

sample = pylsl.vectorf()
while True:
    # get a new sample (you can also omit the timestamp part if you're not interested in it)
    timestamp = inlet.pull_sample(sample)
    print(timestamp, list(sample))