Exemple #1
0
int main(void){
	_delay_ms(1000);

/* Initialize OLED Display */
	init_OLED();
	reset_display();

	while(1){

		/*Draw image on Screen*/
		for(int i=0;i<128*8;i++)     // show 128* 64 Logo
					SendChar(pgm_read_byte(logo2+i));

		sendcommand(0x2f);  /*Scroll on*/
		_delay_ms(4000);
		sendcommand(0x2e);  /*Scroll off*/


		clear_display();

/* Draw text from font */
		sendStrXY("   VISIT US AT  ",0,0);
		sendStrXY("      WWW.      ",2,0);
		sendStrXY(" ELEMENTZONLINE ",4,0);
		sendStrXY("      .COM      ",6,0);

		_delay_ms(8000);
		clear_display();
	}
return 0;
}
Exemple #2
0
Fichier : pg.c Projet : xrg/pg_top
PGconn *
connect_to_db(char *conninfo)
{
	static int	refresh = 0;
	PGconn	   *pgconn = NULL;

	pgconn = PQconnectdb(conninfo);
	if (PQstatus(pgconn) != CONNECTION_OK)
	{
		refresh = 1;
		new_message(MT_standout | MT_delayed, " %s", PQerrorMessage(pgconn));

		PQfinish(pgconn);
		return NULL;
	}
	else
	{
		/*
		 * FIXME: I don't know how expensive this is but I don't know how to
		 * get the header text to redisplay when it gets wipe out by the
		 * above's susequent new_message() calls.  The number of running
		 * processes seems to printed a litle funny when it is 0 too.
		 */
		if (refresh == 1)
		{
			reset_display();
			refresh = 0;
		}
	}
	return pgconn;
}
Exemple #3
0
void Main_win::clear_clicked()
{
  math_->clear();

  remove_matrix();
  build_matrix(mat_dim_);
  reset_display();
}
Exemple #4
0
void on_reset_button_clicked (void) {
	if(state == PAUSED || state == STARTED) {
		state = STOPPED;
		gtk_button_set_label (GTK_BUTTON (button_timer), _("Start"));
		reset_display();
		gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_seconds), 0);
		gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_minutes), 0);
		gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_hours), 0);
		gtk_widget_set_sensitive (button_reset, FALSE);
		gtk_widget_set_sensitive (entry, TRUE);
	}
}
Exemple #5
0
void Main_win::set_x_clicked()
{
  if(mat_dim_.second == 1)
    read_matrix(x_);
  else
  {
    reset_display();
    to_display("x is vector: set col-dim to 1");
  }

  x_set_ = true;
}
Exemple #6
0
void Main_win::solve_clicked()
{
  try
  {
    if(A_set_ && b_set_)
    {
      math_->solve(A_, b_);

      reset_display();
      to_display("x = least-squares solution");
    }
    else
    {
      reset_display();
      to_display("first set A and b");
    }
  }
  catch(std::exception& e)
  {
    reset_display();
    to_display(e.what());
  }
}
Exemple #7
0
void Main_win::dot_clicked()
{
  try
  {
    if(x_set_ && b_set_)
    {
      math_->dot(x_, b_);

      reset_display();
      to_display("< x , b > = a");
    }
    else
    {
      reset_display();
      to_display("first set x and b");
    }
  }
  catch(std::exception& e)
  {
    reset_display();
    to_display(e.what());
  }
}
Exemple #8
0
static uint64_t get_msr(int cpu, uint64_t offset)
{
	ssize_t retval;
	uint64_t msr;

	retval = read_msr(cpu, offset, &msr);
	if (retval < 0) {
		reset_display();
		fprintf(stderr, _("read_msr cpu%d 0x%llx : "), cpu, (unsigned long long)offset);
		fprintf(stderr, "%s\n", strerror(errno));
		exit(-2);
	}

	return msr;
}
Exemple #9
0
void Main_win::det_clicked()
{
  try
  {
    Matrix m(mat_dim_.first, mat_dim_.second);
    read_matrix(m);

    math_->det(m);

    to_display("(");
    to_display(dis_char_.first.at(dis_char_.second));
    to_display(")det");
  }
  catch(std::exception& e)
  {
    reset_display();
    to_display(e.what());
  }
}
Exemple #10
0
int main(int argc, char **argv)
{
	int option_index;
	int c;
	char filename[4096];
	char workload[4096] = {0,};
	int  iterations = 1, auto_tune = 0;

	set_new_handler(out_of_memory);

	setlocale (LC_ALL, "");
	bindtextdomain (PACKAGE, LOCALEDIR);
	textdomain (PACKAGE);

	while (1) { /* parse commandline options */
		c = getopt_long (argc, argv, "ch:C:i:t:uVw:q", long_options, &option_index);
		/* Detect the end of the options. */
		if (c == -1)
			break;

		switch (c) {
			case 'V':
				print_version();
				exit(0);
				break;

			case 'e': /* Extech power analyzer support */
				checkroot();
				extech_power_meter(optarg ? optarg : "/dev/ttyUSB0");
				break;
			case 'u':
				print_usage();
				exit(0);
				break;
			case 'a':
				auto_tune = 1;
				leave_powertop = 1;
				break;
			case 'c':
				powertop_init();
				calibrate();
				break;

			case 'h': /* html report */
				reporttype = REPORT_HTML;
				sprintf(filename, "%s", optarg ? optarg : "powertop.html" );
				break;

			case 't':
				time_out = (optarg ? atoi(optarg) : 20);
				break;

			case 'i':
				iterations = (optarg ? atoi(optarg) : 1);
				break;

			case 'w': /* measure workload */
				sprintf(workload, "%s", optarg ? optarg :'\0' );
				break;
			case 'q':
				if(freopen("/dev/null", "a", stderr))
					fprintf(stderr, _("Quite mode failed!\n"));
				break;

			case 'C': /* csv report*/
				reporttype = REPORT_CSV;
				sprintf(filename, "%s", optarg ? optarg : "powertop.csv");
				break;
			case '?': /* Unknown option */
				/* getopt_long already printed an error message. */
				exit(0);
				break;
		}
	}

	powertop_init();

	if (reporttype != REPORT_OFF)
		make_report(time_out, workload, iterations, filename);

	if (debug_learning)
		printf("Learning debugging enabled\n");

	learn_parameters(250, 0);
	save_parameters("saved_parameters.powertop");


	if (debug_learning) {
	        learn_parameters(1000, 1);
		dump_parameter_bundle();
		end_pci_access();
		exit(0);
	}
	init_display();
	initialize_tuning();
	/* first one is short to not let the user wait too long */
	one_measurement(1, NULL);

	if (!auto_tune) {
		tuning_update_display();
		show_tab(0);
	} else {
		auto_toggle_tuning();
	}

	while (!leave_powertop) {
		show_cur_tab();
		one_measurement(time_out, NULL);
		learn_parameters(15, 0);
	}
	endwin();
	printf("%s\n", _("Leaving PowerTOP"));

	end_process_data();
	clear_process_data();
	end_cpu_data();
	clear_cpu_data();

	save_all_results("saved_results.powertop");
	save_parameters("saved_parameters.powertop");
	learn_parameters(500, 0);
	save_parameters("saved_parameters.powertop");
	end_pci_access();
	clear_tuning();
	reset_display();

	clean_shutdown();

	return 0;
}
Exemple #11
0
void out_of_memory()
{
	reset_display();
	printf("%s...\n",_("PowerTOP is out of memory. PowerTOP is Aborting"));
	abort();
}
Exemple #12
0
int main (int argc, char *argv[]) {
	GError *error_parsearg = NULL;
	GOptionContext *context;
	GtkWidget *window, *vbox, *hbox2;
	GtkAdjustment *sadj, *madj, *hadj;

#ifdef ENABLE_NLS
	bindtextdomain (GETTEXT_PACKAGE, PACKAGE_LOCALE_DIR);
	bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
	textdomain (GETTEXT_PACKAGE);
#endif

	gtk_init (&argc, &argv);
	notify_init ("Gtimer");
	ca_context_create (&sound);

	context = g_option_context_new (_("- a simple countdown timer"));
	g_option_context_add_main_entries (context, entries, NULL);
#ifdef ENABLE_NLS
	g_option_context_set_translation_domain (context, GETTEXT_PACKAGE);
#endif
	if (!g_option_context_parse (context, &argc, &argv, &error_parsearg)) {
		g_fprintf (stderr, "%s\n", error_parsearg->message);
		exit(1);
	}

	vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 5);
	hbox1 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
	hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);

	gtk_box_set_spacing (GTK_BOX (hbox2), 5);
	gtk_container_set_border_width (GTK_CONTAINER (vbox), 5);

	timer_display = gtk_label_new (NULL);
	reset_display();
	
	sadj = gtk_adjustment_new (0, 0, 60, 1, 1, 0);
	madj = gtk_adjustment_new (0, 0, 60, 1, 1, 0);
	hadj = gtk_adjustment_new (0, 0, 24, 1, 1, 0);
	spin_seconds = gtk_spin_button_new (sadj, 1, 0);
	spin_minutes = gtk_spin_button_new (madj, 1, 0);
	spin_hours = gtk_spin_button_new (hadj, 1, 0);

	gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_seconds), TRUE);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_seconds), seconds);
	g_object_set (spin_seconds, "shadow-type", GTK_SHADOW_IN, NULL);
	gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_minutes), TRUE);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_minutes), minutes);
	g_object_set (spin_minutes, "shadow-type", GTK_SHADOW_IN, NULL);
	gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_hours), TRUE);
	gtk_spin_button_set_value (GTK_SPIN_BUTTON (spin_hours), hours);
	g_object_set (spin_hours, "shadow-type", GTK_SHADOW_IN, NULL);

	entry = gtk_entry_new();
	gtk_entry_set_text (GTK_ENTRY (entry), entry_text);
	
	button_timer = gtk_button_new();
	gtk_button_set_label (GTK_BUTTON (button_timer), _("Start"));
	button_reset = gtk_button_new_with_label (_("Reset"));
	gtk_widget_set_sensitive (button_reset, FALSE);

	gtk_box_pack_start (GTK_BOX (hbox1), spin_hours, TRUE, FALSE, 5);
	gtk_box_pack_start (GTK_BOX (hbox1), spin_minutes, TRUE, FALSE, 5);
	gtk_box_pack_start (GTK_BOX (hbox1), spin_seconds, TRUE, FALSE, 5);
	gtk_box_pack_start (GTK_BOX (vbox), timer_display, FALSE, TRUE, 5);
	gtk_box_pack_start (GTK_BOX (hbox2), button_timer, TRUE, TRUE, 0);
	gtk_box_pack_start (GTK_BOX (hbox2), button_reset, TRUE, TRUE, 0);
	gtk_container_add (GTK_CONTAINER (vbox), hbox1);
	gtk_box_pack_start (GTK_BOX (vbox), entry, FALSE, TRUE, 5);
	gtk_container_add (GTK_CONTAINER (vbox), hbox2);

	window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
	gtk_window_set_title (GTK_WINDOW (window), "Gtimer");
	gtk_container_add (GTK_CONTAINER (window), vbox);
	gtk_widget_show_all (window);

	g_timeout_add_seconds (1, (GSourceFunc) timer_function, NULL);
	g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL);
	g_signal_connect (button_timer, "clicked", G_CALLBACK (on_timer_button_clicked), NULL);
	g_signal_connect (button_reset, "clicked", G_CALLBACK (on_reset_button_clicked), NULL);

	gtk_main();
	notify_uninit();
	ca_context_destroy (sound);
	g_option_context_free (context);
	return 0;
}
Exemple #13
0
/**
  * @brief  Task which handles all UI including keypad, LCD and all user power outputs.
	* 				Responds to events caused by other tasks and ISRs
  * @param  None
  * @retval Should never exit
  */
