Skip to content

Instantly share code, notes, and snippets.

@elbruno
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save elbruno/5658d78f1a8ff42746c0 to your computer and use it in GitHub Desktop.
Save elbruno/5658d78f1a8ff42746c0 to your computer and use it in GitHub Desktop.
Pebble Buttons Handlers Sample
#include <pebble.h>
Window *my_window;
TextLayer *text_layer;
void handle_init(void) {
my_window = window_create();
window_set_click_config_provider(window, click_config_provider);
text_layer = text_layer_create(GRect(0, 0, 144, 20));
window_stack_push(my_window, true);
}
void handle_deinit(void) {
text_layer_destroy(text_layer);
window_destroy(my_window);
}
/* Buttons Handlers ;) */
void click_config_provider(void *context)
{
window_single_click_subscribe(BUTTON_ID_UP, up_click_handler);
window_single_click_subscribe(BUTTON_ID_DOWN, down_click_handler);
window_single_click_subscribe(BUTTON_ID_SELECT, select_click_handler);
}
void up_click_handler(ClickRecognizerRef recognizer, void *context)
{
/* Up button code goes here */
}
void down_click_handler(ClickRecognizerRef recognizer, void *context)
{
/* Down button code goes here */
}
void select_click_handler(ClickRecognizerRef recognizer, void *context)
{
/* Select button code goes here */
}
int main(void) {
handle_init();
app_event_loop();
handle_deinit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment