#include <pebble.h>
static Window *s_main_window;
static TextLayer *s_time_layer;
static GFont s_time_font;
static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
// A tap event occured
}
static void accel_data_handler(AccelData *data, uint32_t num_samples) {
// Read sample 0's x, y, and z values
int16_t x = data[0].x;
int16_t y = data[0].y;
int16_t z = data[0].z;
// Determine if the sample occured during vibration, and when it occured
bool did_vibrate = data[0].did_vibrate;
//uint64_t timestamp = data[0].timestamp;
if(!did_vibrate) {
// Print it out
// APP_LOG(APP_LOG_LEVEL_INFO, "t: %llu, x: %d, y: %d, z: %d", timestamp, x, y, z);
#ifdef PBL_COLOR
// text_layer_set_background_color(s_time_layer, GColorFromRGB(rand() % 255, rand() % 255, rand() % 255));
text_layer_set_background_color
(s_time_layer
, GColorFromRGB
(rand() % 170, rand() % 85, rand() % 170)); #endif
}
} else {
// Discard with a warning
APP_LOG(APP_LOG_LEVEL_WARNING, "Vibration occured during collection");
}
}
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
}
static void main_window_load(Window *window) {
Layer *window_layer = window_get_root_layer(window);
GRect bounds = layer_get_frame(window_layer);
s_time_layer = text_layer_create(GRect(0,0, bounds.size.w, bounds.size.h));
text_layer_set_background_color(s_time_layer, GColorBlack);
text_layer_set_text_color(s_time_layer, GColorWhite);
text_layer_set_text(s_time_layer, "");
// Improve the layout to be more like a watchface
//text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
// Create GFont
s_time_font = fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD);
// Apply to TextLayer
text_layer_set_font(s_time_layer, s_time_font);
text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
// Add it as a child layer to the Window's root layer
layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
uint32_t num_samples = 1; // Number of samples per batch/callback
// Subscribe to batched data events
accel_data_service_subscribe(num_samples, accel_data_handler);
//accel_service_set_samples_per_update(3);
accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
}
static void main_window_unload(Window *window) {
// Destroy TextLayer
text_layer_destroy(s_time_layer);
accel_tap_service_unsubscribe();
}
static void init() {
// Create main Window element and assign to pointer
s_main_window = window_create();
// Set handlers to manage the elements inside the Window
window_set_window_handlers(s_main_window, (WindowHandlers) {
.load = main_window_load,
.unload = main_window_unload
});
// Show the Window on the watch, with animated=true
window_stack_push(s_main_window, true);
// Register with TickTimerService
tick_timer_service_subscribe(SECOND_UNIT, tick_handler);
accel_tap_service_subscribe(accel_tap_handler);
}
static void deinit() {
// Destroy Window
window_destroy(s_main_window);
}
int main(void) {
init();
app_event_loop();
deinit();
}