Created
October 15, 2013 20:24
-
-
Save alanchrt/6998075 to your computer and use it in GitHub Desktop.
Listening for MindWave headsets to be attached and connecting automatically
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, serial, threading, time | |
import mindwave | |
headsets = [ | |
{ | |
'name': 'red', | |
'headset': mindwave.Headset('/dev/tty.MindWaveMobile-DevA', open_serial=False), | |
}, | |
{ | |
'name': 'green', | |
'headset': mindwave.Headset('/dev/tty.MindWaveMobile-DevA-1', open_serial=False), | |
}, | |
] | |
class HeadsetDetector(threading.Thread): | |
def run(self): | |
while True: | |
for headset in headsets: | |
if not headset['headset'].dongle or not headset['headset'].dongle.isOpen(): | |
try: | |
headset['headset'].serial_open() | |
except serial.SerialException: | |
continue | |
time.sleep(5.0) | |
headset_detector = HeadsetDetector() | |
headset_detector.daemon = True | |
headset_detector.start() | |
while True: | |
time.sleep(0.1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment