void handle_init() {
	Layer *rootLayer;
	int i;
	
	window = window_create();
	window_set_background_color(window, GColorWhite);
	window_stack_push(window, true);
	
	readConfig();
	app_message_init();

	rootLayer = window_get_root_layer(window);
	
	for (i=0; i<NUMSLOTS; i++) {
		initSlot(i, rootLayer);
	}
		
	animImpl.setup = NULL;
	animImpl.update = animateDigits;
	animImpl.teardown = NULL;
	
	anim = animation_create();
	animation_set_delay(anim, 0);
	animation_set_duration(anim, DIGIT_CHANGE_ANIM_DURATION);
	animation_set_implementation(anim, &animImpl);
	
	app_timer_register(STARTDELAY, handle_timer, NULL);

	tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
	
	accel_tap_service_subscribe(handle_tap);
	
	lastBluetoothStatus = bluetooth_connection_service_peek();
	bluetooth_connection_service_subscribe(handle_bluetooth);
}
Exemple #2
0
void main_window_init(void)
{
	main_window = window_create();
	window_stack_push(main_window, true);
	window_set_background_color(main_window, BACKGROUND_COLOR);
	Layer *window_layer = window_get_root_layer(main_window);
 
	int y_pos = 8;
	for (int index = 0; index < 4; index++) {
		TextLayer *text_layer = text_layer_create(GRect(0, y_pos, 144, 36));
		text_layer_set_text_color(text_layer, TEXT_COLOR);
		text_layer_set_background_color(text_layer, GColorClear);
		text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
		
		memset(lines[index], ' ', LINES_WIDTH);
		text_layer_set_text(text_layer, lines[index]);
		
		layer_add_child(window_layer, text_layer_get_layer(text_layer));
		text_layers[index] = text_layer;
		y_pos += 38;
	}

	force_update();

	tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
	accel_tap_service_subscribe(&accel_tap_handler);
}
Exemple #3
0
static void init(void) {
  pebbleLocale = setlocale(LC_ALL, "");

	window = window_create();
	window_set_background_color(window, GColorBlack);
	window_stack_push(window, true);
	
	rootLayer = window_get_root_layer(window);
	
	srand(time(NULL));
	
	layer = layer_create(GRect(0, 0, WIDTH, HEIGHT));
	layer_set_update_proc(layer, updateScreen);
	layer_add_child(rootLayer, layer);

  fontHour = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BORIS_47));
#if defined(SHOWDATE)
  fontDate = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_BORIS_18));
#endif

	setText();
	initRects();
	reset();

	timer = app_timer_register(DELAY, timerCallback, NULL);
	
	tick_timer_service_subscribe(MINUTE_UNIT, minuteChange);
	
	accel_data_service_subscribe(0, NULL);
	accel_tap_service_subscribe(tapHandler);
}
Exemple #4
0
int main(void)
{
    window = window_create();  /* Инициализируем окно */
    window_set_background_color(window, GColorBlack); /* устанавливаем фоновый цвет */
    window_set_fullscreen(window, true); /* включаем полноэкранность */
    window_stack_push(window, true);  /* открываем окно с анимацией */
    srand(time(NULL)); /* инициализируем генератор случайных чисел текущем временем */
    text_layer = text_layer_create(GRect(0 , 30, 144, 168)); /* создаем текстовый массив, указываем размер и координаты */
    text_layer_set_text_color(text_layer, GColorWhite);  /* устанавливаем цвет текста */
    text_layer_set_background_color(text_layer, GColorClear);  /* устанавливаем цвет фона */
    text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28)); /* устанавливаем шрифт */
    text_layer_set_text_alignment(text_layer, GTextAlignmentCenter); /* устанавливаем выравнивание по центру */
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer));  /* подключаем текстовый слой к основному в качестве дочернего */
#if (LANG == ENG)
    text_layer_set_text(text_layer, "Shake to roll \n the dice!");  /* показываем сообщение при запуске */
