GemSDK Windows
Macros | Typedefs | Functions
GemSDK.h File Reference
#include "Common.h"

Go to the source code of this file.

Macros

#define GEMSDK_API
 
#define GEM_FAILED   0
 
#define GEM_SUCCESS   1
 
#define GEM_INVALID_HANDLE   2
 
#define GEM_CONNECTION_IN_PROGRESS   3
 
#define GEM_ALREADY_EXISTS   4
 
#define GEM_NOT_INITIALIZED   5
 

Typedefs

typedef int GemStatusCode
 
typedef void(* onStateChanged_t) (GemState state)
 Gem state changed callback. More...
 
typedef void(* onCombinedData_t) (const float *quaternion, const float *acceleration)
 IMU data callback More...
 
typedef void(* onTapData_t) (unsigned int direction)
 Tap callback More...
 
typedef void(* onPedometerData_t) (unsigned int steps, float walk_time)
 Pedometer data callback More...
 
typedef void(* onIoDigitalRead_t) (int id, IoValues value)
 Digital read callback More...
 
typedef void(* onIoAnalogRead_t) (int id, int value)
 Analog read callback More...
 
typedef void(* onI2CData_t) (unsigned char address, unsigned char reg, const unsigned char *data, unsigned char data_length)
 I2C data callback More...
 
typedef void(* onSPIData_t) (unsigned char request_id, const unsigned char *data, unsigned char data_length)
 SPI data callback More...
 

Functions

GEMSDK_API GemStatusCode Gem_Initialize ()
 Initializes the GemSDK, call this before anything else! More...
 
GEMSDK_API GemStatusCode Gem_Terminate ()
 Cleanup the GemSDK and releases related resources, it is very important to call this when you are finished with the SDK. Otherwise, the Bluetooth Controller might keep the connection with your Gem active, preventing other devices from connecting to it. More...
 
GEMSDK_API GemStatusCode Gem_Get (const char *address, GemHandle *handle)
 Returns an handle for a given Gem address. If a Gem with the given address already exists, it will return the handle to it, and will return a status code of GEM_ALREADY_EXISTS. More...
 
GEMSDK_API GemStatusCode Gem_Connect (GemHandle handle)
 Initiates a connection operation to a Gem. If this function succeeds (returns GEM_SUCCESS) you will be notified when it ends with the callback set with Gem_SetOnStateChanged. Only one connection operation can be active at the same time, if you want to connect more than one Gem, you need to wait for this operation to finish or stop it manually using GemDisconnect with the matching handle. More...
 
GEMSDK_API GemStatusCode Gem_Disconnect (GemHandle handle)
 Disconnects a Gem. If there is a connection in progress to the Gem it will abort it. More...
 
GEMSDK_API GemStatusCode Gem_SetOnStateChanged (GemHandle handle, onStateChanged_t func)
 Sets a callback for OnStateChanged event. More...
 
GEMSDK_API GemStatusCode Gem_SetOnCombinedData (GemHandle handle, onCombinedData_t func)
 Sets a callback for OnCombinedData event. More...
 
GEMSDK_API GemStatusCode Gem_SetOnTapData (GemHandle handle, onTapData_t func)
 Sets a callback for OnTapData event. More...
 
GEMSDK_API GemStatusCode Gem_SetOnPedometerData (GemHandle handle, onPedometerData_t func)
 Sets a callback for OnPedometerData event. More...
 
GEMSDK_API GemStatusCode Gem_SetOnIoDigitalRead (GemHandle handle, onIoDigitalRead_t func)
 Sets a callback for OnIoDigitalRead event. More...
 
GEMSDK_API GemStatusCode Gem_SetOnIoAnalogRead (GemHandle handle, onIoAnalogRead_t func)
 Sets a callback for OnIoAnalogRead event. More...
 
GEMSDK_API GemStatusCode Gem_SetOnI2CData (GemHandle handle, onI2CData_t func)
 Sets a callback for OnI2CData event. More...
 
GEMSDK_API GemStatusCode Gem_SetOnSPIData (GemHandle handle, onSPIData_t func)
 Sets a callback for OnSPIData event. More...
 
GEMSDK_API GemStatusCode Gem_EnableCombinedData (GemHandle handle)
 Enable CombinedData events More...
 
