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

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

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

File metadata

  • Download URL: thinkgear_py3-2.2.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.2.tar.gz
Algorithm Hash digest
SHA256 1a0b6604e541a3623abc9cae48f32b34a842fa79e14146ed59c4b87cb466b968
MD5 b18c4ed9b770132f20a77246067bac1b
BLAKE2b-256 73f9051bfb22a501284e2a498adbbae3d5a9f54188db8bc67a98efa012acf12c

See more details on using hashes here.

Provenance

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

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

Attestations:

File details

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

File metadata

  • Download URL: thinkgear_py3-2.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d839b930c3924df8d73f1a200e98256fc820e4d344e1027c71e8a8094d0eccc1
MD5 982ebe17f8507e6f3ea41ea018cd0336
BLAKE2b-256 04c12eea80aece3a16ca49141b9e47f56c2e583199f72138be461180c59b6e33

See more details on using hashes here.

Provenance

The following attestation bundles were made for thinkgear_py3-2.2-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