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)
	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
from MindwaveDataPointReader import MindwaveDataPointReader
from MindwaveDataPoints import AttentionDataPoint
from MindwaveDataPoints import DataPoint

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:
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
示例#5
0
#xs = []
#ys = []
#for line in lines:
#   if len(line) > 1:
#      x, y = line.split(',')
#     xs.append(float(x))
#    ys.append(float(y))
#ax1.clear()
#print("HEY YOU GUYS")
#print(dataPoint)
#print(type(dataPoint))
#ax1.plot(time, dataPoint)
#print("sup")

if __name__ == '__main__':
    mindwaveDataPointReader = MindwaveDataPointReader()
    mindwaveDataPointReader.start()
    file = open("out.csv", "w")
    cr = csv.writer(file, delimiter=";", lineterminator="\n")
    cr.writerow([
        "highAlpha", "lowAlpha", "highBeta", "lowBeta", "midGamma", "lowGamma",
        "delta", "theta"
    ])
    style.use('fivethirtyeight')
    dataA1 = []
    dataA2 = []
    dataB1 = []
    dataB2 = []
    dataG1 = []
    dataG2 = []
    dataD = []