def stream(): con = Consider() meditation_threshold = 55 attention_threshold = 35 print "waiting for BCI headset signal ..." turn = False for p in con.packet_generator(): if p.poor_signal == 0: print "meditation: %s / 100 | attention : %s / 100" % ( p.meditation, p.attention) if p.meditation > meditation_threshold: t1 = threading.Thread(target=sound.play_meditation_sound) t1.daemon = True t1.start() if not turn: t2 = threading.Thread(target=arduino.send_turn_left()) t2.daemon = True t2.start() turn = True else: time.sleep(1) turn = False if p.attention > attention_threshold: t3 = threading.Thread(target=sound.play_attention_sound) t3.daemon = True t3.start() t4 = threading.Thread(target=arduino.send_go_foreward()) t4.daemon = True t4.start() else: print "no signal yet"
def record(out): con = Consider() for p in con.packet_generator(): data = map(str, [ p.low_alpha, p.high_alpha, p.low_beta, p.high_beta, p.attention, p.meditation, p.poor_signal ]) out.write(','.join(data)) out.write('\n')
def run(self): con = Consider() for p in con.packet_generator(): if p.poor_signal == 0: timestamp = int(time.time() * 1000) packet = json.dumps({ 'meditation': p.meditation, 'attention': p.attention, 'signal_strength': p.signal, 'timestamp': timestamp }) self.sock.sendto(packet, (self.receiver_ip, self.receiver_port))
def get_packs(Npacks, filename, overwrite): # Inputs: # Npacks - number of packets # filename - name of file for convenience # overwrite - set as 1 for overwrite # Outputs: # a file in your directory called "filename".txt # Initialize counter i = 1 # Append .txt to filename filenametemp = filename + '.txt' # Check if file already exists and handle it appropriately with overwrite if (os.path.isfile(filenametemp) and overwrite == 1): os.remove(filenametemp) elif os.path.isfile(filenametemp): while os.path.isfile(filenametemp): filenametemp = filename + str(i) + '.txt' i += 1 filename = filenametemp # Create file f = open(filename, 'w') # Initialize Consider object con = Consider() # Generate packets to file) print 'hello world' try: for p in islice(con.packet_generator(), Npacks): temp = str(p) temp = temp.replace(",", " ,") print temp f.write(temp + ' ' + strftime("%H:%M:%S") + '\n') except: print("Error: Check if headset is connected") # Close file f.close() del f