Ejemplo n.º 1
0
BatteryComponent* battery_component_create(Layer *parent, int16_t x, int16_t y, bool align_right) {
    battery_state_service_subscribe(battery_handler);

    BatteryComponent *c = malloc(sizeof(BatteryComponent));
    c->icon_layer = NULL;
    c->icon_bitmap = NULL;
    c->text_layer = NULL;

    if (get_prefs()->battery_as_number) {

        FontChoice font = get_font(BATTERY_FONT);
        c->text_layer = add_text_layer(
                            parent,
                            GRect(x, y - font.padding_top + font.padding_bottom, BATTERY_TEXT_WIDTH, font.height + font.padding_top + font.padding_bottom),
                            fonts_get_system_font(font.key),
                            element_fg(parent),
                            align_right ? GTextAlignmentRight : GTextAlignmentLeft
                        );

    } else {

        c->icon_layer = bitmap_layer_create(GRect(x, y + BATTERY_ICON_TOP_FUDGE, BATTERY_ICON_WIDTH, BATTERY_ICON_HEIGHT));
        bitmap_layer_set_compositing_mode(c->icon_layer, element_comp_op(parent));
        layer_add_child(parent, bitmap_layer_get_layer(c->icon_layer));

    }

    // XXX
    s_component = c;
    battery_handler(battery_state_service_peek());

    return c;
}
Ejemplo n.º 2
0
//=====================================
// initiliase/tear down
static void init() {
  // register with the time service
  tick_timer_service_subscribe(SECOND_UNIT, tick_handler);

  //register for battery info updates
  battery_state_service_subscribe(battery_callback);

  // register for bluetooth events
  bluetooth_connection_service_subscribe(bluetooth_callback);

  // 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);

  //open app message
  app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

  //create main window element and assign to pointer
  s_main_window = window_create();
  window_set_background_color(s_main_window, GColorCadetBlue);

  //set handlers to manage elements inside Window
  window_set_window_handlers(s_main_window, (WindowHandlers){
    .load = main_window_load,
    .unload = main_window_unload
  });
Ejemplo n.º 3
0
void init_bar(BatteryChargeState charge_state) {
	battery_state_service_subscribe(&start_bar);
  
  charge_state = battery_state_service_peek();
	uint8_t percent = charge_state.charge_percent*1.44;

  batlayer = text_layer_create(GRect(0, 84, percent, 2));
  text_layer_set_background_color(batlayer,GColorWhite);
  layer_add_child(window_layer, text_layer_get_layer(batlayer));
  batlayer_empty = text_layer_create(GRect(percent, 84, 144, 2));
  text_layer_set_background_color(batlayer_empty,GColorBlack);
  layer_add_child(window_layer, text_layer_get_layer(batlayer_empty));
  
  if(charge_state.is_charging) {
    window_set_background_color(window, GColorWhite);
    text_layer_set_text_color(hour_layer,GColorBlack);
    text_layer_set_text_color(minute_layer,GColorBlack);
    text_layer_set_text_color(day_layer,GColorBlack);
    text_layer_set_text_color(date_layer,GColorBlack);
    text_layer_set_background_color(batlayer,GColorBlack);
    text_layer_set_background_color(batlayer_empty,GColorWhite);
  } else {
    window_set_background_color(window, GColorBlack);
    text_layer_set_text_color(hour_layer,GColorWhite);
    text_layer_set_text_color(minute_layer,GColorWhite);
    text_layer_set_text_color(day_layer,GColorWhite);
    text_layer_set_text_color(date_layer,GColorWhite);
    text_layer_set_background_color(batlayer,GColorWhite);
    text_layer_set_background_color(batlayer_empty,GColorBlack);
  } 
}
Ejemplo n.º 4
0
void watchfaceInit(){
  battery_state_service_subscribe(handle_battery);
  for (int i=0;i<posmax;i++){
    pos[i].x=((i%6)*18)+4;
    pos[i].y=(i/6)*15;
  }
  scramble();
  memset(dsp,0,sizeof(dsp));
  loadBitmapFromResource(0,RESOURCE_ID_d);
  loadBitmapFromResource(1,RESOURCE_ID_e1a1);
  loadBitmapFromResource(2,RESOURCE_ID_e1a2);
  loadBitmapFromResource(3,RESOURCE_ID_edie);
  loadBitmapFromResource(4,RESOURCE_ID_live);
#ifdef PBL_PLATFORM_CHALK
  createTextLayer(0,GRect(40, 130, 100, 45),fonts_get_system_font(FONT_KEY_BITHAM_34_MEDIUM_NUMBERS),GTextAlignmentCenter,GColorGreen,GColorBlack);
  createTextLayer(1,GRect(50, 2, 80, 15),fonts_get_system_font(FONT_KEY_GOTHIC_14),GTextAlignmentCenter,GColorWhite,GColorBlack);
  createTextLayer(2,GRect(50, 120, 80, 15),fonts_get_system_font(FONT_KEY_GOTHIC_14),GTextAlignmentCenter,GColorWhite,GColorBlack);
#else  
 #ifdef PBL_COLOR  
  createTextLayer(0,GRect(-3, 123, 114, 45),fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT),GTextAlignmentLeft,GColorGreen,GColorBlack);
 #else
  createTextLayer(0,GRect(-3, 123, 114, 45),fonts_get_system_font(FONT_KEY_BITHAM_42_LIGHT),GTextAlignmentLeft,GColorWhite,GColorBlack);
 #endif
  createTextLayer(2,GRect(111, 151, 32, 15),fonts_get_system_font(FONT_KEY_GOTHIC_14),GTextAlignmentRight,GColorWhite,GColorBlack);
  createTextLayer(1,GRect(111, 139, 33, 15),fonts_get_system_font(FONT_KEY_GOTHIC_14),GTextAlignmentRight,GColorWhite,GColorBlack);
#endif
  setlocale(LC_ALL, "");
  handle_battery(battery_state_service_peek());
  update_time(true);
}
Ejemplo n.º 5
0
void init() {
	window = window_create();
  window_set_background_color(window, GColorBlack);
	WindowHandlers handlers = {
		.load = window_load,
		.unload = window_unload
	};
	window_set_window_handlers(window, handlers);
  window_set_fullscreen(window, true);

	//Register AppMessage events
	app_message_register_inbox_received(in_received_handler);
	app_message_open(512, 512);		//Large input and output buffer sizes

	window_stack_push(window, true);

  // Init the text layer used to show the time
    time_layer = text_layer_create(GRect(0, 0, 144 /* width */, 50 /* height */));
    text_layer_set_text_color(time_layer, GColorBlack);
    text_layer_set_background_color(time_layer, GColorWhite);
    text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
    text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);

    // Ensures time is displayed immediately (will break if NULL tick event accessed).
    // (This is why it's a good idea to have a separate routine to do the update itself.)
    time_t now = time(NULL);
    struct tm *current_time = localtime(&now);
    handle_battery(battery_state_service_peek());
    handle_second_tick(current_time, SECOND_UNIT);
    tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
    battery_state_service_subscribe(&handle_battery);

    layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));
}
Ejemplo n.º 6
0
void MainMenuWindowAppear(Window *window)
{
	mainMenuVisible = true;
	MenuAppear(window);
	ShowPauseRow(battery_state_service_peek());
	battery_state_service_subscribe(BatteryHandler);
}
Ejemplo n.º 7
0
static void main_window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_frame(window_layer);

  s_text_layer = text_layer_create(GRect(0, 1, bounds.size.w, bounds.size.h - 20));
  text_layer_set_background_color(s_text_layer, GColorBlack);
  text_layer_set_text_color(s_text_layer, GColorWhite);
  text_layer_set_font(s_text_layer, fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD));
  layer_add_child(window_layer, text_layer_get_layer(s_text_layer));
  
  s_connection_layer = text_layer_create(GRect(0, 135, bounds.size.w, 34));
  text_layer_set_text_color(s_connection_layer, GColorWhite);
  text_layer_set_background_color(s_connection_layer, GColorClear);
  text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(s_connection_layer, GTextAlignmentRight);
  handle_bluetooth(bluetooth_connection_service_peek());

  s_battery_layer = text_layer_create(GRect(0, 150, bounds.size.w, 34));
  text_layer_set_text_color(s_battery_layer, GColorWhite);
  text_layer_set_background_color(s_battery_layer, GColorClear);
  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight);
  text_layer_set_text(s_battery_layer, "100% charged");
  
  time_t now = time(NULL);
  struct tm *t = localtime(&now);
  update_time(t);

  tick_timer_service_subscribe(MINUTE_UNIT, &handle_minute_tick);
  battery_state_service_subscribe(handle_battery);
  bluetooth_connection_service_subscribe(handle_bluetooth);

  layer_add_child(window_layer, text_layer_get_layer(s_connection_layer));
  layer_add_child(window_layer, text_layer_get_layer(s_battery_layer));
}
Ejemplo n.º 8
0
void show_watchface(void) {
  initialise_ui();
  
  s_res_charging = gbitmap_create_with_resource(RESOURCE_ID_CHARGING);
  s_res_battery_20 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_20);
  s_res_battery_40 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_40);
  s_res_battery_60 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_60);
  s_res_battery_80 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_80);
  s_res_battery_100 = gbitmap_create_with_resource(RESOURCE_ID_BATTERY_100);
  
  layer_set_update_proc(sCalendarLayer, calendar_layer_update_callback);
  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
  battery_state_service_subscribe(handle_battery);
  bluetooth_connection_service_subscribe(handle_bluetooth);
  
  sTimer = NULL;
  
  btStatus = bluetooth_connection_service_peek();
  handle_battery(battery_state_service_peek());
  
  currentTime = get_time();
  update_time_text();
  update_date_text();
  layer_mark_dirty(sCalendarLayer);
  
  window_set_window_handlers(s_window, (WindowHandlers) {
    .unload = handle_window_unload,
  });
