[英]pebblekit js send array to pebble C by appmessage
I am trying to code my first Pebble C app which is based on a pebble.js app I made.我正在尝试编写我的第一个 Pebble C 应用程序,它基于我制作的一个 pebble.js 应用程序。 I am basically showing the bus schedules.
我基本上是在显示巴士时刻表。
My question, How can I pass the information from pebblekit js to the pebble C by appmessage so that I can construct a menu?我的问题是,如何通过appmessage将pebblekit js中的信息传递给pebble C,以便构建菜单? how can I pass an multiple dimension array by appmessage to the watch?
如何通过 appmessage 将多维数组传递给手表?
here is an example of the json my pebblekit js has to send to the watch:这是我的 pebblekit js 必须发送到手表的 json 示例:
{
"buses":[
{
"bus_number":"55",
"stops":[
{
"stop_id":"109698",
"stop_times":[
{
"arrival_time":"21:22:25",
"departure_time":"21:22:25"
},
{
"arrival_time":"21:52:25",
"departure_time":"21:52:25"
},
...
]
},
...
}
}
Unfortunately there is no way to send an array natively.不幸的是,没有办法本地发送数组。 This is the general framework of how I go about it in my apps.
这是我如何在我的应用程序中处理它的一般框架。 I won't post code because it varies depending on the project.
我不会发布代码,因为它因项目而异。
Add the MessageQueue library to your project.将MessageQueue库添加到您的项目中。 This library is great for sending lots of data at a time or many different pieces quickly.
这个库非常适合一次发送大量数据或快速发送许多不同的数据。
Create a sendArray
function which simply loops through each of the objects in the array and sends them to Pebble with MessageQueue.sendAppMessage()
创建一个
sendArray
函数,它简单地遍历数组中的每个对象,并使用MessageQueue.sendAppMessage()
将它们发送到 Pebble
On the C side, in your inbox handler, check for a certain key which you expect to be sent with the array object.在 C 端,在您的收件箱处理程序中,检查您希望与数组对象一起发送的某个键。 For example, if each array object has a
temperature
key in it, check for that key and then you'll know the rest of the data should be there too.例如,如果每个数组对象中都有一个
temperature
键,请检查该键,然后您就会知道其余的数据也应该在那里。
3.1. 3.1. Insert all of this data you just got on the C side from the
DictionaryIterator
into some sort of struct
which you have created to represent the array item.将您刚刚从
DictionaryIterator
在 C 端获得的所有这些数据插入到您创建的某种struct
中来表示数组项。
3.2. 3.2. After processing all of that data, insert that updated
struct
into an array.处理完所有数据后,将更新后的
struct
插入数组。
Keeping a stack count for that array is usually a good idea too.保持该数组的堆栈计数通常也是一个好主意。
Let me know if you need any more help or if I can explain anything better.如果您需要更多帮助,或者我是否可以解释更好的内容,请告诉我。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.