Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

Created June 3, 2015 20:17
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 JoshuaJB/d12b0bf9a925909e2679 to your computer and use it in GitHub Desktop.
Save JoshuaJB/d12b0bf9a925909e2679 to your computer and use it in GitHub Desktop.
Pebble Accelerometer Average Demo Scaffold
#include <pebble.h>
// NOTE: See for docs
Window *my_window;
TextLayer *text_layer;
static void display_acceleration(AccelData * data, uint32_t num_samples);
// TODO: Write accelerometer event handler
// TODO: All all the data points together for each axis, then divide by the number of samples
// TODO: Create an empty display string variable large enough
// TODO: Use snprintf to format the accelerometer readings into a character stream
// TODO: Use text_layer_set_text(text_layer, char * <your string here>); to display
static void main_window_load(Window *window) {
// Setup the text layer
text_layer = text_layer_create(layer_get_bounds(window_get_root_layer(my_window)));
layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(text_layer));
text_layer_set_text(text_layer, "Acquiring data...");
// TODO: Set Accelerometer sample rate
// Use accel_service_set_sampling_rate(AccelSamplingRate rate) with one of
// TODO: Register accelerometer event handler with a sample buffer
// Use accel_data_service_subscribe(uint32_t samples_per_update, AccelDataHandler handler)
void handle_init(void) {
my_window = window_create();
// Setup main_window_load to run once the window loads
window_set_window_handlers(my_window, (WindowHandlers){.load = main_window_load});
window_stack_push(my_window, true);
void handle_deinit(void) {
// TODO: De-register accelerometer event handler
// Use accel_data_service_unsubscribe()
int main(void) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment