Exemplo n.º 1
0
void check_a()
{
	if (!CFG_REFRESH_INDEXES && !CFG_REFRESH_INDEXES_ALL)
		return;
       /* if ((access(CFG_PKG_LIST, F_OK) == -1) || (access(CFG_PKG_COUNT, F_OK) == -1) ||
            (access(CFG_PKG_LIST_INSTALLED, F_OK) == -1) || (access(CFG_PKG_COUNT_INSTALLED, F_OK) == -1)) {
                generate_index(CFG_PKG_LIST, CFG_PKG_COUNT, CFG_PKG_LIST_INSTALLED, CFG_PKG_COUNT_INSTALLED);
        	free(pkgs);
        	free(pkgs_i);
        	printf("Reading package database...\n");
        	read_index1(CFG_PKG_LIST, CFG_PKG_COUNT);
        	read_index2(CFG_PKG_LIST_INSTALLED, CFG_PKG_COUNT_INSTALLED);		
        } else
        if (update_date(CFG_UPDATE_FILE) > update_date(CFG_PKG_LIST)) {
                generate_index(CFG_PKG_LIST, CFG_PKG_COUNT, CFG_PKG_LIST_INSTALLED, CFG_PKG_COUNT_INSTALLED);
        	free(pkgs);
        	free(pkgs_i);
        	printf("Reading package database...\n");
        	read_index1(CFG_PKG_LIST, CFG_PKG_COUNT);
        	read_index2(CFG_PKG_LIST_INSTALLED, CFG_PKG_COUNT_INSTALLED);
        }*/

	if ((access(CFG_PKG_LIST, F_OK) == -1) || (access(CFG_PKG_COUNT, F_OK) == -1)) {
		generate_index1();
		free(pkgs);
        	printf("Reading package database [1]...\n");
		read_index1(CFG_PKG_LIST, CFG_PKG_COUNT);
	} else
	if (update_date(CFG_UPDATE_FILE) > update_date(CFG_PKG_LIST)) {
		generate_index1();
		free(pkgs);
        	printf("Reading package database [1]...\n");
		read_index1(CFG_PKG_LIST, CFG_PKG_COUNT);
	}

	if ((access(CFG_PKG_LIST_INSTALLED, F_OK) == -1) || (access(CFG_PKG_COUNT_INSTALLED, F_OK) == -1)) {
		generate_index2();
        	free(pkgs_i);
        	printf("Reading package database [2]...\n");
        	read_index2(CFG_PKG_LIST_INSTALLED, CFG_PKG_COUNT_INSTALLED);
	} else
	if (update_date(CFG_UPDATE_FILE_INSTALLED) > update_date(CFG_PKG_LIST_INSTALLED)) {
		generate_index2();
        	free(pkgs_i);
        	printf("Reading package database [2]...\n");
        	read_index2(CFG_PKG_LIST_INSTALLED, CFG_PKG_COUNT_INSTALLED);
	}
}
Exemplo n.º 2
0
void main_window_load(Window *window) {
  marine_spritesheet = gbitmap_create_with_resource(RESOURCE_ID_DOOM_MARINE_SPRITES);
  
  marine_charging = gbitmap_create_with_resource(RESOURCE_ID_DOOM_MARINE_SPRITE_CHARGING);
  
  marine_layer = layer_create(GRect(0, 0, 144, 168));
  layer_set_update_proc(marine_layer, draw_marine_layer);
  layer_add_child(window_get_root_layer(window), marine_layer);
  
  time_layer = rounded_text_layer_create(GRect(0, 140, 144, 28), 8, GCornersTop);
  rounded_text_layer_set_font(time_layer, custom_font_24);
  layer_add_child(window_get_root_layer(window), time_layer);
  
  date_layer = rounded_text_layer_create(GRect(0, 0, 144, 28), 8, GCornersBottom);
  rounded_text_layer_set_font(date_layer, custom_font_24);
  layer_add_child(window_get_root_layer(window), date_layer);
  
  anim_data.current_x = 1;
  anim_data.previous_x = 1;
  anim_data.current_battery_state = battery_state_service_peek();
  
  update_time();
  update_date();
  layer_mark_dirty(marine_layer);
  
  marine_animation_timer = app_timer_register(SPRITE_TIMEOUT, marine_animate, NULL);
}
/**
 * Tick timer handler
 */