Ejemplo n.º 9
0
/**
 * Handler for the main window.
 *
 * @param {Window*} window
 */
void mainWindowLoad(Window *window) {
  // allocate memory for display strings
  createStrings(&strings);

  timeTextLayer = text_layer_create(GRect(0, 0, 200, 20));
  batteryTextLayer = text_layer_create(GRect(0, 20, 200, 20));
  tempTextLayer = text_layer_create(GRect(0, 40, 200, 20));
  condTextLayer = text_layer_create(GRect(0, 60, 200, 20));
  dateTextLayer = text_layer_create(GRect(0, 80, 200, 20));
  testTextLayer = text_layer_create(GRect(0, 100, 200, 20));

  mainLayer = window_get_root_layer(mainWindow);
  mainBounds = layer_get_bounds(mainLayer);

  // create text layers
  appendTextLayer(mainLayer, timeTextLayer, "Time:");
  appendTextLayer(mainLayer, batteryTextLayer, "Battery:");
  appendTextLayer(mainLayer, tempTextLayer, "Temp:");
  appendTextLayer(mainLayer, condTextLayer, "Cond:");
  appendTextLayer(mainLayer, dateTextLayer, "Date:");

  // subscribe to battery state service
  battery_state_service_subscribe(handleBattery);

  // peek at battery value to fill text layer until the battery event is fired next
  handleBattery(battery_state_service_peek());

  // subscribe to time service
  tick_timer_service_subscribe(MINUTE_UNIT, tickHandler);

  // subscribe to app message service
  app_message_register_inbox_received(messageReceivedHandler);
  app_message_register_inbox_dropped(messageDroppedHandler);
  app_message_open(64, 0);
}
void handle_init() {

  // Configure window
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, BKGD_COLOR);
  window_set_fullscreen(window, true);
  Layer *window_layer = window_get_root_layer(window);

  // Dynamic allocation of assets
  minuteFrame = GRect(53, 16, 40, 40);
  minuteLayer = text_layer_create(minuteFrame);
  hourLayer = bitmap_layer_create(GRect(0, 0, 144, 148));
  batteryLogoLayer = bitmap_layer_create(GRect(65, 151, 10, 15));
  batteryPercentLayer = text_layer_create(GRect(78, 150, 30, 167-150));
  dateLayer = text_layer_create(GRect(3, 150, 38, 167-150));
  dayLayer = text_layer_create(GRect(141-30, 150, 30, 167-150));
  text_layer_set_text_alignment(dayLayer, GTextAlignmentRight);
  bottomBarLayer = layer_create(GRect(1, 149, 142, 18));

  // Setup minute layer
  text_layer_set_text_color(minuteLayer, TEXT_COLOR);
  text_layer_set_background_color(minuteLayer, GColorClear);
  text_layer_set_font(minuteLayer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_MINUTE_38)));

  // Setup date & day layer
  text_layer_set_text_color(dateLayer, TEXT_COLOR);
  text_layer_set_background_color(dateLayer, GColorClear);
  text_layer_set_text_color(dayLayer, TEXT_COLOR);
  text_layer_set_background_color(dayLayer, GColorClear);

  // Setup battery layers
  text_layer_set_text_color(batteryPercentLayer, TEXT_COLOR);
  text_layer_set_background_color(batteryPercentLayer, GColorClear);

  // Setup line layer
  layer_set_update_proc(bottomBarLayer, bottom_bar_layer_update_callback);

  // Add layers into hierachy
  layer_add_child(bitmap_layer_get_layer(hourLayer), text_layer_get_layer(minuteLayer));
  layer_add_child(window_layer, bitmap_layer_get_layer(hourLayer));
  layer_add_child(window_layer, bottomBarLayer);
  layer_add_child(window_layer, bitmap_layer_get_layer(batteryLogoLayer));
  layer_add_child(window_layer, text_layer_get_layer(batteryPercentLayer));
  layer_add_child(window_layer, text_layer_get_layer(dateLayer));
  layer_add_child(window_layer, text_layer_get_layer(dayLayer));

  // Avoids a blank screen on watch start.
  time_t tick_time = time(NULL);
  display_time(localtime(&tick_time));
  handle_battery(battery_state_service_peek());
  handle_bluetooth(bluetooth_connection_service_peek());

  tick_timer_service_subscribe(MINUTE_UNIT, &handle_minute_tick);
  battery_state_service_subscribe(&handle_battery);
  bluetooth_connection_service_subscribe(&handle_bluetooth);

  initialized = true;
}
Ejemplo n.º 11
0
static void init(void)
{
    memset(&time_digits_layers, 0, sizeof(time_digits_layers));
    memset(&time_digits_images, 0, sizeof(time_digits_images));

    const int inbound_size = 64;
    const int outbound_size = 64;
    app_message_open(inbound_size, outbound_size);  

    window = window_create();
    if (window == NULL)
    {
        return;
    }

    window_set_background_color(window, GColorBlack);
    
    canvas = layer_create(GRect(0, 0, 144, 168));
	layer_set_update_proc(canvas, (LayerUpdateProc) render);
	layer_add_child(window_get_root_layer(window), canvas);
	
    window_stack_push(window, true);
    Layer *window_layer = window_get_root_layer(window);
    
    load_settings();
    
    // Open AppMessage connection
    app_message_register_inbox_received(inbox_received_handler);
    app_message_open(128, 128);
    
    //owm_weather_init(5ba77aab84470992ddc7e49e4985aeab);
    //events_app_message_open();
    //owm_weather_fetch();    
    handle_weather();
    
    handle_battery(battery_state_service_peek());
    battery_state_service_subscribe(handle_battery);
 
    // Create time and date layers
    GRect dummy_frame = { {0, 0}, {0, 0} };

    for (int i = 0; i < TOTAL_TIME_DIGITS; i++)
    {
        time_digits_layers[i] = bitmap_layer_create(dummy_frame);
        layer_add_child(window_layer, bitmap_layer_get_layer(time_digits_layers[i]));
    }

    mFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_20));
    mDayText = malloc(mDayTextSize);
    mWeatherText = malloc(mWeatherTextSize);
    mBatteryText = malloc(mBatteryTextSize);
    
    // Avoids a blank screen on watch start.
    time_t now = time(NULL);
    struct tm *tick_time = localtime(&now);
    handle_tick(tick_time, DAY_UNIT + HOUR_UNIT + MINUTE_UNIT);
    
    tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
}
Ejemplo n.º 12
0
/*
 * Main - or main as it is known
 */
