Skip to content

Instantly share code, notes, and snippets.

@alanchrt
Created October 15, 2013 20:24
Show Gist options
  • Save alanchrt/6998075 to your computer and use it in GitHub Desktop.
Save alanchrt/6998075 to your computer and use it in GitHub Desktop.
Listening for MindWave headsets to be attached and connecting automatically
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