Esempio n. 1
0
static void worker_message_handler(uint16_t type, AppWorkerMessage *data) {
	static AppWorkerMessage msg_data;
		switch(type) {
		case WORKER_MSG_ECHO:
#if !ECHO_CMDS			
			 // Construct a data packet
			msg_data.data0 = data->data0;
	  		// Send the data to the foreground app
			app_worker_send_message(WORKER_MSG_ECHO, &msg_data);
#endif			
		break;
		
		case WORKER_MSG_ACCEL_START:
			accel_data_service_subscribe(data->data0, worker_accel_data_handler);
			accel_service_set_sampling_rate(data->data1);
			worker_accel_enabled = true;
		break;
		
		case WORKER_MSG_ACCEL_STOP:
			accel_data_service_unsubscribe();
			worker_accel_enabled = false;
		break;
				
		case WORKER_MSG_ACCEL_MODIFY:
			accel_service_set_samples_per_update(data->data0);
			accel_service_set_sampling_rate(data->data1);
		break;
		
		case WORKER_MSG_TICK_START:
			if ( data->data0 != 0 ) 
				tickRate = data->data0; // how often do we want updates.
			tick_timer_service_subscribe(SECOND_UNIT, worker_tick_handler);
			worker_tick_enabled = true;
		break;
		
		case WORKER_MSG_TICK_STOP:
			tick_timer_service_unsubscribe();
			worker_tick_enabled = false;
		break;
			
		case WORKER_MSG_LOGGING_START:
			datalog_ref = data_logging_create(SLEEP_DATA_LOG_TAG, DATA_LOGGING_BYTE_ARRAY, sizeof(struct AccelData), true);
			worker_logging_enabled = true;
		break;
		
		case WORKER_MSG_LOGGING_STOP:
			data_logging_finish(datalog_ref);
			worker_logging_enabled = false;
		break;
			
		case WORKER_MSG_STATUS_RQST:
			worker_send_status_resp();
		break;
	}
	
#if ECHO_CMDS
	msg_data.data0 = type;
	app_worker_send_message(WORKER_MSG_ECHO,&msg_data);
#endif
}
Esempio n. 2
0
static void counter_timeout(void)
{
    //Create variable to store count, down from 3
    static int8_t count = 3;
    static char count_str[] = " ";
    count--;
    if (0 == count)
    {
        //reset the counter for next time,
        app_timer_cancel(s_counter_timer);
        count = 3;
        //Alert chugger with short vibration
        vibes_short_pulse();
        //Start Accelerometer service
        uint32_t num_samples = 5;
        accel_data_service_subscribe(num_samples, data_handler);
        accel_service_set_sampling_rate(ACCEL_SAMPLING_100HZ);
    }
    else
    {
        SINGLE_DIGIT_TO_ASCII(count, count_str);
        text_layer_set_text(s_count_layer, count_str);
        app_timer_register(1000, (AppTimerCallback) counter_timeout, NULL);
    }
}
Esempio n. 3
0
static void init() {
  srand(time(NULL));
  lightup();
  // Create maze
  mazeWidth = 18;
  mazeHeight = 19;
  corridorSize = 8;
  maze = genmaze(mazeWidth, mazeHeight);
  
  // Init Accelerometer
  accel_data_service_subscribe(10, NULL);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
  
  // Init Player Position
  playerX = 0;
  playerY = 0; 
  

  // Create main Window
  s_main_window = window_create();
  window_set_click_config_provider(s_main_window,clickprovider);
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });
Esempio n. 4
0
File: gfs.c Progetto: eigengo/lift
int gfs_start(gfs_sample_callback_t callback, gfs_sampling_rate_t frequency) {
    if (gfs_context.callback != NULL) return E_GFS_ALREADY_RUNNING;

    gfs_context.callback = callback;
    gfs_context.samples_per_second = (uint8_t) frequency;
    gfs_context.buffer = malloc(GFS_BUFFER_SIZE);

    if (gfs_context.buffer == NULL) return E_GFS_MEM;

    gfs_write_header();
    accel_service_set_sampling_rate((AccelSamplingRate)frequency);
    accel_raw_data_service_subscribe(GFS_NUM_SAMPLES, gfs_raw_accel_data_handler);
    accel_service_set_sampling_rate((AccelSamplingRate)frequency);

    return 1;
}
Esempio n. 5
0
/*!
 * Initializes graphic elements and subscribes to accelerometer
 * 
 * \param window the app's main window
 */
