コード例 #1
0
def main():
    neuropy = NeuroPy("/dev/rfcomm0") #instantiate NeuroPy class

    neuropy.start() #start thread
    start_time = 0 
    blinked = False #if blink is detected
    last_blink_time = 0
    double_blink = False
    triple_blink = False
    i = 100
    j = 100

    try:
        while i < 20000:
            i = i + 1 
            value = neuropy.rawValue #gets the raw brain activity level
            print value, "   ", i 
            
            if value > 100: #if the raw level gets above 200, which indicates a spike, start the clock
                start_time = time.clock()
                #print value
            if start_time:
                if value <  -100: #if the spike in brain activity is over
                    total_time = time.clock() - start_time #how long the spike was
                    start_time = 0
                    if 0.01 < total_time < 0.050: #if the spike was a certain length
                        if last_blink_time and time.clock() - last_blink_time < .6: #if the blink occured right after the previous blink
                            if double_blink:
                                triple_blink = True
                            else :
                                double_blink = True
                        last_blink_time = time.clock() #reset the clock
                        i+=1
                        blinked = True
            if blinked and time.clock()-last_blink_time > .61: #if a certain amount of time has passed since the last blink
                if triple_blink:
                    print "Triple blink detected .......... turning left"
                    motor.forward_left()
                    time.sleep(3)
                    motor.forward()
                    break
                
                elif double_blink:
                    print "Double blink detected ........... turning right"
                    motor.forward_right()
                    time.sleep(3)
                    motor.forward()
                    break
                    
                double_blink = blinked = triple_blink = False
        time.sleep(2)
        return
    finally:
        neuropy.stop()
コード例 #2
0
def main():
    print("hallo hallo")

    object1 = NeuroPy("/dev/rfcomm0")

    object1.setCallBack("attention", attention_callback)

    object1.start()

    while True:
        if (object1.meditation > 70):
            object1.stop()
コード例 #3
0
class Nsky():
    def __init__(self):
        self.value = 0
        self.counter = 0
        self.skip_value = 0
        self.data_array = [0.000] * 1024
        self.neuro_object = NeuroPy("COM15")
        self.caller()

    def attention_callback(self, attention_value):
        if (self.neuro_object.attention >= 15
                and self.neuro_object.meditation >= 15
                and self.neuro_object.poorSignal == 0):
            self.counter += 1
            for i in range(len(self.data_array) - 1):
                self.data_array[i] = self.data_array[i + 1]
            self.data_array[1023] = attention_value
            if (self.counter == 1024):
                if (self.skip_value == 0):
                    self.skip_value = 1
                    self.value = input(
                        "(0 for left and 1 for right and 2 for ntg)")
                    self.counter = 0
                    if self.value == 3:
                        self.neuro_object.stop()
                    return None
                with open('traindata.csv', 'ab') as datafile:
                    writer = csv.writer(datafile)
                    writer.writerow([
                        self.neuro_object.attention,
                        self.neuro_object.meditation,
                        self.neuro_object.poorSignal, self.data_array,
                        self.value
                    ])
                self.value = input(
                    "(0 for left and 1 for right and 2 for ntg)")
                self.counter = 0
        return None

    def caller(self):
        #set call back:
        self.neuro_object.setCallBack("rawValue", self.attention_callback)
        #call start method
        self.value = input("(0 for left and 1 for right and 2 for ntg)")
        self.neuro_object.start()

        while True:
            if (
                    self.neuro_object.meditation > 100
            ):  #another way of accessing data provided by headset (1st being call backs)
                print("geda meditationg too much")