#endif
#if (LANG == RUS)
    text_layer_set_text(text_layer, "Встряхните часы для броска костей");  /* показываем сообщение при запуске */
#endif
    accel_tap_service_subscribe(accel_int);  /* подписываемся на прерывания от акселерометра */
    app_event_loop();  /* ждем событий */
    if (first_time == true) /* если выходим без запуска перебора... */
    { 
        text_layer_destroy(text_layer); /* ...то удаляем текстовый слой с сообщением */
    }
    else  /* если выходим уже после запуска... */
    {    
        bitmap_layer_destroy(image_layer); /* ...то уничтожаем текстовый слой... */
        gbitmap_destroy(image); /* ... и уничтожаем массив с графикой, текстовый слой уже удален в функции accel_int */
    }
    accel_tap_service_unsubscribe();  /* отписываемся от прерываний акселерометра */
    window_destroy(window);  /* уничтожаем главное окно, освобождаем ресурсы */
}
// Initialise UI
static void init(void)
{
	srand(time(NULL));
	inverter_timer 	= app_timer_register(INVERTER_TIMEOUT, inverter_timer_callback, 0);
	time_timer 			= app_timer_register(TIME_TIMEOUT, update_time, 0);
	
  window 					= window_create();
	
	window_set_fullscreen(window, true);
  window_stack_push(window, false);
	
	// Assign resources
  s_res_tv_image 				= gbitmap_create_with_resource(RESOURCE_ID_TV_IMAGE);
  s_res_static_1_image 	= gbitmap_create_with_resource(RESOURCE_ID_STATIC_2_IMAGE);
	s_res_bitham_42_bold 	= fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD);
	s_res_gothic_14 			= fonts_get_system_font(FONT_KEY_GOTHIC_14);
		
	// tv_bitmap
	tv_bitmap = bitmap_layer_create(GRect(0,0,144,168));
	bitmap_layer_set_bitmap(tv_bitmap, s_res_tv_image);
	bitmap_layer_set_background_color(tv_bitmap, GColorClear);
	bitmap_layer_set_compositing_mode(tv_bitmap, GCompOpAssign);
	layer_add_child(window_get_root_layer(window), (Layer *) tv_bitmap);
	
  // static_1_bitmap
  static_1_bitmap = bitmap_layer_create(GRect(14, 42, 115, 87));
  bitmap_layer_set_bitmap(static_1_bitmap, s_res_static_1_image);
	bitmap_layer_set_compositing_mode(static_1_bitmap, GCompOpOr);
  layer_add_child(window_get_root_layer(window), (Layer *)static_1_bitmap);
  
  // inverter_layer
  static_inverter_layer = inverter_layer_create(GRect(14, 42, 115, 0));
  layer_add_child(window_get_root_layer(window), (Layer *)static_inverter_layer);
	layer_set_hidden(inverter_layer_get_layer(static_inverter_layer), false);
	
	// Screen On layer
  screen_on_layer = text_layer_create(GRect(14, 42, 115, 87));
  text_layer_set_background_color(screen_on_layer, GColorWhite);
  layer_set_hidden(text_layer_get_layer(screen_on_layer), true);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(screen_on_layer));
	
	// ch_layer
	ch_layer = text_layer_create(GRect(102, 46, 24, 14));
	text_layer_set_background_color(ch_layer, GColorClear);
	text_layer_set_text(ch_layer, "Ch 3");
	text_layer_set_font(ch_layer, s_res_gothic_14);
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(ch_layer));
	
  // time_layer
	clock_copy_time_string(buffer, 12);
  time_layer = text_layer_create(GRect(0, 56, 144, 42));
  text_layer_set_background_color(time_layer, GColorClear);
  text_layer_set_text(time_layer, buffer);
  text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
  text_layer_set_font(time_layer, s_res_bitham_42_bold);
	layer_set_hidden(text_layer_get_layer(time_layer), true);
  layer_add_child(window_get_root_layer(window), (Layer *)time_layer);
	
	accel_tap_service_subscribe(tap_handler); // Subcribe to the tap event service
}
Exemple #6
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);
  }
}
Exemple #7
0
static void inbox_received_callback(DictionaryIterator *iterator, void *context){
	Tuple *minutes = dict_find(iterator, VIBE_TIME);
	if(minutes){
		mins = minutes->value->uint8;
		persist_write_int(KEY_MINUTES, mins);
	}
	
	Tuple *center_t = dict_find(iterator, CENTER);
	if(center_t){
		center = center_t->value->int8;
		persist_write_bool(CENTER, center);
		
		window_stack_pop(false);
		deinit();
		init();
	}
	
	Tuple *date = dict_find(iterator, SHOW_DATE);
	if(date){
		accel_tap_service_unsubscribe();
		if(date->value->int8){
			accel_tap_service_subscribe(accel_tap_handler);
		}
	}
	
}
Exemple #8
0
void handle_init(void) {
  window = window_create();
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  accel_tap_service_subscribe(tap_handler);

  hour_text_layer = text_layer_create(GRect(0, 0, 144, 107));
  text_layer_set_background_color(hour_text_layer, GColorBlack);
  text_layer_set_text_color(hour_text_layer, GColorWhite);
  text_layer_set_text(hour_text_layer, "00");
  text_layer_set_font(hour_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49)); //TODO: Make the numbers prettier. Maybe use custom font/rendering?
  text_layer_set_text_alignment(hour_text_layer, GTextAlignmentCenter);
  
  minute_text_layer = text_layer_create(GRect(0, 107, 144, 61));
  text_layer_set_background_color(minute_text_layer, GColorBlack);
  text_layer_set_text_color(minute_text_layer, GColorWhite);
  text_layer_set_text(minute_text_layer, "00");
  text_layer_set_font(minute_text_layer, fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
  text_layer_set_text_alignment(minute_text_layer, GTextAlignmentCenter);
  
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(hour_text_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(minute_text_layer));
  
  update_hour();
  update_minute();
  
  window_stack_push(window, true);
}
Exemple #9
0
SimplyAccel *simply_accel_create(Simply *simply) {
  if (s_accel) {
    return s_accel;
  }

  SimplyAccel *self = malloc(sizeof(*self));
  *self = (SimplyAccel) {
    .simply = simply,
    .rate = ACCEL_SAMPLING_100HZ,
    .num_samples = 25,
  };
  s_accel = self;

  accel_tap_service_subscribe(handle_accel_tap);

  return self;
}