static void tick_handler(struct tm *tick_time, TimeUnits units_changed)
{ 
  s_is_sleepy_time = (tick_time->tm_hour <= SLEEPY_TIME_END_HOUR && tick_time->tm_hour >= SLEEPY_TIME_START_HOUR);
  
  text_layer_set_text_color(s_timeAccText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));
  text_layer_set_text_color(s_timeText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));
  text_layer_set_text_color(s_dateText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));
  text_layer_set_text_color(s_newsText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));

  //APP_LOG(APP_LOG_LEVEL_INFO, "Updating displayed news story...");
  display_news_weather();
  // Set weather text colour
  set_weather_text_colour();
  
  update_timeish(s_timeText,s_timeAccText);
  
  // update the date on the day change
  if(units_changed == DAY_UNIT)
  {
    //APP_LOG(APP_LOG_LEVEL_INFO, "Updating date...");
    update_date(s_dateText);
  }

  // Get news/weather update every 12 minutes outside sleepy time
  if(!s_is_sleepy_time && (tick_time->tm_min % NEWS_WEATHER_UPDATE_PERIOD_MINS == 0))
  {
    request_news_weather_data();
    
    // refresh time to prevent clipping of third line
    update_timeish(s_timeText,s_timeAccText);
  }
}
Exemplo n.º 4
0
void handle_init(AppContextRef ctx) {
  (void)ctx;

  window_init(&window, "Bar Graph");
  window_stack_push(&window, true /* Animated */);

  resource_init_current_app(&APP_RESOURCES);

  bmp_init_container(RESOURCE_ID_IMAGE_FACE, &faceImage);
  layer_add_child(&window.layer, &faceImage.layer.layer);

  layer_init(&hourLayer, window.layer.frame);
  hourLayer.update_proc = &update_hour;
  layer_add_child(&window.layer, &hourLayer);

  layer_init(&minLayer, window.layer.frame);
  minLayer.update_proc = &update_minute;
  layer_add_child(&window.layer, &minLayer);

  text_layer_init(&dateText, GRect(0,138,144,30));
  text_layer_set_text_color(&dateText, GColorWhite);
  text_layer_set_background_color(&dateText, GColorClear);
  text_layer_set_text_alignment(&dateText, GTextAlignmentCenter);
  text_layer_set_font(&dateText, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_ARIAL_22)));
  layer_add_child(&window.layer, &dateText.layer);

  update_date();
}
Exemplo n.º 5
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
	if (persist_read_bool(KEY_SHOW_DAY)) {
		update_day(tick_time);
	}
	update_time(tick_time);
	if (persist_read_bool(KEY_SHOW_DATE)) {
		update_date(tick_time);
	}
}
Exemplo n.º 6
0
void time_changed_handler(struct tm *tick_time, TimeUnits units_changed) {
  if((units_changed & MINUTE_UNIT) != 0) {
    update_time();
  }

  if((units_changed & DAY_UNIT) != 0) {
    update_date();
  }
}
Exemplo n.º 7
0
static void init_layers() {
  time_t temp = time(NULL);
  struct tm *tick_time = localtime(&temp);
  // Set current date
  update_date(tick_time, MINUTE_UNIT);
  // Set current time
  tick_handler(tick_time, MINUTE_UNIT);
  
  battery_handler(battery_state_service_peek());
}
Exemplo n.º 8
0
// Time handlers
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
	update_time();
  update_date();
  
  if (tick_time->tm_min % 30 == 0) {
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);
    dict_write_uint8(iter, 0, 0);
    app_message_outbox_send();
  }
}
Exemplo n.º 9
0
Arquivo: main.c Projeto: musl/DataFace
/*
 * Handle time changes.
 */
