所以,我正在构建一个 pebble 应用程序,为了了解一些事情,我首先对电话到 pebble 的连接进行了一些测试。尽管像往常一样在 C 中,我被困在最基本的部分。初始文本没有显示,屏幕只是空白。
以下是相关代码:
static void change_text(Layer *layer, GContext *ctx){
text_layer_set_text(textLayer, textRecieved);
APP_LOG(APP_LOG_LEVEL_DEBUG, "Changing to: %s", textRecieved);
}
static void window_load(Window *window){
GRect bounds = layer_get_bounds(window_get_root_layer(window));
textLayer = text_layer_create(GRect(5,5, bounds.size.w-10, 30));
textRecieved = (char *) malloc(BUFFER_SIZE);
memset(textRecieved,0,BUFFER_SIZE);
strcpy(textRecieved, "Nothing yet.");
text_layer_set_text(textLayer, textRecieved);
layer_add_child(window_get_root_layer(window), text_layer_get_layer(textLayer));
APP_LOG(APP_LOG_LEVEL_DEBUG, "Recieved: %s", textRecieved);
layer_set_update_proc(text_layer_get_layer(textLayer), change_text);
}
相关变量定义(在文件的最顶部):
TextLayer* textLayer;
const int BUFFER_SIZE = 100;
char* textRecieved;
如果我注释掉该*layer_set_update_proc(...);*
行,我可以看到文本。我可能在 change_text 方法中做错了。(它在 之后不久被调用window_load
。)我的调试打印输出是:
[DEBUG] app_message.c:70: Recieved: Nothing yet.
[DEBUG] app_message.c:55: Changing to: Nothing yet.