int main(void) {
    init();
    tick_timer_service_subscribe(SECOND_UNIT, &handle_tick);
    bluetooth_connection_service_subscribe(&bt_connection_handler);
    battery_state_service_subscribe	(&battery_state_handler);
    app_event_loop();
    deinit();
}
Ejemplo n.º 13
0
static void prv_init(void) {
  if (!s_handler_list) {
    s_handler_list = linked_list_create_root();
  }
  if (linked_list_count(s_handler_list) == 0) {
    battery_state_service_subscribe(prv_handle_state_change);
  }
}
Ejemplo n.º 14
0
void handle_init(void) {
	// Create a window and text layer
	window = window_create();
	text_layer = text_layer_create(GRect(0, TIME_HEIGHT, 144, 168 - TIME_HEIGHT));

	show_seconds = persist_read_bool(KEY_SHOW_SECONDS);
	invert_face = persist_read_bool(KEY_INVERT);
	metric_units = persist_read_bool(KEY_UNITS);
	
	latitude[0] = 0;
	longitude[0] = 0;
	location[0] = 0;
	weather[0] = 0;
	// Set the text, font, and text alignment
	//text_layer_set_text(text_layer, "");
	// http://www.openweathermap.org/current
	// https://developer.getpebble.com/blog/2013/07/24/Using-Pebble-System-Fonts/
	// https://github.com/JvetS/PebbleSimulator/blob/master/PebbleSimulator/pebble_fonts.h
	text_layer_set_font(text_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
	// https://developer.getpebble.com/2/api-reference/group___graphics_types.html
	text_layer_set_text_alignment(text_layer, GTextAlignmentLeft);

	// Add the text layer to the window
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(text_layer));

//	date_layer = text_layer_create(GRect(0, 112, 144, 56));
//	text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
//	text_layer_set_font(date_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
//	layer_add_child(window_get_root_layer(window), text_layer_get_layer(date_layer));
	time_layer = text_layer_create(GRect(0, 0, 144, TIME_HEIGHT));
	text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);
	text_layer_set_font(time_layer, fonts_get_system_font(FONT_PRO_32));
	layer_add_child(window_get_root_layer(window), text_layer_get_layer(time_layer));

	inverter_layer = inverter_layer_create(GRect(0, 0, 144, 168));
	layer_add_child(window_get_root_layer(window), inverter_layer_get_layer(inverter_layer));
	layer_set_hidden(inverter_layer_get_layer(inverter_layer), invert_face);
	
	battery_state_service_subscribe(handle_battery_change);
	handle_battery_change(battery_state_service_peek());

	bluetooth_connection_service_subscribe(handle_bluetooth_change);
	handle_bluetooth_change(bluetooth_connection_service_peek());
	
	app_message_register_inbox_received(in_received_handler);
	app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());

	time_t current_time = time(0);
	handle_timechanges(localtime(&current_time), SECOND_UNIT);
	
	tick_timer_service_subscribe(SECOND_UNIT, handle_timechanges);
	
	// Push the window
	window_stack_push(window, true);

	// App Logging!
	//APP_LOG(APP_LOG_LEVEL_DEBUG, "Hello World from the applogs!");
}
Ejemplo n.º 15
0
static void do_init(void) {
  window = window_create();

  window_stack_push(window, true);
  window_layer = window_get_root_layer(window);
  
  date_layer = text_layer_create(GRect(layers[0][0][0],layers[0][0][1],layers[0][1][0],layers[0][1][1]));
  text_layer_set_text_alignment(date_layer, GTextAlignmentCenter);
  text_layer_set_text(date_layer, "");
  
  ampm_layer = text_layer_create(GRect(layers[3][0][0],layers[3][0][1],layers[3][1][0],layers[3][1][1]));
  text_layer_set_text_alignment(ampm_layer, GTextAlignmentCenter);
  text_layer_set_text(ampm_layer, "");
  text_layer_set_text_color(date_layer, GColorBlack);
  text_layer_set_background_color(date_layer, GColorWhite);
  text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_BOLD_16)));
  
  conn_layer = bitmap_layer_create(
    GRect(layers[1][0][0],layers[1][0][1],layers[1][1][0],layers[1][1][1]));
  load_icon_into_layer(0, bitmap_layer_get_layer(conn_layer));
  
  battery_layer = bitmap_layer_create(
    GRect(layers[2][0][0],layers[2][0][1],layers[2][1][0],layers[2][1][1]));
  load_icon_into_layer(0, bitmap_layer_get_layer(battery_layer));
  
  int adj = 0;
  for (int slot_number = 0; slot_number < TOTAL_IMAGE_SLOTS; slot_number++) {
    digit_slot[slot_number] = bitmap_layer_create(
        GRect(position[slot_number][0][0], position[slot_number][0][1], position[slot_number][1][0], position[slot_number][1][1]));
    
    load_digit_image_into_slot(slot_number, slot_number);
    layer_add_child(window_layer, bitmap_layer_get_layer(digit_slot[slot_number]));
  }
  
    time_t now = time(NULL);
  struct tm *current_time = localtime(&now);
  
  handle_second_tick(current_time, SECOND_UNIT);
  handle_bluetooth(bluetooth_connection_service_peek());
  handle_battery(battery_state_service_peek());
  
  tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
  battery_state_service_subscribe(&handle_battery);
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  
  layer_add_child(window_layer, text_layer_get_layer(date_layer));
  
  window_set_background_color(window, GColorWhite);
  text_layer_set_text_color(date_layer, GColorBlack);
  text_layer_set_background_color(date_layer, GColorWhite);
  text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_ROBOTO_BOLD_16)));

  layer_add_child(window_layer, bitmap_layer_get_layer(conn_layer));
  layer_add_child(window_layer, bitmap_layer_get_layer(battery_layer));
  
  layer_add_child(window_layer, text_layer_get_layer(ampm_layer));
}
Ejemplo n.º 16
0
void set_lowbat_notification(bool state) {
  watch_config.lowbat = state;
  if (state) {
    battery_state_service_subscribe(battery_state_handler);
  } else {
    battery_state_service_unsubscribe();
    lowbattery_handler(false);
  }
}
Ejemplo n.º 17
0
void handle_init(void) {
  window = window_create();
  window_stack_push(window, true /* Animated */);
  window_set_background_color(window, GColorBlack);
  
  fontRobotoCondensed19  = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ROBOTO_CONDENSED_19));
  
  Layer *window_layer = window_get_root_layer(window);
  GRect bounds = layer_get_bounds(window_layer);

  triangle_overlay_layer = layer_create(bounds);
	layer_set_update_proc(triangle_overlay_layer, triangle_display_layer_update_callback);
	layer_add_child(window_layer, triangle_overlay_layer);
	triangle_overlay_path = gpath_create(&TRIANGLE_OVERLAY_POINTS);
	gpath_move_to(triangle_overlay_path, grect_center_point(&bounds));
  
  // init hand paths
  minute_arrow_path = gpath_create(&MINUTE_HAND_POINTS);
  gpath_move_to(minute_arrow_path, grect_center_point(&bounds));
  
  hour_arrow_path = gpath_create(&HOUR_HAND_POINTS);
  gpath_move_to(hour_arrow_path, grect_center_point(&bounds));

  tick_timer_service_subscribe(MINUTE_UNIT, handle_tick);
  

  s_hands_layer = layer_create(bounds);

  layer_set_update_proc(s_hands_layer, hands_update_proc);
  layer_add_child(window_layer, s_hands_layer);
  
  // Battery Line Basalt
   #ifdef PBL_PLATFORM_BASALT
      GRect line_frame = GRect(22, 160, 104, 6);
      LineLayer = layer_create(line_frame);
      layer_set_update_proc(LineLayer, line_layer_update_callback);
      layer_add_child(window_layer, LineLayer);
   #else //Chalk
      GRect line_round_frame = GRect(1, 1, 180, 180);
      RoundBatteryLayer = layer_create(line_round_frame);
      layer_set_update_proc(RoundBatteryLayer, RoundBatteryLayer_update_callback);
      layer_add_child(window_layer,RoundBatteryLayer);
   #endif
     
  //Service subscribes:
  battery_state_service_subscribe(&handle_battery);
  
  handle_battery(battery_state_service_peek());
  
  bluetooth_connection_service_subscribe(&handle_bluetooth);
  handle_bluetooth(bluetooth_connection_service_peek());
     
  app_focus_service_subscribe(&handle_appfocus);

}
Ejemplo n.º 18
0
static void do_init(void) {
	window = window_create();
	window_stack_push(window, true);
	window_set_background_color(window, GColorBlack);
	window_layer = window_get_root_layer(window);
	
	GRect line_frame = GRect(8, 120, 139, 2);
	line_layer = layer_create(line_frame);
	layer_set_update_proc(line_layer, draw_line);
	layer_add_child(window_layer, line_layer);
	
	time_layer = text_layer_create(GRect(5, 66, 118, 70));
	text_layer_set_text_color(time_layer, GColorWhite);
	text_layer_set_background_color(time_layer, GColorClear);
	text_layer_set_font(time_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_44)));
	text_layer_set_text_alignment(time_layer,GTextAlignmentRight);
	layer_add_child(window_layer, text_layer_get_layer(time_layer));
	
	date_layer = text_layer_create(GRect(65, 125, 79, 25));
	text_layer_set_text_color(date_layer, GColorWhite);
	text_layer_set_background_color(date_layer, GColorClear);
	text_layer_set_font(date_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_18)));
	layer_add_child(window_layer, text_layer_get_layer(date_layer));
	
	wday_layer = text_layer_create(GRect(60, 143, 50, 25));
	text_layer_set_text_color(wday_layer, GColorWhite);
	text_layer_set_background_color(wday_layer, GColorClear);
	text_layer_set_font(wday_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_font_droid_18)));
	layer_add_child(window_layer, text_layer_get_layer(wday_layer));
	
	//+時間のNULL回避?(わかってない→調べる
	
	time_t now = time(NULL);
	struct tm *current_time = localtime(&now);
	handle_time_tick(current_time, SECOND_UNIT);
	
	tick_timer_service_subscribe(SECOND_UNIT, &handle_time_tick);

	batt_layer = bitmap_layer_create(GRect(123, 151, 14, 10));
	layer_add_child(window_layer, bitmap_layer_get_layer(batt_layer)); //親レイヤに載せる 
	
	watchicon_layer = bitmap_layer_create(GRect(131, 151, 6, 10));
	layer_add_child(window_layer, bitmap_layer_get_layer(watchicon_layer));
	bitmap_layer_set_background_color(watchicon_layer, GColorClear);
	
	bt_layer = bitmap_layer_create(GRect(110, 151, 11, 10));
	layer_add_child(window_layer, bitmap_layer_get_layer(bt_layer));
	
	handle_battery(battery_state_service_peek());
	battery_state_service_subscribe(&handle_battery);

	handle_bluetooth(bluetooth_connection_service_peek());
	bluetooth_connection_service_subscribe(&handle_bluetooth);
}
Ejemplo n.º 19
0
static void main_window_load(Window *window) {

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


  s_battery_layer = text_layer_create(PBL_IF_ROUND_ELSE(
    GRect(38, 12, bounds.size.w-76, 32),
    GRect(8, 6, bounds.size.w-16, 32)));
  text_layer_set_text_color(s_battery_layer, GColorBlack);
  text_layer_set_background_color(s_battery_layer, GColorClear);
  text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_battery_layer, GTextAlignmentRight);
  text_layer_set_text(s_battery_layer, "100%");

  s_date_layer = text_layer_create(PBL_IF_ROUND_ELSE(
    GRect(38, 12, bounds.size.w-76, 32),
    GRect(8, 6, bounds.size.w-16, 32)));
  text_layer_set_text_color(s_date_layer, GColorBlack);
  text_layer_set_background_color(s_date_layer, GColorClear);
  text_layer_set_font(s_date_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentLeft);
  text_layer_set_text(s_date_layer, "Jan 1");

  s_time_layer = text_layer_create(GRect(0, 48, bounds.size.w, 56));
  text_layer_set_text_color(s_time_layer, GColorWhite);
  text_layer_set_background_color(s_time_layer, GColorMidnightGreen);
  text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_LECO_42_NUMBERS));
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);

  s_steps_layer = text_layer_create(GRect(0, 100, bounds.size.w, 32));
  text_layer_set_text_color(s_steps_layer, GColorBlack);
  text_layer_set_background_color(s_steps_layer, GColorCadetBlue);
  text_layer_set_font(s_steps_layer, fonts_get_system_font(FONT_KEY_GOTHIC_24_BOLD));
  text_layer_set_text_alignment(s_steps_layer, GTextAlignmentCenter);
  text_layer_set_text(s_steps_layer, "0 steps");

  s_connection_layer = text_layer_create(GRect(0, 136, bounds.size.w, 20));
  text_layer_set_text_color(s_connection_layer, GColorBlack);
  text_layer_set_background_color(s_connection_layer, GColorClear);
  text_layer_set_font(s_connection_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  text_layer_set_text_alignment(s_connection_layer, GTextAlignmentCenter);
  handle_bluetooth(connection_service_peek_pebble_app_connection());

  time_t now = time(NULL);
  struct tm *current_time = localtime(&now);
  handle_minute_tick(current_time, MINUTE_UNIT);

  tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick);
  battery_state_service_subscribe(handle_battery);

  connection_service_subscribe((ConnectionHandlers) {
    .pebble_app_connection_handler = handle_bluetooth
  });