static void tick_cb(struct tm *tick_time, TimeUnits units_changed) {

	if(bit_is_set(units_changed, SECOND_UNIT)) {
		update_cldr(tick_time);
		update_date(tick_time);
		update_time(tick_time);
	}

	if(bit_is_set(units_changed, MINUTE_UNIT)) {
		if(tick_time->tm_min % 15 == 0) fetch_weather();
	}

}
Exemplo n.º 10
0
static void handle_second_tick(struct tm* tick_time, TimeUnits units_changed) {
  static int day_m = 40;
  static int hour_m = 33;
  static int min_m = 77;
  static bool clock24 = false;
  
  if (clock24 != clock_is_24h_style()) {
    clock24 = clock_is_24h_style();
    for (int slot_number = 4; slot_number < TOTAL_IMAGE_SLOTS; slot_number++) {
      GRect bounds = layer_get_frame(bitmap_layer_get_layer(digit_slot[slot_number]));
      if (clock24) {
        bounds.origin.y = 19;
      } else {
        bounds.origin.y = 35;
      }
      layer_set_frame(bitmap_layer_get_layer(digit_slot[slot_number]), bounds);
    }
    GRect bounds = layer_get_frame(text_layer_get_layer(date_layer));
    if (clock24) {
      bounds.origin.y = 52;
    } else {
      bounds.origin.y = 62;
    }
    layer_set_frame(text_layer_get_layer(date_layer), bounds);
    layer_set_hidden((Layer *)ampm_layer, clock24);
  }
  
  if (day_m != tick_time->tm_mday) {
    day_m = tick_time->tm_mday;
    update_date(tick_time);
    text_layer_set_text(date_layer, date_text);
  }
  if (hour_m != tick_time->tm_hour) {
    hour_m = tick_time->tm_hour;
    display_value(get_display_hour(tick_time->tm_hour), 0, true);
    if (!clock_is_24h_style()) {
      if (hour_m >=12) {
        text_layer_set_text(ampm_layer, "PM");
      } else {
        text_layer_set_text(ampm_layer, "AM");
      }
    }
  }
    
  if (min_m != tick_time->tm_min) {
    min_m = tick_time->tm_min;
    display_value(tick_time->tm_min, 1, true);  
  }
  display_value(tick_time->tm_sec, 2, true);
}
Exemplo n.º 11
0
void main()
{
   brdInit();
	sock_init();
	http_init();
	init_dateform();
   init_log();

	tcp_reserveport(80);			// mark port 80 as a server port.

	for(;;) {
		update_date();
		http_handler();
	}
}
Exemplo n.º 12
0
static void
gcal_year_view_set_property (GObject      *object,
                             guint         prop_id,
                             const GValue *value,
                             GParamSpec   *pspec)
{
  switch (prop_id)
    {
    case PROP_DATE:
      update_date (GCAL_YEAR_VIEW (object), g_value_dup_boxed (value));
      break;

    default:
      G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
    }
}
Exemplo n.º 13
0
void handle_tick(AppContextRef ctx, PebbleTickEvent *t) {
  (void)ctx;
  (void)t;

  if ((t->units_changed & HOUR_UNIT) != 0) {
    layer_mark_dirty(&hourLayer);
  }

  if ((t->units_changed & MINUTE_UNIT) != 0) {
    layer_mark_dirty(&minLayer);
  }

  if ((t->units_changed & DAY_UNIT) != 0) {
    update_date();
  }
}
Exemplo n.º 14
0
void main(void)
{
   brdInit();
   sock_init_or_exit(1);   // call debug function (provides handy information)
   http_init();
   init_dateform();
   init_log();

   tcp_reserveport(80); // mark port 80 as a server port.

   for (;;)
   {
      update_date();
      http_handler();
   }
}
Exemplo n.º 15
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time();
  update_date();

  // Get weather update every 30 minutes
  if(tick_time->tm_min % 30 == 0) {
    // Begin dictionary
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);

    // Add a key-value pair
    dict_write_uint8(iter, 0, 0);

    // Send the message!
    app_message_outbox_send();
  }
}
Exemplo n.º 16
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
    if (MINUTE_UNIT)
    {
        update_time();
        if (tick_time->tm_hour >= 9 && tick_time->tm_hour <= 17 && tick_time->tm_min % 15 == 0) {
            ActivityLevelType level = check_active_status();
            if (level == DEAD)
            {
                workout_reminder();
            }
        }

        should_update = (tick_time->tm_hour >= 7 && tick_time->tm_hour <= 22) ? true : false;
    }

    if (DAY_UNIT) {
        update_date();
    }
}
Exemplo n.º 17
0
// Window Handlers
static void main_window_load(Window *window) {
  // background
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_BACKGROUND_IMAGE);
  s_background_layer = bitmap_layer_create(GRect(0, 0, 144, 168));
  bitmap_layer_set_bitmap(s_background_layer, s_background_bitmap);
  layer_add_child(window_get_root_layer(window), bitmap_layer_get_layer(s_background_layer));
  
  // date text layer
  s_date_layer = text_layer_create(GRect(0, 10, 144, 40));
  text_layer_set_background_color(s_date_layer, GColorBlack);
  text_layer_set_text_color(s_date_layer, GColorWhite);
  text_layer_set_text_alignment(s_date_layer, GTextAlignmentCenter);
  
  // time text layer
  s_time_layer = text_layer_create(GRect(5, 52, 139, 50));
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, GColorBlack);
  
  // weather layer
  s_weather_layer = text_layer_create(GRect(0, 120, 144, 25));
  text_layer_set_background_color(s_weather_layer, GColorClear);
  text_layer_set_text_color(s_weather_layer, GColorWhite);
  text_layer_set_text_alignment(s_weather_layer, GTextAlignmentCenter);
  text_layer_set_text(s_weather_layer, "Loading...");
  
  // improve the view
  s_time_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_PERFECT_DOS_VGA_48));
  s_standard_font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
  improve_text_layer(s_time_layer, s_time_font);
  improve_text_layer(s_date_layer, s_standard_font);
  improve_text_layer(s_weather_layer, s_standard_font);
  
  // add our text layers
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_date_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_weather_layer));
  
  // displays time upon load
  update_time();
  update_date();

}
Exemplo n.º 18
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time(tick_time, units_changed);
  
  // On the hour
  if (tick_time->tm_min == 0) {
    // On the day
    if (tick_time->tm_hour == 0) {
      update_date(tick_time, units_changed);
    }
    // Begin dictionary
    DictionaryIterator *iter;
    app_message_outbox_begin(&iter);

    // Add a key-value pair
    dict_write_uint8(iter, 0, 0);

    // Send the message!
    app_message_outbox_send();
  }
}
Exemplo n.º 19
0
static void update_display(struct tm *current_time, bool force_update) {

  update_seconds(current_time->tm_sec);

  if (current_time->tm_sec == 0 || force_update) {
  	// the hours and minutes
    update_time(current_time);

    if ((current_time->tm_hour == 0 && current_time->tm_min == 0) || force_update) {
  		// the day and date
      update_date(current_time->tm_mday, current_time->tm_wday);

	  if (current_time->tm_mday == 1 || force_update) {
    	update_month(current_time->tm_mon);

    	if (current_time->tm_mon == 0 || force_update) {
    	  update_year(current_time->tm_year);
    	}
      }
  	}
  }
}
Exemplo n.º 20
0
Arquivo: main.c Projeto: musl/DataFace
/*
 * Manually update the ui.
 */
