Skip to main content

ThinkGear Serial Stream Protocol implementation

Project description

Installation

To use ThinkGear, first install it using pip:

(.venv) $ pip install thinkgear-py3

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

thinkgear_py3-2.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

thinkgear_py3-2.1-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file thinkgear_py3-2.1.tar.gz.

File metadata

  • Download URL: thinkgear_py3-2.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for thinkgear_py3-2.1.tar.gz
Algorithm Hash digest
SHA256 2de84cbdda9e0abc496e8cf1131b52cc4d4c0b9c8aed88bef5a9c815e1ae4e9e
MD5 2ff705d447ba13a58baedc06b5188e31
BLAKE2b-256 be71ab10756c6462b5f2bf7ae6f62834a0c0446fafa5614c2352c976b2995cbd

See more details on using hashes here.

Provenance

The following attestation bundles were made for thinkgear_py3-2.1.tar.gz:

Publisher: python-publish.yml on gaurapanasenko/python3-thinkgear

Attestations:

File details

Details for the file thinkgear_py3-2.1-py3-none-any.whl.

File metadata

  • Download URL: thinkgear_py3-2.1-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for thinkgear_py3-2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f751c7e3ffdaef1dcca71ab1e2682efdf4666bbec9cd6650b07e63b830e226cf
MD5 7dfffcc1f3eefd0ea9f27d1db94b300e
BLAKE2b-256 a06e3ef8fb7967b51589df276e24423b43ecd399ebbd415fd4b217112b96fad0

See more details on using hashes here.

Provenance

The following attestation bundles were made for thinkgear_py3-2.1-py3-none-any.whl:

Publisher: python-publish.yml on gaurapanasenko/python3-thinkgear

Attestations:

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page