Pebble Foundation Classes
0.2.0
C++ for Pebble
|
Classes | |
struct | SmartstrapHandlers |
Handlers which are passed to smartstrap_subscribe. More... | |
Macros | |
#define | SMARTSTRAP_TIMEOUT_DEFAULT 250 |
The default request timeout in milliseconds (see smartstrap_set_timeout). | |
#define | SMARTSTRAP_RAW_DATA_SERVICE_ID 0 |
The service_id to specify in order to read/write raw data to the smartstrap. | |
#define | SMARTSTRAP_RAW_DATA_ATTRIBUTE_ID 0 |
The attribute_id to specify in order to read/write raw data to the smartstrap. | |
#define | PBL_IF_SMARTSTRAP_ELSE(if_true, if_false) (if_true) |
Typedefs | |
typedef uint16_t | SmartstrapServiceId |
A type representing a smartstrap ServiceId. | |
typedef uint16_t | SmartstrapAttributeId |
A type representing a smartstrap AttributeId. | |
typedef struct SmartstrapAttribute | SmartstrapAttribute |
typedef void(* | SmartstrapServiceAvailabilityHandler) (SmartstrapServiceId service_id, bool is_available) |
typedef void(* | SmartstrapReadHandler) (SmartstrapAttribute *attribute, SmartstrapResult result, const uint8_t *data, size_t length) |
typedef void(* | SmartstrapWriteHandler) (SmartstrapAttribute *attribute, SmartstrapResult result) |
typedef void(* | SmartstrapNotifyHandler) (SmartstrapAttribute *attribute) |
Enumerations | |
enum | SmartstrapResult { SmartstrapResultOk = 0, SmartstrapResultInvalidArgs, SmartstrapResultNotPresent, SmartstrapResultBusy, SmartstrapResultServiceUnavailable, SmartstrapResultAttributeUnsupported, SmartstrapResultTimeOut } |
Error values which may be returned from the smartstrap APIs. More... | |
Functions | |
SmartstrapResult | smartstrap_subscribe (SmartstrapHandlers handlers) |
void | smartstrap_unsubscribe (void) |
void | smartstrap_set_timeout (uint16_t timeout_ms) |
SmartstrapAttribute * | smartstrap_attribute_create (SmartstrapServiceId service_id, SmartstrapAttributeId attribute_id, size_t buffer_length) |
void | smartstrap_attribute_destroy (SmartstrapAttribute *attribute) |
bool | smartstrap_service_is_available (SmartstrapServiceId service_id) |
SmartstrapServiceId | smartstrap_attribute_get_service_id (SmartstrapAttribute *attribute) |
SmartstrapAttributeId | smartstrap_attribute_get_attribute_id (SmartstrapAttribute *attribute) |
SmartstrapResult | smartstrap_attribute_read (SmartstrapAttribute *attribute) |
SmartstrapResult | smartstrap_attribute_begin_write (SmartstrapAttribute *attribute, uint8_t **buffer, size_t *buffer_length) |
SmartstrapResult | smartstrap_attribute_end_write (SmartstrapAttribute *attribute, size_t write_length, bool request_read) |
#define PBL_IF_SMARTSTRAP_ELSE | ( | if_true, | |
if_false | |||
) | (if_true) |
Convenience macro to switch between two expressions depending on smartstrap support. On platforms with a smartstrap the first expression will be chosen, the second otherwise.
typedef struct SmartstrapAttribute SmartstrapAttribute |
A type representing an attribute of a service provided by a smartstrap. This type is used when issuing requests to the smartstrap.
typedef void(* SmartstrapNotifyHandler) (SmartstrapAttribute *attribute) |
The type of function which can be called when the smartstrap sends a notification to the watch
attribute | The attribute which the notification came from. |
typedef void(* SmartstrapReadHandler) (SmartstrapAttribute *attribute, SmartstrapResult result, const uint8_t *data, size_t length) |
The type of function which can be called when a read request is completed.
attribute | The attribute which was read. |
result | The result of the read. |
data | The data read from the smartstrap or NULL if the read was not successful. |
length | The length of the data or 0 if the read was not successful. |
typedef void(* SmartstrapServiceAvailabilityHandler) (SmartstrapServiceId service_id, bool is_available) |
The type of function which is called after the smartstrap connection status changes.
service_id | The ServiceId for which the availability changed. |
is_available | Whether or not this service is now available. |
typedef void(* SmartstrapWriteHandler) (SmartstrapAttribute *attribute, SmartstrapResult result) |
The type of function which can be called when a write request is completed.
attribute | The attribute which was written. |
result | The result of the write. |
enum SmartstrapResult |
Error values which may be returned from the smartstrap APIs.
SmartstrapResult smartstrap_attribute_begin_write | ( | SmartstrapAttribute * | attribute, |
uint8_t ** | buffer, | ||
size_t * | buffer_length | ||
) |
Begins a write request for the specified attribute and returns a buffer into which the app should write the data before calling smartstrap_attribute_end_write.
[in] | attribute | The attribute to begin writing for. |
[out] | buffer | The buffer to write the data into. |
[out] | buffer_length | The length of the buffer in bytes. |
SmartstrapResultOk
if a write operation was started and the buffer
and buffer_length
parameters were set, or an error otherwise. SmartstrapAttribute* smartstrap_attribute_create | ( | SmartstrapServiceId | service_id, |
SmartstrapAttributeId | attribute_id, | ||
size_t | buffer_length | ||
) |
Creates and returns a SmartstrapAttribute for the specified service and attribute. This API will allocate an internal buffer of the requested length on the app's heap.
service_id | The ServiceId to create the attribute for. |
attribute_id | The AttributeId to create the attribute for. |
buffer_length | The length of the internal buffer which will be used to store the read and write requests for this attribute. |
void smartstrap_attribute_destroy | ( | SmartstrapAttribute * | attribute | ) |
Destroys a SmartstrapAttribute. No further handlers will be called for this attribute and it may not be used for any future requests.
[in] | attribute | The SmartstrapAttribute which should be destroyed. |
SmartstrapResult smartstrap_attribute_end_write | ( | SmartstrapAttribute * | attribute, |
size_t | write_length, | ||
bool | request_read | ||
) |
This should be called by the app when it is done writing to the buffer provided by smartstrap_begin_write and the data is ready to be sent to the smartstrap.
[in] | attribute | The attribute to begin writing for. |
write_length | The length of the data to be written, in bytes. | |
request_read | Whether or not a read request on this attribute should be automatically triggered following a successful write request. |
SmartstrapResultOk
if a write operation was queued to be sent to the smartstrap. The did_write
handler will be called when the request is written to the smartstrap, and if request_read
was set to true, the did_read
handler will be called when the read is complete. SmartstrapAttributeId smartstrap_attribute_get_attribute_id | ( | SmartstrapAttribute * | attribute | ) |
Gets the AttributeId which the attribute was created for (see smartstrap_attribute_create).
attribute | The SmartstrapAttribute for which to obtain the attribute ID. |
SmartstrapServiceId smartstrap_attribute_get_service_id | ( | SmartstrapAttribute * | attribute | ) |
Returns the ServiceId which the attribute was created for (see smartstrap_attribute_create).
attribute | The SmartstrapAttribute for which to obtain the service ID. |
SmartstrapResult smartstrap_attribute_read | ( | SmartstrapAttribute * | attribute | ) |
Performs a read request for the specified attribute. The did_read
callback will be called when the response is received from the smartstrap or when an error occurs.
attribute | The attribute to be perform the read request on. |
SmartstrapResultOk
if the read operation was started. The did_read
callback will be called once the read request has been completed. bool smartstrap_service_is_available | ( | SmartstrapServiceId | service_id | ) |
Checks whether or not the specified service is currently supported by a connected smartstrap.
service_id | The SmartstrapServiceId of the service to check for availability. |
void smartstrap_set_timeout | ( | uint16_t | timeout_ms | ) |
Changes the value of the timeout which is used for smartstrap requests. This timeout is started after the request is completely sent to the smartstrap and will be canceled only if the entire response is received before it triggers. The new timeout value will take affect only for requests made after this API is called.
timeout_ms | The duration of the timeout to set, in milliseconds. |
SmartstrapResult smartstrap_subscribe | ( | SmartstrapHandlers | handlers | ) |
Subscribes handlers to be called after certain smartstrap events occur.
SmartstrapResultNotPresent
if the watch does not have a smartstrap port or SmartstrapResultOk
otherwise. void smartstrap_unsubscribe | ( | void | ) |
Unsubscribes the handlers. The handlers will no longer be called, but in-flight requests will otherwise be unaffected.