This presentation introduces the AppMessage framework which is part of Pebble SDK. It allows developer to exchange messages between a watch and a phone with just a few APIs.
Pebble SDK is available from http://developer.getpebble.com
2. Available in Pebble Kit 1.1
Download from developer.getpebble.com
Requires Pebble firmware 1.10.2
3. New opportunities for developers!
• Watchfaces augmented with data from the internet
• Remote controls for internet connected devices
• Multi-player Pebble games
• 4sq/Facebook/Yelp Check-in Apps
• Sports/Weather/News/Traffic tickers
• Emergency beacon activator
• Deeper sports integration
• Bitcoin price trackers
30. if (PebbleKit.areAppMessagesSupported()) {
PebbleDictionary data = new PebbleDictionary();
data.addUint8(ICON_KEY, (byte) weatherIconId);
data.addString(TEMP_KEY, "42°C");
PebbleKit.sendDataToPebble(getApplicationContext(), UUID, data);
}
Find out if the watch supports two-way communication
Push an update to the watch
Android
31. public class MyDataReceiver extends PebbleDataReceiver {
@Override
public void receiveData(final Context context,
final int transactionId,
final PebbleDictionary data)
{
/* Process data */
PebbleKit.sendAckToPebble(getApplicationContext(), transactionId);
}
}
/* ... */
PebbleDataReceiver receiver = new PebbleDataReceiver(UUID);
PebbleKit.registerReceivedDataHandler(getApplicationContext(), receiver);
Register to receive updates
You must acknowledge updates
Android
34. AppMessage
AppSync
A convenience layer on top of AppMessage
Maintains and updates a Dictionary
Provides a callback called whenever the Dictionary changes
35. static void s_main(void *params) {
static PebbleAppHandlers s_handlers = {
...
.messaging_info = {
.buffer_sizes = {
.inbound = 64, // inbound buffer size in bytes
.outbound = 16, // outbound buffer size in bytes
},
},
};
app_event_loop(params, &s_handlers);
}
You still need to declare the input / output buffers
36. Tuplet initial_values[] = {
TupletInteger(WEATHER_ICON_KEY, (uint8_t) 1),
TupletCString(WEATHER_TEMPERATURE_KEY, "42°C"),
};
Prepare the initial values of your data
37. #include <...>
AppSync sync;
uint8_t sync_buffer[32];
Reserve global memory to store a AppSync struct
Reserve global memory to store your dictionary
39. void sync_tuple_changed_callback(const uint32_t key,
const Tuple* new_tuple, const Tuple* old_tuple, void* context)
{
// Update your layers
// Do not forget to call layer_mark_dirty()
}
Process the first (and subsequent) update
40. Tuplet new_tuples[] = {
TupletInteger(WEATHER_ICON_KEY, (uint8_t) 3),
TupletCString(WEATHER_TEMPERATURE_KEY, "73°C"),
};
app_sync_set(&sync, new_tuples, 2);
You can update the value on the Watch side
The callback will be called when the app has acknowledged