void window_load(Window *window)
{
    Layer *window_layer = window_get_root_layer(window);

    bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_MAIN);

    GRect bounds = layer_get_frame(window_layer);
    image_layer = bitmap_layer_create(bounds);
    bitmap_layer_set_alignment(image_layer, GAlignCenter);

    note_layer = bitmap_layer_create(bounds);
    bitmap_layer_set_compositing_mode(note_layer, GCompOpAnd);
    bitmap_layer_set_alignment(note_layer, GAlignCenter);
    bitmap_layer_set_bitmap(note_layer, bitmap);

    bitmap_layer_set_bitmap(image_layer, bitmap);

    notes[NOTE_C] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_C);
    notes[NOTE_D] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_D);
    notes[NOTE_E] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_E);
    notes[NOTE_F] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_F);
    notes[NOTE_G] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_G);
    notes[NOTE_A] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_A);
    notes[NOTE_B] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_B);
    notes[NOTE_HI_C] = gbitmap_create_with_resource(RESOURCE_ID_NOTE_HI_C);

    layer_add_child(window_layer, bitmap_layer_get_layer(image_layer));
    /* layer_add_child(window_layer, bitmap_layer_get_layer(note_layer)); */
    layer_insert_above_sibling(bitmap_layer_get_layer(note_layer), bitmap_layer_get_layer(image_layer));

    accel_data_service_subscribe(0, accel_handler);
    accel_service_set_sampling_rate(ACCEL_SAMPLING_50HZ);
}
Esempio n. 6
0
void analysis_init() {
  /* Subscribe to acceleration data service */
  APP_LOG(APP_LOG_LEVEL_DEBUG,"Analysis Init:  Subcribing to acceleration data");
  accel_data_service_subscribe(NSAMP,accel_handler);
  // Choose update rate
  accel_service_set_sampling_rate(SAMP_FREQ_STR);
}
Esempio n. 7
0
int main(void) {
    accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
    accel_data_service_subscribe(1, handle_accel);
    auto_backlight = true;

    worker_event_loop();
}
Esempio n. 8
0
void action_bar_nav_v_kodi(Window *window){
  // Initialize the action bar:
  action_bar = action_bar_layer_create();
  action_bar_layer_set_background_color(action_bar, GColorGreen);
  // Associate the action bar with the window:
  action_bar_layer_add_to_window(action_bar, window);
  // Set the click config provider:
  action_bar_layer_set_click_config_provider(action_bar, click_config_provider_kodi_nav_v);

  // Set the icons:
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_DOTV);
  // The loading of the icons is omitted for brevity... See gbitmap_create_with_resource()
  action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_SELECT, s_background_bitmap, true);
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_UP);
  action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_UP, s_background_bitmap, true);
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_ICON_DOWN);
  action_bar_layer_set_icon_animated(action_bar, BUTTON_ID_DOWN, s_background_bitmap, true);

  // Use tap service? If not, use data service
  if (TAP_NOT_DATA) {
    // Subscribe to the accelerometer tap service
    accel_tap_service_subscribe(tap_handler_kodi_nav_v);
  } else {
    // Subscribe to the accelerometer data service
    int num_samples = 3;
    accel_data_service_subscribe(num_samples, data_handler);

    // Choose update rate
    accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
  }
}
Esempio n. 9
0
static void init() {
  init_mem_log();
  // accel_data_service_subscribe(SMP_HZ, accel_data_handler);
  // accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);

  // subscribe the summ_datalog tick handler
  // NOTE : we need to be sure to have second-level accuracy, so given the bugs
  // with the MINUTE_UNIT timer, we assume that we need to call every second
  // NOTE! we use SECOND_UNIT, SECOND_UNIT is CORRECT!!
  tick_timer_service_subscribe(MINUTE_UNIT, tick_summ_datalog_second_hander);

  // subscribe to the accelerometer handler
  accel_data_service_subscribe(SMP_HZ, accel_data_handler);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);

  // set the bluetooth state change to also send the data
  bluetooth_connection_service_subscribe(worker_bt_service_handler);

  // init the learning algorithms params, if HAS NOT been init'ed
  // struct acticlass_learn_alg_state aclas;
  // persist_read_data(ACTICLASS_LEARN_ALG_STATE_PERSIST_KEY, &aclas, sizeof(aclas));
  // if( !aclas.init_alg){
  //   init_learn_alg1_stepc_posts_ps();
  // }
}
Esempio n. 10
0
// Handle the start-up of the app
static void init(void)
{
    // Create window
    window = window_create();
    window_stack_push(window, true);
    
    // Load images
    bg_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BG);
    empty_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_EMPTY);
    full_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_FULL);
    
    // Create bg layer
    bg_layer = bitmap_layer_create(GRect(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT));
    bitmap_layer_set_bitmap(bg_layer, bg_image);
    layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(bg_layer));
    
    // Create status layers
    for (int i = 0; i < NUMBER_OF_STATUS_BARS; i++)
    {
        status_layer[i] = bitmap_layer_create(GRect(STATUS_BAR_X_ORIGIN + STATUS_BAR_X_OFFSET * i, STATUS_BAR_Y_ORIGIN, STATUS_BAR_WIDTH, STATUS_BAR_HEIGHT));
        bitmap_layer_set_bitmap(status_layer[i], empty_image);
        layer_add_child(bitmap_layer_get_layer(bg_layer), bitmap_layer_get_layer(status_layer[i]));
    }
    
    // Subscribe minute handler
    //tick_timer_service_subscribe(SECOND_UNIT, &handle_tick);
    
    // Setup accelerator handling
    old_accel = (AccelData) { .x = 0, .y = 0, .z = 0 };
    accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
    accel_service_set_samples_per_update(0);
    accel_data_service_subscribe(0, handle_accel);
    
    timer = app_timer_register(100 /* milliseconds */, handle_timer, NULL);
}

