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.
- class thinkgear.EegDataPoints(level: int, code: int, data: bytes)
Represents EEG data points, including power levels for various brainwave frequencies.
- 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.
- class thinkgear.RawDataPoint(level: int, code: int, data: bytes)
Represents a raw data point, which contains unprocessed signal data.
- 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:
- 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.
- 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.
- 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.
- static connect_device(address: Tuple[str, int]) Serial | None
Establish a serial connection to a ThinkGear device.
- disconnect() None
Disconnect from the ThinkGear device.
Closes the serial connection and sets the device attribute to None.