void simply_accel_destroy(SimplyAccel *self) {
  if (!self) {
    return;
  }

  accel_tap_service_unsubscribe();

  free(self);

  s_accel = NULL;
}
void putCard(){
  accel_tap_service_subscribe(accel_tap_handler);
  window_stack_push(windowCard, true /* Animated */);
  //APP_LOG(APP_LOG_LEVEL_DEBUG,"ACCESSED: text: %s at %d",cdarray[0],0);
  text_layer_set_text(txtlyer, cdarray[0]);
  uninvertText();
  inv=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");
}
Exemple #12
0
static void handle_init(void)
{
   GRect dummy_frame = { {0, 0}, {0, 0} };

   time_t t = time(NULL);
   struct tm *time = localtime(&t);

   window = window_create();
   if (window == NULL)
   {
      APP_LOG(APP_LOG_LEVEL_DEBUG, "...couldn't allocate window memory...");
      return;
   }

   window_set_fullscreen(window, true);
   window_stack_push(window, true /* Animated */);
   Layer *window_layer = window_get_root_layer(window);

   blockp_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BLOCKP);
   blockp_layer = bitmap_layer_create(dummy_frame);
   bitmap_layer_set_bitmap(blockp_layer, blockp_image);

   window_set_click_config_provider(window, click_config_provider);

   strcpy(line1Str[0], "");
   strcpy(line1Str[1], "");
   strcpy(line2Str[0], "");
   strcpy(line2Str[1], "");
   strcpy(line3Str[0], "");
   strcpy(line3Str[1], "");

   // 1st line layers
   line1 = text_layer_create(GRect(0, 0, 144, 168));
   configure_bold_layer(line1);

   // 2nd layers
   line2 = text_layer_create(GRect(0, 55, 144, 50));
   configure_light_layer(line2);

   // 3rd layers
   line3 = text_layer_create(GRect(0, 110, 144, 50));
   configure_light_layer(line3);

   splash_image = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_SPLASH);
   splash_layer = bitmap_layer_create(dummy_frame);
   bitmap_layer_set_bitmap(splash_layer, splash_image);
   layer_add_child(window_layer, bitmap_layer_get_layer(splash_layer));
 
   set_bitmap_image(&splash_image, splash_layer, RESOURCE_ID_IMAGE_SPLASH, GPoint (0, 0));

   // Configure time on init
   display_time(time);

   accel_tap_service_subscribe(&handle_accel_tap);
   tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
}  // handle_init()
Exemple #13
0
static void init(void) {
  autoconfig_init();
  app_message_register_inbox_received(in_received_handler);
  accel_tap_service_subscribe(&accel_tap_handler);

  window = window_create();
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
Exemple #14
0
//INITIALIZE
static void init() {
  //register tap handler
  accel_tap_service_subscribe(tap_handler);
  //make the main window
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  s_main_window = window_create();
  
  window_set_window_handlers(s_main_window, (WindowHandlers){
    .load = main_window_load,
    .unload = main_window_unload
  });
void handle_init(void) {
	window = window_create();
	window_stack_push(window, true);
	window_set_background_color(window, GColorBlack);
    Layer *window_layer = window_get_root_layer(window);
    
    // Set up AppMessage to receive timezone offset
    app_message_register_inbox_received(in_received_handler);
    app_message_open(64, 64);
    
    dolce_vita_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_GEOSANS_LIGHT_26));
	
	// Current Time
	text_time_layer = text_layer_create(GRect(0, 114, 144, 43));
	text_layer_set_text_color(text_time_layer, GColorWhite);
	text_layer_set_background_color(text_time_layer, GColorClear);
	text_layer_set_font(text_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_MEDIUM_NUMBERS));
	text_layer_set_text_alignment(text_time_layer, GTextAlignmentCenter);
	layer_add_child(window_layer, text_layer_get_layer(text_time_layer));
	
    // Apple Logo
    logo_image = gbitmap_create_with_resource(RESOURCE_ID_WWDC14);
    logo_image_layer = bitmap_layer_create(GRect(0, 0, 144, 60));
    bitmap_layer_set_bitmap(logo_image_layer, logo_image);
    layer_add_child(window_layer, bitmap_layer_get_layer(logo_image_layer));
    
    // WWDC14 Text
    text_image = gbitmap_create_with_resource(RESOURCE_ID_WWDC14TEXT);
    text_image_layer = bitmap_layer_create(GRect(0, 60, 144, 30));
    bitmap_layer_set_bitmap(text_image_layer, text_image);
    layer_add_child(window_layer, bitmap_layer_get_layer(text_image_layer));
    
    // Countdown
	text_countdown_layer = text_layer_create(GRect(0, 88, 144, 33));
	text_layer_set_text_color(text_countdown_layer, GColorWhite);
	text_layer_set_background_color(text_countdown_layer, GColorBlack);
	text_layer_set_font(text_countdown_layer, dolce_vita_font);
	text_layer_set_text_alignment(text_countdown_layer, GTextAlignmentCenter);
    text_layer_set_background_color(text_countdown_layer, GColorClear);
	layer_add_child(window_layer, text_layer_get_layer(text_countdown_layer));
    
    tim_cook_image = gbitmap_create_with_resource(RESOURCE_ID_TIMCOOK);
    tim_cook_image_layer = bitmap_layer_create(GRect(0, 0, 144, 168));
    bitmap_layer_set_bitmap(tim_cook_image_layer, tim_cook_image);
    layer_add_child(window_layer, bitmap_layer_get_layer(tim_cook_image_layer));
	layer_set_hidden(bitmap_layer_get_layer(tim_cook_image_layer), true);
    
	tick_timer_service_subscribe(SECOND_UNIT, handle_second_tick);
    accel_tap_service_subscribe(&acceleration_tap_handler);
    
}
Exemple #16
0
void handle_init() {
  int i;

  srand(time(NULL));
  initColors();

  readConfig();
  swapDigitShapes();
  app_message_init();

  initSplash();

  window = window_create();
  if (invertStatus) {
    window_set_background_color(window, GColorWhite);
  } else {
    window_set_background_color(window, GColorBlack);
  }
  window_stack_push(window, true);

  rootLayer = window_get_root_layer(window);
  mainLayer = layer_create(layer_get_bounds(rootLayer));
  layer_add_child(rootLayer, mainLayer);
  layer_set_update_proc(mainLayer, updateMainLayer);

  for (i=0; i<NUMSLOTS; i++) {
    initSlot(i, mainLayer);
  }

  initDigitCorners();

  animImpl.setup = NULL;
  animImpl.update = animateDigits;
#ifdef PBL_PLATFORM_APLITE
  animImpl.teardown = destroyAnim;
#else
  animImpl.teardown = NULL;
#endif
  createAnim();

  timer = app_timer_register(STARTDELAY, handle_timer, NULL);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);

  accel_tap_service_subscribe(handle_tap);

  lastBluetoothStatus = bluetooth_connection_service_peek();
  bluetooth_connection_service_subscribe(handle_bluetooth);
}
Exemple #17
0
static void init(void) {
	my_window = window_create();
    WindowHandlers handlers = {
		.load = window_load,
        .unload = window_unload
    };
	tick_timer_service_subscribe(SECOND_UNIT, tick_handler);
	accel_tap_service_subscribe(handle_accel);
	battery_state_service_subscribe(handle_battery);
	window_set_click_config_provider(my_window,(ClickConfigProvider) config_provider);
	
	#ifdef PBL_SDK_2
    	window_set_fullscreen(my_window, true);
	#endif

    window_stack_push(my_window, true);  
    toggle_light();
       
	//create easter egg
	pow_white = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_POW);
	pow_black = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_POW_BLACK);
	
	#ifdef PBL_PLATFORM_CHALK
		pow_layer = bitmap_layer_create(GRect(20,10,144,168));
	#else 
		pow_layer = bitmap_layer_create(GRect(0,0,144,168));
	#endif
	
	bitmap_layer_set_bitmap(pow_layer, pow_white);
	layer_add_child(window_get_root_layer(my_window), bitmap_layer_get_layer(pow_layer));
	layer_set_hidden(bitmap_layer_get_layer(pow_layer), true);
       
    //create battery meter
	#ifdef PBL_PLATFORM_CHALK
   		battery_layer = text_layer_create(GRect(25, 5, 140, 34));
	    text_layer_set_text_alignment(battery_layer, GTextAlignmentCenter);
	#else
	   	battery_layer = text_layer_create(GRect(0, 0, 140, 34));
	    text_layer_set_text_alignment(battery_layer, GTextAlignmentRight);
	#endif
	
    text_layer_set_text_color(battery_layer, GColorBlack);
    text_layer_set_background_color(battery_layer, GColorClear);
    text_layer_set_font(battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
    text_layer_set_text(battery_layer, "100%");
    layer_add_child(window_get_root_layer(my_window), text_layer_get_layer(battery_layer));
    layer_set_hidden(text_layer_get_layer(battery_layer), true);
    is_battery_showing = false;
}
Exemple #18
0
void update_configuration(void)
{
    bool show_battery = 1;    /* default to true */

    if (persist_exists(CONFIG_KEY_BATTERY))
    {
        show_battery = persist_read_bool(CONFIG_KEY_BATTERY);
    }
	
	if (show_battery) {
		accel_tap_service_unsubscribe();
		qtp_setup();
	} else {
		qtp_app_deinit();
        accel_tap_service_subscribe(&tap_handler);
	}
}
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);
}
Exemple #20
0
void handle_init(void) {
    window = window_create();
    window_stack_push(window, true);
    w_layer = window_get_root_layer(window);

    background = bitmap_layer_create(layer_get_frame(w_layer));
    background_bmp = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);

    bitmap_layer_set_bitmap(background, background_bmp);
    layer_add_child(w_layer, bitmap_layer_get_layer(background));

    tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
    accel_tap_service_subscribe(handle_tap);

    time_t now = time(NULL);
    struct tm* t = localtime(&now);
    show_time(t);
}
Exemple #21
0
/* Initialize listeners to show and hide Quick Tap Plus as well as update data */
void qtp_setup() {
	qtp_is_showing = false;
	accel_tap_service_subscribe(&qtp_tap_handler);
	qtp_battery_images[0] = gbitmap_create_with_resource(RESOURCE_ID_QTP_IMG_BATE);
	qtp_battery_images[1] = gbitmap_create_with_resource(RESOURCE_ID_QTP_IMG_BATP);
	qtp_battery_images[2] = gbitmap_create_with_resource(RESOURCE_ID_QTP_IMG_BAT);
	qtp_battery_image = qtp_battery_images[0];
	qtp_bluetooth_image = gbitmap_create_with_resource(RESOURCE_ID_QTP_IMG_BT);

#ifdef QTP_K_SUBSCRIBE
	qtp_bluetooth_status = bluetooth_connection_service_peek();
	bluetooth_connection_service_subscribe( qtp_bluetooth_callback );
#endif

#ifdef QTP_K_SHOW_WEATHER
	qtp_setup_app_message();
#endif
}
Exemple #22
0
void handle_init(void) {
  my_window = window_create();
  Layer *window_layer = window_get_root_layer(my_window);
  GRect bounds = layer_get_bounds(window_layer);
  static GFont s_time_font, s_date_font;
  srand(time(NULL));    
  
  text_layer = text_layer_create(GRect(0, 48, bounds.size.w, 55));
  text_layer_set_background_color(text_layer, GColorRed);
  text_layer_set_text_color(text_layer, GColorWhite);
  text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
    
  text_layer2 = text_layer_create(GRect(0, 0, bounds.size.w, 168));
  text_layer_set_background_color(text_layer2, GColorBlack);
  text_layer_set_text_color(text_layer2, GColorWhite);
  text_layer_set_font(text_layer2, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(text_layer2, GTextAlignmentCenter);
    
  layer_add_child(window_layer, text_layer_get_layer(text_layer2));
  layer_add_child(window_layer, text_layer_get_layer(text_layer));
    
  s_date_layer = text_layer_create(GRect(0, 103, 144, 37));
  text_layer_set_text_color(s_date_layer, GColorBlack);
  text_layer_set_background_color(s_date_layer, GColorGreen);
  text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_date_layer));
    
  s_batt_layer = text_layer_create(GRect(0, 143, 144, 25)); 
  text_layer_set_text_color(s_batt_layer, GColorBlack);
  text_layer_set_background_color(s_batt_layer, GColorWhite);
  text_layer_set_font(s_batt_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_batt_layer, GTextAlignmentCenter);
  layer_add_child(window_layer, text_layer_get_layer(s_batt_layer));
    
  window_stack_push(my_window, true);
  update_time();

  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  battery_callback(battery_state_service_peek());
  battery_state_service_subscribe(battery_callback);
  accel_tap_service_subscribe(tap_handler); 
}
Exemple #23
0
static void init(void) {
  // Register with TickTimerService
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  // Register callbacks
  app_message_register_inbox_received(inbox_received_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);

  accel_tap_service_subscribe(tap_handler);

  // Open AppMessage
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

  window = window_create();
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
Exemple #24
0
static void init(void) {
	time_t t;
	struct tm *tm;
	
	initRadiuses();

	readConfig();
	app_message_init();

	window = window_create();
	window_set_background_color(window, GColorBlack);
	window_stack_push(window, false);

	rootLayer = window_get_root_layer(window);

	t = time(NULL);
	tm = localtime(&t);
	
	layer = layer_create(GRect(0, 0, 144, 168));
	layer_set_update_proc(layer, updateScreen);
	layer_add_child(rootLayer, layer);
	
	font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_TIMEBURNER_20));
	
	textFrame = GRect(72-innerCircleInnerRadius, 60, 2*innerCircleInnerRadius, 60);
	textLayer = text_layer_create(textFrame);
	text_layer_set_text_alignment(textLayer, GTextAlignmentCenter);
	text_layer_set_overflow_mode(textLayer, GTextOverflowModeWordWrap);
	text_layer_set_background_color(textLayer, GColorClear);
	text_layer_set_text_color(textLayer, GColorWhite);
	text_layer_set_font(textLayer, font);
	layer_set_hidden(text_layer_get_layer(textLayer), true);
	layer_add_child(rootLayer, text_layer_get_layer(textLayer));
	
	setDate(tm);
	calcAngles(tm);

	tick_timer_service_subscribe(MINUTE_UNIT, handleTick);
	
	accel_tap_service_subscribe(tapHandler);
	bluetooth_connection_service_subscribe(&handle_bluetooth);
}
static void window_load(Window *window)
{
    nw_ui_load(window);

    actions_menu_init();
    actions_menu_attach(window_get_root_layer(window));

    accel_tap_service_subscribe(accelerometer_shake);
    tick_timer_service_subscribe(SECOND_UNIT, (TickHandler) second_tick);
    if (config_disconnectedNotification)
        bluetooth_connection_service_subscribe(bt_handler);

    numOfNotifications = 0;

    for (int i = 0; i < NOTIFICATION_SLOTS; i++)
    {
        notificationData[i] = NULL;
    }

    nw_ui_refresh_notification();
}
Exemple #26
0
void handle_init(void) {
	// Create a window and text layer
	window = window_create();
	text_layer = text_layer_create(GRect(0, 0, 144, 154));
	
	// Set the text, font, and text alignment
	text_layer_set_text(text_layer, "Hi, I'm a Pebble!");
	text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD));
	text_layer_set_text_alignment(text_layer, GTextAlignmentCenter);
	
	// Add the text layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer));

	// Push the window
	window_stack_push(window, true);
	
	// App Logging!
	APP_LOG(APP_LOG_LEVEL_DEBUG, "Just pushed a window!");
	
	accel_tap_service_subscribe(accel_tap_handler);

}
Exemple #27
0
void refresh_settings(){
	phrases_set_settings(main_settings);

	//Little hack to update the words beforehand
	phrases_get_main_swear(true, true);
	phrases_get_main_swear(false, true);

	text_layer_set_text(second_word_t, phrases_get_main_swear(altWordBuffer, false));
	layer_set_frame(text_layer_get_layer(second_word_t), get_new_frame(second_word_t, phrases_get_main_swear(altWordBuffer, false)));
	adapt_font_size_to_frame(second_word_t);

	layer_set_hidden(inverter_layer_get_layer(theme), !main_settings.invert);
	layer_set_hidden(battery_bar_layer, !main_settings.batteryBar);
	layer_set_hidden(text_layer_get_layer(slot_t), false);
	layer_set_hidden(text_layer_get_layer(seconds_t), !main_settings.seconds);
	switch(main_settings.slotUse){
		case SLOT_USE_NOTHING:
			layer_set_hidden(text_layer_get_layer(slot_t), true);
			break;
		case SLOT_USE_CUSTOM_TEXT:
			text_layer_set_text(slot_t, main_settings.customslottext[0]);
			break;
		case SLOT_USE_BLUETOOTH_STATUS:;
			bool connected = bluetooth_connection_service_peek();
			text_layer_set_text(slot_t, phrases_get_bluetooth(connected));
			break;
	}
	if(main_settings.shakeAction == SHAKE_USE_DISABLED){
		accel_tap_service_unsubscribe();
	}
	else{
		accel_tap_service_unsubscribe();
		accel_tap_service_subscribe(shake_handler);
	}
	notify_bar_set_enabled(main_settings.alerts);
	set_animation_use(main_settings.animation);
}
void handle_init() {
  uint32_t seed = 4;
  tinymt32_init(&rndstate, seed);

  window = window_create();
  window_set_fullscreen(window, true);
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);

  // resource_init_current_app(&APP_RESOURCES);

  // Init the layer for the minute display
  // layer_init(&layer, window.layer.frame);
  // layer.update_proc = &layer_update_callback;
  // layer_add_child(&window.layer, &layer);

  init_particles();

  // setup debugging text layer
  GRect window_bounds = layer_get_bounds(window_get_root_layer(window));
  text_header_layer = text_layer_create(window_bounds);
  text_layer_set_text_color(text_header_layer, GColorWhite);
  text_layer_set_background_color(text_header_layer, GColorClear);
  text_layer_set_font(text_header_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_header_layer));
 
  particle_layer = layer_create(window_bounds);
  layer_set_update_proc(particle_layer, update_particles_layer);
  layer_add_child(window_get_root_layer(window), particle_layer);

  app_timer_register(50, handle_animation_timer, NULL);
  app_timer_register(random_in_range(5000, 15000), handle_swarm_timer, NULL);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
  accel_tap_service_subscribe(handle_tap);
}
Exemple #29
0
void handle_init(void) {
  my_window = window_create();
	Layer *window_layer = window_get_root_layer(my_window);
	GRect bounds = layer_get_bounds(window_layer);
  time_layer = text_layer_create(bounds);

	// Size date layer 5/12 of display
	bounds.size.h = (bounds.size.h * 7) / 12;
	bounds.origin.y = bounds.size.h;
	bounds.size.h = (bounds.size.h * 5) / 7;
	date_layer = text_layer_create(bounds);
	
	// Configure layers
	text_layer_set_background_color(time_layer, GColorBlack);
	text_layer_set_text_color(time_layer, GColorWhite);
	text_layer_set_font(time_layer,fonts_get_system_font(FONT_KEY_ROBOTO_BOLD_SUBSET_49));
	text_layer_set_text_alignment(time_layer, GTextAlignmentRight);
	
	text_layer_set_background_color(date_layer, GColorBlack);
	text_layer_set_text_color(date_layer, GColorWhite);
	text_layer_set_font(date_layer,fonts_get_system_font(FONT_KEY_GOTHIC_28));
	text_layer_set_text_alignment(date_layer, GTextAlignmentRight);
	
	// Add layers to window
	layer_add_child(window_layer, text_layer_get_layer(time_layer));
	layer_add_child(window_layer, text_layer_get_layer(date_layer));
	
  window_stack_push(my_window, true);
	
	// Respond to taps
	accel_tap_service_subscribe(tap_handler);
	
	// Update window on load and every minute
	tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
	update_time();
}
Exemple #30
0
void init()
{
    // set up global common state
    common_set_update_callback( send_update_request );
    
    // init windows
    bus_stop_selection_create();
    
    bus_display_create();
    bus_display_show();
    
    // set up app messages
    app_message_register_inbox_received( inbox_received_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() );
    
    // set up periodic updates
    tick_timer_service_subscribe( SECOND_UNIT, tick_handler );
    
    // set up tap recognition
    accel_tap_service_subscribe( tap_handler );
}