def get_data(q):

    mindwaveDataPointReader = MindwaveDataPointReader()
    mindwaveDataPointReader.start()

    data = []
    while (1):

        dataPoint = mindwaveDataPointReader.readNextDataPoint()

        if (dataPoint.__class__ is RawDataPoint):
            data.append(dataPoint)
            q.put(data)
gpio.setmode(gpio.BOARD)
Motor1A = 35
Motor1B = 36
Motor2A = 38
Motor2B = 40
gpio.setup(Motor1A, gpio.OUT)
gpio.setup(Motor1B, gpio.OUT)
gpio.setup(Motor2A, gpio.OUT)
gpio.setup(Motor2B, gpio.OUT)

if __name__ == '__main__':
    mindwaveDataPointReader = MindwaveDataPointReader()
    mindwaveDataPointReader.start()
    
    while(True):
        dataPoint = mindwaveDataPointReader.readNextDataPoint()
        if (dataPoint.__class__.__name__=='AttentionDataPoint'):
		if (int(dataPoint) > 60):
			print (dataPoint)
			print "Threshold reached! You are moving."
			gpio.output(Motor1A,gpio.HIGH)
			gpio.output(Motor1B,gpio.LOW)
			gpio.output(Motor2A,gpio.HIGH)
			gpio.output(Motor2B,gpio.LOW)
			time.sleep(2)
			#break
		else:
			print(dataPoint)
			print "Sorry!You are not concentrating."
			gpio.output(Motor1A,gpio.LOW)
			gpio.output(Motor1B,gpio.LOW)
class CtrlRecolectarDatos:
	def __init__(self,login):

		self.__login=login
		self.__datos=None
		self.__neuroSky = MindwaveDataPointReader()
		self.__neuroSkyDatos=None
		self.__senal=None
		
		self.__bd=BaseDatos()
		self.__evento=None

	def conectarNeuroSky(self):
		data={"delta":-1,"tetha":-1,"lowAlpha":-1,"highAlpha":-1,"lowBeta":-1,"highBeta":-1,"lowGamma":-1,"midGamma":-1,"meditacion":-1,"atencion":-1,"id_letras":self.__datos.getIdLetra(),"id_usuario":self.__login.getId(),"ruido":-1}
		k=i=0
		self.__neuroSky.start()
		self.__neuroSkyDatos=self.__neuroSky.readNextDataPoint()
		if self.__neuroSky.isConnected():
			print("Conectado...")
			self.__datos.setConectado(True)
			self.__senal=None
			while(True):
				self.__neuroSkyDatos=self.__neuroSky.readNextDataPoint()
				if (not self.__neuroSkyDatos.__class__ is RawDataPoint):
					#print(self.__neuroSkyDatos)
					if self.__datos.getEstado():
						data["id_usuario"] =self.__login.getId()
						data["id_letras"]=self.__datos.getIdLetra()
						if (i == 0):
							data["meditacion"]=(float(self.__neuroSkyDatos.meditationValue))
							self.__datos.setMeditacion(float(self.__neuroSkyDatos.meditationValue))

						elif (i == 1):
							data["atencion"]=(float(self.__neuroSkyDatos.attentionValue))
							self.__datos.setAtencion(float(self.__neuroSkyDatos.attentionValue))

						elif (i == 2):
							data["delta"]=(float(self.__neuroSkyDatos.delta))
							self.__datos.setDelta(float(self.__neuroSkyDatos.delta))

							data["tetha"]=(float(self.__neuroSkyDatos.theta))
							self.__datos.setTheta(float(self.__neuroSkyDatos.theta))

							data["lowAlpha"]=(float(self.__neuroSkyDatos.lowAlpha))
							self.__datos.setLowAlpha(float(self.__neuroSkyDatos.lowAlpha))

							data["highAlpha"]=(float(self.__neuroSkyDatos.highAlpha))
							self.__datos.setHighAlpha(float(self.__neuroSkyDatos.lowAlpha))

							data["lowBeta"]=(float(self.__neuroSkyDatos.lowBeta))
							self.__datos.setLowBeta(float(self.__neuroSkyDatos.lowAlpha))

							data["highBeta"]=(float(self.__neuroSkyDatos.highBeta))
							self.__datos.setHighBeta(float(self.__neuroSkyDatos.lowAlpha))

							data["lowGamma"]=(float(self.__neuroSkyDatos.lowGamma))
							self.__datos.setLowGamma(float(self.__neuroSkyDatos.lowGamma))

							data["midGamma"]=(float(self.__neuroSkyDatos.midGamma))
							self.__datos.setMidGamma(float(self.__neuroSkyDatos.midGamma))
						elif (i == 3):

							self.__senal=float(self.__neuroSkyDatos.amountOfNoise)
							self.__datos.setRuido(self.__senal)
							self.__datos.setEstado(False)
							data["ruido"]=self.__senal
							#Insertando el valor de las ondas en la bd
							if not self.__datos.getProbando():
								self.__bd.insertarStreamOndas(data)
							print("*"*30)
							print(data)
							print("*"*30)
							self.__evento.set()
							if (self.__senal == 0):
								print(data)
							else:
								print("WARNING [hay mucho ruido]: %s")%self.__senal
						else:
							i = 0
							#data = []

							data["meditacion"]=float(self.__neuroSkyDatos.meditationValue)
						i = i + 1;
						#if k==3*50:
						#	break
						#k=k+1
		else:
			print("No se pudo conectar intente de nuevo...")
			self.__leerDatos.setConectado(False)
		print(data)
	def setDatos(self,datos):
		self.__datos=datos
	def setEvento(self,evento):
		self.__evento=evento
示例#4
0
    df = plt.figure()
    d = df.gca()
    d.set_title("Delta")

    tf = plt.figure()
    t = tf.gca()
    t.set_title("Theta")
    fig.legend(
        (ax1, ax2, bx1, bx2, gx1, gx2, d, t),
        ("highA", "lowA", "highB", "lowB", "highG", "lowG", "delta", "theta"))
    #ax1.xaxis_date()

    count = 0

    while (count < 100):
        dataPoint = mindwaveDataPointReader.readNextDataPoint()
        if (dataPoint.__class__ is EEGPowersDataPoint):
            print(dataPoint.highAlpha)
            print(type(dataPoint.highAlpha))
            #ani = animation.FuncAnimation(fig, animate(now, dataPoint.highAlpha), interval=1000)
            print("sfhsdk")
            dataA1.append(dataPoint.highAlpha)
            dataA2.append(dataPoint.lowAlpha)
            dataB1.append(dataPoint.highBeta)
            dataB2.append(dataPoint.lowBeta)
            dataG1.append(dataPoint.midGamma)
            dataG2.append(dataPoint.lowGamma)
            dataD.append(dataPoint.delta)
            dataT.append(dataPoint.theta)
            cr.writerow([
                dataPoint.highAlpha, dataPoint.lowAlpha, dataPoint.highBeta,