I am programming a Pebble Watchface and a Android App for this watchface. I haven't programmed with C before, so this is a bit tricky for me. The Problem is, that I always get 0 as key in the callback.
On the Pebble Side it looks like this:
static AppSync sync;
static uint8_t sync_buffer[32];
...
Tuplet initial_values[] = {
TupletInteger(WEATHER_KEY, (uint8_t) 0),
TupletInteger(TEMP_KEY, (uint8_t) 20),
TupletInteger(PROB_KEY, (uint8_t) 50),
TupletInteger(BATTERY_KEY, (uint8_t) 100),
TupletInteger(RING_MODE_KEY, (uint8_t) 0),
TupletCString(TITLE_KEY, "TITLE"),
TupletCString(ARTIST_KEY, "ARTIST")
};
app_sync_init(&sync, sync_buffer, sizeof(sync_buffer), initial_values, ARRAY_LENGTH(initial_values),
sync_tuple_changed_callback, sync_error_callback, NULL);
And the Callback:
void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) {
static char temp_buf[] = "aaaaaaaa";
snprintf(temp_buf, sizeof(temp_buf), "%d,%d", (int)key, new_tuple->value->uint8);
text_layer_set_text(title_layer, temp_buf);
switch (key) {
case WEATHER_KEY:
set_weather_state(new_tuple->value->uint8);
break;
case TEMP_KEY:
set_temp(new_tuple->value->uint8);
break;
case PROB_KEY:
set_prob(new_tuple->value->uint8);
break;
case BATTERY_KEY:
vibes_short_pulse();
set_phone_percentage(new_tuple->value->uint8);
break;
case RING_MODE_KEY:
set_ring_state(new_tuple->value->uint8);
break;
case TITLE_KEY:
text_layer_set_text(title_layer, new_tuple->value->cstring);
break;
case ARTIST_KEY:
text_layer_set_text(artist_layer, new_tuple->value->cstring);
break;
}
}
On the Android side:
public void sendBatteryInformation(byte state) {
PebbleDictionary data = new PebbleDictionary();
data.addUint8(3, (byte)30);
PebbleKit.sendDataToPebble(getApplicationContext(), PEBBLE_APP_UUID,
data);
}
When I call the Android function sendBatteryInformation, the callback on the watch gets triggered. Because none of the cases were executed, I printed the key and the value to the textlayer "title_layer". It always prints "0,20" there, although I send "3" as a key.
What am I doing wrong? Thank you for your help!