gpt4 book ai didi

android - 使用 PebbleKit 将 bool 值发送到 Pebble

转载 作者:太空宇宙 更新时间:2023-11-04 04:49:31 25 4
gpt4 key购买 nike

我从来没有真正用过很多 C 语言,对于将 bool 值从 Android 应用程序发送到 Pebble Watch 的最佳方法有点难过。

我的字符串工作正常,但 PebbleDictionary 上似乎没有 addBoolean 方法。作为解决方法,我尝试使用 addUint8 发送 1 或 0,但在处理 Pebble 上的消息时遇到问题。

这是我的安卓代码:

    PebbleDictionary data = new PebbleDictionary();
if (isGPSFix()){
data.addUint8(GPS_HAS_FIX_KEY, Byte.valueOf("1"));
} else {
data.addUint8(GPS_HAS_FIX_KEY, Byte.valueOf("0"));
}
PebbleKit.sendDataToPebble(app.getContext(), UUID, data);

在我的 Pebble 中我有一个数据结构:

static struct MyData {
uint8_t haveGPS[1];
.... // other stuff ommitted
AppSync sync;
uint8_t sync_buffer[256];
} s_data;

然后我尝试在我的 sync_tuple_changed 回调中像这样比较它。

static void sync_tuple_changed_callback(const uint32_t key, const Tuple* new_tuple, const Tuple* old_tuple, void* context) {
(void) old_tuple;

switch (key) {
case GPS_HAS_FIX_KEY:
if (memcmp(s_data.haveGPS, new_tuple->value->data, 8) == 0){
memcpy(s_data.haveGPS,new_tuple->value->data, new_tuple->length);
vibes_short_pulse();
}
break;
default:
return;
}
}

watch 不会崩溃,只是在手机掉落或获取 GPS 时它从不振动。

最佳答案

Android 端看起来不错。我认为这更像是一个 AppSync 问题。

以下是 watch 应用程序中需要检查的几项内容:

  • 确保您在 watch 上创建了一个包含初始值的元组列表。此列表需要包含您的 key GPS_HAS_FIX_KEY
Tuplet initial_values[] = {
TupletInteger(GPS_HAS_FIX_KEY, (uint8_t) 0),
/* Other tuplets that you will synchronize */
};
  • 确保将这些连音传递给 app_sync_init() 函数:
app_sync_init(&sync, sync_buffer, sizeof(sync_buffer),
initial_values, ARRAY_LENGTH(initial_values),
sync_tuple_changed_callback, sync_error_callback, NULL);

这两个步骤是 app_sync 工作所必需的(参见 AppSync reference documentation)。

关于android - 使用 PebbleKit 将 bool 值发送到 Pebble,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17213038/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com