__task void ui (void)
{
	uint16_t event_flag = 0;
	uint8_t key;
	int i;
	uint64_t entry_code = 0;
	
	lcd_init();
	keypad_init();
	
	lcd_backlight(1);
	
	buzzer_init();
	
	pwr_sw_init();
	
	usb_outputs_init();
	dc_outputs_init();

	
	lcd_clear();
	lcd_write_string("    e.quinox    ");
	lcd_goto_XY(0,1);
	lcd_write_string("    izuba.box   ");
	

	//2 second timeout
	os_dly_wait(200);
	
	if ( get_unlock_days () >= 0 )
	{
		ui_state = STATE_NORM;
	}
	
	if( local_ee_data.lvdc_flag == 1 )
	{
		ui_state = STATE_LVDC;
	}
	
	reset_display();
	reset_outputs();
	
	while(1)
	{
		//Wait for any task event or timeout after 1 second
		if ( os_evt_wait_or(0xFFFF, 100) == OS_R_EVT )
		{
			//Find which event 
			event_flag = os_evt_get();
			
			if ( event_flag & UI_BOX_SETUP )
			{
				ui_state = STATE_SETUP;
				lcd_clear();
				reset_display();
				reset_outputs();
			}
			
			if ( (event_flag & UI_LVDC) )
			{
				if ( (ui_state != STATE_LVDC) && (ui_state != STATE_OFF) )
				{
					ui_state = STATE_LVDC;
					local_ee_data.lvdc_flag = 1;
					update_lvdc(1);
					//Turn off outputs
					reset_outputs();
					lcd_power(1);
					lcd_clear();
					lcd_write_string_XY(0, 0, "  Battery Empty ");
					lcd_write_string_XY(0, 1, "  Turning Off   ");

					//Delay and Buzz
					//20 Seconds
					for ( i = 0; i < 5; i++)
					{
						buzz(1);
						//4 second wait
						os_dly_wait(400);
					}
					
					//Turn off Screen
					lcd_power(0);
					
				}
				
			}
			
			if ( event_flag & UI_PWR_SW )
			{
				if ( ui_state != STATE_OFF)
				{
					//Turn off all outputs and UI devices
					//Wait only for UI_PWR_SW tasks
					lcd_power(0);
								
					ui_state = STATE_OFF;
					reset_outputs();
				}
				else
				{
					//Re-init LCD
					lcd_clear();
					lcd_power(1);
					
					check_display_debug();
					
					lcd_splash_screen(2);
					
					if(get_soc() >= CHARGED)
					{
						local_ee_data.lvdc_flag = 0;
						update_lvdc(0);
					}

					if(local_ee_data.lvdc_flag == 1)
					{
						ui_state = STATE_LVDC;
					}
					
					if(ui_state != STATE_LVDC)
					{
						if (get_unlock_days () >= 0 )
							ui_state = STATE_NORM;
						else
							ui_state = STATE_AWAIT_PAYMENT;
					}
					
					reset_outputs();
					reset_display();
				}
				
				//1 second delay
				os_dly_wait(100);
				EXTI_ClearITPendingBit(EXTI_Line0);
			}
			
			if ( event_flag & UI_EVT_USB_OC )
			{
				os_dly_wait(100);
                           
				if(EXTI_GetITStatus(EXTI_Line5) != RESET || EXTI_GetITStatus(EXTI_Line6) != RESET)
				{

					if(EXTI_GetITStatus(EXTI_Line5) != RESET)
						USB1_DISABLE();

					if(EXTI_GetITStatus(EXTI_Line6) != RESET)
						USB2_DISABLE();

					lcd_clear();
					lcd_write_string_XY(0, 0, "       USB      ");
					lcd_write_string_XY(0, 1, "      error!    ");
					//2s wait
					os_dly_wait(200);
					reset_display();
				}
			}

		
			if ( event_flag & (UI_EVT_KEYPAD_1 | UI_EVT_KEYPAD_2 | UI_EVT_KEYPAD_3) )
			{
				if ( (ui_state == STATE_AWAIT_PAYMENT) || (ui_state == STATE_NORM) || (ui_state == STATE_SETUP) )
				{
					//Read which key is pressed
					i = 0;
					do
					{
						key = keypad_get_key();		
						i++;
						os_dly_wait(1);
						if ( i > 20)
							break;
					} while (key == KEY_NONE);
					
					if (key != KEY_NONE)
					{					
						lcd_backlight(1);
						buzz(1);
					}
					
					if (ui_state == STATE_SETUP)
					{
						//If 5 digits and tick then set box_id
						if (key == KEY_CROSS) {
							//'X' Pressed
							//LCDWriteString("x");
							display_str[0] = '\0';
							digit_count = 0;
							local_ee_data.box_id = 0;
							reset_display();
						} else if (key == KEY_NONE) {
							//Do nothing
						} else if ( key == KEY_TICK ) {
							if(digit_count == 5){
								os_dly_wait(50);
								
								//Send message to payment control task
								os_evt_set(PC_SET_BOX_ID, payment_control_t);
								
								ui_state = STATE_AWAIT_PAYMENT;
								display_str[0] = '\0';
								digit_count = 0;
								reset_display();
								reset_outputs();
							}
							}else{
								if(digit_count <5){
									//Add the keypad value to the box id
									display_str[0] = '\0';
									local_ee_data.box_id = (local_ee_data.box_id * 10) + key;
									utoa_b(display_str, local_ee_data.box_id, 10, digit_count);
									lcd_write_string_XY(7, 0, display_str);
									lcd_goto_XY((8 + digit_count), 0);
									reset_display();
								}
								else { // do nothing
								}
								digit_count++;
						}
					}
					else if (ui_state == STATE_AWAIT_PAYMENT)
					{
						if (key == KEY_CROSS) {
							//'X' Pressed
							//LCDWriteString("x");
							display_str[0] = '\0';
							digit_count = 0;
							entry_code = 0;
							lcd_write_string_XY(6, 0, "__________");
							lcd_goto_XY(6, 0);
							//key = KEY_NONE;
							
						} else if (key == KEY_TICK) {
							//Tick Pressed
							//LCDWriteString("./");
						} else if (key == KEY_NONE) {
							//Tick Pressed
							//LCDWriteString("./");
						} else {
							//Add the keypad to the entry code
							entry_code = (entry_code * 10) + key;
							
							//Make the 
							display_str[0] = '\0';
							utoa_b(display_str, entry_code, 10, digit_count);
							lcd_write_string_XY(6, 0, display_str);
							lcd_goto_XY((7 + digit_count), 0);

							if (digit_count++ == 9) {
								os_dly_wait(50);
								
								//Send code to payment control task
								// but send (uint32_t)entry_code							
								if ( check_unlock_code((uint32_t)entry_code))
								{
									TRACE_INFO("2,1,%s\n", display_str);
									ui_state = STATE_NORM;
									// Edited Code
									lcd_clear();
									lcd_write_string_XY(0, 0, "      Valid      ");
									lcd_write_string_XY(0, 1, "      code!    ");
									entry_code = 0;
									digit_count = 0;
									display_str[0] = '\0';
									//2s wait
									os_dly_wait(200);
									// End of Edit
									reset_display();
									reset_outputs();
								}
								else
								{							
									TRACE_INFO("2,0,%s\n", display_str);
									// Edited Code
									lcd_clear();
									lcd_write_string_XY(0, 0, "      Wrong      ");
									lcd_write_string_XY(0, 1, "      code!    ");
									//2s wait
									os_dly_wait(200);
									// End of Edit
									
									entry_code = 0;
									digit_count = 0;
									display_str[0] = '\0';
									reset_display();
									reset_outputs();
								}
							}
						}
					}
					else
					{											
						switch (key)
						{
							case KEY_NONE:
								//No Action
								break;
							//Special Key Cases
							case KEY_TICK:
								TRACE_DEBUG("Key: ./ \n");
								break;
							case KEY_CROSS:
								TRACE_DEBUG("Key: X \n");
								break;
							default:
								//Print the key number
								TRACE_DEBUG("Key: %i \n", key);			
						}
					}
					
					//Wait for release of key (with time-out)
					i = 0;
					while( keypad_get_key() != KEY_NONE )
					{
						i++;
						os_dly_wait(1);
						if ( i > 20)
							break;
					}			
				}					
			}
			
			if(local_ee_data.lvdc_flag == 0)
			{
				if ( event_flag & UI_PAYMENT_INVALID )
				{
					ui_state = STATE_AWAIT_PAYMENT;
					lcd_clear();
					reset_display();
					reset_outputs();
				}
			}
			
			if(local_ee_data.lvdc_flag == 1)
			{
				lcd_clear();
				lcd_write_string_XY(0, 0, "  Battery Low   ");
				lcd_batt_level( get_soc(), get_charging_rate() );
				
				if(get_soc() >= CHARGED)
				{
					local_ee_data.lvdc_flag = 0;
					update_lvdc(0);
				}
			}
			//clear event flags
			os_evt_clr(event_flag, ui_t);
			
		}
		
		/* Debugging Info on LCD
	  sprintf(str, "P=%.2f", get_adc_voltage(ADC_SOL_V)*get_adc_voltage(ADC_SOL_I));
 		lcd_goto_XY(0,0);
 		lcd_write_string(str);
 		
 		str[0] = NULL;
 		
 		sprintf(str, "T=%.2f", get_adc_voltage(ADC_TEMP));
 		lcd_goto_XY(8,0);
 		lcd_write_string(str);
 		
 		str[0] = NULL;
 		
 		sprintf(str, "V=%.2f", get_adc_voltage(ADC_BATT_V));
 		lcd_goto_XY(0,1);
 		lcd_write_string(str);
		
 		str[0] = NULL;
 		
 		sprintf(str, "I=%.2f", get_adc_voltage(ADC_BATT_I));
 		lcd_goto_XY(8,1);
 		lcd_write_string(str);
 		
 		str[0] = NULL;
*/
		//Update battery levels, days remaining and if normal state then time/date
		
		if(local_ee_data.lvdc_flag == 1)
		{
			lcd_write_string_XY(0, 0, "  Battery Low   ");
			lcd_batt_level( get_soc(), get_charging_rate() );
				
			if(get_soc() >= CHARGED)
			{
				local_ee_data.lvdc_flag = 0;
				update_lvdc(0);
				
				if(get_unlock_days () >= 0 )
				{
					ui_state = STATE_NORM;
				}
				else
				{
					ui_state = STATE_AWAIT_PAYMENT;
				}
				
				reset_display();
				reset_outputs();
				
			}
		}
		
		if ( (ui_state == STATE_NORM) || (ui_state == STATE_AWAIT_PAYMENT) )
		{
			lcd_batt_level( get_soc(), get_charging_rate() );
		}
		
		if (ui_state == STATE_NORM)
		{
			//Update remaining days
			if(local_ee_data.full_unlock == EE_FULL_UNLOCK_CODE){
				lcd_write_string_XY(0, 1, "        Unlocked");
				lcd_batt_level( get_soc(), get_charging_rate() );
			}
			else{
				lcd_write_string_XY(0, 1, "            days");
				lcd_write_int_XY(10, 1, get_unlock_days() );
				lcd_batt_level( get_soc(), get_charging_rate() );
			}			
		}

	}
}
Exemple #14
0
void OLED::begin(void) {
	// set up i2c
	Wire.begin(_sda, _scl);
	init_OLED();
	reset_display();
}
void SSD1306::init() {
  Wire.begin(mySda, mySdc);
  Wire.setClock(400000); 
  sendInitCommands();
  reset_display();
}
Exemple #16
0
int gui_choose_search_keep(game *g, int who, int arg1, int arg2) {
 	//GtkWidget *combo;
	card *c_ptr;
	displayed *i_ptr;
	char buf[1024];
	int i;

	/* Get card pointer */
	c_ptr = &g->deck[arg1];

	/* Create prompt */
	sprintf(buf, "Choose to keep/discard %s", c_ptr->d_ptr->name);

	/* Set prompt */
	//gtk_label_set_text(GTK_LABEL(action_prompt), buf);

	/* Reset displayed cards */
	reset_cards(g, true, true);

	/* Activate action button */
	//gtk_widget_set_sensitive(action_button, TRUE);

	/* Get next entry in hand list */
	i_ptr = &hand[hand_size++];

	/* Reset structure */
	reset_display(i_ptr);

	/* Add card information */
	i_ptr->index = arg1;
	i_ptr->d_ptr = c_ptr->d_ptr;

	/* Card is in hand */
	i_ptr->hand = 1;

	/* Card should be separated from hand */
	i_ptr->gapped = 1;
	i_ptr->color = 1;
	/* Create simple combo box */
	//combo = gtk_combo_box_new_text();

	/* Append options to combo box */
	//gtk_combo_box_append_text(GTK_COMBO_BOX(combo),
	//                            "Discard (keep searching)");
	//gtk_combo_box_append_text(GTK_COMBO_BOX(combo), "Keep card");

	/* Set first choice */
	//gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);

	/* Add combo box to action box */
	//gtk_box_pack_end(GTK_BOX(action_box), combo, FALSE, TRUE, 0);

	/* Show everything */
	//gtk_widget_show_all(combo);

	/* Redraw everything */
	redraw_everything();

	/* Process events */
	//gtk_main();

	/* Get selection */
	//i = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));

	/* Destroy combo box */
	//    gtk_widget_destroy(combo);

	/* Return choice */
	return i;
}
Exemple #17
0
void perf_event::create_perf_event(char *eventname, int _cpu)
{
	struct perf_event_attr attr;
	int ret;
	int err;

	struct {
		__u64 count;
		__u64 time_enabled;
		__u64 time_running;
		__u64 id;
	} read_data;

	if (perf_fd != -1)
		clear();

	memset(&attr, 0, sizeof(attr));

	attr.read_format	= PERF_FORMAT_TOTAL_TIME_ENABLED |
				  PERF_FORMAT_TOTAL_TIME_RUNNING |
				  PERF_FORMAT_ID;

	attr.sample_freq	= 0;
	attr.sample_period	= 1;
	attr.sample_type	|= PERF_SAMPLE_RAW | PERF_SAMPLE_CPU | PERF_SAMPLE_TIME;

	attr.mmap		= 1;
	attr.comm		= 1;
	attr.inherit		= 0;
	attr.disabled		= 1;

	attr.type		= PERF_TYPE_TRACEPOINT;
	attr.config		= trace_type;

	if (attr.config <= 0)
		return;

	perf_fd = sys_perf_event_open(&attr, -1, _cpu, -1, 0);

	if (perf_fd < 0) {
		err = errno;
		reset_display();
		if (err == EMFILE)
			fprintf(stderr, _("Too many open files, please increase the limit of open file descriptors.\n"));
		else {
			fprintf(stderr, _("PowerTOP %s needs the kernel to support the 'perf' subsystem\n"), POWERTOP_VERSION);
			fprintf(stderr, _("as well as support for trace points in the kernel:\n"));
			fprintf(stderr, "CONFIG_PERF_EVENTS=y\nCONFIG_PERF_COUNTERS=y\nCONFIG_TRACEPOINTS=y\nCONFIG_TRACING=y\n");
		}
		exit(EXIT_FAILURE);
	}
	if (read(perf_fd, &read_data, sizeof(read_data)) == -1) {
		reset_display();
		perror("Unable to read perf file descriptor\n");
		exit(-1);
	}

	fcntl(perf_fd, F_SETFL, O_NONBLOCK);

	perf_mmap = mmap(NULL, (bufsize+1)*getpagesize(),
				PROT_READ | PROT_WRITE, MAP_SHARED, perf_fd, 0);
	if (perf_mmap == MAP_FAILED) {
		fprintf(stderr, "failed to mmap with %d (%s)\n", errno, strerror(errno));
		return;
	}

	ret = ioctl(perf_fd, PERF_EVENT_IOC_ENABLE, 0);

	if (ret < 0) {
		fprintf(stderr, "failed to enable perf \n");
	}

	pc = (perf_event_mmap_page *)perf_mmap;
	data_mmap = (unsigned char *)perf_mmap + getpagesize();


}