ThinkGear Serial Stream Protocol Implementation
Installation
To use ThinkGear, first install it using pip:
(.venv) $ pip install thinkgear-py3
(.venv) $ pip install pybluez2 # For Bluetooth discovery
(.venv) $ pip install pyserial # For serial communication
Using Serial Communication
For connecting via a serial port, such as COM1 at a speed of 57600 baud, you can use the ThinkGearSerial class. The following examples demonstrate how to read and print PoorSignal, Attention, and Meditation data points.
Example for Windows
from thinkgear.serial import ThinkGearSerial
from thinkgear import PoorSignalDataPoint, MeditationDataPoint, AttentionDataPoint
# Create an instance of ThinkGearSerial
t = ThinkGearSerial()
# Connect to the device (e.g., COM1 at 57600 baud)
t.connect(("COM1", 57600))
# Continuously read and process data
while True:
for data_point in t.read():
if isinstance(data_point, PoorSignalDataPoint):
print("Poor signal:", data_point.value)
elif isinstance(data_point, AttentionDataPoint):
print("Attention:", data_point.value)
elif isinstance(data_point, MeditationDataPoint):
print("Meditation:", data_point.value)
Example for Linux
from thinkgear.serial import ThinkGearSerial
from thinkgear import PoorSignalDataPoint, MeditationDataPoint, AttentionDataPoint
# Create an instance of ThinkGearSerial
t = ThinkGearSerial()
# Connect to the device (e.g., /dev/ttyUSB0 at 57600 baud)
t.connect(("/dev/ttyUSB0", 57600))
# Continuously read and process data
while True:
for data_point in t.read():
if isinstance(data_point, PoorSignalDataPoint):
print("Poor signal:", data_point.value)
elif isinstance(data_point, AttentionDataPoint):
print("Attention:", data_point.value)
elif isinstance(data_point, MeditationDataPoint):
print("Meditation:", data_point.value)
Using Bluetooth Communication
For Bluetooth communication, you can discover and connect to a ThinkGear device. The following steps demonstrate how to discover a Bluetooth device and establish a connection.
Device Discovery
You can discover nearby Bluetooth devices with a specific name, such as MyndBand.
from thinkgear.discover import discover
# Discover a device with the name containing "MyndBand"
device_info = discover("MyndBand")
print(device_info) # Example output: ('XX:XX:XX:XX:XX:XX', 5)
Note: Device discovery is a slow operation. It is good practice to save the discovered device’s address and port for future connections.
Connecting to a Bluetooth Device
Once you have the device’s address and port, you can use ThinkGearBluetooth to connect and process data points.
from thinkgear.bluetooth import ThinkGearBluetooth
from thinkgear import PoorSignalDataPoint, MeditationDataPoint, AttentionDataPoint
# Create an instance of ThinkGearBluetooth
t = ThinkGearBluetooth()
# Use the discovered device information (address and port)
device_info = ('XX:XX:XX:XX:XX:XX', 5)
t.connect(device_info)
# Continuously read and process data
while True:
for data_point in t.read():
if isinstance(data_point, PoorSignalDataPoint):
print("Poor signal:", data_point.value)
elif isinstance(data_point, AttentionDataPoint):
print("Attention:", data_point.value)
elif isinstance(data_point, MeditationDataPoint):
print("Meditation:", data_point.value)
Notes
When using serial communication on Windows, ensure that the COM port (e.g., COM1) is correctly configured.
On Linux, ensure you have the appropriate permissions to access the serial port (e.g., /dev/ttyUSB0). This might involve adding your user to the dialout group or running the program with sudo.
Bluetooth discovery is time-consuming. Save the device’s address and port once discovered to avoid repeated discovery operations.
Metadata
Release files for thinkgear-py3 2.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| thinkgear_py3-2.3.tar.gz | 9.7 kB | With provenance | Details for thinkgear_py3-2.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| thinkgear_py3-2.3-py3-none-any.whl | Python 3 | none | any | Details for thinkgear_py3-2.3-py3-none-any.whl |
Total release size: 21.3 kB
Release files / thinkgear_py3-2.3.tar.gz
| Download URL | thinkgear_py3-2.3.tar.gz |
|---|---|
| Size | 9.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2559febe705423c2b54c0abc92bd711a9555136ba35712cf329069f6afad909f
|
|
BLAKE2b-256 checksum How to use checksums |
c6a56420fd6b021420a607871e70fc58d31f4da7ad21d527df1183a4c1f80778
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 19, 2025.
Transparency logRelease files / thinkgear_py3-2.3-py3-none-any.whl
| Download URL | thinkgear_py3-2.3-py3-none-any.whl |
|---|---|
| Size | 11.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
87b8c61233fd3c7c7618d486addea6311ff2a1bb88b793195739dbede3fc68d0
|
|
BLAKE2b-256 checksum How to use checksums |
42ace8e8b962ce0bdfbbd9926fbd684408d4317ebb426276782b5c01a7e68a86
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.12.9
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 19, 2025.
Transparency logSecurity for thinkgear-py3 2.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for thinkgear_py3-2.3.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Mar 19, 2025.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.