static void update_all() {

	static BatteryChargeState battery_state;
	static bool bluetooth_state;
	static time_t gmt;
	static struct tm *local_time;

	// Prepare to update the UI manually.
	//
	battery_state = battery_state_service_peek();
	bluetooth_state = bluetooth_connection_service_peek();
	gmt = time(NULL);
	local_time = localtime(&gmt);

	// Draw everything that we can, so that there isn't a blank screen
	// on start-up.
	//
	update_time(local_time);
	update_date(local_time);
	update_cldr(local_time);
	update_batt(battery_state);
	update_blth(bluetooth_state);

}
Exemplo n.º 21
0
static void window_load(Window *window) {
	Layer *window_layer = window_get_root_layer(window);
	GRect bounds = layer_get_bounds(window_layer);
		int offset = !b_show_numbers * 10;

	s_simple_bg_layer = layer_create(bounds);
	layer_set_update_proc(s_simple_bg_layer, bg_update_proc);
	layer_add_child(window_layer, s_simple_bg_layer);

	window_set_background_color(window, gcolor_background);

#ifdef PBL_RECT
  date_layer_right = text_layer_create(GRect(
    (bounds.size.w - DATE_LAYER_HORIZONTAL_OFFSET),
    (bounds.size.h/2 - DATE_LAYER_VERTICAL_OFFSET), 
    DATE_LAYER_HORIZONTAL_OFFSET,
    60));

  date_layer_left = text_layer_create(GRect(
    0,
    (bounds.size.h/2 - DATE_LAYER_VERTICAL_OFFSET),
    DATE_LAYER_HORIZONTAL_OFFSET + offset,
    60));
  
  date_layer_bottom = text_layer_create(GRect(
    0,
    (bounds.size.h - DATE_LAYER_BOTTOM_OFFSET),
    bounds.size.w,
    DATE_LAYER_BOTTOM_OFFSET));
#else
  date_layer_right = text_layer_create(GRect(
    (bounds.size.w - DATE_LAYER_HORIZONTAL_OFFSET),
    (bounds.size.h/2 - DATE_LAYER_VERTICAL_OFFSET), 
    DATE_LAYER_HORIZONTAL_OFFSET,
    60));

  date_layer_left = text_layer_create(GRect(
    0,
    (bounds.size.h/2 - DATE_LAYER_VERTICAL_OFFSET),
    DATE_LAYER_HORIZONTAL_OFFSET + (offset * 4),
    60));
  
  date_layer_bottom = text_layer_create(GRect(
    0,
    (bounds.size.h - DATE_LAYER_BOTTOM_OFFSET),
    bounds.size.w,
    DATE_LAYER_BOTTOM_OFFSET + (offset * 2)));
 #endif
 
  text_layer_set_background_color(date_layer_right, GColorClear);
  text_layer_set_text_color(date_layer_right, gcolor_numbers);
  text_layer_set_text_alignment(date_layer_right, GTextAlignmentCenter);
  text_layer_set_font(date_layer_right, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  
  text_layer_set_background_color(date_layer_left, GColorClear);
  text_layer_set_text_color(date_layer_left, gcolor_numbers);
  text_layer_set_text_alignment(date_layer_left, GTextAlignmentCenter);
  text_layer_set_font(date_layer_left, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
  
  text_layer_set_background_color(date_layer_bottom, GColorClear);
  text_layer_set_text_color(date_layer_bottom, gcolor_numbers);
  text_layer_set_text_alignment(date_layer_bottom, GTextAlignmentCenter);
  text_layer_set_font(date_layer_bottom, fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD));
 update_date();
 layer_add_child(window_layer, text_layer_get_layer(date_layer_right));
  layer_add_child(window_layer, text_layer_get_layer(date_layer_left));
  layer_add_child(window_layer, text_layer_get_layer(date_layer_bottom));

	s_hands_layer = layer_create(bounds);
	layer_set_update_proc(s_hands_layer, hands_update_proc);
	layer_add_child(window_layer, s_hands_layer);

	load_persisted_values();
}
Exemplo n.º 22
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time();
  update_steps();
  update_date();
}
Exemplo n.º 23
0
static void parse_trip_date(char *line, struct membuffer *str, void *_trip)
{ dive_trip_t *trip = _trip; update_date(&trip->when, line); }
Exemplo n.º 24
0
static void parse_dc_date(char *line, struct membuffer *str, void *_dc)
{ struct divecomputer *dc = _dc; update_date(&dc->when, line); }
Exemplo n.º 25
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
    layer_mark_dirty(s_wall_time_layer);
    if (settings.show_date) {
        update_date(tick_time);
    }
}
Exemplo n.º 26
0
void update_status()
{
    #ifdef DEBUG
    char buffer[256];
    sprintf(buffer, "Update Status: draw Memory %s", sbar_status_symbols[DrawMemory].active ? "yes" : "no");
    log_str(buffer, LOG_DEBUG);
    sprintf(buffer, "Update Status: draw Battery %s", sbar_status_symbols[DrawBattery].active ? "yes" : "no");
    log_str(buffer, LOG_DEBUG);
    sprintf(buffer, "Update Status: draw Uptime %s", sbar_status_symbols[DrawUptime].active ? "yes" : "no");
    log_str(buffer, LOG_DEBUG);
    sprintf(buffer, "Update Status: draw Termal %s", sbar_status_symbols[DrawTermal].active ? "yes" : "no");
    log_str(buffer, LOG_DEBUG);
    #ifdef NF310_A01
    sprintf(buffer, "Update Status: draw Backlight %s", sbar_status_symbols[DrawBacklight].active ? "yes" : "no");
    log_str(buffer, LOG_DEBUG);
    #endif
    sprintf(buffer, "Update Status: draw Net %s", sbar_status_symbols[DrawNet].active ? "yes" : "no");
    log_str(buffer, LOG_DEBUG);
    #endif
    
    if(sbar_status_symbols[DrawMemory].active) {
      get_memory();
      
      #ifdef DEBUG
      log_str("Sucessfully Updated Memory", LOG_DEBUG);
      #endif
    }
    
    if(sbar_status_symbols[DrawBattery].active) {
      check_battery();

      #ifdef DEBUG
      log_str("Sucessfully Updated Battery", LOG_DEBUG);
      #endif
    }

    cpu_usage();

    #ifdef DEBUG
    log_str("Sucessfully Updated CPU", LOG_DEBUG);
    #endif

    update_date();

    #ifdef DEBUG
    log_str("Sucessfully Updated Date", LOG_DEBUG);
    #endif

    if(sbar_status_symbols[DrawUptime].active) {
      update_uptime();

      #ifdef DEBUG
      log_str("Sucessfully Updated Uptime", LOG_DEBUG);
      #endif
    }

    if(sbar_status_symbols[DrawTermal].active) {
      get_thermal();

      #ifdef DEBUG
      log_str("Sucessfully Updated Termal", LOG_DEBUG);
      #endif
    }

    #ifdef NF310_A01
    if(sbar_status_symbols[DrawBacklight].active) {
      update_backlight();

      #ifdef DEBUG
      log_str("Sucessfully Updated Backlight", LOG_DEBUG);
      #endif
    }
    #endif

    if(sbar_status_symbols[DrawNet].active) {
      update_net();

      #ifdef DEBUG
      log_str("Sucessfully Updated Net", LOG_DEBUG);
      #endif
    }

    update_disk();

    #ifdef DEBUG
    log_str("Sucessfully Updated Disk", LOG_DEBUG);
    #endif

}
Exemplo n.º 27
0
static void hands_update_proc(Layer *layer, GContext *ctx) {
	GRect bounds = layer_get_bounds(layer);
	GPoint center = grect_center_point(&bounds);
	int16_t second_hand_length = bounds.size.w / 2 - 5;
	int16_t second_hand_tail_length = 15;

	time_t now = time(NULL);
	struct tm *t = localtime(&now);
	int32_t second_angle = TRIG_MAX_ANGLE * t->tm_sec / 60;
	int32_t second_angle_tail = TRIG_MAX_ANGLE * (t->tm_sec + 30) / 60;

	GPoint second_hand = {
		.x = (int16_t)(sin_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.x,
		.y = (int16_t)(-cos_lookup(second_angle) * (int32_t)second_hand_length / TRIG_MAX_RATIO) + center.y,
	};
	GPoint second_hand_tail = {
		.x = (int16_t)(sin_lookup(second_angle_tail) * (int32_t)second_hand_tail_length / TRIG_MAX_RATIO) + center.x,
		.y = (int16_t)(-cos_lookup(second_angle_tail) * (int32_t)second_hand_tail_length / TRIG_MAX_RATIO) + center.y,
	};

	// temperature
	if (b_show_temperature) {
		graphics_context_set_text_color(ctx, gcolor_numbers);
		int offset = !b_show_numbers * 10;
#ifdef PBL_RECT
		graphics_draw_text(ctx, s_temp_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_14), GRect(27 - offset, 75, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
#else
		graphics_draw_text(ctx, s_temp_buffer, fonts_get_system_font(FONT_KEY_GOTHIC_18), GRect(40 - offset, 78, 40 + offset, 14), GTextOverflowModeWordWrap, GTextAlignmentCenter, NULL);
#endif
	}

	// minute hand
	graphics_context_set_fill_color(ctx, gcolor_minute_hand);
	gpath_rotate_to(s_minute_arrow, TRIG_MAX_ANGLE * t->tm_min / 60);
	gpath_draw_filled(ctx, s_minute_arrow);

	// hour hand
	graphics_context_set_fill_color(ctx, gcolor_hour_hand);
	gpath_rotate_to(s_hour_arrow, (TRIG_MAX_ANGLE * (((t->tm_hour % 12) * 6) + (t->tm_min / 10))) / (12 * 6));
	gpath_draw_filled(ctx, s_hour_arrow);

	// second hand
	if (b_show_second_hand) {
		graphics_context_set_stroke_color(ctx, gcolor_second_hand);
		graphics_draw_line(ctx, second_hand, center);
		graphics_draw_line(ctx, second_hand_tail, center);
	}

	// dot in the middle
	graphics_context_set_fill_color(ctx, gcolor_second_hand);
	graphics_fill_circle(ctx, GPoint(bounds.size.w / 2, bounds.size.h / 2), 4);
}

static void update_date(void){
  time_t now = time(NULL);
  struct tm *t = localtime(&now);
  
  //corrects for 24h time
  int hour = (t->tm_hour < 13) ? t->tm_hour : t->tm_hour - 12;
  
  static char date_buffer[16];
  
  //strategically put the date where the hands are not covering
  if((t->tm_min < 7 || t->tm_min > 23) && (hour < 1 || hour >= 5)){
    strftime(date_buffer, sizeof(date_buffer), "%a\n%d", t);
    text_layer_set_text(date_layer_right, date_buffer);
    text_layer_set_text(date_layer_left, "\0");
    text_layer_set_text(date_layer_bottom, "\0"); 
  }
  else if((t->tm_min < 37 || t->tm_min > 53) && (hour < 7 || hour > 11)){
    strftime(date_buffer, sizeof(date_buffer), "%a\n%d", t);
    text_layer_set_text(date_layer_left, date_buffer);
    text_layer_set_text(date_layer_right, "\0");
    text_layer_set_text(date_layer_bottom, "\0");
  }
  else{
    strftime(date_buffer, sizeof(date_buffer), "%a %d", t);
    text_layer_set_text(date_layer_bottom, date_buffer);
    text_layer_set_text(date_layer_right, "\0");
    text_layer_set_text(date_layer_left, "\0");
  }
}

static void handle_second_tick(struct tm *tick_time, TimeUnits units_changed) {
	layer_mark_dirty(window_get_root_layer(window));
  update_date();
}
Exemplo n.º 28
0
static void main_window_load(Window *window) {
    Layer *window_layer = window_get_root_layer(window);
    GRect bounds = layer_get_bounds(window_layer);
    s_timehour_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_Font_AgentB_72));
    s_timemin_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_Font_AgentB_44));
    s_timeampm_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_Font_AgentB_22));
    s_smaller_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_Font_AgentB_22));
    xHalf = bounds.size.w / 2;

    // Create Hours Time display
    s_timehours_layer = text_layer_create(
                            GRect(0, 39, xHalf + 20, 94));
    text_layer_set_background_color(s_timehours_layer, GColorClear);
    text_layer_set_text_color(s_timehours_layer, GColorRed);
    text_layer_set_font(s_timehours_layer, s_timehour_font);
    text_layer_set_text_alignment(s_timehours_layer, GTextAlignmentRight);

    // Create Minutes Time display
    s_timemins_layer = text_layer_create(
                           GRect(0, 46, xHalf + 20, 68));
    text_layer_set_background_color(s_timemins_layer, GColorClear);
    text_layer_set_text_color(s_timemins_layer, GColorWhite);
    text_layer_set_font(s_timemins_layer, s_timemin_font);
    text_layer_set_text_alignment(s_timemins_layer, GTextAlignmentRight);

    // Create AM or PM Time display
    s_time_ampm_layer = text_layer_create(
                            GRect(0, 89, xHalf + 20, 68));
    text_layer_set_background_color(s_time_ampm_layer, GColorClear);
    text_layer_set_text_color(s_time_ampm_layer, GColorLightGray);
    text_layer_set_font(s_time_ampm_layer, s_timeampm_font);
    text_layer_set_text_alignment(s_time_ampm_layer, GTextAlignmentRight);

    // Create Steps display
    s_steps_layer = text_layer_create(
                        GRect(0, 125, bounds.size.w, 24));
    text_layer_set_background_color(s_steps_layer, GColorClear);
    text_layer_set_text_color(s_steps_layer, GColorWhite);
    text_layer_set_font(s_steps_layer, s_smaller_font);
    text_layer_set_text_alignment(s_steps_layer, GTextAlignmentCenter);

    //Create Day display
    s_day_layer = text_layer_create(
                      GRect(0, 24, bounds.size.w, 26));
    text_layer_set_background_color(s_day_layer, GColorClear);
    text_layer_set_text_color(s_day_layer, GColorLightGray);
    text_layer_set_font(s_day_layer, s_smaller_font);
    text_layer_set_text_alignment(s_day_layer, GTextAlignmentCenter);

    //Create Battery display
    s_battery_layer = layer_create(bounds);
    layer_set_update_proc(s_battery_layer, layer_update_proc);

    update_time();
    update_date();
    battery_state_handler(battery_state_service_peek());

    layer_add_child(window_layer, text_layer_get_layer(s_timehours_layer));
    layer_add_child(window_layer, text_layer_get_layer(s_timemins_layer));
    layer_add_child(window_layer, text_layer_get_layer(s_time_ampm_layer));
    layer_add_child(window_layer, text_layer_get_layer(s_steps_layer));
    layer_add_child(window_layer, text_layer_get_layer(s_day_layer));
    layer_add_child(window_layer, s_battery_layer);
}
Exemplo n.º 29
0
/**
 * Window load handler function
 */
