Example #1
0
static void main_window_load(Window *window) {
	
	s_white_effect_offset.offset_x = 2;
	s_white_effect_offset.offset_y = 2;
	s_white_effect_offset.orig_color = GColorWhite;
	s_white_effect_offset.offset_color = GColorBlack;
	
	s_yellow_effect_offset.offset_x = 2;
	s_yellow_effect_offset.offset_y = 2;
	s_yellow_effect_offset.orig_color = GColorYellow;
	s_yellow_effect_offset.offset_color = GColorBlack;
	
	GRect bounds = window_get_bounds(window);
	
	window_set_background_color(window, GColorBlack);
	
	s_time_font = fonts_load_resource_font(RESOURCE_ID_GASLIGHT_30);
	s_large_font = fonts_load_resource_font(RESOURCE_ID_GASLIGHT_40);
	s_small_font = fonts_load_resource_font(RESOURCE_ID_VIPNAGOR_12);
	
	s_effect_layer = effect_layer_create(bounds);
	
	s_blue_layer = layer_create(GRect(0,-168,144,168));
	s_yellow_layer = layer_create(GRect(144,120,144,48));
	s_time_layer = layer_create(GRect(144,0,144,168));
	s_date_layer = layer_create(GRect(-144,0,144,168));
	
	s_red_parent = layer_create(GRect(-42,0,42,168));
	
	s_red_layer = bitmap_layer_create(GRect(0,0,42,168));
	
	s_time_label = text_layer_create(GRect(0,30,129,40));
	s_month_label = text_layer_create(GRect(0,60,64,40));
	s_day_label = text_layer_create(GRect(0,60,129,40));
	s_brand_label = text_layer_create(GRect(0,5,139,40));
	
	layer_set_update_proc(s_blue_layer, update_blue);
	layer_set_update_proc(s_yellow_layer, update_yellow);
	
	s_red_bitmap = gbitmap_create_with_resource(RESOURCE_ID_SONIC);
	
	bitmap_layer_set_bitmap(s_red_layer, s_red_bitmap);
	
	bitmap_layer_set_compositing_mode(s_red_layer, GCompOpSet);
	
	text_layer_set_colors(s_time_label, GColorWhite, GColorClear);
	text_layer_set_colors(s_month_label, GColorWhite, GColorClear);
	text_layer_set_colors(s_day_label, GColorYellow, GColorClear);
	text_layer_set_colors(s_brand_label, GColorBlack, GColorClear);
	
	text_layer_set_text_alignment(s_time_label, GTextAlignmentRight);
	text_layer_set_text_alignment(s_month_label, GTextAlignmentRight);
	text_layer_set_text_alignment(s_day_label, GTextAlignmentRight);
	text_layer_set_text_alignment(s_brand_label, GTextAlignmentRight);
	
	text_layer_set_font(s_time_label, s_time_font);
	text_layer_set_font(s_month_label, s_time_font);
	text_layer_set_font(s_day_label, s_large_font);
	text_layer_set_font(s_brand_label, s_small_font);
	
	text_layer_set_text(s_brand_label, "PEBBLE TIME");
	
	layer_add_to_window(s_blue_layer, window);
	layer_add_to_window(s_yellow_layer, window);
	
	layer_add_to_window(s_red_parent, window);
	
	bitmap_layer_add_to_layer(s_red_layer, s_red_parent);
	
	layer_add_to_window(s_time_layer, window);
	layer_add_to_window(s_date_layer, window);
	
	text_layer_add_to_layer(s_time_label, s_time_layer);
	text_layer_add_to_layer(s_month_label, s_date_layer);
	text_layer_add_to_layer(s_day_label, s_date_layer);
	text_layer_add_to_layer(s_brand_label, s_yellow_layer);
	
	effect_layer_add_effect(s_effect_layer, effect_shadow, &s_white_effect_offset);
	effect_layer_add_effect(s_effect_layer, effect_shadow, &s_yellow_effect_offset);
	
	layer_add_child(s_time_layer, effect_layer_get_layer(s_effect_layer));
	layer_add_child(s_date_layer, effect_layer_get_layer(s_effect_layer));
	
	do_animation();
	update_time();
}
Example #2
0
void switch_menu()
{
   if(!MENU_BTN)
   {
      // bat loa len tao xung o chan loa
      Speaker = 1;
      delay_ms(150);
      Speaker = 0;
      delay_ms(150); 
      state_settime=1;
      lcd_gotoxy(1,4);
      printf(lcd_putc,"                    ");
      menu_system++;
      if(menu_system==5)   menu_system=0;
   }
   switch(menu_system)
   {
      // chay chuong trinh chinh
      case 0:
      {
         // chay chuong trinh chinh
         if(mode_run ==1)
         {
            // hien thi cac gia tri len lcd
            // hien thi che do mode len dong 1
            lcd_gotoxy(1,1);
           // update_time();
            // hien thi led led 7 thanh
            
            printf(lcd_putc,"  CHE DO : MODE 1   ");
            // hien thi thoi gian + date
            put_time_info();
            put_date_info();
            delay_ms(100);
            // chay chuong trinh tu uart dieu khien may bom
            
         }
         if(mode_run==2)
         {
            update_time();
            lcd_gotoxy(1,1);
            printf(lcd_putc,"  CHE DO : MODE 2   ");
            // hien thi thoi gian + date
            put_time_info();
            put_date_info();
            lcd_gotoxy(1,4);
            printf(lcd_putc,"                    ");
            delay_ms(100);
            run_mode2();
         }
         if(mode_run==3)
         {
            // hien thi gia tri nhiet do va do am lcd
            //run_mode3();
         }
      }
      break;
      // chay chuong trinh setup time
      case 1:
      {
         set_time();
      }
      break;
      // chay chuong trinh setup date
      case 2:
      {
         set_date();
      }
      break;
      // chay chuong trinh setup time
      case 3:
      {
         set_mode();
      }
      break;
      // neu dang o mode 2 setup thoi gian on off
      case 4:
      {
         //
         if(mode_run==2)
            set_time_on_off();
         //if(mode_run==3);
            //set_temp_huff();
         if(mode_run==1)
            menu_system=0;        
      }
      break;
      // neu dang o mode 3 setup nhiet do on off
      default:
      break;
   }
}
Example #3
0
void
etimer_adjust(struct etimer *et, int timediff)
{
  et->timer.start += timediff;
  update_time();
}
Example #4
0
File: rom.cpp Project: broftkd/mame
void gba_s3511_device::write(uint16_t data, int gpio_dirs)
{
//  printf("gpio_dev_write data %X\n", data);
	if (m_phase == S3511_RTC_IDLE && (m_last_val & 5) == 1 && (data & 5) == 5)
	{
		m_phase = S3511_RTC_COMMAND;
		m_bits = 0;
		m_command = 0;
	}
	else
	{
//      if (m_phase == 3)
//          printf("RTC command OK\n");
		if (!(m_last_val & 1) && (data & 1))
		{
			// bit transfer
			m_last_val = data & 0xff;
			switch (m_phase)
			{
				case S3511_RTC_DATAIN:
					if (!BIT(gpio_dirs, 1))
					{
						m_data[m_bits >> 3] = (m_data[m_bits >> 3] >> 1) | ((data << 6) & 0x80);
						m_bits++;
						if (m_bits == 8 * m_data_len)
						{
							//for (int i = 0; i < m_data_len; i++)
							//  printf("RTC DATA IN COMPLETE %X (reg %d) \n", m_data[i], i);
							m_bits = 0;
							m_phase = S3511_RTC_IDLE;
						}
					}
					break;
				case S3511_RTC_DATAOUT:
					break;
				case S3511_RTC_COMMAND:
					m_command |= (BIT(data, 1) << (7 - m_bits));
					m_bits++;
					if (m_bits == 8)
					{
						m_bits = 0;
						//printf("RTC command %X ENTERED!!!\n", m_command);
						switch (m_command)
						{
							case 0x60:
								// reset?
								m_phase = S3511_RTC_IDLE;
								m_bits = 0;
								break;
							case 0x62:
								m_phase = S3511_RTC_DATAIN;
								m_data_len = 1;
								break;
							case 0x63:
								m_data_len = 1;
								m_data[0] = 0x40;
								m_phase = S3511_RTC_DATAOUT;
								break;
							case 0x64:
								break;
							case 0x65:
								m_data_len = 7;
								update_time(m_data_len);
								m_phase = S3511_RTC_DATAOUT;
								break;
							case 0x67:
								m_data_len = 3;
								update_time(m_data_len);
								m_phase = S3511_RTC_DATAOUT;
								break;
							default:
								printf("Unknown RTC command %02X\n", m_command);
								m_phase = S3511_RTC_IDLE;
								break;
						}
					}
					break;
				case S3511_RTC_IDLE:
				default:
					break;
			}
		}
Example #5
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);
}
Example #6
0
int merry_start(int argc, const char **argv, void (*help)(), void (*master)(), void (*onexit)(), void (*worker)(),
                int worker_count)
{
    update_time();

    /// 初始化进程命令行信息
    init_process_title(argc, argv);

    int i = strlen(argv[0]);

    while(argv[0][--i] != '/');

    program_name = argv[0] + i + 1;

    if(getarg("help")) {
        help();
        exit(0);
    }

    if(getarg("log")) {
        LOGF_T = open_log(getarg("log"), 40960); // filename, bufsize
    }

    /// 把进程放入后台
    if(getarg("daemon")) {
        daemonize();
    }

    process_count = 1;

    if(is_daemon == 1) {
        process_count = atoi(getarg("daemon"));

        if(process_count < 1) {
            process_count = get_cpu_num();
        }

        if(process_count < 1) {
            process_count = 1;
        }
    }

    if(worker_count > 0 && process_count > worker_count) {
        process_count = worker_count;
    }

    sprintf(bind_addr, "0.0.0.0");

    if(getarg("bind")) {
        if(strstr(getarg("bind"), ".")) {
            sprintf(bind_addr, "%s", getarg("bind"));

        } else {
            int _be_port = atoi(getarg("bind"));

            if(_be_port > 0) {
                bind_port = _be_port;
            }
        }
    }

    char *_port = strstr(bind_addr, ":");

    if(_port) {
        bind_addr[strlen(bind_addr) - strlen(_port)] = '\0';
        _port = _port + 1;

        if(atoi(_port) > 0 && atoi(_port) < 99999) {
            bind_port = atoi(_port);
        }
    }

    sprintf(ssl_bind_addr, "0.0.0.0");

    if(getarg("ssl-bind")) {
        if(strstr(getarg("ssl-bind"), ".")) {
            sprintf(ssl_bind_addr, "%s", getarg("ssl-bind"));
            _port = strstr(ssl_bind_addr, ":");

            if(_port) {
                ssl_bind_addr[strlen(ssl_bind_addr) - strlen(_port)] = '\0';
                _port = _port + 1;

                if(atoi(_port) > 0 && atoi(_port) < 99999) {
                    ssl_bind_port = atoi(_port);
                }
            }

        } else {
            int _be_port = atoi(getarg("ssl-bind"));

            if(_be_port > 0) {
                ssl_bind_port = _be_port;
            }
        }
    }

    server_fd = network_bind(bind_addr, bind_port);

    if(ssl_bind_port > 0) {
        ssl_server_fd = network_bind(ssl_bind_addr, ssl_bind_port);
        LOGF(INFO, "bind %s:%d ssl:%d", bind_addr, bind_port, ssl_bind_port);

    } else {
        LOGF(INFO, "bind %s:%d", bind_addr, bind_port);
    }

    for(i = 0; i < process_count; i++) {
        if(is_daemon == 1) {
            fork_process(worker);

        } else {
            set_cpu_affinity(0);
            new_thread_p(worker, 0);
        }
    }

    /// 进入主进程处理
    start_master_main(master, onexit);

    return 1;
}
Example #7
0
static void handle_minute_tick(AppContextRef app_ctx, PebbleTickEvent* e) {
    update_time(e->tick_time);
}
Example #8
0
void handle_init(AppContextRef ctx) { 
  if (clock_is_24h_style()) {
    format_time = "%H:%M";
    format_date = "%d-%m-%Y";
  }
  else {
    format_time = "%I:%M";
    format_date = "%m/%d/%Y";
  }
  
  update_time();

  resource_init_current_app(&APP_RESOURCES);
  ubuntu_time = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_UBUNTU_BOLD_50));
  ubuntu_date = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_UBUNTU_16));
  ubuntu_text = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_UBUNTU_10));

  window_init(&window, MY_NAME);
  window_stack_push(&window, true);

  text_layer_init(&layer_time, GRect(0, 20, 144, 54));
  text_layer_set_font(&layer_time, ubuntu_time);
  text_layer_set_text(&layer_time, (const char*)&string_time);
  text_layer_set_text_alignment(&layer_time, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(&window), &layer_time.layer);

  text_layer_init(&layer_date, GRect(0, 74, 144, 20));
  text_layer_set_font(&layer_date, ubuntu_date);
  text_layer_set_text(&layer_date, (const char*)&string_date);
  text_layer_set_text_alignment(&layer_date, GTextAlignmentCenter);
  layer_add_child(window_get_root_layer(&window), &layer_date.layer);
    
  bitmap_layer_init(&layer_battery, GRect(8, 140, 14, 8));
  bitmap_layer_set_bitmap(&layer_battery, &bitmap_battery.bmp);
  layer_add_child(window_get_root_layer(&window), &layer_battery.layer);

  bitmap_layer_init(&layer_signal, GRect(8, 150, 14, 8));
  bitmap_layer_set_bitmap(&layer_signal, &bitmap_signal.bmp);
  layer_add_child(window_get_root_layer(&window), &layer_signal.layer);
  
  bmp_init_container(RESOURCE_ID_PNG_CALL, &layer_call);
  layer_call.layer.layer.frame.origin.x = 142 - 8 - 9;
  layer_call.layer.layer.frame.origin.y = 140;
  layer_add_child(window_get_root_layer(&window), &layer_call.layer.layer);

  bmp_init_container(RESOURCE_ID_PNG_MESSAGE, &layer_message);
  layer_message.layer.layer.frame.origin.x = 142 - 8 - 9;
  layer_message.layer.layer.frame.origin.y = 150;
  layer_add_child(window_get_root_layer(&window), &layer_message.layer.layer);
  
  text_layer_init(&layer_numbercall, GRect(101, 138, 22, 10));
  text_layer_set_font(&layer_numbercall, ubuntu_text);
  text_layer_set_text(&layer_numbercall, (const char*)&string_call);
  text_layer_set_text_alignment(&layer_numbercall, GTextAlignmentRight);
  layer_add_child(window_get_root_layer(&window), &layer_numbercall.layer);

  text_layer_init(&layer_numbermessage, GRect(101, 148, 22, 10));
  text_layer_set_font(&layer_numbermessage, ubuntu_text);
  text_layer_set_text(&layer_numbermessage, (const char*)&string_message);
  text_layer_set_text_alignment(&layer_numbermessage, GTextAlignmentRight);
  layer_add_child(window_get_root_layer(&window), &layer_numbermessage.layer);  
  
  update_stats();
 
  request_command(REACTOR_COMMAND_REFRESH);
}
static void update_proc(Layer *layer, GContext *ctx) {
  int padding;
  
  PBL_IF_ROUND_ELSE(padding = 16, padding = 12);
  
  HOURS_TRACK_RADIUS = (window_bounds.size.w - padding) / 2; //66
  HOURS_TRACK_STROKE = 2;
  
  MINUTES_TRACK_RADIUS = HOURS_TRACK_RADIUS - 10; //56
  MINUTES_TRACK_STROKE = 2;
  
  SECONDS_TRACK_RADIUS = HOURS_TRACK_RADIUS - 20; //46
  SECONDS_TRACK_STROKE = 2;
  
  SECONDS_HAND_RADIUS = 2;
  MINUTES_HAND_RADIUS = 3;
  HOURS_HAND_RADIUS = 4;
  
  // Color background
  graphics_context_set_fill_color(ctx, GColorBlack);
  graphics_fill_rect(ctx, window_bounds, 0, GCornerNone);
  
  //APP_LOG(APP_LOG_LEVEL_DEBUG, "bounds: %d %d %d %d", window_bounds.origin.x, window_bounds.origin.y, window_bounds.size.h, window_bounds.size.w );
  

  //set colour for tracks
  graphics_context_set_stroke_color(ctx, GColorWhite );

  graphics_context_set_antialiased(ctx, ANTIALIASING);

  // Don't use current time while animating
  Time mode_time = s_last_time;
  
  // generate position of hands
  
  GPoint second_hand = (GPoint) {
    .x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * mode_time.seconds / 60) * (int32_t)(SECONDS_TRACK_RADIUS) / TRIG_MAX_RATIO) + s_center.x,
    .y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * mode_time.seconds / 60) * (int32_t)(SECONDS_TRACK_RADIUS) / TRIG_MAX_RATIO) + s_center.y,
  };
	
  float minutes, hours;	
	
  if (SWEEP_MINUTES == true) {
	minutes = mode_time.minutes + (float)mode_time.seconds / 60;
  } else {
	minutes = mode_time.minutes;
  }
	
  GPoint minute_hand = (GPoint) {
    .x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * minutes / 60) * (int32_t)(MINUTES_TRACK_RADIUS) / TRIG_MAX_RATIO) + s_center.x,
    .y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * minutes/ 60) * (int32_t)(MINUTES_TRACK_RADIUS) / TRIG_MAX_RATIO) + s_center.y,
  };

  if( SWEEP_HOURS == true) {
    hours = mode_time.hours + (float)mode_time.minutes / 60;
  } else {
	hours = mode_time.hours; 
  }

  GPoint hour_hand = (GPoint) {
    .x = (int16_t)(sin_lookup(TRIG_MAX_ANGLE * hours / 12) * (int32_t)(HOURS_TRACK_RADIUS) / TRIG_MAX_RATIO) + s_center.x,
    .y = (int16_t)(-cos_lookup(TRIG_MAX_ANGLE * hours / 12) * (int32_t)(HOURS_TRACK_RADIUS) / TRIG_MAX_RATIO) + s_center.y,
  };
	
  graphics_context_set_fill_color(ctx, GColorWhite);
  
  GRect seconds_rect = GRect(s_center.x - SECONDS_TRACK_RADIUS, s_center.y - SECONDS_TRACK_RADIUS, SECONDS_TRACK_RADIUS * 2, SECONDS_TRACK_RADIUS * 2);
  
  GRect minutes_rect = GRect(s_center.x - MINUTES_TRACK_RADIUS, s_center.y - MINUTES_TRACK_RADIUS, MINUTES_TRACK_RADIUS * 2, MINUTES_TRACK_RADIUS * 2);
  
  GRect hours_rect = GRect(s_center.x - HOURS_TRACK_RADIUS, s_center.y - HOURS_TRACK_RADIUS, HOURS_TRACK_RADIUS * 2, HOURS_TRACK_RADIUS * 2);
  
 //----------------------------------
    
  int seconds_start_angle, seconds_end_angle;
  
  int seconds_delta = 12;
  int minutes_delta = 12;
  int hours_delta = 12;
	
  get_angles_60(mode_time.seconds, 0, seconds_delta, &seconds_start_angle, &seconds_end_angle);
  
  //----------------------------------
  
  //int minutes_angle = mode_time.minutes * 360 / 60;
  int minutes_start_angle, minutes_end_angle;
    
  get_angles_60(mode_time.minutes, (SWEEP_MINUTES == true) ? mode_time.seconds : 0, minutes_delta, &minutes_start_angle, &minutes_end_angle);
  //get_angles_60(mode_time.minutes, mode_time.seconds, minutes_delta, &minutes_start_angle, &minutes_end_angle);
  
  //----------------------------------
  
  //int hours_angle = mode_time.hours * 360 / 12;
  int hours_start_angle, hours_end_angle;

  get_angles_12(mode_time.hours,(SWEEP_HOURS == true) ? mode_time.minutes : 0, hours_delta, &hours_start_angle, &hours_end_angle);
  
  //APP_LOG(APP_LOG_LEVEL_DEBUG, "seconds: %d, start: %d, end: %d",  mode_time.seconds, seconds_start_angle, seconds_end_angle);
  
   //set colour for arcs and "hands"
    graphics_context_set_fill_color(ctx, GColorWhite );
    
  //draw seconds arc
  graphics_fill_radial(ctx, seconds_rect, GOvalScaleModeFitCircle, SECONDS_TRACK_STROKE,  DEG_TO_TRIGANGLE(seconds_start_angle), DEG_TO_TRIGANGLE(seconds_end_angle));
  
  //draw minutes arc
  graphics_fill_radial(ctx, minutes_rect, GOvalScaleModeFitCircle, MINUTES_TRACK_STROKE,  DEG_TO_TRIGANGLE(minutes_start_angle), DEG_TO_TRIGANGLE(minutes_end_angle));
  
  //draw hours arc
  graphics_fill_radial(ctx, hours_rect, GOvalScaleModeFitCircle, HOURS_TRACK_STROKE,  DEG_TO_TRIGANGLE(hours_start_angle), DEG_TO_TRIGANGLE(hours_end_angle));
  
  //draw minute hand
  graphics_fill_circle(ctx, minute_hand, MINUTES_HAND_RADIUS);
  
  //draw hour hand
  graphics_fill_circle(ctx, hour_hand, HOURS_HAND_RADIUS);
  
  //draw second hand
  graphics_context_set_fill_color(ctx, GColorRed );
  graphics_fill_circle(ctx, second_hand, SECONDS_HAND_RADIUS);
	
	update_time();
}