コード例 #4
0
        count = 0

    if (flag > 0):
        print("along y")
        # pi.moveTo(map(ob.attention, 1, 100, 1, GetSystemMetrics(0))+1,  x, pytweening.easeInQuad(0.5))
        if (ob.attention > lastAttention):
            lastAttention = ob.attention
            pi.moveTo(x,
                      map(ob.attention, 1, 100, 1, GetSystemMetrics(1)) + 1,
                      pytweening.easeInQuad(0.5))
        else:
            pi.moveTo(
                x,
                map(ob.attention - 2, 1, 100, 1, GetSystemMetrics(1)) + 1,
                pytweening.easeInQuad(0.5))
    else:
        # pi.moveTo(y,  map(ob.attention, 1, 100, 1, GetSystemMetrics(1))+1, pytweening.easeInQuad(0.5))
        print("along x")
        if (ob.attention > lastAttention):
            lastAttention = ob.attention
            pi.moveTo(
                map(ob.attention, 1, 100, 1, GetSystemMetrics(1)) + 1, y,
                pytweening.easeInQuad(0.5))
        else:
            pi.moveTo(
                map(ob.attention - 2, 1, 100, 1, GetSystemMetrics(1)) + 1, y,
                pytweening.easeInQuad(0.5))
    # ob.save()
    # print("alpha ",ob.highAlpha," ",ob.lowAlpha," Beta ",ob.highBeta," ",ob.lowBeta)
ob.stop()
ob.save()
コード例 #5
0
ファイル: pyPy.py プロジェクト: gabrielr291/Pruebas
##Sample Program##

from NeuroPy import NeuroPy
object1=NeuroPy("COM6",57600) #If port not given 57600 is automatically assumed
#object1=NeuroPy("/dev/rfcomm0") for linux
def attention_callback(attention_value):
    "this function will be called everytime NeuroPy has a new value for attention"  
    print ("Value of attention is",attention_value)
#do other stuff (fire a rocket), based on the obtained value of attention_value
#do some more stuff
    return None

#set call back:
object1.setCallBack("attention",attention_callback)

#call start method
object1.start()

while True:
    if(object1.meditation>70): #another way of accessing data provided by headset (1st being call backs)
        object1.stop() #if meditation level reaches above 70, stop fetching data from the headset
コード例 #6
0
sleep(3)


with open('_jamanna blink.csv', 'w') as csvfile:
    fieldnames = ['attention', 'delta', 'meditation', 'rawValue', 'theta', 
    'lowAlpha', 'highAlpha', 'lowBeta', 'highBeta', 'lowGamma', 'midGamma', 'poorSignal', 'blinkStrength' ,'label']
    writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
    writer.writeheader()
    i = time()
    j = time()
    print "Action 1 = truth"
    while(j-i<140):
    	writer.writerow({'attention': neuropy.attention, 'delta': neuropy.delta, 
    		'meditation': neuropy.meditation, 'rawValue': neuropy.rawValue, 
    		'theta': neuropy.theta, 'lowAlpha': neuropy.lowAlpha, 'highAlpha': neuropy.highAlpha, 
    		'lowBeta': neuropy.lowBeta, 'highBeta': neuropy.highBeta, 
    		'lowGamma' : neuropy.lowGamma, 'midGamma' : neuropy.midGamma, 
    		'poorSignal' : neuropy.poorSignal, 'blinkStrength': neuropy.blinkStrength, 'label': '1'})
        sleep(0.1)
        j = time()
    
csvfile.close()
neuropy.stop()

