Ejemplo n.º 1
0
void set_face_fonts() {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Setting fonts. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
    text_layer_set_font(hours, time_font);
    text_layer_set_font(date, medium_font);
    text_layer_set_font(alt_time, base_font);
    text_layer_set_font(battery, base_font);
    text_layer_set_font(bluetooth, custom_font);
    text_layer_set_font(update, custom_font);
    text_layer_set_font(weather, weather_font);
    text_layer_set_font(min_icon, custom_font);
    text_layer_set_font(max_icon, custom_font);
    text_layer_set_font(temp_cur, base_font);
    text_layer_set_font(temp_min, base_font);
    text_layer_set_font(temp_max, base_font);
    text_layer_set_font(speed, base_font);
    text_layer_set_font(direction, custom_font);
    text_layer_set_font(wind_unit, custom_font);

    #if defined(PBL_HEALTH)
    text_layer_set_font(steps, base_font);
    text_layer_set_font(dist, base_font);
    text_layer_set_font(cal, base_font);
    text_layer_set_font(sleep, base_font);
    text_layer_set_font(deep, base_font);
    #endif

    APP_LOG(APP_LOG_LEVEL_DEBUG, "Fonts set. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
}
Ejemplo n.º 2
0
static void process_frame(const char * const body)
{
   jsmn_parser parser;
   qword elapsed = time_ms();
   
   jsmn_init(&parser);
   int r = jsmn_parse(&parser, body, tokens, NUM_TOKENS);
   if(r != 0) 
   {
      _log(MAJOR, "Parser result %d.  Message discarded.", r);
      stats[NotRecog]++;
   }
   else
   {
      size_t messages, i, index;
      // Is it an array?
      if(tokens[0].type == JSMN_ARRAY)
      {
         messages = tokens[0].size;
         index = 1;
         _log(DEBUG, "STOMP message is array of %d TD messages.", messages);
      }
      else
      {
         messages = 1;
         index = 0;
         _log(DEBUG, "STOMP message contains a single TD message.");
      }

      for(i=0; i < messages && run; i++)
      {
         char area_id[4];
         word describer;
         jsmn_find_extract_token(body, tokens, index, "area_id", area_id, sizeof(area_id));

         stats[GoodMessage]++;
         message_count++;

         for(describer = 0; describer < DESCRIBERS; describer++)
         {
            if(!strcasecmp(area_id, describers[describer]))
            {
               process_message(describer, body, index);
               stats[RelMessage]++;
               message_count_rel++;
               describer = DESCRIBERS;
            }
         }
         
         size_t message_ends = tokens[index].end;
          do  index++; 
         while ( tokens[index].start < message_ends && tokens[index].start >= 0 && index < NUM_TOKENS);
      }
   }
   elapsed = time_ms() - elapsed;
   if(debug || elapsed > 2500)
   {
      _log(MINOR, "Frame took %s ms to process.", commas_q(elapsed));
   }
}
Ejemplo n.º 3
0
static void update_display(Layer* layer, GContext *ctx) {
  double BRANCHES = dbl(8.0);
  double INITIAL_LENGTH = dbl(20.0);
  double pi_8 = dbl(0.39269908169);
  double width = dbl(72.0);
  double height = dbl(158.0);
  double negone = dbl(-1.0);
  double dzero = dbl(0.0);
  
  time_t start_time;
  uint16_t start_time_ms; 
  time_ms(&start_time, &start_time_ms);

  lean_left = dbl(1.12);
  lean_right = dbl(1.12);

  draw_tree(ctx,
      width, //144 / 2,
      height,//168 - 10,
      dzero, negone,
      INITIAL_LENGTH,
      pi_8,
      BRANCHES);
  time_t end_time;
  uint16_t end_time_ms; 
  time_ms(&end_time, &end_time_ms);
  printf("took %ld ms", 
      (end_time * 1000 + end_time_ms) -
      (start_time * 1000 + start_time_ms));
}
Ejemplo n.º 4
0
void service_runonce(struct service_t * service) {
	uint32_t count = 0;
	service_tick(service, time_ms()/100);	//处理定时器
	while (1) {	//处理业务
		int type = 0;
		void * packet = gsq_pop(service->g2s_queue, &type);
		if (!packet) break;
		switch (type) {
		case G2S_TCP_ACCEPTED: {
			struct g2s_tcp_accepted_t * ev = (struct g2s_tcp_accepted_t*)packet;
			l_on_tcp_accepted(service, ev);
			break;
		}
		case G2S_TCP_CLOSED: {
			struct g2s_tcp_closed_t * ev = (struct g2s_tcp_closed_t*)packet;
			l_on_tcp_closed(service, ev);
			break;
		}
		case G2S_TCP_DATA: {
			struct g2s_tcp_data_t * ev = (struct g2s_tcp_data_t*)packet;
			l_on_tcp_data(service, ev);
			break;
		}
		case G2S_TCP_CONNECTED: {
			struct g2s_tcp_connected_t* ev = (struct g2s_tcp_connected_t*)packet;
			l_on_tcp_connected(service, ev);
			break;
		}
		case G2S_TCP_LISTENED: {
			struct g2s_tcp_listened_t* ev = (struct g2s_tcp_listened_t*)packet;
			l_on_tcp_listened(service, ev);
			break;
		}
		default: {
			assert(0);
		}
		}
		FREE (packet);
		if (++count%100 == 0)	{					//100是经验值可换成别的, 每处理100个业务包就处理一下定时器
			service_tick(service, time_ms()/100);	//处理定时器	
		}
		service_check_notify_gate_to_work(service);
	}

	if (count) service_tick(service, time_ms()/100);
	service_check_notify_gate_to_work(service);
	gsq_notify_wait_g(service->g2s_queue, 100);
}
Ejemplo n.º 5
0
double time_count() {
	time_t seconds;
	uint16_t mill;
	time_ms(&seconds, &mill);
	//Returns the current time
	return (seconds * 1000 + mill);
}
Ejemplo n.º 6
0
int ExpirationHandler::set_ttl(const Bytes &key, int64_t ttl){
	int64_t expired = time_ms() + ttl * 1000;
	char data[30];
	int size = snprintf(data, sizeof(data), "%" PRId64, expired);
	if(size <= 0){
		log_error("snprintf return error!");
		return -1;
	}

	int ret = ssdb->zset(this->list_name, key, Bytes(data, size));
	if(ret == -1){
		return -1;
	}

	if(!this->enable){
	    return 0;
	}

	if(expired < first_timeout){
		first_timeout = expired;
	}
	std::string s_key = key.String();
	fast_keys.del(s_key);
	if(expired <= fast_keys.max_score()){
		fast_keys.add(s_key, expired);
		if(fast_keys.size() > BATCH_SIZE){
			log_debug("pop_back");
			fast_keys.pop_back();
		}
	}else{
		//log_debug("don't put in fast_keys");
	}
	
	return 0;
}
Ejemplo n.º 7
0
int main(void)
{
	struct timeval t;
	struct timeval beginning = current_time();
	float m;	/* Used for a fun calculation. */

	t = current_time();
	printf("Current time in seconds since the epoch:  %d.%06ds\n",
		t.tv_sec, t.tv_usec);

	t = time_difference(current_time(), t);
	printf("Since that last printf, %d.%06d seconds have passed.\n",
		t.tv_sec, t.tv_usec);

	printf("Now we'll sleep for a second and time it.  (whee...)\n");
	t = current_time();
	sleep(1);
	t = time_difference(current_time(), t);
	m = 100.0 * ((float)t.tv_sec - 1.0 + (float)(t.tv_usec) / 1000000.0);
	printf("'sleep(1)' actually took %d.%06ds; it was off by %f%%.\n",
		t.tv_sec, t.tv_usec, m);
	printf("thank you for your time...your %dms to be more precise.\n",
		time_ms(time_difference(current_time(), beginning)));

	return 0;
}
Ejemplo n.º 8
0
void update_layer_callback(Layer *me, GContext *ctx) {
    // Get the amount of seconds and the milliseconds part since the Epoch
    // time_ms also returns the milliseconds, so you can optionally pass in null
    // for any output parameters you don't need
    time_t t = 0;
    uint16_t t_ms = 0;
    time_ms(&t, &t_ms);

    // Get the next pseudo-random number
    int r = rand();

    // Print formatted text into a buffer
    snprintf(info_text, sizeof(info_text),
             "str: %s\n"
             "time: %lu\n"
             "milliseconds: %u\n"
             "rand: %d",
             str_example, t, t_ms, r);

    // Draw the formatted text
    graphics_context_set_text_color(ctx, GColorBlack);
    graphics_text_draw(ctx,
                       info_text,
                       fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD),
    (GRect) {
        .origin = GPoint(10, 5), .size = window.layer.frame.size
    },
Ejemplo n.º 9
0
static void countdown_layer_update_proc(Layer *layer, GContext *ctx) {
  uint16_t ms;
  time_t time;
  time_ms(&time, &ms);
  int seconds = time % 30;
  int units = (seconds*20) + (ms / 50);
  
  graphics_context_set_fill_color(ctx, layer_color);
  
  /*
	#ifdef PBL_COLOR
  */
		if (seconds >= 24) {
			if (seconds % 2 == 0)
				graphics_context_set_fill_color(ctx, GColorRed);
		}
  /*
	#endif
  */
  if (hidden && thickness > 0)
    thickness--;
  else if (!hidden && thickness < 7)
    thickness++;
    /*
  if (!hidden)
    countdown_rect.size.w = ((24 * reverse_seconds) / 5) - (ms / 208);
  */
//  APP_LOG(APP_LOG_LEVEL_DEBUG, "S:%d MS:%d W:%d", reverse_seconds, ms, countdown_width);
  
  graphics_fill_radial(ctx, layer_get_bounds(countdown_layer), GOvalScaleModeFitCircle, thickness, 0, TIME_ANGLE(units));
}
Ejemplo n.º 10
0
Archivo: db.c Proyecto: josephg/sharedb
void db_create(database *db, dstr doc_name, ot_type *type,
    void *user, db_create_cb callback) {
  assert(db);
  assert(doc_name);
  assert(type);
  dictEntry *entry = dictFind(db->docs, doc_name);
  if (entry) {
    if (callback) callback("Document already exists", dictGetVal(entry), user);
  } else {
    // Create it.
    ot_document *doc = malloc(sizeof(ot_document));
    doc->name = dstr_retain(doc_name);
    doc->type = type;
    doc->snapshot = type->create(),
    doc->version = 0;
    doc->op_cache_capacity = 100;
    doc->op_cache = malloc(type->op_size * doc->op_cache_capacity);
    doc->retain_count = 0;
    doc->open_pair_head = NULL;
    doc->ctime = doc->mtime = time_ms();
    
    dictAdd(db->docs, (void *)doc_name, doc);
    if (callback) callback(NULL, doc, user);
  }
}
Ejemplo n.º 11
0
int64_t ExpirationHandler::get_ttl(const Bytes &key){
	std::string score;
	if(ssdb->zget(this->list_name, key, &score) == 1){
		int64_t ex = str_to_int64(score);
		return (ex - time_ms())/1000;
	}
	return -1;
}
Ejemplo n.º 12
0
void updateSecondHand(Layer* secondLayer, GContext* ctx) {
	struct tm* currentTime = getTime();
	
	updateGenericHand(secondHandPath, ctx,
		currentTime->tm_sec / 60.0 + 
		time_ms(NULL, NULL) / 60000.0
	);
}
Ejemplo n.º 13
0
uint64_t stop_timer(time_t *sec, uint16_t *msec) {
  time_t elapsed_sec;
  uint16_t elapsed_msec;
  time_ms(&elapsed_sec, &elapsed_msec);
  uint64_t time1 = *sec * 1000 + *msec;
  uint64_t time2 = elapsed_sec * 1000 + elapsed_msec;
  return time2 - time1;
}
Ejemplo n.º 14
0
int main() {
	unsigned long start_time = time_ms();
		
	// A contains real values
	for (int i=0; i<N; i++) {
		for (int j=0; j<M; j++) {
			A[i][j] = i*j;
		}
	}

	// B is the identity matrix
	for (int i=0; i<M; i++) {
		for (int j=0; j<K; j++) {
			B[i][j] = (i==j)?1:0;
		}
	}

	// conduct multiplication
	for (int i=0; i<N; i++) {
		for (int j=0; j<K; j++) {
			for (int k=0; k<M; k++) {
				C[i][j] += A[i][k] * B[k][j];
			}
		}
	}

	// verify result
	int success = 1;	
	for (int i=0; i<N; i++) {
		for (int j=0; j<MIN(M,K); j++) {
			if (A[i][j] != C[i][j]) {
				success = 0;
			}
		}
		for (int j=MIN(M,K); j<MAX(M,K); j++) {
			if (C[i][j] != 0) {
				success = 0;
			}
		}
	}

	// print verification result
	printf("Verification: %4s\n", (success) ? "OK" : "ERR");
	printf("Time: %9lu ms\n", time_ms() - start_time);
}
Ejemplo n.º 15
0
void set_colors(Window *window) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Defining colors. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
    base_color = persist_exists(KEY_HOURSCOLOR) ? GColorFromHEX(persist_read_int(KEY_HOURSCOLOR)) : GColorWhite;
    text_layer_set_text_color(hours, base_color);
    enable_advanced = is_advanced_colors_enabled();
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Advanced colors %d", enable_advanced);
    GColor min_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_MINCOLOR)) : base_color;
    GColor max_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_MAXCOLOR)) : base_color;

    #if defined(PBL_HEALTH)
    steps_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_STEPSCOLOR)) : base_color;
    steps_behind_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_STEPSBEHINDCOLOR)) : base_color;
    dist_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_DISTCOLOR)) : base_color;
    dist_behind_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_DISTBEHINDCOLOR)) : base_color;
    cal_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_CALCOLOR)) : base_color;
    cal_behind_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_CALBEHINDCOLOR)) : base_color;
    sleep_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_SLEEPCOLOR)) : base_color;
    sleep_behind_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_SLEEPBEHINDCOLOR)) : base_color;
    deep_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_DEEPCOLOR)) : base_color;
    deep_behind_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_DEEPBEHINDCOLOR)) : base_color;
    #endif

    text_layer_set_text_color(date,
            enable_advanced ? GColorFromHEX(persist_read_int(KEY_DATECOLOR)) : base_color);
    text_layer_set_text_color(alt_time,
            enable_advanced ? GColorFromHEX(persist_read_int(KEY_ALTHOURSCOLOR)) : base_color);
    text_layer_set_text_color(weather,
            enable_advanced ? GColorFromHEX(persist_read_int(KEY_WEATHERCOLOR)) : base_color);
    text_layer_set_text_color(temp_cur,
            enable_advanced ? GColorFromHEX(persist_read_int(KEY_TEMPCOLOR)) : base_color);
    text_layer_set_text_color(temp_min, min_color);
    text_layer_set_text_color(min_icon, min_color);
    text_layer_set_text_color(temp_max, max_color);
    text_layer_set_text_color(max_icon, max_color);

    text_layer_set_text_color(speed, enable_advanced ? GColorFromHEX(persist_read_int(KEY_WINDSPEEDCOLOR)) : base_color);
    text_layer_set_text_color(wind_unit, enable_advanced ? GColorFromHEX(persist_read_int(KEY_WINDSPEEDCOLOR)) : base_color);
    text_layer_set_text_color(direction, enable_advanced ? GColorFromHEX(persist_read_int(KEY_WINDDIRCOLOR)) : base_color);

    battery_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_BATTERYCOLOR)) : base_color;
    battery_low_color = enable_advanced ? GColorFromHEX(persist_read_int(KEY_BATTERYLOWCOLOR)) : base_color;

    window_set_background_color(window, persist_read_int(KEY_BGCOLOR) ? GColorFromHEX(persist_read_int(KEY_BGCOLOR)) : GColorBlack);
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Defined colors. %d%03d", (int)time(NULL), (int)time_ms(NULL, NULL));
}
Ejemplo n.º 16
0
HIDE void profReport(char *fmt, ...) {
  long npt=time_ms();
  va_list v;
  va_start(v,fmt);
  Rvprintf(fmt,v);
  va_end(v);
  Rprintf(" %ld ms\n",npt-profilerTime);
  profilerTime=npt;
}
Ejemplo n.º 17
0
static void render(GContext *ctx) {
#ifdef BENCHMARK
  uint16_t start = time_ms(NULL, NULL);
#endif

  pge_isometric_begin(ctx);

  // Tiles
  for(int z = 0; z < GRID_DEPTH; z++) {
    for(int y = 0; y < GRID_HEIGHT; y++) {
      for(int x = 0; x < GRID_WIDTH; x++) {
        block_render(s_block_array[vec2i(Vec3(x, y, z))]);
      }
    }
  }

  for(int i = 0; i < MAX_CLOUDS; i++) {
    cloud_render(s_cloud_array[i]);
  }

  // Selection
  switch(s_input_mode) {
    case MODE_X:
      pge_isometric_draw_rect(Vec3(0, s_cursor.y * BLOCK_SIZE, (s_cursor.z + 1) * BLOCK_SIZE), GSize(GRID_WIDTH * BLOCK_SIZE, BLOCK_SIZE), GColorWhite);
      break;
    case MODE_Y:
      pge_isometric_draw_rect(Vec3(s_cursor.x * BLOCK_SIZE, 0, (s_cursor.z + 1) * BLOCK_SIZE), GSize(BLOCK_SIZE, GRID_HEIGHT * BLOCK_SIZE), GColorWhite);
      break;
    case MODE_Z:
      pge_isometric_draw_box(Vec3(s_cursor.x * BLOCK_SIZE, s_cursor.y * BLOCK_SIZE,  BLOCK_SIZE), GSize(BLOCK_SIZE, BLOCK_SIZE), (GRID_DEPTH - 1) * BLOCK_SIZE, GColorWhite);
      break;
  }
  pge_isometric_draw_box(Vec3(s_cursor.x * BLOCK_SIZE, s_cursor.y * BLOCK_SIZE, s_cursor.z * BLOCK_SIZE), GSize(BLOCK_SIZE, BLOCK_SIZE), BLOCK_SIZE, GColorRed);

  // Box
  pge_isometric_draw_box(Vec3(0, 0, 0), GSize(BLOCK_SIZE * GRID_WIDTH, BLOCK_SIZE * GRID_HEIGHT), SKY_HEIGHT, GColorLightGray);

  pge_isometric_finish(ctx);

#ifdef BENCHMARK
  uint16_t finish = time_ms(NULL, NULL);
  APP_LOG(APP_LOG_LEVEL_INFO, "Frame time: %d ms", (int)finish - start);
#endif
}
Ejemplo n.º 18
0
void* ExpirationHandler::thread_func(void *arg){
	ExpirationHandler *handler = (ExpirationHandler *)arg;
	
	int64_t last_load_empty_times = 0;
	while(!handler->thread_quit){
		SSDB *ssdb = handler->ssdb;
		if(!ssdb){
			break;
		}
		if(!handler->enable){
			usleep(10 * 1000);
			continue;
		}
		int64_t current = time_ms();
		if(handler->fast_keys.empty() && (current - last_load_empty_times) < ADVANCE_READ_TTL * 1000){
			usleep(10 * 1000);
			continue;
		}
		if(!handler->fast_keys.empty() && handler->first_timeout > current){
			usleep(10 * 1000);
			continue;
		}
		{
			Locking l(&handler->mutex);
			if(!handler->enable){
			    continue;
			}
            // TOODO 增加最大值的限制
			if(handler->fast_keys.empty()){
				int64_t expired = current + ADVANCE_READ_TTL * 1000;
				handler->load_expiration_keys_from_db(expired, BATCH_SIZE);
				handler->first_timeout = INT64_MAX;
				if(handler->fast_keys.empty()) {
				    last_load_empty_times = current;
				}
			}
		
			int64_t score;
			std::string key;
			if(handler->fast_keys.front(&key, &score)){
				handler->first_timeout = score;
				
				if(score <= current){
					log_debug("expired %s", key.c_str());
					ssdb->del(key);
					ssdb->zdel(handler->list_name, key);
					handler->fast_keys.pop_front();
				}
			}
		}
	}
	
	log_debug("ExpirationHandler thread quit");
	handler->thread_quit = false;
	return (void *)NULL;
}
Ejemplo n.º 19
0
void timer_callback(void* _) {
  time_t time;
  uint16_t mstime = time_ms(&time, 0);
  //setTime(time/60, time%60, mstime/100);
  char buffer[129];
  snprintf(buffer, 128, "Timer");
  APP_LOG(APP_LOG_LEVEL_DEBUG, "Timer callback called");
  view_setDebugLabel("Timer callback called");
  g_timer = app_timer_register(TIMER_TIMEOUT, timer_callback, 0);
}
Ejemplo n.º 20
0
Archivo: ttl.cpp Proyecto: beykery/ssdb
void* ExpirationHandler::thread_func(void *arg){
	ExpirationHandler *handler = (ExpirationHandler *)arg;
	
	while(!handler->thread_quit){
		SSDB *ssdb = handler->ssdb;
		if(!ssdb){
			break;
		}
		if(handler->first_timeout > time_ms()){
			usleep(10 * 1000);
			continue;
		}
		
		{
			Locking l(&handler->mutex);
			if(handler->fast_keys.empty()){
				handler->load_expiration_keys_from_db(BATCH_SIZE);
				handler->first_timeout = INT64_MAX;
			}
		
			int64_t score;
			std::string key;
			if(handler->fast_keys.front(&key, &score)){
				handler->first_timeout = score;
				
				if(score <= time_ms()){
					log_debug("expired %s", key.c_str());
					ssdb->del(key);
					ssdb->zdel(handler->list_name, key);
					handler->fast_keys.pop_front();
				}
			}
		}
	}
	
	log_debug("ExpirationHandler thread quit");
	handler->thread_quit = false;
	return (void *)NULL;
}
Ejemplo n.º 21
0
static void step(struct arcan_shmif_cont* cont)
{
	printf("pre;%lld;%d;%d\n", time_ms(), pi, ti);
	pi = (pi + 1) % (sizeof(palette) / sizeof(palette[0]));
	ti = (ti + 1) % (sizeof(tones) / sizeof(tones[0]));
	size_t count = cont->pitch * cont->h;
	for (size_t i = 0; i < count; i++)
		cont->vidp[i] = palette[pi];

/* will create pop:ing as any queued buffers are dropped */
	arcan_shmif_enqueue(cont, &(arcan_event){
		.tgt.kind = ARCAN_EVENT(FLUSHAUD)
	});
Ejemplo n.º 22
0
// Returns the number of milliseconds since midnight, UTC.
unsigned int get_time_ms() {
  time_t s;
  uint16_t ms;
  unsigned int result;

  time_ms(&s, &ms);
  result = (unsigned int)((s % SECONDS_PER_DAY) * 1000 + ms);

#ifdef FAST_TIME
  result *= 67;
#endif  // FAST_TIME

  return result;
}
Ejemplo n.º 23
0
static void timer_callback(void *data) {
  currentAnimationStep--;

  if(currentAnimationStep < 0){
    isAnimating = false;
    from_image->addr = from_addr;
    currentAnimationStep = NUMBER_OF_IMAGES_IN_ANIMATION;
  }
  else {
    time_t now = time(NULL);
    uint16_t ms = 0;
    time_ms (&now,&ms); 
    uint32_t totaltime = now * 1000 + ms;
    computeMorphingBitmap(from_image, dest_image, tmp_image, currentAnimationStep);
    time_ms (&now,&ms); 
    totaltime = now * 1000 + ms - totaltime;
    APP_LOG(APP_LOG_LEVEL_INFO, "Image %d/%d computed in %ld ms", (NUMBER_OF_IMAGES_IN_ANIMATION-currentAnimationStep), NUMBER_OF_IMAGES_IN_ANIMATION, totaltime);
    uint8_t* addr = from_image->addr;
    from_image->addr = tmp_image->addr;
    tmp_image->addr = addr;
  }
  layer_mark_dirty(layer);
}
Ejemplo n.º 24
0
Archivo: main.c Proyecto: x/pebble-test
static int32_t get_ms_since_last_call() {
  /* Returns the number of milliseconds since global last_time and
     updates last_time to be the current time in ms. Will return 0
     the first time it's called.
  */
  time_t secs;
  uint16_t millisecs;
  int32_t this_time, ms_since;
  time_ms(&secs, &millisecs);
  this_time = 1000 * (int32_t)secs + (int32_t)millisecs;
  ms_since = last_time ? this_time - last_time : 0;
  last_time = this_time;
  return ms_since;
}
Ejemplo n.º 25
0
static void tap_handler(AccelAxisType axis, int32_t direction) {
  static time_t last_tap = 0;
  time_t seconds;
  
  time_ms(&seconds, NULL);

  if (seconds - last_tap < 5) {
    last_tap = seconds;
    return;
  }
  
  last_tap = seconds;
  spin_globe(0, direction);
}
Ejemplo n.º 26
0
// Returns the number of milliseconds since midnight, UTC.
unsigned int get_time_ms() {
  time_t gmt;
  uint16_t t_ms;
  unsigned int ms_utc;

  time_ms(&gmt, &t_ms);
  ms_utc = (unsigned int)((gmt % SECONDS_PER_DAY) * 1000 + t_ms);

#ifdef FAST_TIME
  ms_utc *= 67;
#endif  // FAST_TIME

  return ms_utc;
}
Ejemplo n.º 27
0
// Pause timing
static void select_click_handler(ClickRecognizerRef recognizer, void *context) {
    timer.paused = !timer.paused;
    APP_LOG(APP_LOG_LEVEL_DEBUG, "Paused: %s", timer.paused?"true":"false");

    if(!timer.paused){
        time_ms(&timer.last_paused_s, &timer.last_paused_ms);
        timer.elapsed_ms_at_pause = timer.elapsed_ms;
        s_select_button_icon = s_pause_icon;
    }
    else{
        s_select_button_icon = s_play_icon;
    }

    action_bar_layer_set_icon(action_bar, BUTTON_ID_SELECT, s_select_button_icon);
}
Ejemplo n.º 28
0
static void pge_render(GContext *ctx) {
#ifdef BENCHMARK
  uint16_t start = time_ms(NULL, NULL);
#endif

  pge_isometric_begin(ctx);
  for(int i = 0; i < 4; i++) {
    digit_render(s_digits[i]);
  }
  pge_isometric_finish(ctx);

  if(!digits_are_animating()) {
    pge_pause();
    if(!s_initd) {
      // Any further interruptions will cause fast-forwarding
      s_initd = true;
    }
  }

#ifdef BENCHMARK
  uint16_t finish = time_ms(NULL, NULL);
  APP_LOG(APP_LOG_LEVEL_INFO, "Frame time: %d", (int)finish - start);
#endif
}
Ejemplo n.º 29
0
void request_send_acc(void) {
	
	uint16_t ms;
	time_t now;
	time_ms(&now, &ms);
	char buffer[15];
	snprintf(buffer, sizeof(buffer) - 1, "%lu%03d", now, ms);
	
	// snprintf(xyz_str,22 ,"X,Y,Z: %d,%d,%d",acc_data[0],acc_data[1],acc_data[2] );
	//APP_LOG(APP_LOG_LEVEL_DEBUG, "%s",xyz_str);
	app_message_outbox_begin(&iter);

    long long nowz = now;
    nowz = nowz * 1000 + ms;

    

	Tuplet t = TupletStaticCString(KEY_OFFSET + T_TIME_BASE, buffer, strlen(buffer));
	dict_write_tuplet(iter, &t);
	Tuplet act = TupletStaticCString(KEY_OFFSET + T_ACTIVITY, cur_activity, strlen(cur_activity));
	dict_write_tuplet(iter, &act);
    
    for(int i = 0; i < NUM_SAMPLES; i++) {
    
        int point = KEY_OFFSET + (10 * i);
        
        Tuplet ts = TupletInteger(point + T_TS, (int)(nowz - accl_data[i].timestamp));
        dict_write_tuplet(iter, &ts);
        
        Tuplet x = TupletInteger(point + T_X, accl_data[i].x);
        dict_write_tuplet(iter, &x);

        Tuplet y = TupletInteger(point + T_Y, accl_data[i].y);
        dict_write_tuplet(iter, &y);

        Tuplet z = TupletInteger(point + T_Z, accl_data[i].z);
        dict_write_tuplet(iter, &z);

        Tuplet dv = TupletStaticCString(point + T_DID_VIBRATE, accl_data[i].did_vibrate?"1":"0", 1);
        dict_write_tuplet(iter, &dv);

	}
	
	app_message_outbox_send();
	waiting_data = false;
	msg_run = true;
	acc_count++;
}
Ejemplo n.º 30
0
oid_t oid_gen(void)
{
    static oid_t id = 0;
    oid_t time = (oid_t)time_ms();

    assert(MAGIC_INDEX < MAX_INDEX && time < MAX_TIME);

    oid_t cid = ((oid_t)MAGIC_INDEX * MAX_TIME) + time;

    if (id >= cid) {
        ++id;
    } else {
        id = cid;
    }
    return id;
}