// Handle the shutdown of the app
static void deinit(void)
{
    // Disable accelerator handling
    accel_data_service_unsubscribe();
    
    // Destroy status layers
    for (int i = 0; i < NUMBER_OF_STATUS_BARS; i++)
    {
        bitmap_layer_destroy(status_layer[i]);
    }
    
    // Destroy bg layer
    bitmap_layer_destroy(bg_layer);
    
    // Unload images
    gbitmap_destroy(bg_image);
    gbitmap_destroy(empty_image);
    gbitmap_destroy(full_image);
    
    // Destroy window
    window_destroy(window);
}
Esempio n. 11
0
void checkTiltMode() {
  s_tiltMode = getTiltStatus();
  if (s_tiltMode > 0) {
    accel_data_service_subscribe(1, dataHandler);
    accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);
  } else{
    accel_data_service_unsubscribe();
  }
}
Esempio n. 12
0
/*----------------------------------------------------------------------------*/
int main(void)
{
  APP_LOG(APP_LOG_LEVEL_INFO, "main: entry:  %s %s", __TIME__, __DATE__);

  /*
   *   Commission App
   */
  window = window_create();

  WindowHandlers handlers = {.load = window_load, .unload = window_unload };
  window_set_window_handlers(window, handlers);

  const bool animated = true;
  window_stack_push(window, animated);

  Layer * window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  /* Display the simple splash screen to indicate PebblePointer is running. */
  image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_PEBBLEPOINTER);
  image_layer = bitmap_layer_create(bounds);
  bitmap_layer_set_bitmap(image_layer, image);
  bitmap_layer_set_alignment(image_layer, GAlignCenter);
  layer_add_child(window_layer, bitmap_layer_get_layer(image_layer));

  /* Basic accelerometer initialization.  Enable Tap-Tap functionality. */
  accel_service_set_sampling_rate( SAMPLING_RATE );
  accel_tap_service_subscribe( (AccelTapHandler) accel_tap_callback );
  app_message_open(SYNC_BUFFER_SIZE, SYNC_BUFFER_SIZE);

  /* Request notfication on Bluetooth connectivity changes.  */
  bluetooth_connection_service_subscribe( bluetooth_connection_callback );
  isConnected = bluetooth_connection_service_peek();
  APP_LOG(APP_LOG_LEVEL_INFO, "initially %sonnected", (isConnected) ? "c" : "disc");

  /*
   *   Event Processing
   */
  app_event_loop();

  /*
   *   Decommission App
   */
  if (tapSwitchState == true) {
    accel_data_service_unsubscribe();
  }

  /* Remove the Tap-Tap callback */
  accel_tap_service_unsubscribe();

  /* Release splash-screen resources */
  gbitmap_destroy(image);
  bitmap_layer_destroy(image_layer);
  window_destroy(window);

  APP_LOG(APP_LOG_LEVEL_INFO, "main: exit");
}
Esempio n. 13
0
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)));
  text_layer_set_text(text_layer, "Acquiring data...");
  layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(text_layer));
  // Set Accelerometer to 100Hz sample rate
  accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);
  // Register event handler with 25 sample buffer
  accel_data_service_subscribe(25, display_acceleration);
}
Esempio n. 14
0
inline void StartSteps()
{
  int num_samples = 1;
  accel_data_service_subscribe(num_samples, data_handler);
	
	// Choose update rate
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
	
	bInForwardPart = false;
}
Esempio n. 15
0
/*
 * Initialise comms and accelerometer
 */