"""
 #To connect headset to laptop
#sudo rfcomm bind /dev/rfcomm1 74:E5:43:D5:6C:07
#ls -l /dev/rfcomm1


 
コード例 #7
0
ファイル: neuro.py プロジェクト: jaywon/horny-unicorn
from NeuroPy import NeuroPy
object1=NeuroPy("/dev/rfcomm0") #If port not given 57600 is automatically assumed
                        #object1=NeuroPy("/dev/rfcomm0") for linux
def attention_callback(attention_value):
    "this function will be called everytime NeuroPy has a new value for attention"
    print ("Value of attention is",attention_value)
    #do other stuff (fire a rocket), based on the obtained value of attention_value
    #do some more stuff
    return None

def blink_callback(blink_value):
    "this function will be called everytime NeuroPy has a new value for blink"
    print ("Value of blinks is",blink_value)
    #do other stuff (fire a rocket), based on the obtained value of attention_value
    #do some more stuff
    return None

#set call back:
object1.setCallBack("attention",attention_callback)
object1.setCallBack("blink", blink_callback)

#set call back:
object1.setCallBack("meditation",attention_callback)

#call start method
object1.start()

while True:
    if(object1.meditation>70): #another way of accessing data provided by headset (1st being call backs)
        object1.stop()         #if meditation level reaches above 70, stop fetching data from the headset
コード例 #8
0
class BrainWindow(QWidget):
	def __init__(self, parent=None, sensorNUmber=0): #sensorNUmber - rfcomm port number - 0 for rfcomm0 etc
		super(BrainWindow, self).__init__(parent)
		
		self.sensorNUmber = sensorNUmber
		self.setWindowTitle(u"Mindwave"+str(self.sensorNUmber))
		
		layout = QGridLayout()
		layout.addWidget(QLabel("Value"),0,1)
		layout.addWidget(QLabel("Min"),0,2)
		layout.addWidget(QLabel("Max"),0,3)
		layout.addWidget(QLabel("Relative"),0,4)
		
		layout.addWidget(QLabel("Attention:"),1,0)
		layout.addWidget(QLabel("Poor signal:"),1,2)
		layout.addWidget(QLabel("Low beta"),2,0)
		layout.addWidget(QLabel("High beta"),3,0)
		layout.addWidget(QLabel("Low gamma"),4,0)
		layout.addWidget(QLabel("Mid gamma"),5,0)
		layout.addWidget(QLabel("Raw data:"),6,0)
		
		self.attentionLabel = QLabel()
		layout.addWidget(self.attentionLabel,1,1)
		
		self.poorSignalLabel = QLabel()
		layout.addWidget(self.poorSignalLabel,1,3)
		
		self.lBetaLabel = QLabel()
		self.lBetaMinLabel = QLabel()
		self.lBetaMaxLabel = QLabel()
		self.lBetaRelLabel = QLabel()
		layout.addWidget(self.lBetaLabel,2,1)
		layout.addWidget(self.lBetaMinLabel,2,2)
		layout.addWidget(self.lBetaMaxLabel,2,3)
		layout.addWidget(self.lBetaRelLabel,2,4)
		
		self.hBetaLabel = QLabel()
		self.hBetaMinLabel = QLabel()
		self.hBetaMaxLabel = QLabel()
		self.hBetaRelLabel = QLabel()
		layout.addWidget(self.hBetaLabel,3,1)
		layout.addWidget(self.hBetaMinLabel,3,2)
		layout.addWidget(self.hBetaMaxLabel,3,3)
		layout.addWidget(self.hBetaRelLabel,3,4)
		
		self.lGammaLabel = QLabel()
		self.lGammaMinLabel = QLabel()
		self.lGammaMaxLabel = QLabel()
		self.lGammaRelLabel = QLabel()
		layout.addWidget(self.lGammaLabel,4,1)
		layout.addWidget(self.lGammaMinLabel,4,2)
		layout.addWidget(self.lGammaMaxLabel,4,3)
		layout.addWidget(self.lGammaRelLabel,4,4)
		
		self.mGammaLabel = QLabel()
		self.mGammaMinLabel = QLabel()
		self.mGammaMaxLabel = QLabel()
		self.mGammaRelLabel = QLabel()
		layout.addWidget(self.mGammaLabel,5,1)
		layout.addWidget(self.mGammaMinLabel,5,2)
		layout.addWidget(self.mGammaMaxLabel,5,3)
		layout.addWidget(self.mGammaRelLabel,5,4)
		
		
		
		
		#stop
		stopButton = QPushButton("Stop")
		stopButton.clicked.connect(self.stop)
		layout.addWidget(stopButton,7,0)
		
		self.setLayout(layout)
		
		
		self.headSet = NeuroPy("/dev/rfcomm"+str(sensorNUmber),57600)
		self.headSet.setCallBack("attention",self.attention_callback)
		self.headSet.setCallBack("lowBeta",self.lowBeta_callback)
		self.headSet.setCallBack("highBeta",self.highBeta_callback)
		self.headSet.setCallBack("lowGamma",self.lowGamma_callback)
		self.headSet.setCallBack("midGamma",self.midGamma_callback)
		self.headSet.setCallBack("rawValue",self.rawValue_callback)
		self.headSet.setCallBack("poorSignal",self.poorSignal_callback)
		self.headSet.start()
		
		self.highLimit = 100000 # ignore occasional  higher values from EEG data
		self.lowLimit = 100
		
		self.lBetamin = 10000
		self.lBetamax = 0.1
		self.lBetarelative = 0
		self.hBetamin = 10000
		self.hBetamax = 0.1
		self.hBetarelative = 0
		self.lGammamin = 10000
		self.lGammamax = 0.1
		self.lGammarelative = 0
		self.mGammamin = 10000
		self.mGammamax = 0.1
		self.mGammarelative = 0
		
		
		
	def __del__(self):
		self.stop()
	
	def stop(self):
		self.headSet.stop()
		#self.perf.Stop()
		#self.perf.Join()
		#self.cs.Stop()
	
	#TEMPORARY -delete later
	
		
	
	def lowBeta_callback(self, value):
		#print "Low beta: ", value
		if (value>self.highLimit or value<self.lowLimit): # don't handle occasional high values
			return
		self.lBetaLabel.setText(str(value))
		if (value<self.lBetamin and value!=0):
			self.lBetamin = value
			self.lBetaMinLabel.setText(str(value))
		if (value>self.lBetamax):
			self.lBetamax = value
			self.lBetaMaxLabel.setText(str(value))
		self.lBetarelative = float(value-self.lBetamin)/(self.lBetamax-self.lBetamin+1)
		self.lBetaRelLabel.setText(str(self.lBetarelative))
		sendUdpMessage("sensor,lb"+str(self.sensorNUmber+1)+","+str(self.lBetarelative))

		#self.cs.SetChannel("lowBetaRelative",self.lBetarelative)		
		return None
	
	def highBeta_callback(self, value):
		#print "high beta: ", value
		if (value>self.highLimit or value<self.lowLimit): # don't handle occasional high values
			return
		self.hBetaLabel.setText(str(value))
		if (value<self.hBetamin and value!=0):
			self.hBetamin = value
			self.hBetaMinLabel.setText(str(value))
		if (value>self.hBetamax):
			self.hBetamax = value
			self.hBetaMaxLabel.setText(str(value))
		self.hBetarelative = float(value-self.hBetamin)/(self.hBetamax-self.hBetamin+1)
		self.hBetaRelLabel.setText(str(self.hBetarelative))
		sendUdpMessage("sensor,hb"+str(self.sensorNUmber+1)+","+str(self.hBetarelative))
		#self.cs.SetChannel("highBetaRelative",self.hBetarelative)		
		return None
	
	def lowGamma_callback(self, value):
		#print "Low gamma: ", value
		if (value>self.highLimit or value<self.lowLimit): # don't handle occasional high values
			return
		self.lGammaLabel.setText(str(value))
		if (value<self.lGammamin and value!=0):
			self.lGammamin = value
			self.lGammaMinLabel.setText(str(value))
		if (value>self.lGammamax):
			self.lGammamax = value
			self.lGammaMaxLabel.setText(str(value))
		self.lGammarelative = float(value-self.lGammamin)/(self.lGammamax-self.lGammamin+1)
		self.lGammaRelLabel.setText(str(self.lGammarelative))
		#self.cs.SetChannel("lowBetaRelative",self.lGammarelative)		
		return None
	
	def midGamma_callback(self, value):
		#print "mid gamma: ", value
		if (value>self.highLimit or value<self.lowLimit): # don't handle occasional high values
			return
		self.mGammaLabel.setText(str(value))
		if (value<self.mGammamin and value!=0):
			self.mGammamin = value
			self.mGammaMinLabel.setText(str(value))
		if (value>self.mGammamax):
			self.mGammamax = value
			self.mGammaMaxLabel.setText(str(value))
		self.mGammarelative = float(value-self.mGammamin)/(self.mGammamax-self.mGammamin+1)
		self.mGammaRelLabel.setText(str(self.mGammarelative))
		#self.cs.SetChannel("midmGammaRelative",self.mGammarelative)		
		return None
	
	def attention_callback(self, value):
		#print "Attention: ",value
		self.attentionLabel.setText(str(value))
		sendUdpMessage("sensor,attention"+str(self.sensorNUmber+1)+","+str(float(value)/100))
		#self.cs.SetChannel("attention",value)
		return None
	
	def rawValue_callback(self, value):
		#this is very fast don't print this 
		#print "rawValue: ", value
		#self.cs.SetChannel("rawValue",value)
		if (abs(value)<1000):
			sendUdpMessage("sensor,raw"+str(self.sensorNUmber+1)+","+str(value))
		return None
	
	def poorSignal_callback(self,value):
		print "headset: ",self.sensorNUmber,"poor signal: ",value
		self.poorSignalLabel.setText(str(value))
コード例 #9
0
            high_beta = mindwave.high_beta
            meditation = mindwave.meditation
            if response:
                jsonlist.append(response)
                if len(jsonlist) == 2:
                    z = {jsonlist[0]: jsonlist[1]}
                    jsonlist1.append(z)
                    jsonlist.clear()
            if len(jsonlist1) == 8:
                jsonlist1.insert(0, {"Time": now_time})
                jsonlist1.append({"low_alpha": low_alpha})
                jsonlist1.append({"high_alpha": high_alpha})
                jsonlist1.append({"low_beta": low_beta})
                jsonlist1.append({"high_beta": high_beta})
                jsonlist1.append({"meditation": meditation})
                jd = json.dumps(jsonlist1)
                print(jd)
                jsonlist1.clear()
                r.lpush("test", jd)
                PostRequest(jd)
                ser.flushOutput()
                ser.flushInput()
                # pass

    except KeyboardInterrupt:
        print('KeyboardInterrupt')
        mindwave.stop()
        ser.close()
    except Exception as e:
        print(f'f****d {e}')
コード例 #10
0
#t_end = time.time() + 60 * 1 to define time for the while-loop if needed

print 'Are you ready to break a spoon bitch !!!'
a = input('Shall we continue sucker ?')
#request a keyboard input, which is '' to continue with the script
#this is done to allow time for the servo to go to the initial position

try:
    while True:

        if object1.attention > 40:
            #this statement tells the arduino to start moving the motor if
            #attention level is over 40 (attention level varies 0-100)
            ser.write('5')
            time.sleep(0.5)
            #0.5s time delay to make consistent and smooth movement of the motor
            print object1.attention
        else:
            #this statement tells the arduino to stop moving the motor if
            # attention level is bellow the threshold
            time.sleep(0.5)
            # another time delay for consistency
            ser.write('2')
            print object1.attention

except KeyboardInterrupt:

    #this is set so that if the script is stopped both ports are closed
    ser.close()
    object1.stop()
コード例 #11
0
class MindwaveTracker:
    com = "COM16"

    time_last_notified = time.clock()
    MAX_ZERO_VALUES_BEFORE_WARNING = 10
    attention_value = 0
    meditation_value = 0
    poorSignal = 0
    blinkStrength = 0
    index = 0
    aantal_avg = 0
    interval = 0
    teller_duration_iteration_sec = 0.0
    datetime_from = datetime.datetime.today()
    teller_zero_values = 0
    mindwave_instance = None

    def __init__(self, aantal_avg, interval, com_port_mindwave):
        self.aantal_avg = aantal_avg
        self.interval = interval
        self.com = com_port_mindwave
        self.mindwave_instance = NeuroPy(self.com)
        self.mindwave_instance.start()

    def notify(self):
        time_now = time.clock()
        duration_iteration_sec = time_now - self.time_last_notified
        self.time_last_notified = time.clock()
        self.teller_duration_iteration_sec += duration_iteration_sec
        if self.teller_duration_iteration_sec >= self.interval:
            self.teller_duration_iteration_sec = 0.0
            self.record_measurement()

    def record_measurement(self):
        print str(
            str('attention: ' + str(self.mindwave_instance.attention)) + '\t' +
            str('meditation: ' + str(self.mindwave_instance.meditation)))
        if (self.index == self.aantal_avg):
            print str('avg attention: ' +
                      str(float(self.attention_value / self.aantal_avg)))
            average_attention = float(
                self.attention_value / self.aantal_avg) / 100
            average_meditation = float(
                self.meditation_value / self.aantal_avg) / 100
            average_poorSignal = float(self.poorSignal / self.aantal_avg)
            average_blinkStrength = float(self.blinkStrength / self.aantal_avg)
            datetime_to = datetime.datetime.today()
            DAMindwave_SQLite.insert_row_mindwave(
                self.datetime_from, datetime_to, average_attention,
                average_meditation, average_poorSignal, average_blinkStrength)

            self.attention_value = self.mindwave_instance.attention
            self.meditation_value = self.mindwave_instance.meditation
            self.poorSignal = self.mindwave_instance.poorSignal
            self.blinkStrength = self.mindwave_instance.blinkStrength

            self.index = 1
            self.datetime_from = datetime.datetime.today()

        else:
            if self.mindwave_instance.attention != 0 and self.mindwave_instance.meditation != 0:
                self.attention_value += self.mindwave_instance.attention
                self.meditation_value += self.mindwave_instance.meditation
                self.poorSignal += self.mindwave_instance.poorSignal
                self.blinkStrength += self.mindwave_instance.blinkStrength

                self.index += 1
            else:
                self.teller_zero_values += 1
                if self.teller_zero_values == self.MAX_ZERO_VALUES_BEFORE_WARNING:
                    tkMessageBox.showinfo(
                        title="Warning",
                        message=
                        "The attention and meditation values are 0 for a long time. Possible problem with the device"
                    )
                    self.teller_zero_values = 0

    def stop_device(self):
        try:
            self.mindwave_instance.stop()
        except Exception, e:
            raise Exception(e)
コード例 #12
0
ファイル: lihas_demo.py プロジェクト: LazaUK/NeuroPy-MindBand
from NeuroPy import NeuroPy

object1 = NeuroPy("COM6") #If baud rate not given, it's set automatically 

def attention_callback(attention_value): 
"called everytime NeuroPy has a new value for attention" 
    print("Value of attention is", attention_value)
    #do some more stuff 
    return None 

#set call back: 
object1.setCallBack("attention",attention_callback) 

#call start method 
object1.start() 

while True: 
    if(object1.meditation > 70): #another way of accessing headset data (1st being callbacks)
        object1.stop() #if meditation level reaches above 70, stop fetching data
コード例 #13
0
class BrainWindow(QWidget):
    def __init__(self,
                 parent=None,
                 sensorNUmber=0
                 ):  #sensorNUmber - rfcomm port number - 0 for rfcomm0 etc
        super(BrainWindow, self).__init__(parent)

        self.sensorNUmber = sensorNUmber
        self.setWindowTitle(u"Mindwave " + str(self.sensorNUmber + 1))

        layout = QGridLayout()
        layout.addWidget(QLabel("Value"), 0, 1)
        layout.addWidget(QLabel("Min"), 0, 2)
        layout.addWidget(QLabel("Max"), 0, 3)
        layout.addWidget(QLabel("Relative"), 0, 4)

        layout.addWidget(QLabel("Attention:"), 1, 0)
        layout.addWidget(QLabel("Poor signal:"), 1, 2)
        layout.addWidget(QLabel("Low beta"), 2, 0)
        layout.addWidget(QLabel("High beta"), 3, 0)
        layout.addWidget(QLabel("Low gamma"), 4, 0)
        layout.addWidget(QLabel("Mid gamma"), 5, 0)
        layout.addWidget(QLabel("Raw data:"), 6, 0)

        self.attentionLabel = QLabel()
        layout.addWidget(self.attentionLabel, 1, 1)

        self.poorSignalLabel = QLabel()
        layout.addWidget(self.poorSignalLabel, 1, 3)

        self.lBetaLabel = QLabel()
        self.lBetaMinLabel = QLabel()
        self.lBetaMaxLabel = QLabel()
        self.lBetaRelLabel = QLabel()
        layout.addWidget(self.lBetaLabel, 2, 1)
        layout.addWidget(self.lBetaMinLabel, 2, 2)
        layout.addWidget(self.lBetaMaxLabel, 2, 3)
        layout.addWidget(self.lBetaRelLabel, 2, 4)

        self.hBetaLabel = QLabel()
        self.hBetaMinLabel = QLabel()
        self.hBetaMaxLabel = QLabel()
        self.hBetaRelLabel = QLabel()
        layout.addWidget(self.hBetaLabel, 3, 1)
        layout.addWidget(self.hBetaMinLabel, 3, 2)
        layout.addWidget(self.hBetaMaxLabel, 3, 3)
        layout.addWidget(self.hBetaRelLabel, 3, 4)

        self.lGammaLabel = QLabel()
        self.lGammaMinLabel = QLabel()
        self.lGammaMaxLabel = QLabel()
        self.lGammaRelLabel = QLabel()
        layout.addWidget(self.lGammaLabel, 4, 1)
        layout.addWidget(self.lGammaMinLabel, 4, 2)
        layout.addWidget(self.lGammaMaxLabel, 4, 3)
        layout.addWidget(self.lGammaRelLabel, 4, 4)

        self.mGammaLabel = QLabel()
        self.mGammaMinLabel = QLabel()
        self.mGammaMaxLabel = QLabel()
        self.mGammaRelLabel = QLabel()
        layout.addWidget(self.mGammaLabel, 5, 1)
        layout.addWidget(self.mGammaMinLabel, 5, 2)
        layout.addWidget(self.mGammaMaxLabel, 5, 3)
        layout.addWidget(self.mGammaRelLabel, 5, 4)

        #stop
        stopButton = QPushButton("Stop")
        stopButton.clicked.connect(self.stop)
        layout.addWidget(stopButton, 7, 0)

        self.setLayout(layout)

        self.headSet = NeuroPy("/dev/rfcomm" + str(sensorNUmber), 57600)
        self.headSet.setCallBack("attention", self.attention_callback)
        self.headSet.setCallBack("lowBeta", self.lowBeta_callback)
        self.headSet.setCallBack("highBeta", self.highBeta_callback)
        self.headSet.setCallBack("lowGamma", self.lowGamma_callback)
        self.headSet.setCallBack("midGamma", self.midGamma_callback)
        self.headSet.setCallBack("rawValue", self.rawValue_callback)
        self.headSet.setCallBack("poorSignal", self.poorSignal_callback)
        self.headSet.start()

        self.highLimit = 100000  # ignore occasional  higher values from EEG data
        self.lowLimit = 100

        self.lBetamin = 10000
        self.lBetamax = 0.1
        self.lBetarelative = 0
        self.hBetamin = 10000
        self.hBetamax = 0.1
        self.hBetarelative = 0
        self.lGammamin = 10000
        self.lGammamax = 0.1
        self.lGammarelative = 0
        self.mGammamin = 10000
        self.mGammamax = 0.1
        self.mGammarelative = 0

    def __del__(self):
        self.stop()

    def stop(self):
        self.headSet.stop()
        #self.perf.Stop()
        #self.perf.Join()
        #self.cs.Stop()

    #TEMPORARY -delete later

    def lowBeta_callback(self, value):
        #print "Low beta: ", value
        if (value > self.highLimit or
                value < self.lowLimit):  # don't handle occasional high values
            return
        self.lBetaLabel.setText(str(value))
        if (value < self.lBetamin and value != 0):
            self.lBetamin = value
            self.lBetaMinLabel.setText(str(value))
        if (value > self.lBetamax):
            self.lBetamax = value
            self.lBetaMaxLabel.setText(str(value))
        self.lBetarelative = float(value - self.lBetamin) / (self.lBetamax -
                                                             self.lBetamin + 1)
        self.lBetaRelLabel.setText(str(self.lBetarelative))
        sendUdpMessage("sensor,lb" + str(self.sensorNUmber + 1) + "," +
                       str(self.lBetarelative))

        #self.cs.SetChannel("lowBetaRelative",self.lBetarelative)
        return None

    def highBeta_callback(self, value):
        #print "high beta: ", value
        if (value > self.highLimit or
                value < self.lowLimit):  # don't handle occasional high values
            return
        self.hBetaLabel.setText(str(value))
        if (value < self.hBetamin and value != 0):
            self.hBetamin = value
            self.hBetaMinLabel.setText(str(value))
        if (value > self.hBetamax):
            self.hBetamax = value
            self.hBetaMaxLabel.setText(str(value))
        self.hBetarelative = float(value - self.hBetamin) / (self.hBetamax -
                                                             self.hBetamin + 1)
        self.hBetaRelLabel.setText(str(self.hBetarelative))
        sendUdpMessage("sensor,hb" + str(self.sensorNUmber + 1) + "," +
                       str(self.hBetarelative))
        #self.cs.SetChannel("highBetaRelative",self.hBetarelative)
        return None

    def lowGamma_callback(self, value):
        #print "Low gamma: ", value
        if (value > self.highLimit or
                value < self.lowLimit):  # don't handle occasional high values
            return
        self.lGammaLabel.setText(str(value))
        if (value < self.lGammamin and value != 0):
            self.lGammamin = value
            self.lGammaMinLabel.setText(str(value))
        if (value > self.lGammamax):
            self.lGammamax = value
            self.lGammaMaxLabel.setText(str(value))
        self.lGammarelative = float(value - self.lGammamin) / (
            self.lGammamax - self.lGammamin + 1)
        self.lGammaRelLabel.setText(str(self.lGammarelative))
        #self.cs.SetChannel("lowBetaRelative",self.lGammarelative)
        return None

    def midGamma_callback(self, value):
        #print "mid gamma: ", value
        if (value > self.highLimit or
                value < self.lowLimit):  # don't handle occasional high values
            return
        self.mGammaLabel.setText(str(value))
        if (value < self.mGammamin and value != 0):
            self.mGammamin = value
            self.mGammaMinLabel.setText(str(value))
        if (value > self.mGammamax):
            self.mGammamax = value
            self.mGammaMaxLabel.setText(str(value))
        self.mGammarelative = float(value - self.mGammamin) / (
            self.mGammamax - self.mGammamin + 1)
        self.mGammaRelLabel.setText(str(self.mGammarelative))
        #self.cs.SetChannel("midmGammaRelative",self.mGammarelative)
        return None

    def attention_callback(self, value):
        #print "Attention: ",value
        self.attentionLabel.setText(str(value))
        sendUdpMessage("sensor,attention" + str(self.sensorNUmber + 1) + "," +
                       str(float(value) / 100))
        #self.cs.SetChannel("attention",value)
        return None

    def rawValue_callback(self, value):
        #this is very fast don't print this
        #print "rawValue: ", value
        #self.cs.SetChannel("rawValue",value)
        if (abs(value) < 1000):
            sendUdpMessage("sensor,raw" + str(self.sensorNUmber + 1) + "," +
                           str(value))
        return None

    def poorSignal_callback(self, value):
        print "headset: ", self.sensorNUmber, "poor signal: ", value
        self.poorSignalLabel.setText(str(value))
コード例 #14
0
ファイル: test.py プロジェクト: johnmelodyme/EEG_FYP
    volume.pop(0)
    med.update(value)
    med.refresh()
    med.update(-value)
    value = 0
    for v in volume:
        value = value + v
    value = value / len(volume)

    os.system("amixer sset 'Master' " + str(value) + "% > /dev/null")
    #do other stuff (fire a rocket), based on the obtained value of attention_value
    #do some more stuff
    return None

def blink_cb(value):
    print("Blink ", value)

#set call back:
object1.setCallBack("attention",attention_callback)
object1.setCallBack("meditation",meditation_callback)
object1.setCallBack("blinkStrength",blink_cb)
#call start method
object1.start()

try:
    while True:
        time.sleep(0.5)
except:
    print("exit")
    object1.stop();