This is a sample implementation of Pebble's TicToc watchface written entierly in JavaScript. This example, as seen at JSConf (YouTube), was run both in the browser using Rocky.js, and on a physical watch running modified firmware that included the Espruino runtime, and the API implemented in rocky-extended.js.
This example demonstrates how you can create wrappers on top of Pebble's existing C-Style API to extend functionality and write code that "looks" more like JavaScript. There are 2 important files to look at to fully understand this example.
The code in espruino-compat.js wraps and extends the available functionality to include a Window class similar to Pebble's standard Window object, and a TimerService similar to Pebble's TickTimerService.
In addition to creating new objects for the developer to use, the Window
constructor extends the context
parameter passed into the rocky.update_proc
callback to simplify a variety of graphics related API calls.
The code in tictoc.js implements the TicToc watchface using the extended API defined in rocky-extended.js.