Hello!

Just today the development environment in her cloud of Pebble, CloudPebble has changed to support the 2.1 SDK.So the example today comes without video until you arrive to Madrid and to “put everything in order”.

First of all what we will do is to create an app in “minimal” mode, in PebbleCloud (because explained it here)…We have something similar to the following:

image

After selecting the file holds, we will begin to work on it. First add a general driver to capture the 3 buttons on the right side of Pebble click: Select, Up and Down Button. This controller is on line 15 and we recorded it in the general Init() of the application on line 8.


#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();
}

Finally we have the different functions that will be executed on every click associates in lines 21, 22 and 23. For now the app does nothing, in the next post we will make interact with the buttons.

I’m going to the Airport now!

Saludos @ Home

El Bruno

image image image Google

One response to “[#PEBBLE] Working with buttons”

  1. […] the yesterday’s post, I have been able today to update the Pebble smartwatch and the SDK to the version 2.1. That means […]

    Like

Leave a comment

Discover more from El Bruno

Subscribe now to keep reading and get access to the full archive.

Continue reading