API

class thinkgear.AttentionDataPoint(level: int, code: int, data: bytes)

Represents an attention level data point.

class thinkgear.BatteryDataPoint(level: int, code: int, data: bytes)

Represents a battery level data point.

class thinkgear.BlinkDataPoint(level: int, code: int, data: bytes)

Represents a blink level data point.

class thinkgear.DataPoint(level: int, code: int, data: bytes)

Base class for data points, containing raw data bytes and an interpreted value.

level

The EXCODE level.

Type:

int

code

The operation code for the data point.

Type:

int

data

The raw data bytes.

Type:

bytes

value

The interpreted value extracted from the data.

Type:

int

class thinkgear.EegDataPoints(level: int, code: int, data: bytes)

Represents EEG data points, including power levels for various brainwave frequencies.

delta

Power of delta waves.

Type:

int

theta

Power of theta waves.

Type:

int

lowAlpha

Power of low-alpha waves.

Type:

int

highAlpha

Power of high-alpha waves.

Type:

int

lowBeta

Power of low-beta waves.

Type:

int

highBeta

Power of high-beta waves.

Type:

int

lowGamma

Power of low-gamma waves.

Type:

int

midGamma

Power of mid-gamma waves.

Type:

int

class thinkgear.MeditationDataPoint(level: int, code: int, data: bytes)

Represents a meditation level data point.

class thinkgear.PoorSignalDataPoint(level: int, code: int, data: bytes)

Represents a poor signal level data point.

property has_contact: bool

Check if the headset has proper contact with the skin.

Returns:

True if contact is good, False otherwise.

Return type:

bool

class thinkgear.RawDataPoint(level: int, code: int, data: bytes)

Represents a raw data point, which contains unprocessed signal data.

level

The EXCODE level.

Type:

int

code

The operation code.

Type:

int

data

The raw data bytes.

Type:

bytes

value

The interpreted raw signal value.

Type:

int

class thinkgear.ThinkGearProtocol(debug: bool = False)

A base class to interface with ThinkGear devices using the ThinkGear Serial Stream Protocol.

This class provides methods to read and parse data transmitted by ThinkGear devices. It is intended as an abstract class and should be subclassed to implement the _recv method for actual device communication.

_debug

Flag to enable or disable debug mode. If enabled, additional debugging information may be printed or logged.

Type:

bool

read() List[DataPoint | RawDataPoint | EegDataPoints]

Read and parse a single data payload from the ThinkGear device.

The method synchronizes on the SYNC bytes, validates the payload length, calculates a checksum, and verifies it against the received checksum. The payload is parsed into a list of data points.

Returns:

A list of parsed data points, or an empty list if parsing fails.

Return type:

List[DataPointType]

Raises:

IOError – If the full payload cannot be read.

class thinkgear.UnknownDataPoint(level: int, code: int, data: bytes)

Represents an unknown data point.

class thinkgear.bluetooth.ThinkGearBluetooth(debug: bool = False)

A class for managing Bluetooth communication with ThinkGear devices.

This class extends ThinkGearProtocol to implement Bluetooth-specific communication protocols. It establishes a Bluetooth connection, facilitates data transfer, and manages the connection lifecycle.

socket

The Bluetooth socket used for communication.

Type:

Optional[socket.socket]

connect(address: Tuple[str, int]) None

Connect to the ThinkGear device using the provided Bluetooth address and port.

Parameters:

address (Tuple[str, int]) – A tuple containing the Bluetooth address and port.

Raises:

socket.error – If the connection fails.

static connect_device(address: Tuple[str, int]) socket | None

Establish a Bluetooth connection to a ThinkGear device.

Parameters:

address (Tuple[str, int]) – A tuple containing the Bluetooth address and port.

Returns:

The connected socket object, or None if the connection fails.

Return type:

Optional[socket.socket]

disconnect() None

Disconnect from the ThinkGear device.

Closes the Bluetooth socket and sets it to None.

get_device() socket | None

Get current instance of bluetooth socket device.

Returns:

socket object connected to device

Return type:

socket.socket

is_connected() bool

Check if the device is currently connected.

Returns:

True if the device is connected, False otherwise.

Return type:

bool

thinkgear.discover.discover(lookup_name: str = 'MindWave') Tuple[str, int] | None

Discover a Bluetooth device by name and retrieve its RFCOMM service details.

This function scans for nearby Bluetooth devices and attempts to locate one with a name containing the specified lookup_name. If a matching device is found, it searches for an RFCOMM service on the device and returns its address and port.

Parameters:

lookup_name (str) – The name or part of the name of the target Bluetooth device. Defaults to “MindWave”.

Returns:

A tuple containing the Bluetooth address and RFCOMM port

of the discovered device, or None if no matching device or service is found.

Return type:

Optional[Tuple[str, int]]

class thinkgear.serial.ThinkGearSerial(debug: bool = False)

A class for managing serial communication with ThinkGear devices.

This class extends ThinkGearProtocol to implement serial communication protocols. It provides methods for connecting to a device via a serial interface, receiving data, and managing the connection lifecycle.

device

The serial connection object to the ThinkGear device.

Type:

Optional[serial.Serial]

connect(device: Tuple[str, int] | Serial) None

Connect to a ThinkGear device using a serial interface.

Parameters:

device (Union[Tuple[str, int], serial.Serial]) – Either a tuple specifying the serial port and baud rate, or an already initialized serial.Serial object.

Raises:

serial.SerialException – If the connection fails when using the address tuple.

static connect_device(address: Tuple[str, int]) Serial | None

Establish a serial connection to a ThinkGear device.

Parameters:

address (Tuple[str, int]) – A tuple containing the serial port (e.g., ‘/dev/ttyUSB0’) and the baud rate.

Returns:

The connected serial device object, or None if the connection fails.

Return type:

Optional[serial.Serial]

disconnect() None

Disconnect from the ThinkGear device.

Closes the serial connection and sets the device attribute to None.

get_device() Serial | None

Get current instance of serial device.

Returns:

serial device object

Return type:

serial.Serial

is_connected() bool

Check if the device is currently connected.

Returns:

True if the device is connected, False otherwise.

Return type:

bool