static void window_load(Window *window) {
  Layer *window_layer = window_get_root_layer(window);
  
  window_bounds = layer_get_bounds(window_layer);
  
  //APP_LOG(APP_LOG_LEVEL_DEBUG, "bounds: %d %d %d %d", window_bounds.origin.x, window_bounds.origin.y, window_bounds.size.h, window_bounds.size.w );

  s_center = grect_center_point(&window_bounds);
  
  s_canvas_layer = layer_create(window_bounds);
  layer_set_update_proc(s_canvas_layer, update_proc);
  layer_add_child(window_layer, s_canvas_layer);
	
// Create time TextLayer
  
  int font_height;
  
  PBL_IF_ROUND_ELSE(font_height = 45, font_height = 36); //fudge factor to get text vertically centred
  
  s_time_layer = text_layer_create(GRect(window_bounds.origin.x, (window_bounds.size.h-font_height)/2, window_bounds.size.w, font_height));
	
  //s_center.y - MINUTES_TRACK_RADIUS + 18 + 18;
		
  s_day_layer = text_layer_create(GRect(0, s_center.y - 18 - 18  , window_bounds.size.w, 18)); //need to calculate proper y-location
  s_month_layer = text_layer_create(GRect(0, s_center.y +36 , window_bounds.size.w, 18)); //need to calculate proper y-location
  
  text_layer_set_background_color(s_day_layer, GColorRed);
  text_layer_set_text_color(s_day_layer, GColorLightGray  );
  text_layer_set_text(s_day_layer, "00");
  
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, GColorWhite);
  text_layer_set_text(s_time_layer, "00:00");
	
  text_layer_set_background_color(s_month_layer, GColorClear);
  text_layer_set_text_color(s_month_layer, GColorLightGray );
  text_layer_set_text(s_month_layer, "XXX");
  
  PBL_IF_ROUND_ELSE(s_custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DOSIS_SEMIBOLD_40)), s_custom_font = fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DOSIS_SEMIBOLD_30)));

  text_layer_set_font(s_time_layer, s_custom_font);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
	
  text_layer_set_font(s_day_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DOSIS_SEMIBOLD_18)));
  text_layer_set_text_alignment(s_day_layer, GTextAlignmentCenter);

  text_layer_set_font(s_month_layer, fonts_load_custom_font(resource_get_handle(RESOURCE_ID_FONT_DOSIS_SEMIBOLD_18)));
  text_layer_set_text_alignment(s_month_layer, GTextAlignmentCenter);
  
  // Add it as a child layer to the Window's root 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_day_layer));
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_month_layer));
	// Make sure the time is displayed from the start
  update_time();
}

