Update Pebble has released version 2 of its OS and this invalidates much of what follows, which was written for an earlier version of the OS.
In Part 1 we got our basic Pebble app up and running, but it doesn’t do very much. Let’s add some user interaction.
To respond to button presses, Pebble OS now uses a system akin to its event handling mechanism, the better to help the coder give the user more ways to control the three-button watch. The new approach lets you directly accommodate single clicks short and long, double-clicks, and press-and-hold events, rather than simply waiting for a push on a specific button and then trying to anticipate the user’s intentions.
The Pebble SDK, then, defines a ClickConfigProvider entity which is essentially an array of function calls for specific buttons and the various ways each of them can be used. This list of calls is attached to the host window. First, we need to add the line
handle_init() initialisation function, and we need to run it after the app’s Window – reached using the pointer variable
window – has been pushed onto the OS’s Window stack, or it will be ignored. The above line tells the window where to get its array of button configurations from, which it does by calling a second function, the
config_provider passed in the first call.