A library for easier setup and prototyping of IoT devices (pucks), by collecting everything that is common for all pucks in one place.

Dependencies:   BLE_API nRF51822

Dependents:   ir-puck display-puck ir-puck2 BLE_ScoringDevice ... more

Embed: (wiki syntax)

« Back to documentation index

Puck Class Reference

A library for easier setup and prototyping of IoT devices (pucks), by collecting everything that is common for all pucks in one place. More...

#include <Puck.h>

Public Member Functions

void init (uint16_t minor)
 Call after finishing configuring puck (adding services, characteristics, callbacks).
bool drive ()
 Pass control to the bluetooth stack, executing pending callbacks afterwards.
int countFreeMemory ()
 Approximates malloc-able heap space.
void onDataWritten (GattAttribute::Handle_t handle, const uint8_t *data, const uint8_t length)
 For internal use only.
void addCharacteristic (const UUID serviceUuid, const UUID characteristicUuid, int bytes, int properties=0xA)
 Extends the given gatt service with the given gatt characteristic.
void onCharacteristicWrite (const UUID *uuid, CharacteristicWriteCallback callback)
 Register callback to be triggered on characteristic write.
void updateCharacteristicValue (const UUID uuid, uint8_t *value, int length)
 Update the value of the given gatt characteristic.
uint8_t * getCharacteristicValue (const UUID uuid)
 Returns current value of provided gatt characteristic.

Static Public Member Functions

static PuckgetPuck ()
 Returns singleton instance of puck object.

Detailed Description

A library for easier setup and prototyping of IoT devices (pucks), by collecting everything that is common for all pucks in one place.

Definition at line 46 of file Puck.h.


Member Function Documentation

void addCharacteristic ( const UUID  serviceUuid,
const UUID  characteristicUuid,
int  bytes,
int  properties = 0xA 
)

Extends the given gatt service with the given gatt characteristic.

If the service doesn't exist, it is created.

Parameters:
serviceUuidUUID of the gatt service to be extended.
characteristicUuidUUID to use for this characteristic.
bytesLength in bytes of this characteristic's value.
properties8-bit bit field containing the characteristic's properties. See ble_gatt_char_properties_t.
Returns:
Void.

Definition at line 271 of file Puck.h.

int countFreeMemory (  )

Approximates malloc-able heap space.

Do not use in production code, as it may crash.

Definition at line 144 of file Puck.h.

bool drive (  )

Pass control to the bluetooth stack, executing pending callbacks afterwards.

Should be used inside a while condition loop.

Example:

  while (puck->drive()) {
      // Do stuff
  }
Returns:
true.

Definition at line 367 of file Puck.h.

uint8_t * getCharacteristicValue ( const UUID  uuid )

Returns current value of provided gatt characteristic.

Definition at line 420 of file Puck.h.

Puck & getPuck (  ) [static]

Returns singleton instance of puck object.

Returns:
singleton instance of puck object.

Definition at line 90 of file Puck.h.

void init ( uint16_t  minor )

Call after finishing configuring puck (adding services, characteristics, callbacks).

Starts advertising over bluetooth le.

minor Minor number to use for iBeacon identifier.

Definition at line 177 of file Puck.h.

void onCharacteristicWrite ( const UUID *  uuid,
CharacteristicWriteCallback  callback 
)

Register callback to be triggered on characteristic write.

uuid UUID of the gatt characteristic to bind callback to.

callback CharacteristicWriteCallback to be executed on characteristic write.It's signature should be void (*CharacteristicWriteCallback)(const uint8_t* value, uint8_t length); "value" is the value that was written, and "length" is the length of the value that was written.

Returns:
Void.

Definition at line 395 of file Puck.h.

void onDataWritten ( GattAttribute::Handle_t  handle,
const uint8_t *  data,
const uint8_t  length 
)

For internal use only.

Exposed to hack around mbed framework limitation.

Definition at line 436 of file Puck.h.

void updateCharacteristicValue ( const UUID  uuid,
uint8_t *  value,
int  length 
)

Update the value of the given gatt characteristic.

Parameters:
uuidUUID of the gatt characteristic to be updated.
valueNew value of the characteristic.
lengthLength in bytes of the characteristic's value.
Returns:
Void.

Definition at line 337 of file Puck.h.