EXTFN void init_morpheuz() {

  open_comms();

  // Accelerometer
  accel_data_service_subscribe(25, accel_data_handler);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);

  // Set the smart status
  set_smart_status();
}
Esempio n. 16
0
void accl_init(void) {
	tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick);
	accel_data_service_subscribe(10, &accel_data_handler);
	accel_service_set_sampling_rate(sample_freq); //This is the place that works
	
	app_message_register_outbox_failed(accl_out_failed_handler);
	app_message_register_outbox_sent(accl_out_received_handler);

    timer = app_timer_register(timer_interval, timer_callback, NULL);
	app_comm_set_sniff_interval(SNIFF_INTERVAL_REDUCED);
}
Esempio n. 17
0
void simply_accel_set_data_subscribe(SimplyAccel *self, bool subscribe) {
  if (self->data_subscribed == subscribe) {
    return;
  }
  if (subscribe) {
    accel_data_service_subscribe(self->num_samples, handle_accel_data);
    accel_service_set_sampling_rate(self->rate);
  } else {
    accel_data_service_unsubscribe();
  }
  self->data_subscribed = subscribe;
}
Esempio n. 18
0
static void begin_sending_data() {
  if(s_sending)
    return;  // has already begun

  // Begin sending data
  s_sending = true;

  accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);
  accel_data_service_subscribe(SAMPLES_PER_UPDATE, accel_data_handler);

  accel_logging_start();
}
Esempio n. 19
0
static void toggle_accelerometer(){
  running = !running;
  if (running){
    accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
    accel_data_service_subscribe(0, handle_accel);
  }
  else{
    accel_data_service_unsubscribe();
  }
  
  set_timer();
}
Esempio n. 20
0
// PRESENTATION: Callbacks in general...
void select_click_callback(MenuLayer *menu_layer, MenuIndex *cell_index, void *callback_context)
{
   //cell_index->row use this to get the value in the array exercise_names and post the name to a new window..
  // just like the other select click.
  //Get which row
  // draw row maybe?

  strcpy(selected_exercise, exercise_names[(int)cell_index->row]);
  
  if (strstr(selected_exercise, "http://wger.de/api/v2/exercise/") != NULL) {
    LIST_MESSAGE_WINDOW_NUM_ROWS  = 20; // need to reset to max

   //window_stack_pop(false);
    sendString(0,selected_exercise); // 2 is the page number.. need to figure this out.   
  }
  else {
  
    s_tracking_window = window_create();
    
    window_set_click_config_provider(s_tracking_window, (ClickConfigProvider) tracking_config_provider);
    
    
    window_set_window_handlers(s_tracking_window, (WindowHandlers) {
      .load = tracking_window_load,
      .unload = tracking_window_unload
    }); 
  
  // PRESENTATION: Push to navigation stack... back button automatically pulls from stack

    window_stack_push(s_tracking_window, false);
  
    char new_str2[strlen("Selected exercise: ")+strlen(selected_exercise)+1] ;
    
    new_str2[0] = '\0';   // ensures the memory is an empty string
    strcat(new_str2,"Selected exercise: ");
      
    strcat(new_str2,selected_exercise);
    
    text_layer_set_text(s_tracking_layer,  new_str2);
  
    int num_samples = 3;
    
  // PRESENTATION: Accelerometer setup.. pretty simple to use. Data_handler method handles accelerometer data 
  // as it comes in
    accel_data_service_subscribe(num_samples, data_handler);
  
    // Choose update rate
    accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);
    

    
  }
