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
(.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.

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.3.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

thinkgear_py3-2.3-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: thinkgear_py3-2.3.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for thinkgear_py3-2.3.tar.gz
Algorithm Hash digest
SHA256 2559febe705423c2b54c0abc92bd711a9555136ba35712cf329069f6afad909f
MD5 5e91b1fcd9b5d9d28ca77a7d7161bb4d
BLAKE2b-256 c6a56420fd6b021420a607871e70fc58d31f4da7ad21d527df1183a4c1f80778

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: thinkgear_py3-2.3-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for thinkgear_py3-2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 87b8c61233fd3c7c7618d486addea6311ff2a1bb88b793195739dbede3fc68d0
MD5 82b653c6babad8b87b274bf4a6ebeeba
BLAKE2b-256 42ace8e8b962ce0bdfbbd9926fbd684408d4317ebb426276782b5c01a7e68a86

See more details on using hashes here.

Provenance

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

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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