So, I'm building a pebble app and to get my head around some things I'm first making some tests with the phone-to-pebble connection. Although, as always in C, I get stuck on the most basic parts. The initial text is not being displayed and the screen is just blank.
Here's the relevant code:
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);
}
Relevant variable definitions (in the top-most of the file):
TextLayer* textLayer;
const int BUFFER_SIZE = 100;
char* textRecieved;
If I comment out the *layer_set_update_proc(...);*
line I can see the text. I'm probably doing something wrong in the change_text method. (It gets called shortly after window_load
.) The outputs from my debugging prints is:
[DEBUG] app_message.c:70: Recieved: Nothing yet.
[DEBUG] app_message.c:55: Changing to: Nothing yet.