Created
June 3, 2015 20:17
-
-
Save JoshuaJB/d12b0bf9a925909e2679 to your computer and use it in GitHub Desktop.
Pebble Accelerometer Average Demo Scaffold
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <pebble.h> | |
// NOTE: See http://developer.getpebble.com/docs/c/Foundation/Event_Service/AccelerometerService/ 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 | |
// ACCEL_SAMPLING_10HZ, ACCEL_SAMPLING_25HZ, ACCEL_SAMPLING_50HZ, or ACCEL_SAMPLING_100HZ | |
// 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() | |
text_layer_destroy(text_layer); | |
window_destroy(my_window); | |
} | |
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