GEMSDK_API GemStatusCode Gem_DisableCombinedData (GemHandle handle)
 Disables CombinedData events More...
 
GEMSDK_API GemStatusCode Gem_EnableTapData (GemHandle handle)
 Enable TapData events More...
 
GEMSDK_API GemStatusCode Gem_DisableTapData (GemHandle handle)
 Disables TapData events More...
 
GEMSDK_API GemStatusCode Gem_EnablePedometerData (GemHandle handle)
 Enable PedometerData events More...
 
GEMSDK_API GemStatusCode Gem_DisablePedometerData (GemHandle handle)
 Disables PedometerData events More...
 
GEMSDK_API GemStatusCode Gem_ConfigureDigital (GemHandle handle, int id, PinIoConfiguration value)
 Configurates digital I/O More...
 
GEMSDK_API GemStatusCode Gem_WriteDigital (GemHandle handle, int id, IoValues value)
 Writes to digital I/O More...
 
GEMSDK_API GemStatusCode Gem_ReadDigital (GemHandle handle, int id)
 Requests I/O read operation. Result will be returned via the callback set with Gem_SetOnIoDigitalRead More...
 
GEMSDK_API GemStatusCode Gem_ReadAnalog (GemHandle handle, int id)
 Requests I/O read operation. Result will be returned via the callback set with Gem_SetOnIoAnalogRead More...
 
GEMSDK_API GemStatusCode Gem_WritePWM (GemHandle handle, float value)
 Writes to PWM output pin More...
 
GEMSDK_API GemStatusCode Gem_DisablePWM (GemHandle handle)
 Disables PWM More...
 
GEMSDK_API GemStatusCode Gem_WriteI2CData (GemHandle handle, unsigned char address, unsigned char *data, unsigned char data_length)
 Writes data to I2C bus More...
 
GEMSDK_API GemStatusCode Gem_WriteI2CDataReg (GemHandle handle, unsigned char address, unsigned char reg, unsigned char *data, unsigned char data_length)
 Writes data to I2C bus to certain register More...
 
GEMSDK_API GemStatusCode Gem_ReadI2CData (GemHandle handle, unsigned char address, unsigned char count)
 Requests data reading from I2C bus. Result will be returned via the callback set with Gem_SetOnI2CData More...
 
GEMSDK_API GemStatusCode Gem_ReadI2CDataReg (GemHandle handle, unsigned char address, unsigned char reg, unsigned char count)
 Requests data reading from I2C bus for certain register. Result will be returned via the callback set with Gem_SetOnI2CData More...
 
GEMSDK_API GemStatusCode Gem_WriteSPI (GemHandle handle, unsigned char *data, unsigned char data_length)
 Writes data to SPI bus More...
 
GEMSDK_API GemStatusCode Gem_ReadSPI (GemHandle handle, unsigned char requestId, unsigned char count)
 Writes data to SPI bus. Result will be returned via the callback set with Gem_SetOnSPIData with the requestId set here More...
 
GEMSDK_API GemStatusCode Gem_ReadWriteSPI (GemHandle handle, unsigned char requestId, unsigned char *data, unsigned char data_length)
 Writes to SPI bus with following reading simultaneously. Result will be returned via the callback set with Gem_SetOnSPIData with the requestId set here More...
 

Macro Definition Documentation

#define GEM_ALREADY_EXISTS   4
#define GEM_CONNECTION_IN_PROGRESS   3
#define GEM_FAILED   0
#define GEM_INVALID_HANDLE   2
#define GEM_NOT_INITIALIZED   5
#define GEM_SUCCESS   1
#define GEMSDK_API

Typedef Documentation

typedef int GemStatusCode
typedef void(* onCombinedData_t) (const float *quaternion, const float *acceleration)

IMU data callback

Parameters
quaternionQuaternion data, float array of 4 elements (x, y, z, w)
accelerationAcceleration data, float array of 3 elements (x, y, z)
typedef void(* onI2CData_t) (unsigned char address, unsigned char reg, const unsigned char *data, unsigned char data_length)

I2C data callback

