使用PebbleKit向Pebble发送布尔值(Sending boolean to Pebble with PebbleKit)
我从来没有真正做过太多的C,并且对于从Android应用程序向Pebble Watch发送布尔值的最佳方式感到有些困惑。
我的字符串工作正常,但在PebbleDictionary上似乎没有addBoolean方法。 作为一个解决方法我试图使用addUint8发送1或0,但我在处理Pebble上的消息时遇到问题。
这是我的Android代码:
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; } }
手表不会崩溃,当手机掉落或获得GPS时,它永远不会振动。
I've never really done much C and am a bit stumped on the best way to send a boolean from an Android app to the Pebble Watch.
I have strings working fine, but there doesn't seem to be an addBoolean method on PebbleDictionary. As a work around I am trying to use addUint8 to send a 1 or 0, but am having trouble handling the message on the Pebble.
Here is my Android code:
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);
And in my Pebble I have a data struct:
static struct MyData { uint8_t haveGPS[1]; .... // other stuff ommitted AppSync sync; uint8_t sync_buffer[256]; } s_data;
And then I am trying to compare it like this in my sync_tuple_changed callback.
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; } }
The watch doesn't crash, it just never vibrates when the phone drops or acquires GPS.
原文:https://stackoverflow.com/questions/17213038
最满意答案
我认为最后使用.apply()方法应该可以解决问题。
希望能帮助到你..!!
I think by using the .apply() method at the end should do the trick.
Hope it helps..!!
相关问答
更多-
你对所见所闻的解释是不正确的。 list值的更改与将list.pop()的结果分配给reject_list 。 Python是一种基于对象的语言,它意味着数据的基本元素是对象 ,它是数据(或状态 )和函数(称为方法 )的集合。 方法可以访问它们被调用的对象中包含的状态,并且可以对其进行修改。 在列表的情况下,其元素是其状态。 pop()的行为是通过删除调用它的列表的最后一个元素并返回它来修改此状态。 因此,在调用它之后,原始列表会缩短一个元素。 看看这个例子: >>> a = [1, 2, 3] >>> b ...
-
如何在基础表更改时自动重新定义视图(新列)?(How to auto-redefine view when underlying table changes (new column)?)[2021-12-16]
在Oracle中,这一额外步骤是必需的:您必须手动重新编译视图。 正如您已经注意到的,创建视图后,“*”会丢失: SQL> create table t (id number); Table created SQL> create view v as select * from t; View created SQL> select text from user_views where view_name = 'V'; TEXT ---------------------------------- ... -
“无法解决schemalocation”为什么我会收到此错误? URL指向具有.xsd文件扩展名的HTML文档。 当我转到:“ http://www.w3.org/2001/xml.xsd ”时,为什么我会看到HTML而不是XSD文件? 该文件的来源是HTML。 标题解释了它的目的:
Schema document for namespace http://www.w3.org/XML/1998/namespace W3C没有在该URL上托管架构源代码本身,以避免过多的带宽和 ... -
我已经更新你的小提琴请检查和审查。 http://jsfiddle.net/8MVLJ/2652/ 它不会推动它的价值,因为你已经在模态控制器中传递了作用域,并设置了父级作用域 ModalService.showModal({ templateUrl: 'modal.html', controller: "Controller", scope:$scope <-- added here scope }).then(function(modal) { m ...
-
如果您有两个重载新操作员的原型,则必须同时导出这两个原型。 Hopefulyl,这是你的问题。 If you have two two prototypes of overloading the new operator you must export both. Hopefulyl that is your problem.
-
仅在实际调用f1时抛出异常。 但是,您不要在try块中调用它 - 在f2或f3 - 您只需在那里评估引用并将返回值赋给本地f1变量。 导致异常的实际调用始终为f1 tm 。 你似乎在寻找 let f4 tm = try print_string "s1"; f1 tm with _ -> print_string "s2"; failwith "s3";; Th ...
-
重新定义:全部(Redefining :all)[2021-11-30]
这通常使用默认范围完成。 阅读所有关于他们 来自Ryan网站的代码: class User < ActiveRecord::Base default_scope :hibernate => false end # get all non-hibernating users @users = User.all # get all users, not just non-hibernating (break out of default scope) @users = User.with_exclusi ... -
您可能会认为它记录在C ++程序中发生的任何分配。 因此,您需要定义自己的新操作,以记录此分配。 您还需要重新定义删除以记录在C ++中进行的所有取消分配。 有些工具重新定义它并为内存块的开始和结束分配更多内存,并在头部和尾部分出一些签名,以找出代码中运行问题的任何缓冲区。 您可以检查MS Application Verifier。 You may think of it as away to log any allocation that happens in C++ program. So you ne ...
-
我认为最后使用.apply()方法应该可以解决问题。 希望能帮助到你..!! I think by using the .apply() method at the end should do the trick. Hope it helps..!!
-
那是对的。 大多数现代浏览器都会阻止更改undefined的值。 来自Mozilla文档 : 在现代浏览器(JavaScript 1.8.5 / Firefox 4+)中,undefined是ECMAScript 5规范中不可配置的不可写属性。 即使不是这种情况,也要避免覆盖它。 所以undefined在现代浏览器中是不可变的,即使它是全局对象的属性。 That is correct. Most modern browsers prevent changing the value of undefined. ...