Esempio n. 1
0
File: dino.py Progetto: ziny1138/hci
def blinks_detector(quit_program, blink, blink_det, blinks_num):
    def detect_blinks(sample):
        smp = sample.channels_data[0]
        smp_flted = frt.filterIIR(smp, 0)
        #print(smp_flted)

        brt.blink_detect(smp_flted, -38000)
        # report it the new blink is spotted
        if brt.new_blink:
            if brt.blinks_num == 1:
                # First detected blink is in fact artifact from filter
                # settling. Correct blink number by subtracting 1.
                # First "blink" successfully detected - device is connected.
                connected.set()
                print('CONNECTED. Speller starts detecting blinks.')
            else:
                blink_det.put(brt.blinks_num)
                blinks_num.value = brt.blinks_num
                blink.value = 1
                print('BLINK!')


        if quit_program.is_set():
            print('Disconnect signal sent...')
            board.stop_stream()

    if __name__ == '__main__':
        # filtering in real time object creation
        frt = flt.FltRealTime()

        # blink detection in real time object creation
        brt = blk.BlinkRealTime()

        board = OpenBCIGanglion(mac=mac_adress)
        board.start_stream(detect_blinks)
Esempio n. 2
0
def blinks_detector(
    quit_program,
    blink_det,
    blinks_num,
    blink,
):
    def detect_blinks(sample):
        if SYMULACJA_SYGNALU:
            smp_flted = sample
        else:
            smp = sample.channels_data[0]
            smp_flted = frt.filterIIR(smp, 0)
        #print(smp_flted)

        brt.blink_detect(smp_flted, -38000)
        if brt.new_blink:
            if brt.blinks_num == 1:
                #connected.set()
                print('CONNECTED. Speller starts detecting blinks.')
            else:
                blink_det.put(brt.blinks_num)
                blinks_num.value = brt.blinks_num
                blink.value = 1
                print("sss")

        if quit_program.is_set():
            if not SYMULACJA_SYGNALU:
                print('Disconnect signal sent...')
                board.stop_stream()


####################################################

    SYMULACJA_SYGNALU = False
    ####################################################
    mac_adress = 'e5:32:b4:53:55:ba'
    ####################################################

    clock = pg.time.Clock()
    frt = flt.FltRealTime()
    brt = blk.BlinkRealTime()

    if SYMULACJA_SYGNALU:
        df = pd.read_csv('dane_do_symulacji/data.csv')
        for sample in df['signal']:
            if quit_program.is_set():
                break
            detect_blinks(sample)
            clock.tick(200)
        print('KONIEC SYGNAŁU')
        quit_program.set()
    else:
        board = OpenBCIGanglion(mac=mac_adress)
        board.start_stream(detect_blinks)
print("Creating LSL stream for EEG. \nName: OpenBCIEEG\nID: OpenBCItestEEG\n")

info_eeg = StreamInfo('OpenBCIEEG', 'EEG', 4, 250, 'float32', 'OpenBCItestEEG')

print("Creating LSL stream for AUX. \nName: OpenBCIAUX\nID: OpenBCItestEEG\n")

info_aux = StreamInfo('OpenBCIAUX', 'AUX', 3, 250, 'float32', 'OpenBCItestAUX')

outlet_eeg = StreamOutlet(info_eeg)
outlet_aux = StreamOutlet(info_aux)

info = StreamInfo('MyMarkerStream', 'Markers', 1, 0, 'string', 'myuidw43536')
# next make an outlet
outlet = StreamOutlet(info)
markernames = ['Marker', 'Marker', 'Marker', 'Marker', 'Marker', 'Marker']


def lsl_streamers(sample):
    outlet_eeg.push_sample(np.array(sample.channels_data) * SCALE_FACTOR_EEG)
    outlet.push_sample([random.choice(markernames)])
    print(np.array(sample.channels_data) * SCALE_FACTOR_EEG)
    # outlet_aux.push_sample(np.array(sample.aux_data)*SCALE_FACTOR_AUX)


board = OpenBCIGanglion(mac='E0:40:DA:FF:A2:F7')

board.start_stream(lsl_streamers)

# myResol = ContinuousResolver()
# print(myResol.results)
from pyOpenBCI import OpenBCIGanglion


def print_raw(sample):
    print(sample.channels_data)


#Set (daisy = True) to stream 16 ch
board = OpenBCIGanglion(mac='E0:40:DA:FF:A2:F7')

board.start_stream(print_raw)