4

I got a Neurosky Mindwave for Christmas and was immediately unimpressed with the standard software for it. So I took my basic understanding in python to it and quickly found my shortcomings. So I started poking around and found two pieces of code that I would like to combine.

My intent is to create a live graphing utility that takes input from the Mindwave and outputs it to graphs.

The first code I found was the interface to the Think gear. It receives the packets from the COM port and displays them using the logging method:

thinkgear.py

The second piece of code I found that I would like to integrate is the graphing method. I have extensively used the Tkinter package so I choose this as a first choice. I am open to easier methods that dont require to much third party software (matlab?) The graphing code I found here:

https://stackoverflow.com/a/7605072/1110140

What I would like to do is feed the output from the first into the second for live graphs. However I have no experience with the logging module and don't know how to segregate it from the original code to use as an input to the second. Also the code for the second is mostly for demonstration purposes and im again not sure how to manipulate it to look good with things other than the demo.

Any help is greatly appreciated.

Community
  • 1
  • 1
Ryan McDevitt
  • 73
  • 1
  • 11

1 Answers1

2

It looks like, from thinkgear.py, ThinkGearProtocol is just a factory that uses ThinkGearMetaClass to generate objects whose type is the type of data that was returned. The following code -

global packet_log
packet_log = []
logging.basicConfig(level=logging.DEBUG)

for pkt in ThinkGearProtocol('/dev/rfcomm9').get_packets():
    packet_log.append(pkt)

looks like it is intended to stream packets to a logger in a single thread. For your application, you are not necessarily using a logger (this is where it might be confusing). It might be easier for you to use something like

def PacketHandler(packet):
    # Send an event out to objects 
    for obj in listeners:
        obj.packet_callback(packet)

for pkt in ThinkGearProtocol('/dev/rfcomm9').get_packets():
    PacketHandler(pkt)

Alternatively, I don't use Tkinter, but if it has some method of handling events, you can use the above code to post events. Now, you can glue your thinkgear.py module to your StripChart class by writing something that converts the incoming packet to raw data, and then posts this raw data to the graph. I would first play around with StripChart to see what it takes to get it working, and then write the above listener with a dummy handler to see if you can print a data stream (with actual values rather than packets). From there it's pretty application specific.

This ends up looking like

[thinkgear.py] -> [Packet Thread (procs events)] -> [Packet Data Parser (gets raw data)] -> [Internal Model] -> [StripChart].

user1110728
  • 113
  • 1
  • 5