Mindwave Python Counts

I got Neurosky Mindwave for Christmas and was not immediately impressed with the standard software for it. So I understood my basic understanding in python and quickly found my flaws. So I started picking around and found two pieces of code that I would like to combine.

My intention is to create a real-time graphical display utility that takes input from Mindwave and displays it on graphs.

The first code I found was an interface for a Think device. It receives packets from the COM port and displays them using the logging method:

thinkgear.py

The second part of the code that I found that I would like to integrate is the graphical display method. I used the Tkinter package extensively, so I choose this as my first choice. I am open to simpler methods that do not require a lot of third-party software (matlab?). The code for the graphic code I found here is:

stack overflow

What I would like to do is submit a conclusion from the first to the second for live schedules. However, I have no experience with the logging module and I do not know how to separate it from the source code in order to use it as an input to the second. Also, the code for the second is mainly for demonstration purposes, and again I'm not sure how to manipulate it to look good with things other than the demo.

Any help is greatly appreciated.

+4
source share
1 answer

It seems that 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 is

global packet_log packet_log = [] logging.basicConfig(level=logging.DEBUG) for pkt in ThinkGearProtocol('/dev/rfcomm9').get_packets(): packet_log.append(pkt) 

It looks like it is designed to stream packets to a log in a single thread. For your application, you do not have to use a registrar (this can be confusing). It may 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) 

As an alternative, I do not use Tkinter, but if it has some kind of event handling method, you can use the above code to post events. Now you can stick your thinkgear.py module to your StripChart class by writing something that converts the incoming packet into raw data, and then sends that raw data to the chart. First, I would start playing with StripChart to see what it takes to get it working, and then write above the listener using a dummy handler to see if you can print the data stream (with actual values, not packets). From there it is a rather specific application.

It looks like

[thinkgear.py] β†’ [Packet Thread (procs events)] β†’ [Parser Data Parser (gets raw data)] β†’ [Internal model] β†’ [StripChart].

+2
source

Source: https://habr.com/ru/post/1388226/


All Articles