static void mainWindowLoad(Window *w)
{
  init_hardware_icons();
  
  // Get information about the root window
  Layer *windowLayer = window_get_root_layer(w);
  GRect bounds = layer_get_bounds(windowLayer);
  
  // Set sleepy time flag
  time_t temp_time = time(NULL);
  struct tm *cur_time = localtime(&temp_time); 
  s_is_sleepy_time = (cur_time->tm_hour <= SLEEPY_TIME_END_HOUR && cur_time->tm_hour >= SLEEPY_TIME_START_HOUR);
  
  //////////////////////////////////////////
  // Battery
  
  GRect bat_icon_bounds = get_battery_icon_bounds();
  
  // Create BitmapLayer to display the GBitmap
  s_powerIconLayer = bitmap_layer_create(GRect(bounds.size.w - (bat_icon_bounds.size.w + 2),
                                               0, bat_icon_bounds.size.w, bat_icon_bounds.size.h));

  // set background colout and compositing mode 
  bitmap_layer_set_background_color(s_powerIconLayer, POWER_ICON_BACK_COLOR);
  bitmap_layer_set_compositing_mode(s_powerIconLayer, GCompOpSet);
  
  update_power_status(battery_state_service_peek());
  
  // add the bitmap layer to the window
  layer_add_child(windowLayer, bitmap_layer_get_layer(s_powerIconLayer));
  
  //////////////////////////////////////////
  // BT connection

  GRect bt_icon_bounds = get_bt_icon_bounds();
  
  // Create BitmapLayer to display the GBitmap
  s_btIconLayer = bitmap_layer_create(GRect(bounds.size.w - (bat_icon_bounds.size.w + bt_icon_bounds.size.w + 4), 4, bt_icon_bounds.size.w, bt_icon_bounds.size.h));

  // set background colout and compositing mode 
  bitmap_layer_set_background_color(s_btIconLayer, BT_ICON_BACK_COLOR);
  bitmap_layer_set_compositing_mode(s_btIconLayer, GCompOpSet);
  
  update_bt_status(connection_service_peek_pebble_app_connection());
  
  // add the bitmap layer to the window
  layer_add_child(windowLayer, bitmap_layer_get_layer(s_btIconLayer));
  
  ////////////////////////////////////
  // Create the time text layers
  
  // time accuracy text layer
  s_timeAccText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(-2, -6), 94, 28));
  
  // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_timeAccText, TIME_TEXT_BACK_COLOR);
  text_layer_set_text_color(s_timeAccText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));
  
  //s_timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_42));
  GFont timeFont = fonts_get_system_font(FONT_KEY_GOTHIC_24);
  
  text_layer_set_font(s_timeAccText, timeFont);
  text_layer_set_text_alignment(s_timeAccText, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_timeAccText));
    
  // time text layer
  s_timeText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(20, 16), bounds.size.w-4, 100));
  
  // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_timeText, TIME_TEXT_BACK_COLOR);
  text_layer_set_text_color(s_timeText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));

  update_timeish(s_timeText,s_timeAccText);
  
  //s_timeFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_42));
  timeFont = fonts_get_system_font(FONT_KEY_BITHAM_30_BLACK);
  
  text_layer_set_font(s_timeText, timeFont);
  text_layer_set_text_alignment(s_timeText, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_timeText));
  
  ///////////////////////////////////
  // Create the date text layer
  s_dateText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(128, 122), bounds.size.w-4, 16));
  
   // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_dateText, TIME_TEXT_BACK_COLOR);
  text_layer_set_text_color(s_dateText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));

  update_date(s_dateText);
  
  //s_dateFont = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_FFF_TUSJ_24));
  GFont dateFont = fonts_get_system_font(FONT_KEY_GOTHIC_14_BOLD);
  
  text_layer_set_font(s_dateText, dateFont);
  text_layer_set_text_alignment(s_dateText, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_dateText));
  
  //////////////////////////////////
  // Create the weather text layer
  s_weatherText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(112, 108), bounds.size.w-4, 18));
  
   // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_weatherText, TIME_TEXT_BACK_COLOR);

  update_weather((Tuple *)NULL,(Tuple *)NULL, (Tuple *)NULL);
  
  GFont weatherFont = fonts_get_system_font(FONT_KEY_GOTHIC_14);
  
  text_layer_set_font(s_weatherText, weatherFont);
  text_layer_set_text_alignment(s_weatherText, GTextAlignmentLeft);
  
  // Set weather text colour
  set_weather_text_colour();

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_weatherText));
  
  //////////////////////////////////
  // Create the news text layer
  s_newsText = text_layer_create(GRect(2, PBL_IF_ROUND_ELSE(142, 136), bounds.size.w-4, 30));
  
   // Improve the layout to be more like a watchface
  text_layer_set_background_color(s_newsText, TIME_TEXT_BACK_COLOR);
  text_layer_set_text_color(s_newsText, (s_is_sleepy_time ? TIME_TEXT_FORE_COLOR_NIGHT : TIME_TEXT_FORE_COLOR_DAY));

  display_news_weather();
  
  text_layer_set_font(s_newsText, weatherFont);
  text_layer_set_text_alignment(s_newsText, GTextAlignmentLeft);

  // Add it as a child layer to the Window's root layer
  layer_add_child(windowLayer, text_layer_get_layer(s_newsText));
  
}
Exemplo n.º 30
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time();
  update_date();
  send_message_to_get_temp();
}