static void init() {
  
  tick_timer_service_subscribe(INTERVAL_UPDATE, tick_handler);
  bluetooth_connection_service_subscribe(bt_handler);
  battery_state_service_subscribe(batt_handler);
  
  s_main_window = window_create();
  
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });
Ejemplo n.º 21
0
void init() {
  main_window = window_create();
  
  custom_font_24 = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_CUSTOM_24));
  
  battery_state_service_subscribe(battery_state_changed_handler);
  tick_timer_service_subscribe(MINUTE_UNIT | DAY_UNIT, time_changed_handler);
  
  window_set_window_handlers(main_window, (WindowHandlers) {
    .load = main_window_load,
    .unload = main_window_unload
  });
Ejemplo n.º 22
0
//Инициализация
void init()
{
  //Подписка на события ежеминутного "тика" и смены состояний батареи/блютуза
  tick_timer_service_subscribe(MINUTE_UNIT, (TickHandler) tick_handler);
  battery_state_service_subscribe(batt_handler);
  bluetooth_connection_service_subscribe(bt_handler);
  //Создание окна и задание обработчиков
  window = window_create();
  window_set_window_handlers(window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
Ejemplo n.º 23
0
static void do_init(void) {

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

	Layer *root_layer = window_get_root_layer(window);
	GRect frame = layer_get_frame(root_layer);

	/* Background */
	Anonymous = gbitmap_create_with_resource(RESOURCE_ID_BG_ANONYMOUS);
	Anonymous_Layer = bitmap_layer_create(GRect(0, 0, WIDTH, HEIGHT));
	bitmap_layer_set_background_color(Anonymous_Layer, GColorBlack);
	bitmap_layer_set_bitmap(Anonymous_Layer, Anonymous);
	layer_add_child(root_layer, bitmap_layer_get_layer(Anonymous_Layer));

	/* Time block */
	time_layer = text_layer_create(GRect(0, 52, frame.size.w, 34));
	text_layer_set_text_color(time_layer, GColorBlack);
	text_layer_set_background_color(time_layer, GColorClear);
	text_layer_set_font(time_layer, fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD ));
	text_layer_set_text_alignment(time_layer, GTextAlignmentCenter);

	/* Bluetooth block */
	bt_connected = gbitmap_create_with_resource(RESOURCE_ID_BT_DISCONNECTED);
	bt_connected_layer = bitmap_layer_create(GRect(WIDTH - ICON_WIDTH, 1, ICON_WIDTH, ICON_HEIGHT));
	bitmap_layer_set_background_color(bt_connected_layer, GColorBlack);
	layer_add_child(root_layer, bitmap_layer_get_layer(bt_connected_layer));

	/* Battery block */
	battery_layer = text_layer_create(GRect(2, -2, frame.size.w, 16 ));
	text_layer_set_text_color(battery_layer, GColorWhite);
	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_alignment(battery_layer, GTextAlignmentLeft);
	text_layer_set_text(battery_layer, "100% charged");

	/* Init blocks */
	time_t now = time(NULL);
	struct tm *current_time = localtime(&now);
	handle_second_tick(current_time, SECOND_UNIT);

	tick_timer_service_subscribe(SECOND_UNIT, &handle_second_tick);
	battery_state_service_subscribe(&handle_battery);

	bool connected = bluetooth_connection_service_peek();
	handle_bluetooth(connected);
	bluetooth_connection_service_subscribe(&handle_bluetooth);

	layer_add_child(root_layer, text_layer_get_layer(time_layer));
	layer_add_child(root_layer, text_layer_get_layer(battery_layer));
}
Ejemplo n.º 24
0
/*!
 @brief putメソッドのメッセージを処理する.

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

 */
static void in_received_put_battery_handler(DictionaryIterator *received) {
    DBG_LOG(APP_LOG_LEVEL_DEBUG, "in_received_put_battery_handler");

    Tuple *attributeTuple = dict_find(received, KEY_ATTRIBUTE);
    switch (attributeTuple->value->uint8) {
    case BATTERY_ATTRIBUTE_ON_CHARGING_CHANGE:
        entry_log( "put battery", "ON_CHARGING_CHANGE" ) ;
        event_onchargingchange = true ;
        last_state = battery_state_service_peek();
        battery_state_service_subscribe(&in_event_battery_handler);
        break;
    case BATTERY_ATTRIBUTE_ON_BATTERY_CHANGE:
        entry_log( "put battery", "ON_BATTERY_CHANGE" ) ;
        event_onbatterychange = true ;
        last_state = battery_state_service_peek();
        battery_state_service_subscribe(&in_event_battery_handler);
        break;
    default:
        entry_log( "put battery", "not support" ) ;
        pebble_set_error_code(ERROR_NOT_SUPPORT_ATTRIBUTE);
        break;
    }
}
Ejemplo n.º 25
0
static void do_init(void) {
  s_data.window = window_create();
  const bool animated = true;
  window_stack_push(s_data.window, animated);

  window_set_background_color(s_data.window, GColorBlack);
  GFont font = fonts_get_system_font(FONT_KEY_DROID_SERIF_28_BOLD);

  Layer *root_layer = window_get_root_layer(s_data.window);
  GRect frame = layer_get_frame(root_layer);

  s_data.label = text_layer_create(GRect(0, 0, frame.size.w, frame.size.h));
  text_layer_set_background_color(s_data.label, GColorBlack);
  text_layer_set_text_color(s_data.label, GColorWhite);
  text_layer_set_font(s_data.label, font);
  text_layer_set_text_alignment(s_data.label, GTextAlignmentLeft);
  layer_add_child(root_layer, text_layer_get_layer(s_data.label));

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

  tick_timer_service_subscribe(SECOND_UNIT, &handle_minute_tick);


  bluetoothstatus_layer = text_layer_create(GRect(0, 100, frame.size.w, frame.size.h));
  text_layer_set_text_color(bluetoothstatus_layer, GColorWhite);
  text_layer_set_background_color(bluetoothstatus_layer, GColorBlack);
  text_layer_set_font(bluetoothstatus_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  text_layer_set_text_alignment(bluetoothstatus_layer, GTextAlignmentCenter);	
  layer_add_child(root_layer, text_layer_get_layer(bluetoothstatus_layer));
  
  bluetooth_connection_service_subscribe(bluetooth_connection_callback);	
 
  update_bluetooth(bluetooth_connection_service_peek());
	
  batterystatus_layer = text_layer_create(GRect(0, 120, frame.size.w, frame.size.h));
  text_layer_set_text_color(batterystatus_layer, GColorWhite);
  text_layer_set_background_color(batterystatus_layer, GColorBlack);
  text_layer_set_font(batterystatus_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  text_layer_set_text_alignment(batterystatus_layer, GTextAlignmentCenter);	
  layer_add_child(root_layer, text_layer_get_layer(batterystatus_layer));
  
  BatteryChargeState pb_bat = battery_state_service_peek();
  pebble_batteryPercent = pb_bat.charge_percent;  
  battery_state_service_subscribe(pebble_battery_callback);
  update_pebble_battery(battery_state_service_peek());
	
  icon_bt_on  = gbitmap_create_with_resource( RESOURCE_ID_IMAGE_BT_ON_ICON );
}
Ejemplo n.º 26
0
static void main_window_load(Window *window) {
 // Create GBitmap, then set to created BitmapLayer
//s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_1);


 // Create quote TextLayer 
  s_quote_layer = text_layer_create(GRect(0, 30, 144, 75));
  text_layer_set_background_color(s_quote_layer, GColorClear);
  text_layer_set_text_color(s_quote_layer, GColorBlack);
  text_layer_set_font(s_quote_layer, fonts_get_system_font(FONT_KEY_GOTHIC_18));
  text_layer_set_text_alignment(s_quote_layer, GTextAlignmentCenter);
  
// Create time TextLayer
  s_time_layer = text_layer_create(GRect(0, 106, 144, 50));
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, GColorBlack);
  text_layer_set_font(s_time_layer, fonts_get_system_font(FONT_KEY_BITHAM_42_BOLD));
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  
   s_stat_layer = text_layer_create(GRect(0, 0, 144, 30));
   //text_layer_set_text(s_stat_layer, "World Record: 264.4 hours");
  
   s_twitter_layer = text_layer_create(GRect(0, 101, 144, 16));
   text_layer_set_background_color(s_twitter_layer, GColorClear);
   text_layer_set_text_alignment(s_twitter_layer, GTextAlignmentCenter);
   text_layer_set_font(s_twitter_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  
   s_battery_layer = text_layer_create(GRect(0, 152, 144, 16));
   text_layer_set_background_color(s_battery_layer, GColorBlack);
   text_layer_set_text_color(s_battery_layer, GColorWhite);
   text_layer_set_font(s_battery_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
  
//    s_heading_layer = text_layer_create(GRect(35, 150, 144, 16));
//    text_layer_set_font(s_heading_layer, fonts_get_system_font(FONT_KEY_GOTHIC_14));
//    text_layer_set_text(s_heading_layer, "00.0000  ");
  
  
   // Add as a child layer to the Window's root layer
   layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_stat_layer));
   layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));
   layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_twitter_layer));
   layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_battery_layer));
   layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_quote_layer)); 
  
  
    //layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_heading_layer));
  
    battery_state_service_subscribe(handle_battery);
   
}
Ejemplo n.º 27
0
static void init() {
  APP_LOG(APP_LOG_LEVEL_DEBUG, "start of init");
  autoconfig_init(512, 512);
  app_message_register_inbox_received(in_received_handler);
  main_window_set_config(getMinutes_color(), getMinutes_no_bt_color(), getHours_color(), getHours_no_bt_color(), getText_color(), getText_low_battery_color(), getBg_color(), getBar_radius(), getBar_offset(), getRing_markings(), getLow_bat_threshold());
  BT_VIBE = getBt_vibe();
  main_window_init();
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  battery_state_service_subscribe(battery_callback);
  battery_callback(battery_state_service_peek());
  bluetooth_connection_service_subscribe(bluetooth_callback);
  bluetooth_callback(bluetooth_connection_service_peek());
  APP_LOG(APP_LOG_LEVEL_DEBUG, "end of init");
}
Ejemplo n.º 28
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;
}
Ejemplo n.º 29
0
void init() {
	
	tick_timer_service_subscribe(MINUTE_UNIT, &handle_time);
	bluetooth_connection_service_subscribe(&handle_bluetooth);
	battery_state_service_subscribe(&handle_battery);
	app_message_register_inbox_received((AppMessageInboxReceived) in_recv_handler);
	app_message_open(app_message_inbox_size_maximum(), app_message_outbox_size_maximum());
	
	pwindow = window_create();
	//window_set_click_config_provider(pwindow, click_config_provider);
	
	window_set_window_handlers(pwindow, (WindowHandlers) {
		.load = window_load,
		.unload = window_unload,
	});
Ejemplo n.º 30
0
static void init() {
  // Register with TickTimerService
  tick_timer_service_subscribe(MINUTE_UNIT, tick_handler);
  
  // Register for battery level updates
battery_state_service_subscribe(battery_callback);
  
  // 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
  });