This header file defines the ThinkGear Communications Driver (TGCD) API, which is a set of functions for users to connect to and receive data from a ThinkGear data stream.
More...
|
THINKGEAR_API int | TG_GetDriverVersion () |
| Returns a number indicating the version of the ThinkGear Communications Driver (TGCD) library accessed by this API. More...
|
|
THINKGEAR_API int | TG_GetNewConnectionId () |
| Returns an ID handle (an int) to a newly-allocated ThinkGear Connection object. More...
|
|
THINKGEAR_API int | TG_SetStreamLog (int connectionId, const char *filename) |
| As a ThinkGear Connection reads bytes from its serial stream, it may automatically log those bytes into a log file. More...
|
|
THINKGEAR_API int | TG_SetDataLog (int connectionId, const char *filename) |
| As a ThinkGear Connection reads and parses Packets of data from its serial stream, it may log the parsed data into a log file. More...
|
|
THINKGEAR_API int | TG_WriteStreamLog (int connectionId, int insertTimestamp, const char *msg) |
|
THINKGEAR_API int | TG_WriteDataLog (int connectionId, int insertTimestamp, const char *msg) |
|
THINKGEAR_API int | TG_EnableLowPassFilter (int connectionId, int rawSamplingRate) |
| As a ThinkGear Connection reads and parses raw EEG wave values (via the TG_ReadPackets() function), the driver can automatically apply a 30Hz low pass filter to the raw wave data. More...
|
|
THINKGEAR_API int | TG_EnableBlinkDetection (int connectionId, int enable) |
| Enables and disables the non-embedded eye blink detection. More...
|
|
THINKGEAR_API int | TG_Connect (int connectionId, const char *serialPortName, int serialBaudrate, int serialDataFormat) |
| Connects a ThinkGear Connection, given by connectionId , to a serial communication (COM) port in order to communicate with a ThinkGear module. More...
|
|
THINKGEAR_API int | TG_ReadPackets (int connectionId, int numPackets) |
| Attempts to use the ThinkGear Connection, given by connectionId , to read numPackets of data from the serial stream. More...
|
|
THINKGEAR_API int | TG_GetValueStatus (int connectionId, int dataType) |
| Returns Non-zero if the dataType was updated by the most recent call to TG_ReadPackets(). More...
|
|
THINKGEAR_API float | TG_GetValue (int connectionId, int dataType) |
| Returns the most recently read value of the given dataType , which is one of the TG_DATA_* constants defined above. More...
|
|
THINKGEAR_API int | TG_SendByte (int connectionId, int b) |
| Sends a byte through the ThinkGear Connection (presumably to a ThinkGear module). More...
|
|
THINKGEAR_API int | TG_SetBaudrate (int connectionId, int serialBaudrate) |
| Attempts to change the baud rate of the ThinkGear Connection, given by connectionId , to serialBaudrate . More...
|
|
THINKGEAR_API int | TG_SetDataFormat (int connectionId, int serialDataFormat) |
| Attempts to change the data Packet parsing format used by the ThinkGear Connection, given by connectionId , to serialDataFormat . More...
|
|
THINKGEAR_API int | TG_EnableAutoRead (int connectionId, int enable) |
| Enables or disables background auto-reading of the connection. More...
|
|
THINKGEAR_API void | TG_Disconnect (int connectionId) |
| Disconnects the ThinkGear Connection, given by connectionId , from its serial communication (COM) port. More...
|
|
THINKGEAR_API void | TG_FreeConnection (int connectionId) |
| Frees all memory associated with the given ThinkGear Connection. More...
|
|
This header file defines the ThinkGear Communications Driver (TGCD) API, which is a set of functions for users to connect to and receive data from a ThinkGear data stream.
There are three "tiers" of functions in this API, where functions of a lower "tier" should not be called until an appropriate function in the "tier" above it is called first:
Regarding preprocessor macro constants: Typical users do not need to (and should NOT) define any special macros in order to use this header file with a ThinkGear Communications Driver shared library (i.e. .dll or .so). The following macros should only be defined by maintainers of the ThinkGear Communications Driver shared library itself: THINKGEAR_DLL_COMPILE (or NO_DLL_MODIFIERS) COMPILE_FOR_JNI
- Author
- Kelvin Soo
- Version
- 4.2 Sep 28, 2009 Kelvin Soo
-
4.1 Jun 26, 2009 Kelvin Soo
- Updated name of library from ThinkGear Connection API to ThinkGear Communications Driver (TGCD). The library still uses ThinkGear Connection objects and IDs to communicate.
-
4.0 May 14, 2008 Kelvin Soo
- Overhauled API entirely to support new features of ThinkGear-EM.
-
3.2 Nov 29, 2007 Kelvin Soo
Disconnects the ThinkGear Connection, given by connectionId
, from its serial communication (COM) port.
Note that after this call, the Connection will not be valid to use with any of the API functions that require a valid ThinkGear Connection, except TG_SetStreamLog(), TG_SetDataLog(), TG_Connect(), and TG_FreeConnection().
Note that TG_FreeConnection() will automatically disconnect a Connection as well, so it is not necessary to call this function unless you wish to reuse the connectionId
to call TG_Connect() again.
- Parameters
-
THINKGEAR_API int TG_EnableLowPassFilter |
( |
int |
connectionId, |
|
|
int |
rawSamplingRate |
|
) |
| |
As a ThinkGear Connection reads and parses raw EEG wave values (via the TG_ReadPackets() function), the driver can automatically apply a 30Hz low pass filter to the raw wave data.
Subsequent calls to TG_GetValue() on TG_DATA_RAW will therefore return the filtered value. This is sometimes useful for visualizing (displaying) the raw wave when the ThinkGear is in an electrically noisy environment. This function only applies the filtering within the driver and does not affect the behavior of the ThinkGear hardware in any way. This function may be called at any time after calling TG_GetNewConnectionId().
Automatic low pass filtering is disabled by default.
NOTE: Automatic low pass filtering is currently only applicable to ThinkGear hardware that samples raw wave at 512Hz (such as TGAM in MindSet). It is not applicable to hardware that samples at 128Hz or 256Hz and should NOT be enabled for those hardware.
- Parameters
-
connectionId | The ID of the ThinkGear Connection to enable low pass filtering for, as obtained from TG_GetNewConnectionId(). |
rawSamplingRate | Specify the sampling rate that the hardware is currently sampling at. Set this to 0 (zero) or any invalid rate at any time to immediately disable the driver's automatic low pass filtering. NOTE: Currently, the only valid raw sampling rate is 512 (MindSet headsets). All other rates will return -2. |
- Returns
- -1 if
connectionId
does not refer to a valid ThinkGear Connection ID handle.
-
-2 if
rawSamplingRate
is not a valid rate. Currently only a sampling rate of 512 (Hz) is valid (which is the raw sampling rate of MindSet headsets.
-
0 on success.
Returns an ID handle (an int) to a newly-allocated ThinkGear Connection object.
The Connection is used to perform all other operations of this API, so the ID handle is passed as the first argument to all functions of this API.
When the ThinkGear Connection is no longer needed, be sure to call TG_FreeConnection() on the ID handle to free its resources. No more than TG_MAX_CONNECTION_HANDLES Connection handles may exist simultaneously without being freed.
- Returns
- -1 if too many Connections have been created without being freed by TG_FreeConnection().
-
-2 if there is not enough free memory to allocate to a new ThinkGear Connection.
-
The ID handle of a newly-allocated ThinkGear Connection.
THINKGEAR_API float TG_GetValue |
( |
int |
connectionId, |
|
|
int |
dataType |
|
) |
| |
Returns the most recently read value of the given dataType
, which is one of the TG_DATA_* constants defined above.
Use TG_ReadPackets()
to read more Packets in order to obtain updated values. Afterwards, use TG_GetValueStatus()
to check if a call to TG_ReadPackets()
actually updated a particular dataType
.
NOTE: This function will terminate the program with a message printed to stderr if connectionId
is not a valid ThinkGear Connection, or if dataType
is not a valid TG_DATA_* constant.
- Parameters
-
connectionId | The ID of the ThinkGear Connection to get a data value from, as obtained from TG_GetNewConnectionId(). |
dataType | The type of data value desired. Select from one of the TG_DATA_* constants defined above. Although many types of TG_DATA_* constants are available, each model of ThinkGear hardware and headset will only output a certain subset of these data types. Refer to the Communication Protocol document for your particular ThinkGear hardware or headset to determine which data types are actually output by that hardware or headset. Data types that are not output by the headset will always return their default value of 0.0 when this function is called. |
- Returns
- The most recent value of the requested
dataType
.
THINKGEAR_API int TG_ReadPackets |
( |
int |
connectionId, |
|
|
int |
numPackets |
|
) |
| |
Attempts to use the ThinkGear Connection, given by connectionId
, to read numPackets
of data from the serial stream.
The Connection will (internally) "remember" the most recent value it has seen of each possible ThinkGear data type, so that any subsequent call to TG_GetValue()
will return the most recently seen values.
Set numPackets
to -1 to attempt to read all Packets of data that may be currently available on the serial stream.
Note that different models of ThinkGear hardware and headsets may output different types of data values at different rates. Refer to the "Communications Protocol" document for your particular headset to determine the rate at which you need to call this function.
- Parameters
-
connectionId | The ID of the ThinkGear Connection which should read packets from its serial communication stream, as obtained from TG_GetNewConnectionId(). |
numPackets | The number of data Packets to attempt to read from the ThinkGear Connection. Only the most recently read value of each data type will be "remembered" by the ThinkGear Connection. Setting this parameter to -1 will attempt to read all currently available Packets that are on the data stream. |
- Returns
- -1 if
connectionId
does not refer to a valid ThinkGear Connection ID handle.
-
-2 if there were not even any bytes available to be read from the Connection's serial communication stream.
-
-3 if an I/O error occurs attempting to read from the Connection's serial communication stream.
-
The number of Packets that were successfully read and parsed from the Connection.
Sends a byte through the ThinkGear Connection (presumably to a ThinkGear module).
This function is intended for advanced ThinkGear Command Byte operations.
WARNING: Always make sure at least one valid Packet has been read (i.e. through the TG_ReadPackets()
function) at some point BEFORE calling this function. This is to ENSURE the Connection is communicating at the right baud rate. Sending Command Byte at the wrong baud rate may put a ThinkGear module into an indeterminate and inoperable state until it is reset by power cycling (turning it off and then on again).
NOTE: After sending a Command Byte that changes a ThinkGear baud rate, you will need to call TG_SetBaudrate()
to change the baud rate of your connectionId
as well. After such a baud rate change, it is important to check for a valid Packet to be received by TG_ReadPacket()
before attempting to send any other Command Bytes, for the same reasons as describe in the WARNING above.
- Parameters
-
connectionId | The ID of the ThinkGear Connection to send a byte through, as obtained from TG_GetNewConnectionId(). |
b | The byte to send through. Note that only the lowest 8-bits of the value will actually be sent through. |
- Returns
- -1 if
connectionId
does not refer to a valid ThinkGear Connection ID handle.
-
-2 if
connectionId
is connected to an input file stream instead of an actual ThinkGear COM stream (i.e. nowhere to send the byte to).
-
-3 if an I/O error occurs attempting to send the byte (i.e. broken stream connection).
-
0 on success.
THINKGEAR_API int TG_SetDataLog |
( |
int |
connectionId, |
|
|
const char * |
filename |
|
) |
| |
As a ThinkGear Connection reads and parses Packets of data from its serial stream, it may log the parsed data into a log file.
This is useful primarily for debugging purposes. Calling this function with a valid filename
will turn this feature on. Calling this function with an invalid filename
, or with filename
set to NULL, will turn this feature off. This function may be called at any time for either purpose on a ThinkGear Connection.
- Parameters
-
connectionId | The ID of the ThinkGear Connection to enable data logging for, as obtained from TG_GetNewConnectionId(). |
filename | The name of the file to use for data logging. Any existing contents of the file will be erased. Set to NULL or an empty string to disable stream logging by the ThinkGear Connection. |
- Returns
- -1 if
connectionId
does not refer to a valid ThinkGear Connection ID handle.
-
-2 if
filename
could not be opened for writing. You may check errno for the reason.
-
0 on success.
THINKGEAR_API int TG_SetStreamLog |
( |
int |
connectionId, |
|
|
const char * |
filename |
|
) |
| |
As a ThinkGear Connection reads bytes from its serial stream, it may automatically log those bytes into a log file.
This is useful primarily for debugging purposes. Calling this function with a valid filename
will turn this feature on. Calling this function with an invalid filename
, or with filename
set to NULL, will turn this feature off. This function may be called at any time for either purpose on a ThinkGear Connection.
- Parameters
-
connectionId | The ID of the ThinkGear Connection to enable stream logging for, as obtained from TG_GetNewConnectionId(). |
filename | The name of the file to use for stream logging. Any existing contents of the file will be erased. Set to NULL or an empty string to disable stream logging by the ThinkGear Connection. |
- Returns
- -1 if
connectionId
does not refer to a valid ThinkGear Connection ID handle.
-
-2 if
filename
could not be opened for writing. You may check errno for the reason.
-
0 on success.