static void window_unload(Window *window) {
  layer_destroy(s_canvas_layer);
  // Destroy TextLayer
  text_layer_destroy(s_time_layer);
  text_layer_destroy(s_day_layer);
  text_layer_destroy(s_month_layer);
  fonts_unload_custom_font(s_custom_font);
}

/*********************************** App **************************************/

static void init() {
  srand(time(NULL));

  time_t t = time(NULL);
  struct tm *time_now = localtime(&t);
  tick_handler(time_now, SECOND_UNIT);

  s_main_window = window_create();
  window_set_window_handlers(s_main_window, (WindowHandlers) {
    .load = window_load,
    .unload = window_unload,
  });
Example #10
0
static void tick_handler(tm *tick_time, TimeUnits units_changed)
{
    // if not showing exact time, reduce battery usage by only updating screen when required
    if (shaken || tick_time->tm_min % 5 == 3) 
        update_time(tick_time);
}
Example #11
0
void handle_tick(AppContextRef ctx, PebbleTickEvent *event) {
  update_time();
  layer_mark_dirty(&layer_time.layer);
  layer_mark_dirty(&layer_date.layer);
}
Example #12
0
int main(int argc, const char **argv)
{
    bind_port = default_port;
    char *cwd = init_process_title(argc, argv);
    char *msg = NULL;
    update_time();

    if(getarg("cache-size")) {
        msg = getarg("cache-size");
        YAC_CACHE_SIZE = atoi(msg);

        if(msg[strlen(msg) - 1] == 'm') {
            YAC_CACHE_SIZE = YAC_CACHE_SIZE * 1024 * 1024;

        } else if(msg[strlen(msg) - 1] == 'k') {
            YAC_CACHE_SIZE = YAC_CACHE_SIZE * 1024;
        }

    }

    if(YAC_CACHE_SIZE < 1024 * 1024 * 2) {
        YAC_CACHE_SIZE = 1024 * 1024 * 2;
    }

    if(!yac_storage_startup(YAC_CACHE_SIZE / 16, YAC_CACHE_SIZE - (YAC_CACHE_SIZE / 16), &msg)) {
        LOGF(ERR, "Shared memory allocator startup failed at '%s': %s", msg, strerror(errno));
        exit(1);
    }

    lua_State *L = luaL_newstate();

    if(!L) {
        LOGF(ERR, "error for luaL_newstate");
        exit(1);
    }

    luaL_openlibs(L);
    lua_getglobal(L, "_VERSION");
    const char *lua_ver = lua_tostring(L, -1);
    lua_getglobal(L, "jit");

    if(lua_istable(L, -1)) {
        lua_getfield(L, -1, "version");

        if(lua_isstring(L, -1)) {
            lua_ver = lua_tostring(L, -1);
        }
    }

    sprintf(hostname, "%s", lua_ver);
    lua_close(L);

    _L = luaL_newstate();
    lua_gc(_L, LUA_GCSTOP, 0);
    luaL_openlibs(_L);    /* Load Lua libraries */
    lua_gc(_L, LUA_GCRESTART, 0);

    if(getarg("host-route")) {
        lua_pushstring(_L, getarg("host-route"));
        lua_setglobal(_L, "HOST_ROUTE");
    }

    if(!update_vhost_routes(getarg("host-route")) && !getarg("app")) {
        LOGF(WARN, "no host-route or app arguments! using defalut settings.");
        sprintf(tbuf_4096, "%s/host-route.lua", process_chdir);
        update_vhost_routes(tbuf_4096);
    }

    if(getarg("code-cache-ttl")) {       /// default = 60s
        lua_pushnumber(_L, atoi(getarg("code-cache-ttl")));
        lua_setglobal(_L, "CODE_CACHE_TTL");

    } else {
        lua_pushnumber(_L, code_cache_ttl);
        lua_setglobal(_L, "CODE_CACHE_TTL");
    }

    lua_getglobal(_L, "require");
    lua_pushcfunction(_L, lua_f_package_require);
    lua_getfenv(_L, -2);
    int ret = lua_setfenv(_L, -2);
    lua_setglobal(_L, "require");
    lua_pop(_L, 1);

    lua_register(_L, "echo", lua_echo);
    lua_register(_L, "print_error", lua_print_error);
    lua_register(_L, "sendfile", lua_sendfile);
    lua_register(_L, "header", lua_header);
    lua_register(_L, "clear_header", lua_clear_header);
    lua_register(_L, "__end", lua_end);
    lua_register(_L, "die", lua_die);
    lua_register(_L, "flush", lua_flush);
    lua_register(_L, "read_request_body", lua_read_request_body);
    lua_register(_L, "get_boundary", lua_f_get_boundary);
    lua_register(_L, "check_timeout", lua_check_timeout);
    lua_register(_L, "is_websocket", lua_f_is_websocket);
    lua_register(_L, "upgrade_to_websocket", lua_f_upgrade_to_websocket);
    lua_register(_L, "websocket_send", lua_f_websocket_send);
    lua_register(_L, "check_websocket_close", lua_f_check_websocket_close);

    lua_register(_L, "router", lua_f_router);

    lua_register(_L, "random_string", lua_f_random_string);
    lua_register(_L, "file_exists", lua_f_file_exists);
    lua_register(_L, "readfile", lua_f_readfile);
    lua_register(_L, "filemtime", lua_f_filemtime);

    lua_register(_L, "cache_set", lua_f_cache_set);
    lua_register(_L, "cache_get", lua_f_cache_get);
    lua_register(_L, "cache_del", lua_f_cache_del);

    luaopen_fastlz(_L);
    luaopen_coevent(_L);
    luaopen_libfs(_L);
    luaopen_string_utils(_L);
    luaopen_i18n(_L);
    luaopen_crypto(_L);

    lua_pop(_L, 1);

    sprintf(tbuf_4096,
            "package.path = '%slua-libs/?.lua;' .. package.path package.cpath = '%slua-libs/?.so;' .. package.cpath", cwd, cwd);
    luaL_dostring(_L, tbuf_4096);

    luaL_dostring(_L, ""
                  "if not CODE_CACHE_TTL then CODE_CACHE_TTL = 60 end " \
                  "startloop = nil __CodeCache = {{},{}} __CodeCacheC = {false,false} "
                 );

    if(getarg("accesslog")) {
        ACCESS_LOG = open_log(getarg("accesslog"), 40960);

        if(!ACCESS_LOG) {
            LOGF(ERR, "Couldn't open access log file: %s", getarg("accesslog"));
        }
    }

    if(getarg("ssl-bind") && getarg("ssl-cert") && getarg("ssl-key")) {
        ssl_ctx = SSL_CTX_new(SSLv23_server_method());

        if(!ssl_ctx) {
            LOGF(ERR, "SSL_CTX_new Failed");
            exit(1);
        }

        if(SSL_CTX_use_certificate_file(ssl_ctx, getarg("ssl-cert"), SSL_FILETYPE_PEM) != 1) {
            SSL_CTX_free(ssl_ctx);
            LOGF(ERR, "SSL_CTX_use_certificate_file");
            exit(1);
        }

        if(SSL_CTX_use_PrivateKey_file(ssl_ctx, getarg("ssl-key"), SSL_FILETYPE_PEM) != 1) {
            SSL_CTX_free(ssl_ctx);
            LOGF(ERR, "SSL_CTX_use_PrivateKey_file");
            exit(1);
        }

        SSL_CTX_set_options(ssl_ctx, SSL_OP_ALL);

        if(getarg("ssl-ca")) {
            ssl_epd_idx = SSL_get_ex_new_index(0, NULL, NULL, NULL, NULL);

            if(ssl_epd_idx == -1) {
                LOGF(ERR, "SSL_get_ex_new_index Failed");
                exit(1);
            }

            if(SSL_CTX_load_verify_locations(ssl_ctx, getarg("ssl-ca"), NULL) != 1) {
                SSL_CTX_free(ssl_ctx);
                LOGF(ERR, "SSL_CTX_load_verify_locations");
                exit(1);

            } else {
                SSL_CTX_set_verify(ssl_ctx, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, verify_callback);
                SSL_CTX_set_verify_depth(ssl_ctx, 4);

            }
        }
    }

    _shm_serv_status = shm_malloc(sizeof(serv_status_t));
    bzero(_shm_serv_status->p, sizeof(serv_status_t));

    attach_on_exit(on_master_exit_handler);
    return merry_start(argc, argv, help, master_main, on_master_exit_handler, worker_main, 0);
}
Example #13
0
/**
 * Minute tick handler
 **/
void handle_minute_tick(AppContextRef ctx, PebbleTickEvent* e) {
	(void) ctx;
	update_time(e->tick_time);
}
Example #14
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(etimer_process, ev, data)
{
  struct etimer *t, *u;

  PROCESS_BEGIN();

  timerlist = NULL;
  
  while(1) {
    PROCESS_YIELD();

    if(ev == PROCESS_EVENT_EXITED) {
      struct process *p = data;

      while(timerlist != NULL && timerlist->p == p) {
	timerlist = timerlist->next;
      }

      if(timerlist != NULL) {
	t = timerlist;
	while(t->next != NULL) {
	  if(t->next->p == p) {
	    t->next = t->next->next;
	  } else
	    t = t->next;
	}
      }
      continue;
    } else if(ev != PROCESS_EVENT_POLL) {
      continue;
    }

  again:
    
    u = NULL;
    
    for(t = timerlist; t != NULL; t = t->next) {
      if(timer_expired(&t->timer)) {
	if(process_post(t->p, PROCESS_EVENT_TIMER, t) == PROCESS_ERR_OK) {

	  /* Reset the process ID of the event timer, to signal that the
	     etimer has expired. This is later checked in the
	     etimer_expired() function. */
	  t->p = PROCESS_NONE;
	  if(u != NULL) {
	    u->next = t->next;
	  } else {
	    timerlist = t->next;
	  }
	  t->next = NULL;
	  update_time();
	  goto again;
	} else {
	  etimer_request_poll();
	}
      }
      u = t;
    }
    
  }
  
  PROCESS_END();
}
Example #15
0
void wakeUp_User(){
	mp3Player_onoff();
	if(snoozeCounter == 0){
		next_song();
	}
	play_pause();
	_delay_ms(1000);//warten bis mp3Player an ist
	boot_amp();

	bool user_awake = false;
	
	LCD_LED = 1;
	LED_AUSTRALIA = 1;
	LED_NORWAY = 1;
	int secondsStart = seconds;
	while((!btn_light_pushed) && (rotary == 0) && (!btn_drehenc_pushed)){//Könnte auch von Sekundenzähler aufgewacht sein
		goodNight();
		if(check_TimeUpdate());
			update_time();
		if(seconds == secondsStart + 30){
			LCD_LED = 0;
			LED_AUSTRALIA = 0;
			LED_NORWAY = 0;
		}
	}
	
	LCD_LED = 0;
	LED_AUSTRALIA = 0;
	LED_NORWAY = 0;
	
	if(snoozeCounter==0){
		if(btn_light_pushed){
			//while(!btn_light_pushed){_delay_ms(100);}
			start_btnPress();
			while((PINB & (1<<PINB1)) && (btn_press_duration<BTN_PRESS_LONG)){_delay_ms(50);}
			stop_btnPress();
			if(btn_press_duration>=BTN_PRESS_LONG){
				user_awake = true;
			} else {
				reset_alarmLogo();
				print_snoozeLogo();
				update_LCD();

				snooze_alarm();
				snoozeCounter = 1;
			}
		} else {
			reset_alarmLogo();
			print_snoozeLogo();
			update_LCD();
			snooze_alarm();
			snoozeCounter = 1;
		}
	} else {
		while(!user_awake){
			goodNight();
			if(check_TimeUpdate())
				update_time();
			start_btnPress();
			while((PINB & (1<<PINB1)) && (btn_press_duration<BTN_PRESS_LONG)){_delay_ms(50);}
			stop_btnPress();
			if(btn_press_duration>=BTN_PRESS_LONG){
				user_awake = true;
				alarm = OFF;
				reset_alarmLogo();
				reset_snoozeLogo();
				snoozeCounter = 0;
				alarm_hour = saved_alarm_h;
				alarm_minute = saved_alarm_m;
				
			}
		}
	}
	play_pause();//Pause
	shutdown_amp();
	mp3Player_onoff();
}
Example #16
0
// handle clock ticks (by the minute)
void handle_tick(AppContextRef ctx, PebbleTickEvent *t) {
  (void)ctx;
  update_time(ctx, t->tick_time);
}
static void
cc_date_time_panel_init (CcDateTimePanel *self)
{
  CcDateTimePanelPrivate *priv;
  gchar *objects[] = { "datetime-panel", "region-liststore", "city-liststore",
      "month-liststore", "city-modelfilter", "city-modelsort", NULL };
  char *buttons[] = { "hour_up_button", "hour_down_button", "min_up_button",
          "min_down_button", "ampm_up_button", "ampm_down_button" };
  GtkWidget *widget;
  GtkAdjustment *adjustment;
  GError *err = NULL;
  GtkTreeModelFilter *city_modelfilter;
  GtkTreeModelSort *city_modelsort;
  guint i, num_days;
  gboolean using_ntp;
  gboolean can_use_ntp;
  int ret;
  DateEndianess endianess;
  GError *error;

  priv = self->priv = DATE_TIME_PANEL_PRIVATE (self);

  priv->cancellable = g_cancellable_new ();
  error = NULL;
  priv->dtm = date_time_mechanism_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
                                                          G_DBUS_PROXY_FLAGS_NONE,
                                                          "org.gnome.SettingsDaemon.DateTimeMechanism",
                                                          "/",
                                                          priv->cancellable,
                                                          &error);
  if (priv->dtm == NULL) {
        g_warning ("could not get proxy for DateTimeMechanism: %s", error->message);
        g_error_free (error);
  }

  priv->builder = gtk_builder_new ();

  ret = gtk_builder_add_objects_from_file (priv->builder, DATADIR"/datetime.ui",
                                           objects, &err);

  if (ret == 0)
    {
      g_warning ("Could not load ui: %s", err ? err->message : "No reason");
      if (err)
        g_error_free (err);
      return;
    }

  /* set up network time button */
  error = NULL;
  using_ntp = can_use_ntp = FALSE;
  if (!date_time_mechanism_call_get_using_ntp_sync (priv->dtm,
                                                    &can_use_ntp,
                                                    &using_ntp,
                                                    priv->cancellable,
                                                    &error))
    {
      g_warning ("Failed to get using ntp: %s", error->message);
      g_error_free (error);
    }

  gtk_switch_set_active (GTK_SWITCH (W("network_time_switch")), using_ntp);
  update_widget_state_for_ntp (self, using_ntp);
  g_signal_connect (W("network_time_switch"), "notify::active",
                    G_CALLBACK (change_ntp), self);

  /* set up time editing widgets */
  for (i = 0; i < G_N_ELEMENTS (buttons); i++)
    {
      g_signal_connect (W(buttons[i]), "clicked",
                        G_CALLBACK (change_time), self);
    }

  /* set up date editing widgets */
  priv->date = g_date_time_new_now_local ();
  endianess = date_endian_get_default (FALSE);
  reorder_date_widget (endianess, priv);

  /* Force the direction for the time, so that the time
   * is presented correctly for RTL languages */
  gtk_widget_set_direction (W("table2"), GTK_TEXT_DIR_LTR);

  gtk_combo_box_set_active (GTK_COMBO_BOX (W ("month-combobox")),
                            g_date_time_get_month (priv->date) - 1);
  g_signal_connect (G_OBJECT (W("month-combobox")), "changed",
                    G_CALLBACK (month_year_changed), self);

  num_days = g_date_get_days_in_month (g_date_time_get_month (priv->date),
                                       g_date_time_get_year (priv->date));
  adjustment = (GtkAdjustment*) gtk_adjustment_new (g_date_time_get_day_of_month (priv->date), 1,
                                                    num_days + 1, 1, 10, 1);
  gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (W ("day-spinbutton")),
                                  adjustment);
  g_signal_connect (G_OBJECT (W("day-spinbutton")), "value-changed",
                    G_CALLBACK (day_changed), self);

  adjustment = (GtkAdjustment*) gtk_adjustment_new (g_date_time_get_year (priv->date),
                                                    G_MINDOUBLE, G_MAXDOUBLE, 1,
                                                    10, 1);
  gtk_spin_button_set_adjustment (GTK_SPIN_BUTTON (W ("year-spinbutton")),
                                  adjustment);
  g_signal_connect (G_OBJECT (W("year-spinbutton")), "value-changed",
                    G_CALLBACK (month_year_changed), self);

  /* set up timezone map */
  priv->map = widget = (GtkWidget *) cc_timezone_map_new ();
  gtk_widget_show (widget);

  gtk_container_add (GTK_CONTAINER (gtk_builder_get_object (priv->builder,
                                                            "aspectmap")),
                     widget);

  gtk_container_add (GTK_CONTAINER (self),
                     GTK_WIDGET (gtk_builder_get_object (priv->builder,
                                                         "datetime-panel")));


  /* setup the time itself */
  priv->clock_tracker = g_object_new (GNOME_TYPE_WALL_CLOCK, NULL);
  g_signal_connect (priv->clock_tracker, "notify::clock", G_CALLBACK (on_clock_changed), self);

  priv->settings = g_settings_new (CLOCK_SCHEMA);
  clock_settings_changed_cb (priv->settings, CLOCK_FORMAT_KEY, self);
  g_signal_connect (priv->settings, "changed::" CLOCK_FORMAT_KEY,
                    G_CALLBACK (clock_settings_changed_cb), self);

  g_signal_connect (W("24h_button"), "notify::active",
                    G_CALLBACK (change_clock_settings), self);

  update_time (self);

  priv->locations = (GtkTreeModel*) gtk_builder_get_object (priv->builder,
                                                            "region-liststore");

  load_regions_model (GTK_LIST_STORE (priv->locations),
                      GTK_LIST_STORE (gtk_builder_get_object (priv->builder,
                                                              "city-liststore")));

  city_modelfilter = GTK_TREE_MODEL_FILTER (gtk_builder_get_object (priv->builder, "city-modelfilter"));

  widget = (GtkWidget*) gtk_builder_get_object (priv->builder,
                                                "region_combobox");
  city_modelsort = GTK_TREE_MODEL_SORT (gtk_builder_get_object (priv->builder, "city-modelsort"));
  gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (city_modelsort), CITY_COL_CITY_TRANSLATED,
                                        GTK_SORT_ASCENDING);

  gtk_tree_model_filter_set_visible_func (city_modelfilter,
                                          (GtkTreeModelFilterVisibleFunc) city_model_filter_func,
                                          widget,
                                          NULL);

  /* After the initial setup, so we can be sure that
   * the model is filled up */
  date_time_mechanism_call_get_timezone (priv->dtm,
                                         priv->cancellable,
                                         get_timezone_cb,
                                         self);

  /* add the lock button */
  priv->permission = polkit_permission_new_sync ("org.gnome.settingsdaemon.datetimemechanism.configure", NULL, NULL, NULL);
  if (priv->permission == NULL)
    {
      g_warning ("Your system does not have the '%s' PolicyKit files installed. Please check your installation",
                 "org.gnome.settingsdaemon.datetimemechanism.configure");
      return;
    }

  g_signal_connect (priv->permission, "notify",
                    G_CALLBACK (on_permission_changed), self);
  on_permission_changed (priv->permission, NULL, self);
}
Example #18
0
static void main_window_load(Window *window) {    
  init_globe(main_window);
  init_time(main_window);
  init_battery(main_window);
  update_time();
}
Example #19
0
int main(int argc,char *argv[])
{
  int       mmm[] = { 8, 10, 12, 15, 16, 18, 20, 24, 25, 27, 30, 32, 36, 40,
		      45, 48, 50, 54, 60, 64, 72, 75, 80, 81, 90, 100 };
  int       nnn[] = { 24, 32, 48, 60, 72, 84, 96 };
#define NNN asize(nnn)
  FILE      *fp,*fplog;
  int       *niter;
  int       i,j,n,nit,ntot,n3,rsize;
  double    t,nflop,start;
  double    *rt,*ct;
  t_fftgrid *g;
  t_commrec *cr;
  static gmx_bool bReproducible = FALSE;
  static int  nnode    = 1;
  static int  nitfac  = 1;
  t_pargs pa[] = {
    { "-reproducible",   FALSE, etBOOL, {&bReproducible}, 
      "Request binary reproducible results" },
    { "-np",    FALSE, etINT, {&nnode},
      "Number of NODEs" },
    { "-itfac", FALSE, etINT, {&nitfac},
      "Multiply number of iterations by this" }
  };
  static t_filenm fnm[] = {
    { efLOG, "-g", "fft",      ffWRITE },
    { efXVG, "-o", "fft",      ffWRITE }
  };
#define NFILE asize(fnm)
  
  cr = init_par(&argc,&argv);
  if (MASTER(cr))
    CopyRight(stdout,argv[0]);
  parse_common_args(&argc,argv,
		    PCA_CAN_SET_DEFFNM | (MASTER(cr) ? 0 : PCA_QUIET),
		    NFILE,fnm,asize(pa),pa,0,NULL,0,NULL);
  gmx_log_open(ftp2fn(efLOG,NFILE,fnm),cr,1,0,&fplog);

  snew(niter,NNN);
  snew(ct,NNN);
  snew(rt,NNN);
  rsize = sizeof(real);
  for(i=0; (i<NNN); i++) {
    n  = nnn[i];
    if (n < 16)
      niter[i] = 50;
    else if (n < 26)
      niter[i] = 20;
    else if (n < 51)
      niter[i] = 10;
    else
      niter[i] = 5;
    niter[i] *= nitfac;
    nit = niter[i];
    
    if (MASTER(cr))
      fprintf(stderr,"\r3D FFT (%s precision) %3d^3, niter %3d     ",
	      (rsize == 8) ? "Double" : "Single",n,nit);
    
    g  = mk_fftgrid(n,n,n,NULL,NULL,cr,bReproducible);

    if (PAR(cr))
      start = time(NULL);
    else
      start_time();
    for(j=0; (j<nit); j++) {
      gmxfft3D(g,GMX_FFT_REAL_TO_COMPLEX,cr);
      gmxfft3D(g,GMX_FFT_COMPLEX_TO_REAL,cr);
    }
    if (PAR(cr)) 
      rt[i] = time(NULL)-start;
    else {
      update_time();
      rt[i] = node_time();
    }
    done_fftgrid(g);
    sfree(g);
  }
  if (MASTER(cr)) {
    fprintf(stderr,"\n");
    fp=xvgropen(ftp2fn(efXVG,NFILE,fnm),
		"FFT timings","n^3","t (s)");
    for(i=0; (i<NNN); i++) {
      n3 = 2*niter[i]*nnn[i]*nnn[i]*nnn[i];
      fprintf(fp,"%10d  %10g\n",nnn[i],rt[i]/(2*niter[i]));
    }
    gmx_fio_fclose(fp);
  }
  return 0;
}
Example #20
0
static void main_window_load(Window *window) {
  
  
  // Set up the weather areas
  // Use system font, apply it and add to Window
  s_weather_font = fonts_get_system_font(FONT_KEY_GOTHIC_28_BOLD);
  s_weather_title_font = fonts_get_system_font(FONT_KEY_GOTHIC_18_BOLD);
  
  //Create GBitmap, then set to created BitmapLayer
  s_background_bitmap = gbitmap_create_with_resource(RESOURCE_ID_IMAGE_BACKGROUND);
  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));
  
  // Create time TextLayer
  s_time_layer = text_layer_create(GRect(0, 138, 144, 30));
  text_layer_set_background_color(s_time_layer, GColorClear);
  text_layer_set_text_color(s_time_layer, GColorWhite);
  
  //Apply to TextLayer
  text_layer_set_font(s_time_layer, s_weather_font);
  text_layer_set_text_alignment(s_time_layer, GTextAlignmentCenter);
  
  // Add it as a child layer to the Window's root layer
  layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_time_layer));

  // Set some intial string
  text_layer_set_text(s_time_layer, "00:00:00");  

  
  // Create temperature Layer
  s_weather_layer[0] = text_layer_create(GRect(0, 0, 144, 28));
  s_weather_title[0] = text_layer_create(GRect(0, 28, 144, 18));
  s_weather_layer[1] = text_layer_create(GRect(0, 46, 144, 28));
  s_weather_title[1] = text_layer_create(GRect(0, 74, 144, 18));
  s_weather_layer[2] = text_layer_create(GRect(0, 92, 144, 28));
  s_weather_title[2] = text_layer_create(GRect(0, 120, 144, 18));
  

  int i;
  for (i =0; i < 3; i++)
    {
    text_layer_set_background_color(s_weather_layer[i], GColorClear);
    text_layer_set_text_color(s_weather_layer[i], GColorWhite);
    text_layer_set_text_alignment(s_weather_layer[i], GTextAlignmentCenter);
    text_layer_set_text(s_weather_layer[i], "00-00 NNN");
    text_layer_set_font(s_weather_layer[i], s_weather_font);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_layer[i]));

    text_layer_set_background_color(s_weather_title[i], GColorClear);
    text_layer_set_text_color(s_weather_title[i], GColorWhite);
    text_layer_set_text_alignment(s_weather_title[i], GTextAlignmentCenter);
    text_layer_set_font(s_weather_title[i], s_weather_title_font);
    layer_add_child(window_get_root_layer(window), text_layer_get_layer(s_weather_title[i]));

  }
  
  text_layer_set_text(s_weather_title[0], "North Head");
  text_layer_set_text(s_weather_title[1], "Sydney Harbour");
  text_layer_set_text(s_weather_title[2], "Fort Denison");
  
  // Make sure the time is displayed from the start
  update_time();
}
Example #21
0
// called every minute
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
    update_text();
    if (question_answered) update_time();
}
static void inbox_received_handler(DictionaryIterator *iter, void *context) {
    APP_LOG(APP_LOG_LEVEL_DEBUG, "inbox received handler");
    Tuple *top_bar_color_t = dict_find(iter, KEY_TOP_BAR_COLOR);
    Tuple *middle_bar_color_t = dict_find(iter, KEY_MIDDLE_BAR_COLOR);
    Tuple *bottom_bar_color_t = dict_find(iter, KEY_BOTTOM_BAR_COLOR);
    Tuple *background_color_t = dict_find(iter, KEY_BACKGROUND_COLOR);

    Tuple *temp_t = dict_find(iter, KEY_TEMPERATURE);
    Tuple *conditions_t = dict_find(iter, KEY_CONDITIONS);

    Tuple *degreeOption_t = dict_find(iter, KEY_DEGREEOPTION);

    //Store incoming information
    static char temperature_buffer[8];
    static char conditions_buffer[32];
    static char weather_layer_buffer[42];

    if (degreeOption_t) {
        degreeOption = degreeOption_t->value->uint32;
        APP_LOG(APP_LOG_LEVEL_DEBUG, "degree Option : %d", degreeOption);
        persist_write_int(KEY_DEGREEOPTION, degreeOption);
    }

    if (temp_t) {
        int kelvin = (int) temp_t->value->int32;
        if (degreeOption == 0) {
            //celsius
            int celsius = kelvin - 273.15;
            snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) celsius);
            APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Celsius: %d", degreeOption);
        } else {
            //fahrenheit
            int fahrenheit = (kelvin - 273.15) * 1.8 + 32;
            snprintf(temperature_buffer, sizeof(temperature_buffer), "%d\u00B0", (int) fahrenheit);
            APP_LOG(APP_LOG_LEVEL_DEBUG, "Degree option is Fahrenheit: %d", degreeOption);
        }
    }

    if (conditions_t) {
        snprintf(conditions_buffer, sizeof(conditions_buffer), "%s", conditions_t->value->cstring);
    }

    if (conditions_t && temp_t) {
        snprintf(weather_layer_buffer, sizeof(weather_layer_buffer), "%s, %s", temperature_buffer, conditions_buffer);
        text_layer_set_text_color(s_weather_layer, gcolor_legible_over(background_color));
        text_layer_set_text(s_weather_layer, weather_layer_buffer);
    }

    if (top_bar_color_t) {
        int top_bar_color = top_bar_color_t->value->int32;
        if (top_bar_color == 0) { //quick fix so that black colour persists
            top_bar_color++;
        }

        persist_write_int(KEY_TOP_BAR_COLOR, top_bar_color);

        //set_background_and_text_color(background_color);
        s_top_bar_color = GColorFromHEX(top_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "top bar color:  %d", top_bar_color);
    }

    if (middle_bar_color_t) {
        int middle_bar_color = middle_bar_color_t->value->int32;
        if (middle_bar_color == 0) { //quick fix so that black colour persists
            middle_bar_color++;
        }

        persist_write_int(KEY_MIDDLE_BAR_COLOR, middle_bar_color);

        s_middle_bar_color = GColorFromHEX(middle_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "middle bar color:  %d", middle_bar_color);
    }

    if (bottom_bar_color_t) {
        int bottom_bar_color = bottom_bar_color_t->value->int32;
        if (bottom_bar_color == 0) { //quick fix so that black colour persists
            bottom_bar_color++;
        }

        persist_write_int(KEY_BOTTOM_BAR_COLOR, bottom_bar_color);

        s_bottom_bar_color = GColorFromHEX(bottom_bar_color);
        APP_LOG(APP_LOG_LEVEL_DEBUG, "bottom bar color:  %d", bottom_bar_color);
    }

    if (background_color_t) {
        int background_color = background_color_t->value->int32;
        if (background_color == 0) { //quick fix so that black colour persists
            background_color++;
        }

        persist_write_int(KEY_BACKGROUND_COLOR, background_color);

        APP_LOG(APP_LOG_LEVEL_DEBUG, "background color: %d", background_color);

        set_background_and_text_color(background_color);
    }

    time_t start_time = time(NULL);
    update_time(localtime(&start_time));

}
Example #23
0
void
io_wait_dowork (struct context *c, const unsigned int flags)
{
  unsigned int socket = 0;
  unsigned int tuntap = 0;
  struct event_set_return esr[4];

  /* These shifts all depend on EVENT_READ and EVENT_WRITE */
  static int socket_shift = 0;     /* depends on SOCKET_READ and SOCKET_WRITE */
  static int tun_shift = 2;        /* depends on TUN_READ and TUN_WRITE */
  static int err_shift = 4;        /* depends on ES_ERROR */
#ifdef ENABLE_MANAGEMENT
  static int management_shift = 6; /* depends on MANAGEMENT_READ and MANAGEMENT_WRITE */
#endif
#ifdef ENABLE_ASYNC_PUSH
  static int file_shift = 8;       /* listening inotify events */
#endif

  /*
   * Decide what kind of events we want to wait for.
   */
  event_reset (c->c2.event_set);

  /*
   * On win32 we use the keyboard or an event object as a source
   * of asynchronous signals.
   */
  if (flags & IOW_WAIT_SIGNAL)
    wait_signal (c->c2.event_set, (void*)&err_shift);

  /*
   * If outgoing data (for TCP/UDP port) pending, wait for ready-to-send
   * status from TCP/UDP port. Otherwise, wait for incoming data on
   * TUN/TAP device.
   */
  if (flags & IOW_TO_LINK)
    {
      if (flags & IOW_SHAPER)
	{
	  /*
	   * If sending this packet would put us over our traffic shaping
	   * quota, don't send -- instead compute the delay we must wait
	   * until it will be OK to send the packet.
	   */
#ifdef ENABLE_FEATURE_SHAPER
	  int delay = 0;

	  /* set traffic shaping delay in microseconds */
	  if (c->options.shaper)
	    delay = max_int (delay, shaper_delay (&c->c2.shaper));
	  
	  if (delay < 1000)
	    {
	      socket |= EVENT_WRITE;
	    }
	  else
	    {
	      shaper_soonest_event (&c->c2.timeval, delay);
	    }
#else /* ENABLE_FEATURE_SHAPER */
	  socket |= EVENT_WRITE;
#endif /* ENABLE_FEATURE_SHAPER */
	}
      else
	{
	  socket |= EVENT_WRITE;
	}
    }
  else if (!((flags & IOW_FRAG) && TO_LINK_FRAG (c)))
    {
      if (flags & IOW_READ_TUN)
	tuntap |= EVENT_READ;
    }

  /*
   * If outgoing data (for TUN/TAP device) pending, wait for ready-to-send status
   * from device.  Otherwise, wait for incoming data on TCP/UDP port.
   */
  if (flags & IOW_TO_TUN)
    {
      tuntap |= EVENT_WRITE;
    }
  else
    {
      if (flags & IOW_READ_LINK)
	socket |= EVENT_READ;
    }

  /*
   * outgoing bcast buffer waiting to be sent?
   */
  if (flags & IOW_MBUF)
    socket |= EVENT_WRITE;

  /*
   * Force wait on TUN input, even if also waiting on TCP/UDP output
   */
  if (flags & IOW_READ_TUN_FORCE)
    tuntap |= EVENT_READ;

  /*
   * Configure event wait based on socket, tuntap flags.
   */
  socket_set (c->c2.link_socket, c->c2.event_set, socket, (void*)&socket_shift, NULL);
  tun_set (c->c1.tuntap, c->c2.event_set, tuntap, (void*)&tun_shift, NULL);

#ifdef ENABLE_MANAGEMENT
  if (management)
    management_socket_set (management, c->c2.event_set, (void*)&management_shift, NULL);
#endif

#ifdef ENABLE_ASYNC_PUSH
  /* arm inotify watcher */
  event_ctl (c->c2.event_set, c->c2.inotify_fd, EVENT_READ, (void*)&file_shift);
#endif

  /*
   * Possible scenarios:
   *  (1) tcp/udp port has data available to read
   *  (2) tcp/udp port is ready to accept more data to write
   *  (3) tun dev has data available to read
   *  (4) tun dev is ready to accept more data to write
   *  (5) we received a signal (handler sets signal_received)
   *  (6) timeout (tv) expired
   */

  c->c2.event_set_status = ES_ERROR;

  if (!c->sig->signal_received)
    {
      if (!(flags & IOW_CHECK_RESIDUAL) || !socket_read_residual (c->c2.link_socket))
	{
	  int status;

#ifdef ENABLE_DEBUG
	  if (check_debug_level (D_EVENT_WAIT))
	    show_wait_status (c);
#endif

	  /*
	   * Wait for something to happen.
	   */
	  status = event_wait (c->c2.event_set, &c->c2.timeval, esr, SIZE(esr));

	  check_status (status, "event_wait", NULL, NULL);

	  if (status > 0)
	    {
	      int i;
	      c->c2.event_set_status = 0;
	      for (i = 0; i < status; ++i)
		{
		  const struct event_set_return *e = &esr[i];
		  c->c2.event_set_status |= ((e->rwflags & 3) << *((int*)e->arg));
		}
	    }
	  else if (status == 0)
	    {
	      c->c2.event_set_status = ES_TIMEOUT;
	    }
	}
      else
	{
	  c->c2.event_set_status = SOCKET_READ;
	}
    }

  /* 'now' should always be a reasonably up-to-date timestamp */
  update_time ();

  /* set signal_received if a signal was received */
  if (c->c2.event_set_status & ES_ERROR)
    get_signal (&c->sig->signal_received);

  dmsg (D_EVENT_WAIT, "I/O WAIT status=0x%04x", c->c2.event_set_status);
}
Example #24
0
static void parse_dc_time(char *line, struct membuffer *str, void *_dc)
{ struct divecomputer *dc = _dc; update_time(&dc->when, line); }
Example #25
0
void optimize(Index& index, php::Program& program) {
    assert(check(program));
    trace_time tracer("optimize");
    SCOPE_EXIT { state_after("optimize", program); };

    // Counters, just for debug printing.
    std::atomic<uint32_t> total_funcs{0};
    auto round = uint32_t{0};

    /*
     * Algorithm:
     *
     * Start by running an analyze pass on every function.  During
     * analysis, information about functions or classes will be
     * requested from the Index, which initially won't really know much,
     * but will record a dependency.  This part is done in parallel: no
     * passes are mutating anything, just reading from the Index.
     *
     * After a pass, we do a single-threaded "update" step to prepare
     * for the next pass: for each function that was analyzed, note the
     * facts we learned that may aid analyzing other functions in the
     * program, and register them in the index.  At this point, if any
     * of these facts are more useful than they used to be, add all the
     * Contexts that had a dependency on the new information to the work
     * list again, in case they can do better based on the new fact.
     *
     * Repeat until the work list is empty.
     */
    auto work = initial_work(program);
    while (!work.empty()) {
        auto const results = [&] {
            trace_time trace(
                "analyzing",
                folly::format("round {} -- {} work items", round, work.size()).str()
            );
            return parallel_map(
                work,
            [&] (const Context& ctx) -> folly::Optional<FuncAnalysis> {
                total_funcs.fetch_add(1, std::memory_order_relaxed);
                return analyze_func(index, ctx);
            }
            );
        }();
        work.clear();

        ++round;
        trace_time update_time("updating");

        std::set<Context> revisit;
        for (auto i = size_t{0}; i < results.size(); ++i) {
            auto& result = *results[i];

            assert(result.ctx.func == work[i].func);
            assert(result.ctx.cls == work[i].cls);
            assert(result.ctx.unit == work[i].unit);

            auto deps = index.refine_return_type(
                            result.ctx.func, result.inferredReturn
                        );
            for (auto& d : deps) revisit.insert(d);
        }

        std::copy(begin(revisit), end(revisit), std::back_inserter(work));
    }

    if (Trace::moduleEnabledRelease(Trace::hhbbc_time, 1)) {
        Trace::traceRelease("total function visits %u\n", total_funcs.load());
    }

    /*
     * Finally, use the results of all these iterations to perform
     * optimization.  This reanalyzes every function using our
     * now-very-updated Index, and then runs optimize_func with the
     * results.
     *
     * We do this in parallel: all the shared information is queried out
     * of the index, and each thread is allowed to modify the bytecode
     * for the function it is looking at.
     *
     * NOTE: currently they can't modify anything other than the
     * bytecode/Blocks, because other threads may be doing unlocked
     * queries to php::Func and php::Class structures.
     */
    trace_time final_pass("final pass");
    work = initial_work(program);
    parallel_for_each(
        initial_work(program),
    [&] (Context ctx) {
        optimize_func(index, analyze_func(index, ctx));
    }
    );
}
Example #26
0
static void parse_trip_time(char *line, struct membuffer *str, void *_trip)
{ dive_trip_t *trip = _trip; update_time(&trip->when, line); }
Example #27
0
void handle_tick(struct tm *tick_time, TimeUnits units_changed) {  
  update_time(tick_time);
}
Example #28
0
void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time(tick_time);
  change_logo_color();
}
Example #29
0
static void tick_handler(struct tm *tick_time, TimeUnits units_changed) {
  update_time();
}
Example #30
0
void
NetworkTimeView::MessageReceived(BMessage* message)
{
	switch (message->what) {
		case kMsgSetDefaultServer:
		{
			int32 sel = fServerListView->CurrentSelection();
			if (sel < 0)
				fServerListView->Select(fSettings.GetDefaultServer());
			else {
				fSettings.SetDefaultServer(sel);
				Looper()->PostMessage(new BMessage(kMsgChange));
			}
			break;
		}
		case kMsgServerEdited:
		{
			rgb_color defaultColor = ui_color(B_CONTROL_TEXT_COLOR);
			rgb_color red = {255, 0, 0};
			int32 length = fServerTextControl->TextView()->TextLength();

			if (_IsValidServerName(fServerTextControl->TextView()->Text()))
				fServerTextControl->TextView()->SetFontAndColor(0, length, NULL, 0, &defaultColor);
			else
				fServerTextControl->TextView()->SetFontAndColor(0, length, NULL, 0, &red);

			break;
		}
		case kMsgAddServer:
			if (!_IsValidServerName(fServerTextControl->TextView()->Text()))
				break;
				
			fSettings.AddServer(fServerTextControl->Text());
			_UpdateServerList();
			fServerTextControl->SetText("");
			Looper()->PostMessage(new BMessage(kMsgChange));
			break;

		case kMsgRemoveServer:
			fSettings.RemoveServer(((BStringItem*)
				fServerListView->ItemAt(
					fServerListView->
					CurrentSelection()))->Text());
			_UpdateServerList();
			Looper()->PostMessage(new BMessage(kMsgChange));
			break;

		case kMsgResetServerList:
			fSettings.ResetServersToDefaults();
			_UpdateServerList();
			Looper()->PostMessage(new BMessage(kMsgChange));
			break;

		case kMsgTryAllServers:
			fSettings.SetTryAllServers(
				fTryAllServersCheckBox->Value());
			Looper()->PostMessage(new BMessage(kMsgChange));
			break;

		case kMsgSynchronizeAtBoot:
			fSettings.SetSynchronizeAtBoot(
				fSynchronizeAtBootCheckBox->Value());
			Looper()->PostMessage(new BMessage(kMsgChange));
			break;

		case kMsgStopSynchronization:
			if (fUpdateThread >= B_OK)
				kill_thread(fUpdateThread);
			_DoneSynchronizing();
			break;

		case kMsgSynchronize:
		{
			if (fUpdateThread >= B_OK)
				break;

			BMessenger* messenger = new BMessenger(this);
			update_time(fSettings, messenger, &fUpdateThread);
			fSynchronizeButton->SetLabel(B_TRANSLATE("Stop"));
			fSynchronizeButton->Message()->what = kMsgStopSynchronization;
			break;
		}

		case kMsgSynchronizationResult:
		{
			_DoneSynchronizing();
			
			status_t status;
			if (message->FindInt32("status", (int32 *)&status) == B_OK) {
				if (status == B_OK) return;

				const char* errorString;
				message->FindString("error string", &errorString);	
				char buffer[256];

				int32 errorCode;
				if (message->FindInt32("error code", &errorCode)
					== B_OK)
					snprintf(buffer, sizeof(buffer),
						B_TRANSLATE("The following error occured "
						"while synchronizing:\r\n%s: %s"),
						errorString, strerror(errorCode));
				else
					snprintf(buffer, sizeof(buffer),
						B_TRANSLATE("The following error occured "
						"while synchronizing:\r\n%s"),
						errorString);

				(new BAlert(B_TRANSLATE("Time"), buffer, 
					B_TRANSLATE("OK")))->Go();
			}
			break;
		}
		
		case kMsgRevert:
			fSettings.Revert();
		    fTryAllServersCheckBox->SetValue(
		    	fSettings.GetTryAllServers());
			fSynchronizeAtBootCheckBox->SetValue(
				fSettings.GetSynchronizeAtBoot());
			_UpdateServerList();
			break;
	}
}