Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.