0

我正在为这个表盘编写一个 Pebble 表盘和一个 Android 应用程序。我以前没有用 C 编程过,所以这对我来说有点棘手。问题是,我总是在回调中得到 0 作为键。

在 Pebble 一侧,它看起来像这样:

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);

和回调:

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;


}

}

在安卓端:

public void sendBatteryInformation(byte state) {
PebbleDictionary data = new PebbleDictionary();
data.addUint8(3, (byte)30);
PebbleKit.sendDataToPebble(getApplicationContext(), PEBBLE_APP_UUID,
    data);
}

当我调用 Android 函数 sendBatteryInformation 时,手表上的回调被触发。因为没有一个案例被执行,我将键和值打印到文本层“title_layer”。它总是在那里打印“0,20”,尽管我发送“3”作为键。

我究竟做错了什么?谢谢您的帮助!

4

1 回答 1

1

找到了。我不得不增加缓冲区。另外:回调总是为所有键触发,而不仅仅是更新的键。

于 2014-07-31T16:34:19.637 回答