Parameters
addressI2C device address
regRegister address (if you didn't use register in the request this value will be 0)
dataThe data read from the I2C device
data_lengthLength of the buffer (0-16 bytes).
typedef void(* onIoAnalogRead_t) (int id, int value)

Analog read callback

Parameters
idPin id
valuePin read value
typedef void(* onIoDigitalRead_t) (int id, IoValues value)

Digital read callback

Parameters
idPin id
valuePin read value
typedef void(* onPedometerData_t) (unsigned int steps, float walk_time)

Pedometer data callback

Parameters
stepsStep count
walk_timeTime walking (in seconds)
typedef void(* onSPIData_t) (unsigned char request_id, const unsigned char *data, unsigned char data_length)

SPI data callback

Parameters
addressRequest id of the SPI call
dataThe data read from the SPI device
data_lengthLength of the buffer (0-16 bytes).
typedef void(* onStateChanged_t) (GemState state)

Gem state changed callback.

Parameters
stateThe new state
typedef void(* onTapData_t) (unsigned int direction)

Tap callback

Parameters
directionDirection of tap

Function Documentation

GEMSDK_API GemStatusCode Gem_ConfigureDigital ( GemHandle  handle,
int  id,
PinIoConfiguration  value 
)

Configurates digital I/O

Parameters
handleThe handle of the Gem.
idId of the I/O to write.
valueDesired type for the I/O
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_Connect ( GemHandle  handle)

Initiates a connection operation to a Gem. If this function succeeds (returns GEM_SUCCESS) you will be notified when it ends with the callback set with Gem_SetOnStateChanged. Only one connection operation can be active at the same time, if you want to connect more than one Gem, you need to wait for this operation to finish or stop it manually using GemDisconnect with the matching handle.

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, GEM_CONNECTION_IN_PROGRESS if another connection operation is in progress, error code otherwise
GEMSDK_API GemStatusCode Gem_DisableCombinedData ( GemHandle  handle)

Disables CombinedData events

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_DisablePedometerData ( GemHandle  handle)

Disables PedometerData events

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_DisablePWM ( GemHandle  handle)

Disables PWM

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_DisableTapData ( GemHandle  handle)

Disables TapData events

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_Disconnect ( GemHandle  handle)

Disconnects a Gem. If there is a connection in progress to the Gem it will abort it.

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_EnableCombinedData ( GemHandle  handle)

Enable CombinedData events

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_EnablePedometerData ( GemHandle  handle)

Enable PedometerData events

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_EnableTapData ( GemHandle  handle)

Enable TapData events

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_Get ( const char *  address,
GemHandle handle 
)

Returns an handle for a given Gem address. If a Gem with the given address already exists, it will return the handle to it, and will return a status code of GEM_ALREADY_EXISTS.

Parameters
addressThe address of the desired Gem, as a string (char array) with the following format: 12:34:56:78:9A:BC
handleA pointer to a GemHandle to store the result handle in
Returns
GEM_SUCCESS on success, GEM_ALREADY_EXISTS if a gem with the same address already exists, error code otherwise
GEMSDK_API GemStatusCode Gem_Initialize ( )

Initializes the GemSDK, call this before anything else!

Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_ReadAnalog ( GemHandle  handle,
int  id 
)

Requests I/O read operation. Result will be returned via the callback set with Gem_SetOnIoAnalogRead

Parameters
handleThe handle of the Gem.
idId of the I/O to read.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_ReadDigital ( GemHandle  handle,
int  id 
)

Requests I/O read operation. Result will be returned via the callback set with Gem_SetOnIoDigitalRead

Parameters
handleThe handle of the Gem.
idId of the I/O to read.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_ReadI2CData ( GemHandle  handle,
unsigned char  address,
unsigned char  count 
)

Requests data reading from I2C bus. Result will be returned via the callback set with Gem_SetOnI2CData

Parameters
handleThe handle of the Gem.
addressI2C address of the remote device.
countBytes count to read. Supported up to 16 bytes per request.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_ReadI2CDataReg ( GemHandle  handle,
unsigned char  address,
unsigned char  reg,
unsigned char  count 
)

Requests data reading from I2C bus for certain register. Result will be returned via the callback set with Gem_SetOnI2CData

Parameters
handleThe handle of the Gem.
addressI2C address of the remote device.
regData register to read
countBytes count to read. Supported up to 16 bytes per request.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_ReadSPI ( GemHandle  handle,
unsigned char  requestId,
unsigned char  count 
)

Writes data to SPI bus. Result will be returned via the callback set with Gem_SetOnSPIData with the requestId set here

Parameters
handleThe handle of the Gem.
requestIdThis parameter will be passed to the callback so you'll be able to match the response to the request
countBytes count to read. Supported up to 16 bytes per request.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_ReadWriteSPI ( GemHandle  handle,
unsigned char  requestId,
unsigned char *  data,
unsigned char  data_length 
)

Writes to SPI bus with following reading simultaneously. Result will be returned via the callback set with Gem_SetOnSPIData with the requestId set here

Parameters
handleThe handle of the Gem.
requestIdThis parameter will be passed to the callback so you'll be able to match the response to the request
dataData to write. Supported up to 16 bytes
data_lengthData length (0-16), this is will also be the amount of data read back
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_SetOnCombinedData ( GemHandle  handle,
onCombinedData_t  func 
)

Sets a callback for OnCombinedData event.

Parameters
handleThe handle of the Gem.
funcA function pointer to be called.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_SetOnI2CData ( GemHandle  handle,
onI2CData_t  func 
)

Sets a callback for OnI2CData event.

Parameters
handleThe handle of the Gem.
funcA function pointer to be called.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_SetOnIoAnalogRead ( GemHandle  handle,
onIoAnalogRead_t  func 
)

Sets a callback for OnIoAnalogRead event.

Parameters
handleThe handle of the Gem.
funcA function pointer to be called.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_SetOnIoDigitalRead ( GemHandle  handle,
onIoDigitalRead_t  func 
)

Sets a callback for OnIoDigitalRead event.

Parameters
handleThe handle of the Gem.
funcA function pointer to be called.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_SetOnPedometerData ( GemHandle  handle,
onPedometerData_t  func 
)

Sets a callback for OnPedometerData event.

Parameters
handleThe handle of the Gem.
funcA function pointer to be called.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_SetOnSPIData ( GemHandle  handle,
onSPIData_t  func 
)

Sets a callback for OnSPIData event.

Parameters
handleThe handle of the Gem.
funcA function pointer to be called.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_SetOnStateChanged ( GemHandle  handle,
onStateChanged_t  func 
)

Sets a callback for OnStateChanged event.

Parameters
handleThe handle of the Gem.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_SetOnTapData ( GemHandle  handle,
onTapData_t  func 
)

Sets a callback for OnTapData event.

Parameters
handleThe handle of the Gem.
funcA function pointer to be called.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_Terminate ( )

Cleanup the GemSDK and releases related resources, it is very important to call this when you are finished with the SDK. Otherwise, the Bluetooth Controller might keep the connection with your Gem active, preventing other devices from connecting to it.

Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_WriteDigital ( GemHandle  handle,
int  id,
IoValues  value 
)

Writes to digital I/O

Parameters
handleThe handle of the Gem.
idId of the I/O to write.
valuepin state, high or low
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_WriteI2CData ( GemHandle  handle,
unsigned char  address,
unsigned char *  data,
unsigned char  data_length 
)

Writes data to I2C bus

Parameters
handleThe handle of the Gem.
addressI2C address of the remote device.
dataData to write. Supported up to 16 bytes
data_lengthData length, (0-16)
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_WriteI2CDataReg ( GemHandle  handle,
unsigned char  address,
unsigned char  reg,
unsigned char *  data,
unsigned char  data_length 
)

Writes data to I2C bus to certain register

Parameters
handleThe handle of the Gem.
addressI2C address of the remote device.
regData register to write
dataData to write. Supported up to 16 bytes
data_lengthData length, (0-16)
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_WritePWM ( GemHandle  handle,
float  value 
)

Writes to PWM output pin

Parameters
handleThe handle of the Gem.
idId of the I/O to read.
valueVoltage to write in volts 0.0f to 3.6f.
Returns
GEM_SUCCESS on success, error code otherwise
GEMSDK_API GemStatusCode Gem_WriteSPI ( GemHandle  handle,
unsigned char *  data,
unsigned char  data_length 
)

Writes data to SPI bus

Parameters
handleThe handle of the Gem.
dataData to write. Supported up to 16 bytes
data_lengthData length (0-16)
Returns
GEM_SUCCESS on success, error code otherwise