/*!
 @brief putメソッド,DeviceOrientationプロファイルのメッセージを処理する.

 @param[in] received 受信したメッセージ
 @param[in] iter レスポンスを格納するイテレータ

 */
static void in_received_put_device_orientation_handler(DictionaryIterator *received) {
    Tuple *attributeTuple = dict_find(received, KEY_ATTRIBUTE);
    switch (attributeTuple->value->uint8) {
    case DEVICE_ORIENTATION_ATTRIBUTE_ON_DEVICE_ORIENTATION:
        accel_data_service_subscribe(PER_UPDATE, &in_event_accel_handler);//イベントハンドラと呼び出す回数の設定
        accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);//サンプリングレートの設定
        break;
    default:
        // not support
        pebble_set_error_code(ERROR_NOT_SUPPORT_ATTRIBUTE);
        break;
    }
}
Esempio n. 22
0
void show_go(void) {
  initialise_ui();
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
  accel_data_service_subscribe(1, Accel_Data_Handler);
  accel_subscribed=true;
  app_message_register_inbox_received(inbox_recieved_callback);
  app_message_register_inbox_dropped(inbox_dropped_callback);
  app_message_register_outbox_failed(outbox_failed_callback);
  app_message_register_outbox_sent(outbox_sent_callback);
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
  window_set_window_handlers(s_window, (WindowHandlers) {
    .unload = handle_window_unload,
  });
Esempio n. 23
0
static void accel_tap_handler(AccelAxisType axis, int32_t direction) {
    accel_data_service_unsubscribe();
    vibes_short_pulse();
    psleep(2000);
    accel_data_service_subscribe(1, accel_handler);
    accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
    pause = 1;
    accel_tap_service_unsubscribe();
    text_layer_set_text(text_layer_2, "RUNNING");
    text_layer_set_text(text_layer_3, "");
    action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_pause);   
    start_time = time(NULL);
    app_timer_register(10000, endtrial_callback, (void*)start_time);
}
Esempio n. 24
0
static bool init(void) {
    
    accel_data_service_subscribe(ACCEL_BATCH, &data_handler);
    accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
    
    accel_data_log = data_logging_create(
        0x1010,
        DATA_LOGGING_BYTE_ARRAY,
        sizeof(AccelData) * ACCEL_BATCH,
        false
    );
    
    return true;
    
}
Esempio n. 25
0
/*
 * Initialise comms and accelerometer
 */
