Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
AccelerometerSample01
#include <pebble.h>
#define MATH_PI 3.141592653589793238462
#define NUM_DISCS 20
#define DISC_DENSITY 0.25
#define ACCEL_RATIO 0.05
#define ACCEL_STEP_MS 50
Window *window;
TextLayer *text_layer;
static AppTimer *timer;
static void timer_callback(void *data) {
AccelData accel = (AccelData) { .x = 0, .y = 0, .z = 0 };
accel_service_peek(&accel);
APP_LOG(APP_LOG_LEVEL_DEBUG, "x:" + accel.x);
APP_LOG(APP_LOG_LEVEL_DEBUG, "y:" + accel.y);
APP_LOG(APP_LOG_LEVEL_DEBUG, "z:" + accel.z);
}
void init(void) {
window = window_create();
text_layer = text_layer_create(GRect(0, 0, 144, 154));
text_layer_set_text(text_layer, "Acel Sample!");
text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer));
window_stack_push(window, true);
accel_data_service_subscribe(0, NULL);
timer = app_timer_register(ACCEL_STEP_MS, timer_callback, NULL);
}
void handle_deinit(void) {
accel_data_service_unsubscribe();
text_layer_destroy(text_layer);
window_destroy(window);
}
int main(void) {
init();
app_event_loop();
handle_deinit();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.