def main(CyINIT): if 'CyINIT' not in locals(): # global CyINIT CyINIT = 2 CyINIT += 1 HOST = str(sys.argv[1]) PORT = int(sys.argv[2]) MODEL = int(sys.argv[3]) # Initialize CyKIT if CyINIT == 2: global ioTHREAD print "> Listening on " + HOST + " : " + str(PORT) print "> Trying Key Model #: " + str(MODEL) myi = eeg.MyIO() ioTHREAD = CyWebSocket.socketIO(PORT, 1, myi) myi.setServer(ioTHREAD) check_connection = ioTHREAD.Connect() cyIO = ioTHREAD.start() cyHeadset = eeg.EEG(MODEL, myi, str(sys.argv[4])).start() for t in threading.enumerate(): print str(t.getName()) CyINIT += 1 # Loop. while CyINIT > 2: CyINIT += 1 if CyINIT > 100: modelCheck = myi.modelChange() if modelCheck != 0: MODEL = modelCheck CyINIT = 3 check_threads = 0 for t in threading.enumerate(): if t.getName() == "ioThread" or t.getName() == "eegThread": check_threads += 1 if check_threads == 1: ioTHREAD.onClose() print "*** Reseting . . ." CyINIT = 1 main(1)
def main(CyINIT): # obtain global CyINIT CyINIT = locals().get('CyINIT', 2) CyINIT += 1 HOST = str(sys.argv[1]) PORT = int(sys.argv[2]) MODEL = int(sys.argv[3]) # Initialize CyKIT if CyINIT == 2: global ioTHREAD # FIXME print('> Listening on {host}:{port}'.format(host=HOST, port=PORT)) print("> Probing Key Model #: {model}".format(model=MODEL)) myi = eeg.MyIO() ioTHREAD = CyWebSocket.socketIO(PORT, 1, myi) myi.setServer(ioTHREAD) check_connection = ioTHREAD.Connect() cyIO = ioTHREAD.start() cyHeadset = eeg.EEG(MODEL, myi, str(sys.argv[4])).start() for t in threading.enumerate(): print(str(t.getName())) CyINIT += 1 # Loop. while CyINIT > 2: CyINIT += 1 if CyINIT > 100: modelCheck = myi.modelChange() # FIXME if modelCheck != 0: MODEL = modelCheck CyINIT = 3 check_threads = 0 for t in threading.enumerate(): if t.getName() == "ioThread" or t.getName() == "eegThread": check_threads += 1 if check_threads == 1: ioTHREAD.onClose() print("*** Reseting . . .") CyINIT = 1 main(1)
def main(CyINIT): parameters = str(sys.argv[4]).lower() if 'CyINIT' not in locals(): #global CyINIT CyINIT = 2 CyINIT += 1 HOST = str(sys.argv[1]) PORT = int(sys.argv[2]) MODEL = int(sys.argv[3]) # Initialize CyKIT if CyINIT == 2: global ioTHREAD print "> Listening on " + HOST + " : " + str(PORT) print "> Trying Key Model #: " + str(MODEL) myi = eeg.MyIO() if "noheader" in parameters: myi.setHeader(True) if "openvibe" in parameters: myi.setOpenvibe(True) if "generic" in parameters: ioTHREAD = CyWebSocket.socketIO(PORT, 0, myi) else: ioTHREAD = CyWebSocket.socketIO(PORT, 1, myi) myi.setServer(ioTHREAD) check_connection = ioTHREAD.Connect() cyIO = ioTHREAD.start() cyHeadset = eeg.EEG(MODEL, myi, parameters).start() for t in threading.enumerate(): print str(t.getName()) CyINIT += 1 if myi.getOpenvibe() == True: time.sleep(3) while CyINIT > 2: CyINIT += 1 if CyINIT > 1000: modelCheck = myi.modelChange() if modelCheck != 0: MODEL = modelCheck CyINIT = 3 check_threads = 0 #print "testing" for t in threading.enumerate(): if t.getName() == "ioThread" or t.getName() == "eegThread": check_threads += 1 if myi.getOpenvibe() == True: if check_threads == 0: ioTHREAD.onClose() print "*** Reseting . . ." CyINIT = 1 main(1) continue if check_threads == 1: ioTHREAD.onClose() print "*** Reseting . . ." CyINIT = 1 main(1)
def main(CyINIT): HOST = str(sys.argv[1]) PORT = int(sys.argv[2]) MODEL = int(sys.argv[3]) check_connection = None parameters = str(sys.argv[4]).lower() # Stage 1. # ¯¯¯¯¯¯¯¯¯¯¯ # Acquire I/O Object. # ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ cy_IO = eeg.ControllerIO() cy_IO.setInfo("ioObject", cy_IO) cy_IO.setInfo("config", parameters) if "verbose" in parameters: cy_IO.setInfo("verbose", "True") else: cy_IO.setInfo("verbose", "False") if "noweb" in parameters: noweb = True cy_IO.setInfo("noweb", "True") cy_IO.setInfo("status", "True") else: noweb = False cy_IO.setInfo("noweb", "False") if "noheader" in parameters: cy_IO.setInfo("noheader", "True") if "openvibe" in parameters: cy_IO.setInfo("openvibe", "True") headset = eeg.EEG(MODEL, cy_IO, parameters) while str(cy_IO.getInfo("DeviceObject")) == "0": time.sleep(.001) continue if "bluetooth" in parameters: mirror("> [Bluetooth] Pairing Device . . .") else: if "noweb" not in parameters: mirror("> Listening on " + HOST + " : " + str(PORT)) mirror("> Trying Key Model #: " + str(MODEL)) if "generic" in parameters: ioTHREAD = CyWebSocket.socketIO(PORT, 0, cy_IO) else: ioTHREAD = CyWebSocket.socketIO(PORT, 1, cy_IO) cy_IO.setServer(ioTHREAD) time.sleep(1) check_connection = ioTHREAD.Connect() ioTHREAD.start() while eval(cy_IO.getInfo("status")) != True: time.sleep(.001) continue headset.start() if eval(cy_IO.getInfo("openvibe")) == True: time.sleep(3) CyINIT = 3 while CyINIT > 2: CyINIT += 1 time.sleep(.001) if (CyINIT % 10) == 0: check_threads = 0 t_array = str( list(map(lambda x: x.getName(), threading.enumerate()))) # if eval(cy_IO.getInfo("verbose")) == True: # mirror(" Active Threads :{ " + str(t_array) + " } ") # time.sleep(15) if 'ioThread' in t_array: check_threads += 1 if 'eegThread' in t_array: check_threads += 1 if eval(cy_IO.getInfo("openvibe")) == True: if check_threads == 0: ioTHREAD.onClose("CyKIT.main() 2") mirror("\r\n*** Reseting . . .") CyINIT = 1 main(1) continue # (1 if noweb == True else 2) if check_threads < (1 if noweb == True else 2): threadMax = 2 totalTries = 0 while threadMax > 1 and totalTries < 2: totalTries += 1 time.sleep(0) threadMax = 0 for t in threading.enumerate(): if "eegThread" in t.getName(): cy_IO.setInfo("status", "False") # mirror(t.getName()) if "ioThread" in t.getName(): # mirror(t.getName()) CyWebSocket.socketIO.stopThread(ioTHREAD) if "Thread-" in t.getName(): # mirror(t.getName()) threadMax += 1 try: t.abort() except: continue t_array = str( list(map(lambda x: x.getName(), threading.enumerate()))) # mirror(str(t_array)) ioTHREAD.onClose("CyKIT.main() 1") mirror("*** Reseting . . .") CyINIT = 1 main(1)
def main(): global cyHeadset myi = eeg.MyIO() parameters = "info+confirm" cyHeadset = eeg.EEG(6, myi, parameters)
def main(CyINIT): HOST = '127.0.0.1' PORT = 54123 MODEL = 6 check_connection = None #parameters = str(sys.argv[4]).lower() parameters = 'noweb' # Stage 1. # ¯¯¯¯¯¯¯¯¯¯¯ # Acquire I/O Object. # ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ cy_IO.setInfo("ioObject", cy_IO) cy_IO.setInfo("config", parameters) if "verbose" in parameters: cy_IO.setInfo("verbose","True") else: cy_IO.setInfo("verbose","False") if "noweb" in parameters: noweb = True cy_IO.setInfo("noweb","True") cy_IO.setInfo("status","True") else: noweb = False cy_IO.setInfo("noweb","False") if "noheader" in parameters: cy_IO.setInfo("noheader","True") if "openvibe" in parameters: cy_IO.setInfo("openvibe","True") headset = eeg.EEG(MODEL, cy_IO, parameters) while str(cy_IO.getInfo("DeviceObject")) == "0": time.sleep(.001) continue if "bluetooth" in parameters: mirror("> [Bluetooth] Pairing Device . . .") else: if "noweb" not in parameters: mirror("> Listening on " + HOST + " : " + str(PORT)) mirror("> Trying Key Model #: " + str(MODEL)) if "generic" in parameters: ioTHREAD = CyWebSocket.socketIO(PORT, 0, cy_IO) else: ioTHREAD = CyWebSocket.socketIO(PORT, 1, cy_IO) cy_IO.setServer(ioTHREAD) time.sleep(1) check_connection = ioTHREAD.Connect() ioTHREAD.start() while eval(cy_IO.getInfo("status")) != True: time.sleep(.001) continue headset.start() CyINIT = 3 #################################################################################### print("CONNECTED TO USB DONGLE") print("EPOC MODEL " + str(MODEL) + " needs to be ON") print("Caps Lock Toggles Recording EEG DATA") t = threading.Thread(target=keyboardListener) t.start() #################################################################################### while CyINIT > 2: #print('while CyINIT > 2:') CyINIT += 1 time.sleep(.001) if (CyINIT % 10) == 0: #print('if (CyINIT % 10) == 0:') check_threads = 0 t_array = str(list(map(lambda x: x.getName(), threading.enumerate()))) #if eval(cy_IO.getInfo("verbose")) == True: # mirror(" Active Threads :{ " + str(t_array) + " } ") #time.sleep(15) if 'ioThread' in t_array: check_threads += 1 if 'eegThread' in t_array: check_threads += 1 #(1 if noweb == True else 2) if check_threads < (1 if noweb == True else 2): #print('if check_threads < (1 if noweb == True else 2):') threadMax = 2 totalTries = 0 while threadMax > 1 and totalTries < 2: #print('while threadMax > 1 and totalTries < 2:') totalTries += 1 time.sleep(0) threadMax = 0 for t in threading.enumerate(): #print('for t in threading.enumerate():') if "eegThread" in t.getName(): cy_IO.setInfo("status","False") #mirror(t.getName()) if "ioThread" in t.getName(): #mirror(t.getName()) CyWebSocket.socketIO.stopThread(ioTHREAD) if "Thread-" in t.getName(): #mirror(t.getName()) threadMax += 1 try: t.abort() except: continue t_array = str(list(map(lambda x: x.getName(), threading.enumerate()))) #mirror(str(t_array)) ioTHREAD.onClose("CyKIT.main() 1") mirror("*** Reseting . . .") CyINIT = 1 main(1)