void init_morpheuz(Window *window) {

  init_alarm();

  open_comms();

  // Accelerometer
  accel_data_service_subscribe(25, accel_data_handler);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);

  // Set click provider
  window_set_click_config_provider(window, (ClickConfigProvider) click_config_provider);

  // Set the smart status
  set_smart_status();
}
//Initialization of parameters for the mobile app
void handle_init(void) {
  	//Initialize handshake flag
	IS_HANDSHAKE = 0;

    //Create a window to display content
	my_window = window_create();
    
    //Push window onto the window stack
    window_stack_push(my_window, true /* true means use default window load animation */);
    
    //Create a rendering layer for window
    Layer *window_layer = window_get_root_layer(my_window);
    
    //Get window layer dimensions/bounds
    GRect bounds = layer_get_frame(window_layer);
  
    //Create a text layer
    layer = layer_create(bounds);
  	
  	//Set rendering function for text layer
  	layer_set_update_proc(layer, update_layer_callback);
  	
  	//Add text layer to the window
  	layer_add_child(window_layer, layer);

    //Subscribe/initialize the batch accelerometer data processing with 14 samples 
    //per batch and pass to accel_data_handler for processing
    accel_data_service_subscribe(WINDOW_SIZE, &accel_data_handler);
  
    //Set accelerometer sampling rate to 10Hz (important for window size).
    //If sampling rate is increased, then batch size must be increased to 
    //capture whole handshake within the window.s
    accel_service_set_sampling_rate(SAMPLE_RATE);

    if(MODE == DTW){
	    //Initialize handshake signature
	    handshake_ref = allocAccBuf(WINDOW_SIZE);

	    //Populate reference handshake matrix pointer
	    int z;
	    for(z=0; z<WINDOW_SIZE;z++){
	    	handshake_ref[z][0] = handshake_signature[z][0];
	    	handshake_ref[z][1] = handshake_signature[z][1];
	    	handshake_ref[z][2] = handshake_signature[z][2];
	    }
  	}
}
Esempio n. 27
0
void window_load(Window *window)
{
  Layer *window_layer = window_get_root_layer(window);

  text_layer_1 = text_layer_create(GRect(0, 0, 104, 30));
  text_layer_set_text_color(text_layer_1, GColorBlack);
  text_layer_set_background_color(text_layer_1, GColorWhite);
  text_layer_set_font(text_layer_1, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_1));

  s_action_bar = action_bar_layer_create();
  action_bar_layer_add_to_window(s_action_bar, window);
  action_bar_layer_set_click_config_provider(s_action_bar, click_config_provider);
  action_bar_layer_set_icon(s_action_bar, BUTTON_ID_DOWN, s_icon_reset);
  action_bar_layer_set_icon(s_action_bar, BUTTON_ID_SELECT, s_icon_play);
  action_bar_layer_set_icon(s_action_bar, BUTTON_ID_UP, s_icon_calib);
  
  text_layer_2 = text_layer_create(GRect(0, 30, 104, 40));
  text_layer_set_font(text_layer_2, fonts_get_system_font(FONT_KEY_GOTHIC_24));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_2));
  
  text_layer_3 = text_layer_create(GRect(0, 70, 104, 20));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_3));
  text_layer_set_overflow_mode(text_layer_3, GTextOverflowModeWordWrap);
  
  text_layer_4 = text_layer_create(GRect(0, 90, 104, 20));
  layer_add_child(window_layer, text_layer_get_layer(text_layer_4));
  int calib_stored = persist_exists(CALIB_PKEY) ? persist_read_int(CALIB_PKEY) : CALIB_DEFAULT;
  if (calib_stored != 0) {
    text_layer_set_text(text_layer_1, "HELLO,");
    text_layer_set_text(text_layer_2, "DRINK SAFE");
    text_layer_set_text(text_layer_4, "Flick to start");
    display(text_layer_3,"Calib: %d", calib_stored);
  }
  else {
    text_layer_set_text(text_layer_1, "PLEASE");
    text_layer_set_text(text_layer_2, "CALIBRATE");
    text_layer_set_text(text_layer_3, "Press UP button");
    text_layer_set_text(text_layer_4, "to calibrate.");
  }
  accel_data_service_subscribe(1, accel_handler);
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);

  accel_tap_service_subscribe(accel_tap_handler);
}
Esempio n. 28
0
static void main_window_load(Window *win){
  s_canvas = layer_create(GRect(0, 0, 144, 168));
  layer_set_update_proc(s_canvas, update_proc);
  layer_add_child(window_get_root_layer(win),s_canvas);
  accel_data_service_subscribe(1, accel_handler);
  
  accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);

  //set font
  system_font = fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD);
  custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_TTF_24));
  
  
  //set weatfer_or_time_text
  weatfer_or_time_text = text_layer_create(GRect(0, 72, 144, 56));
  text_layer_set_background_color(weatfer_or_time_text, GColorClear);
  text_layer_set_text_color(weatfer_or_time_text, GColorWhite);
  text_layer_set_text_alignment(weatfer_or_time_text, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(win), text_layer_get_layer(weatfer_or_time_text));
  
  //set month_text
  month_text = text_layer_create(GRect(58, 122, 30, 30));
  text_layer_set_background_color(month_text, GColorClear);
  text_layer_set_text(month_text, "00:00");
  text_layer_set_font(month_text, system_font);
  text_layer_set_text_alignment(month_text, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(win), text_layer_get_layer(month_text));
  
  //set day_text
  day_text = text_layer_create(GRect(106, 122, 30, 30));
  text_layer_set_background_color(day_text, GColorClear);
  text_layer_set_text(day_text, "00:00");
  text_layer_set_font(day_text, system_font);
  text_layer_set_text_alignment(day_text, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(win), text_layer_get_layer(day_text));
  
  //set week_text
  week_text = text_layer_create(GRect(0, 121, 50, 30));
  text_layer_set_background_color(week_text, GColorClear);
  text_layer_set_text(week_text, "week");
  text_layer_set_font(week_text, system_font);
  text_layer_set_text_alignment(week_text, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(win), text_layer_get_layer(week_text));
}
Esempio n. 29
0
void calibrate_accel_start() {
   periodsStatic = 0;
   periodsLift = 0;
   periodsSki = 0;
   calibrationCount = 0;

   calibrationSamples = malloc (DATAHZ * 10 * sizeof(uint32_t)); // keeps space for 10 seconds of samples

   pendingDecel = false;
   thresholdUp = STATICTHRESHOLD;
   thresholdDown = STATICTHRESHOLD;
   derivData = NULL;
   lastAccel.x = lastAccel.y = lastAccel.z = lastAccel.timestamp = 0;
   app_log(APP_LOG_LEVEL_INFO, __FILE__ , __LINE__, "Subscribe Calib");
   accel_data_service_subscribe(NUMSAMPLES, (AccelDataHandler) &calibrate_data_handler);
   accel_service_set_sampling_rate(ACCEL_SAMPLING_25HZ);
   vibes_short_pulse();
}
Esempio n. 30
0
static void init() {
  // Register with TickTimerService
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  // Subscribe to the accelerometer data service
  int num_samples = 3;
    accel_data_service_subscribe(num_samples, accel_handler);

    // Choose update rate
    accel_service_set_sampling_rate(ACCEL_SAMPLING_10HZ);
// Create main Window element and assign to pointer
  s_main_window = window_create();
  
  #ifdef PBL_SDK_2
    window_set_fullscreen(s_main_window, true);
  #endif
    
  // 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
  });