Ejemplo n.º 1
0
/*!
  \brief bind_group_data() is called to bind data widget that is defined in
  a group. (saves from having to duplicate a large number of keys/values for 
  a big group of widgets) This function will set the necessary data on the 
  Gui object.
  \param cfg is the pointer to the config file object to read data from
  \param object is the widget to bind the data to
  \param groups is the hashtable that holds the group common data
  \param groupname is the textual name of the group to get the data for to
  be bound to the widget
  \returns the page of the group
  */
G_MODULE_EXPORT gint bind_group_data(ConfigFile *cfg, GObject *object, GHashTable *groups, const gchar *groupname)
{
	gint i = 0;
	gint tmpi = 0;
	Group *group = NULL;
	DataType keytype = MTX_STRING;

	ENTER();
	group = (Group *)g_hash_table_lookup(groups,groupname);
	if (!group)
	{
		MTXDBG(TABLOADER|CRITICAL,_("Group \"%s\" not found in file %s\n"),groupname,cfg->filename);
		EXIT();
		return -1;
	}
	/* Copy data from the group object to the */
	/* Grab hidden data if it exists */
	if (OBJ_GET(group->object, "dep_object"))
		OBJ_SET(object,"dep_object",OBJ_GET(group->object, "dep_object"));

	for (i=0;i<group->num_keys;i++)
	{
		keytype = (DataType)translate_string(group->keys[i]);
		switch((DataType)keytype)
		{
			case MTX_INT:
			case MTX_BOOL:
			case MTX_ENUM:
				tmpi = (GINT)OBJ_GET(group->object,group->keys[i]);
				OBJ_SET(object,group->keys[i],GINT_TO_POINTER(tmpi));
				if (strstr(group->keys[i], "temp_dep"))
				{
					OBJ_SET(object,"widget_temp",DATA_GET(global_data,"mtx_temp_units"));
				}
				break;
			case MTX_FLOAT:
				OBJ_SET_FULL(object,group->keys[i],g_memdup(OBJ_GET(group->object,group->keys[i]),sizeof(gfloat)),g_free);
				break;
			case MTX_STRING:
				OBJ_SET_FULL(object,group->keys[i],(gchar *)g_strdup((gchar *)OBJ_GET(group->object,group->keys[i])),g_free);
				if (OBJ_GET(object,"tooltip") != NULL)
					gtk_widget_set_tooltip_text((GtkWidget *)OBJ_GET(object,"self"),(gchar *)OBJ_GET(object,"tooltip"));
				if (OBJ_GET(group->object, "bind_to_list"))
					bind_to_lists((GtkWidget *)OBJ_GET(object,"self"),(gchar *)OBJ_GET(group->object, "bind_to_list"));
				break;
			default:
				break;
		}
	}
	EXIT();
	return group->page;
}
Ejemplo n.º 2
0
void load_gauge(GtkWidget *dash, xmlNode *node)
{
	xmlNode *cur_node = NULL;
	GtkWidget *gauge = NULL;
	gchar * filename = NULL;
	gint width = 0;
	gint height = 0;
	gint x_offset = 0;
	gint y_offset = 0;
	gchar *xml_name = NULL;
	gchar *datasource = NULL;
	if (!node->children)
	{
		printf("ERROR, load_gauge, xml node is empty!!\n");
		return;
	}
	cur_node = node->children;
	while (cur_node->next) { if (cur_node->type == XML_ELEMENT_NODE)
		{
			if (g_strcasecmp((gchar *)cur_node->name,"width") == 0)
				generic_xml_gint_import(cur_node,&width);
			if (g_strcasecmp((gchar *)cur_node->name,"height") == 0)
				generic_xml_gint_import(cur_node,&height);
			if (g_strcasecmp((gchar *)cur_node->name,"x_offset") == 0)
				generic_xml_gint_import(cur_node,&x_offset);
			if (g_strcasecmp((gchar *)cur_node->name,"y_offset") == 0)
				generic_xml_gint_import(cur_node,&y_offset);
			if (g_strcasecmp((gchar *)cur_node->name,"gauge_xml_name") == 0)
				generic_xml_gchar_import(cur_node,&xml_name);
			if (g_strcasecmp((gchar *)cur_node->name,"datasource") == 0)
				generic_xml_gchar_import(cur_node,&datasource);
		}
		cur_node = cur_node->next;

	}
	if (xml_name && datasource)
	{
		gauge = mtx_gauge_face_new();
		gtk_fixed_put(GTK_FIXED(dash),gauge,x_offset,y_offset);
		xml_name = g_strdelimit(xml_name,"\\",'/');
		filename = get_file(g_build_filename(PSEP,GAUGES_DATA_DIR,xml_name,NULL),NULL);
		mtx_gauge_face_import_xml(MTX_GAUGE_FACE(gauge),filename);
		gtk_widget_set_usize(gauge,width,height);
		g_free(filename);
		OBJ_SET_FULL((gauge),"datasource",g_strdup(datasource),g_free);
		/* Cheat to get property window created... */


		create_preview_list(NULL,NULL);
		update_properties(gauge,GAUGE_ADD);
		g_free(xml_name);
		g_free(datasource);
		gtk_widget_show_all(dash);
	}

}
Ejemplo n.º 3
0
/*!
  \brief populate_master() stores a pointer to all of the glade loaded 
  widgets into a master hashtable so that it can be recalled by name 
  anywhere in the program.
  \param widget is the pointer to Widget
  \param user_data is the pointer to ConfigFile structure
  */
G_MODULE_EXPORT void populate_master(GtkWidget *widget, gpointer user_data )
{
	gchar *name = NULL;
	gchar *fullname = NULL;
	gchar *prefix = NULL;
	GHashTable *dynamic_widgets = NULL;
	ConfigFile *cfg = (ConfigFile *) user_data;
	/*!
	 Populates a big master hashtable of all dynamic widgets so that 
	 various functions can do a lookup for the widgets name and get it's
	 GtkWidget * for manipulation.  We do NOT insert the topframe
	 widgets from the XML tree as if more than 1 tab loads there will 
	 be a clash, and there's no need to store the top frame widget 
	 anyways...
	 */
	if (GTK_IS_CONTAINER(widget))
		gtk_container_foreach(GTK_CONTAINER(widget),populate_master,user_data);
	if (!cfg_read_string(cfg,"global","id_prefix",&prefix))
		prefix = g_strdup("");

	name = (char *)glade_get_widget_name(widget);
	/*printf("name of widget stored is %s\n",name);*/

	if (name == NULL)
	{
		g_free(prefix);
		return;
	}
	if (g_strrstr((gchar *)name,"topframe"))
	{
		g_free(prefix);
		return;
	}
	dynamic_widgets = DATA_GET(global_data,"dynamic_widgets");
	if(!dynamic_widgets)
	{
		dynamic_widgets = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,NULL);
		DATA_SET_FULL(global_data,"dynamic_widgets",dynamic_widgets,g_hash_table_destroy);
	}
	fullname = g_strdup_printf("%s%s",prefix,name);
	OBJ_SET_FULL(widget,"fullname",g_strdup(fullname),g_free);
	OBJ_SET(widget,"last_value",GINT_TO_POINTER(-G_MAXINT));
	if (!g_hash_table_lookup(dynamic_widgets,fullname))
		g_hash_table_insert(dynamic_widgets,g_strdup(fullname),(gpointer)widget);
	else
		MTXDBG(CRITICAL,_("Key %s  for widget %s from file %s already exists in master table\n"),name,fullname,cfg->filename);

	g_free(prefix);
	g_free(fullname);
}
Ejemplo n.º 4
0
/*!
  \brief Creates a group of 2D Table Editors packed into a GtkNotebook
  \param button is a pointer to the widget the user click on, which has bound
  to is a list of the TE Table ID's which we need to create on-screen 
  representations for
  \returns TRUE on success, FALSE otherwise
  */
G_MODULE_EXPORT gboolean create_2d_table_editor_group(GtkWidget *button)
{
	GladeXML *main_xml = NULL;
	GladeXML *xml = NULL;
	GtkWidget *widget = NULL;
	GtkWidget *window = NULL;
	GtkWidget *notebook = NULL;
	GtkWidget *curve = NULL;
	GtkWidget *x_parent = NULL;
	GtkWidget *y_parent = NULL;
	GtkWidget *x_table = NULL;
	GtkWidget *y_table = NULL;
	GtkWidget *label = NULL;
	GtkWidget *entry = NULL;
	GtkWidget *dummy = NULL;
	GtkWidget *gauge = NULL;
	GtkWidget *parent = NULL;
	GtkWidget *curve_parent = NULL;
	CurveData *cdata = NULL;
	GArray *x_entries = NULL;
	GArray *y_entries = NULL;
	GList *widget_list = NULL;
	GList *curve_list = NULL;
	GList *gauge_list = NULL;
	gchar * tmpbuf = NULL;
	gchar * filename = NULL;
	gchar **vector = NULL;
	GList ***ecu_widgets = NULL;
	gint num_tabs = 0;
	gint x_mult = 0;
	gint y_mult = 0;
	gint page = 0;
	gint offset = 0;
	gint i = 0;
	gint j = 0;
	gfloat tmpf = 0.0;
	guint32 id = 0;
	gint rows = 0;
	gint table_num = 0;
	Firmware_Details *firmware = NULL;

	firmware = DATA_GET(global_data,"firmware");
	ecu_widgets = DATA_GET(global_data,"ecu_widgets");

	main_xml = (GladeXML *)DATA_GET(global_data,"main_xml");
	if (!main_xml)
		return FALSE;

	xml = glade_xml_new(main_xml->filename,"table_editor_window",NULL);
	window = glade_xml_get_widget(xml,"table_editor_window");

	glade_xml_signal_autoconnect(xml);

	g_signal_connect(G_OBJECT(window),"destroy_event",
			G_CALLBACK(close_2d_editor),NULL);
	g_signal_connect(G_OBJECT(window),"delete_event",
			G_CALLBACK(close_2d_editor),NULL);
	gtk_window_set_title(GTK_WINDOW(window),_("2D Table Group Editor"));
	gtk_window_resize(GTK_WINDOW(window),800,530);

	widget = glade_xml_get_widget(xml,"2d_close_button");
	g_signal_connect_swapped(G_OBJECT(widget),"clicked",
			G_CALLBACK(close_2d_editor),window);

	widget = glade_xml_get_widget(xml,"get_data_button");
	OBJ_SET(widget,"handler",GINT_TO_POINTER(READ_VE_CONST));
	OBJ_SET_FULL(widget,"bind_to_list",g_strdup("get_data_buttons"),g_free);
	bind_to_lists_f(widget,"get_data_buttons");
	widget_list = g_list_prepend(widget_list,(gpointer)widget);

	widget = glade_xml_get_widget(xml,"burn_data_button");
	OBJ_SET(widget,"handler",GINT_TO_POINTER(BURN_FLASH));
	OBJ_SET_FULL(widget,"bind_to_list",g_strdup("burners"),g_free);
	bind_to_lists_f(widget,"burners");
	widget_list = g_list_prepend(widget_list,(gpointer)widget);

	/*
	widget = glade_xml_get_widget(xml,"curve_editor_menuitem");
	gtk_widget_set_sensitive(GTK_WIDGET(widget), FALSE);
	*/

	widget = glade_xml_get_widget(xml,"close_menuitem");
	OBJ_SET(widget,"window",(gpointer)window);

	widget = glade_xml_get_widget(xml,"te_layout_hbox1");
	gtk_widget_destroy(widget);

	widget = glade_xml_get_widget(xml,"te_layout_vbox");

	tmpbuf = OBJ_GET(button,"te_tables");
	vector = parse_keys_f(tmpbuf,&num_tabs,",");
	notebook = gtk_notebook_new();
	gtk_notebook_set_tab_pos(GTK_NOTEBOOK(notebook),GTK_POS_LEFT);
	gtk_box_pack_start(GTK_BOX(widget),notebook,TRUE,TRUE,0);
	for (j = 0;j < num_tabs;j++)
	{
		table_num = (gint)strtod(vector[j],NULL);
		if (table_num >= firmware->total_te_tables)
		{
			warn_user_f("Requested to create 2D table editor window for an undefined (out of range) table ID");
			return FALSE;
		}
		if (!firmware->te_params)
		{
			warn_user_f("No 2D table Editor tables (te_tables) defined in interrogation profile, yet told to create a graph for a table... BUG detected!");
			continue;
		}
		if (!firmware->te_params[table_num])
		{
			warn_user_f("Requested to create a 2D table editor window for an undefined table!");
			continue;
		}
		xml = glade_xml_new(main_xml->filename,"te_layout_hbox1",NULL);
		widget = glade_xml_get_widget(xml,"te_layout_hbox1");
		label = gtk_label_new(firmware->te_params[table_num]->title);
		gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
		if (firmware->te_params[table_num]->bind_to_list)
		{
			OBJ_SET_FULL(widget,"bind_to_list", g_strdup(firmware->te_params[table_num]->bind_to_list),g_free);
			OBJ_SET(widget,"match_type", GINT_TO_POINTER(firmware->te_params[table_num]->match_type));
			bind_to_lists_f(widget,firmware->te_params[table_num]->bind_to_list);
			widget_list = g_list_prepend(widget_list,(gpointer)widget);
			OBJ_SET_FULL(label,"bind_to_list", g_strdup(firmware->te_params[table_num]->bind_to_list),g_free);
			OBJ_SET(label,"match_type", GINT_TO_POINTER(firmware->te_params[table_num]->match_type));
			bind_to_lists_f(label,firmware->te_params[table_num]->bind_to_list);
			widget_list = g_list_prepend(widget_list,(gpointer)label);
		}

		if (firmware->te_params[table_num]->gauge ||
				firmware->te_params[table_num]->c_gauge ||
				firmware->te_params[table_num]->f_gauge)
		{
			parent = glade_xml_get_widget(xml,"te_gaugeframe");
			gauge = mtx_gauge_face_new();
			gauge_list = g_list_prepend(gauge_list,(gpointer)gauge);

			OBJ_SET(window,"gauge",gauge);
			if (firmware->te_params[table_num]->gauge_temp_dep)
			{
				if ((GINT)DATA_GET(global_data,"mtx_temp_units") == CELSIUS)
					tmpbuf = g_strdelimit(firmware->te_params[table_num]->c_gauge,"\\",'/');
				else if ((GINT)DATA_GET(global_data,"mtx_temp_units") == KELVIN)
					tmpbuf = g_strdelimit(firmware->te_params[table_num]->c_gauge,"\\",'/');
				else
					tmpbuf = g_strdelimit(firmware->te_params[table_num]->f_gauge,"\\",'/');
			}
			else
				tmpbuf = g_strdelimit(firmware->te_params[table_num]->gauge,"\\",'/');
			filename = get_file(g_strconcat(GAUGES_DATA_DIR,PSEP,tmpbuf,NULL),NULL);
			mtx_gauge_face_import_xml(MTX_GAUGE_FACE(gauge),filename);
			lookup_current_value_f(firmware->te_params[table_num]->gauge_datasource, &tmpf);
			mtx_gauge_face_set_value(MTX_GAUGE_FACE(gauge),tmpf);
			g_free(filename);
			id = create_rtv_value_change_watch_f(firmware->te_params[table_num]->gauge_datasource,FALSE,"update_misc_gauge",(gpointer)gauge);
			OBJ_SET(gauge,"gauge_id",GINT_TO_POINTER(id));
			gtk_container_add(GTK_CONTAINER(parent),gauge);
		}
		gtk_notebook_append_page(GTK_NOTEBOOK(notebook),widget,label);
		curve_parent = glade_xml_get_widget(xml,"te_right_frame");
		curve = mtx_curve_new();
		curve_list = g_list_prepend(curve_list,(gpointer)curve);
		mtx_curve_set_title(MTX_CURVE(curve),_(firmware->te_params[table_num]->title));
		mtx_curve_set_x_axis_label(MTX_CURVE(curve),_(firmware->te_params[table_num]->x_axis_label));
		mtx_curve_set_y_axis_label(MTX_CURVE(curve),_(firmware->te_params[table_num]->y_axis_label));
		cdata = g_new0(CurveData, 1);
		cdata->curve = curve;
		cdata->axis = _X_;
		cdata->source = firmware->te_params[table_num]->x_source;
		id = create_rtv_value_change_watch_f(cdata->source,FALSE,"update_curve_marker",(gpointer)cdata);
		mtx_curve_set_show_x_marker(MTX_CURVE(curve),TRUE);
		OBJ_SET(curve,"cdata",(gpointer)cdata);
		OBJ_SET(curve,"marker_id",GINT_TO_POINTER(id));
		mtx_curve_set_auto_hide_vertexes(MTX_CURVE(curve),TRUE);
		g_signal_connect(G_OBJECT(curve),"coords-changed",
				G_CALLBACK(coords_changed), NULL);
		g_signal_connect(G_OBJECT(curve),"vertex-proximity",
				G_CALLBACK(vertex_proximity), NULL);
		g_signal_connect(G_OBJECT(curve),"marker-proximity",
				G_CALLBACK(marker_proximity), NULL);

		label = glade_xml_get_widget(xml,"x_units");
		gtk_label_set_markup(GTK_LABEL(label),firmware->te_params[table_num]->x_units);
		label = glade_xml_get_widget(xml,"y_units");
		gtk_label_set_markup(GTK_LABEL(label),firmware->te_params[table_num]->y_units);
		label = glade_xml_get_widget(xml,"x_title");
		gtk_label_set_markup(GTK_LABEL(label),firmware->te_params[table_num]->x_name);
		label = glade_xml_get_widget(xml,"y_title");
		gtk_label_set_markup(GTK_LABEL(label),firmware->te_params[table_num]->y_name);
		rows = firmware->te_params[table_num]->bincount;
		mtx_curve_set_empty_array(MTX_CURVE(curve),rows);
		x_table = gtk_table_new(rows+1,1,FALSE);
		y_table = gtk_table_new(rows+1,1,FALSE);

		x_parent = glade_xml_get_widget(xml,"te_x_frame");
		y_parent = glade_xml_get_widget(xml,"te_y_frame");
		gtk_container_set_border_width(GTK_CONTAINER(x_table),5);
		gtk_container_set_border_width(GTK_CONTAINER(y_table),5);
		gtk_container_add(GTK_CONTAINER(x_parent),x_table);
		gtk_container_add(GTK_CONTAINER(y_parent),y_table);

		x_mult = get_multiplier_f(firmware->te_params[table_num]->x_size);
		y_mult = get_multiplier_f(firmware->te_params[table_num]->y_size);
		x_entries = g_array_new(FALSE,TRUE,sizeof(GtkWidget *));
		y_entries = g_array_new(FALSE,TRUE,sizeof(GtkWidget *));
		for (i=0;i<rows;i++)
		{
			/* X Column */
			entry = gtk_entry_new();
			OBJ_SET(entry,"last_value",GINT_TO_POINTER(-G_MAXINT));
			gtk_entry_set_width_chars(GTK_ENTRY(entry),7);
			OBJ_SET(entry,"curve_index",GINT_TO_POINTER(i));
			g_array_insert_val(x_entries,i,entry);
			OBJ_SET(entry,"curve_axis",GINT_TO_POINTER(_X_));
			OBJ_SET(entry,"dl_type",GINT_TO_POINTER(IMMEDIATE));
			OBJ_SET(entry,"handler",GINT_TO_POINTER(GENERIC));
			OBJ_SET_FULL(entry,"raw_lower",g_strdup_printf("%i",(firmware->te_params[table_num]->x_raw_lower)),g_free);
			OBJ_SET_FULL(entry,"raw_upper",g_strdup_printf("%i",(firmware->te_params[table_num]->x_raw_upper)),g_free);
			OBJ_SET(entry,"fromecu_mult",firmware->te_params[table_num]->x_fromecu_mult);
			OBJ_SET(entry,"fromecu_add",firmware->te_params[table_num]->x_fromecu_add);
			OBJ_SET(entry,"precision",GINT_TO_POINTER(firmware->te_params[table_num]->x_precision));
			OBJ_SET(entry,"size",GINT_TO_POINTER(firmware->te_params[table_num]->x_size));
			OBJ_SET(entry,"page",GINT_TO_POINTER(firmware->te_params[table_num]->x_page));
			OBJ_SET(entry,"temp_dep",GINT_TO_POINTER(firmware->te_params[table_num]->x_temp_dep));
			OBJ_SET(entry,"use_color",GINT_TO_POINTER(firmware->te_params[table_num]->x_use_color));
			if(firmware->te_params[table_num]->x_temp_dep)
			{
				OBJ_SET(entry,"widget_temp",DATA_GET(global_data,"mtx_temp_units"));
				OBJ_SET_FULL(entry,"bind_to_list", g_strdup("temperature"),g_free);
				bind_to_lists_f(entry,"temperature");
			}

			offset = (i*x_mult) + firmware->te_params[table_num]->x_base;
			OBJ_SET(entry,"offset",GINT_TO_POINTER(offset));

			g_signal_connect(G_OBJECT(entry),"changed",
					G_CALLBACK(update_2d_curve),curve);
			g_signal_connect(G_OBJECT(entry),"changed",
					G_CALLBACK(entry_changed_handler_f),NULL);
			g_signal_connect(G_OBJECT(entry),"key_press_event",
					G_CALLBACK(key_event_f),NULL);
			g_signal_connect(G_OBJECT(entry),"key_release_event",
					G_CALLBACK(key_event_f),NULL);
			g_signal_connect(G_OBJECT(entry),"focus_out_event",
					G_CALLBACK(focus_out_handler_f),NULL);
			g_signal_connect(G_OBJECT(entry),"activate",
					G_CALLBACK(std_entry_handler_f),NULL);

			if (firmware->te_params[table_num]->reversed)
				gtk_table_attach(GTK_TABLE(x_table),entry,
						0,1,rows-i-1,rows-i, GTK_SHRINK,GTK_SHRINK,0,0);
			else
				gtk_table_attach(GTK_TABLE(x_table),entry,
						0,1,i,i+1, GTK_SHRINK,GTK_SHRINK,0,0);
			page = firmware->te_params[table_num]->x_page;
			ecu_widgets[page][offset] = g_list_prepend(ecu_widgets[page][offset],(gpointer)entry);
			widget_list = g_list_prepend(widget_list,(gpointer)entry);
			update_widget(G_OBJECT(entry),NULL);

			/* Y Column */
			entry = gtk_entry_new();
			OBJ_SET(entry,"last_value",GINT_TO_POINTER(-G_MAXINT));
			gtk_entry_set_width_chars(GTK_ENTRY(entry),7);
			OBJ_SET(entry,"curve_index",GINT_TO_POINTER(i));
			g_array_insert_val(y_entries,i,entry);
			OBJ_SET(entry,"curve_axis",GINT_TO_POINTER(_Y_));
			OBJ_SET(entry,"dl_type",GINT_TO_POINTER(IMMEDIATE));
			OBJ_SET(entry,"handler",GINT_TO_POINTER(GENERIC));
			OBJ_SET_FULL(entry,"raw_lower",g_strdup_printf("%i",(firmware->te_params[table_num]->y_raw_lower)),g_free);
			OBJ_SET_FULL(entry,"raw_upper",g_strdup_printf("%i",(firmware->te_params[table_num]->y_raw_upper)),g_free);
			OBJ_SET(entry,"fromecu_mult",firmware->te_params[table_num]->y_fromecu_mult);
			OBJ_SET(entry,"fromecu_add",firmware->te_params[table_num]->y_fromecu_add);
			OBJ_SET(entry,"precision",GINT_TO_POINTER(firmware->te_params[table_num]->y_precision));
			OBJ_SET(entry,"size",GINT_TO_POINTER(firmware->te_params[table_num]->y_size));
			OBJ_SET(entry,"page",GINT_TO_POINTER(firmware->te_params[table_num]->y_page));
			OBJ_SET(entry,"temp_dep",GINT_TO_POINTER(firmware->te_params[table_num]->y_temp_dep));
			OBJ_SET(entry,"use_color",GINT_TO_POINTER(firmware->te_params[table_num]->y_use_color));
			if(firmware->te_params[table_num]->y_temp_dep)
			{
				OBJ_SET(entry,"widget_temp",DATA_GET(global_data,"mtx_temp_units"));
				OBJ_SET_FULL(entry,"bind_to_list", g_strdup("temperature"),g_free);
				bind_to_lists_f(entry,"temperature");
			}
			offset = (i*y_mult) + firmware->te_params[table_num]->y_base;
			OBJ_SET(entry,"offset",GINT_TO_POINTER(offset));

			g_signal_connect(G_OBJECT(entry),"changed",
					G_CALLBACK(update_2d_curve),curve);
			g_signal_connect(G_OBJECT(entry),"changed",
					G_CALLBACK(entry_changed_handler_f),NULL);
			g_signal_connect(G_OBJECT(entry),"key_press_event",
					G_CALLBACK(key_event_f),NULL);
			g_signal_connect(G_OBJECT(entry),"key_release_event",
					G_CALLBACK(key_event_f),NULL);
			g_signal_connect(G_OBJECT(entry),"focus_out_event",
					G_CALLBACK(focus_out_handler_f),NULL);
			g_signal_connect(G_OBJECT(entry),"activate",
					G_CALLBACK(std_entry_handler_f),NULL);

			if (firmware->te_params[table_num]->reversed)
				gtk_table_attach(GTK_TABLE(y_table),entry,
						0,1,rows-i-1,rows-i, GTK_SHRINK,GTK_SHRINK,0,0);
			else
				gtk_table_attach(GTK_TABLE(y_table),entry,
						0,1,i,i+1, GTK_SHRINK,GTK_SHRINK,0,0);
			page = firmware->te_params[table_num]->y_page;
			ecu_widgets[page][offset] = g_list_prepend(ecu_widgets[page][offset],(gpointer)entry);
			widget_list = g_list_prepend(widget_list,(gpointer)entry);
			update_widget(G_OBJECT(entry),NULL);
		}
		/* Create the "LOCK" buttons */
		dummy = gtk_toggle_button_new_with_label("Unlocked");
		OBJ_SET(dummy,"axis",GINT_TO_POINTER(_X_));
		g_signal_connect(G_OBJECT(dummy),"toggled",
				G_CALLBACK(set_axis_locking),curve);
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy),firmware->te_params[table_num]->x_lock);
		gtk_table_attach(GTK_TABLE(x_table),dummy,
				0,1,i,i+1, GTK_EXPAND|GTK_FILL,0,0,0);
		dummy = gtk_toggle_button_new_with_label("Unlocked");
		OBJ_SET(dummy,"axis",GINT_TO_POINTER(_Y_));
		g_signal_connect(G_OBJECT(dummy),"toggled",
				G_CALLBACK(set_axis_locking),curve);
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(dummy),firmware->te_params[table_num]->y_lock);
		gtk_table_attach(GTK_TABLE(y_table),dummy,
				0,1,i,i+1, GTK_EXPAND|GTK_FILL,0,0,0);

		mtx_curve_set_x_precision(MTX_CURVE(curve),firmware->te_params[table_num]->x_precision);
		mtx_curve_set_y_precision(MTX_CURVE(curve),firmware->te_params[table_num]->y_precision);
		mtx_curve_set_hard_limits(MTX_CURVE(curve),
				(gfloat)firmware->te_params[table_num]->x_raw_lower,
				(gfloat)firmware->te_params[table_num]->x_raw_upper,
				(gfloat)firmware->te_params[table_num]->y_raw_lower,
				(gfloat)firmware->te_params[table_num]->y_raw_upper);
		OBJ_SET(curve,"x_entries",x_entries);
		OBJ_SET(curve,"y_entries",y_entries);
		if (firmware->te_params[table_num]->bind_to_list)
			g_list_foreach(get_list_f(firmware->te_params[table_num]->bind_to_list),alter_widget_state_f,NULL);
		create_rtv_value_change_watch_f(cdata->source,TRUE,"update_curve_marker",(gpointer)cdata);
		gtk_container_add(GTK_CONTAINER(curve_parent),curve);
	}
	OBJ_SET(window,"widget_list",widget_list);
	OBJ_SET(window,"curve_list",curve_list);
	OBJ_SET(window,"gauge_list",gauge_list);
	gtk_widget_show_all(window);
	return TRUE;
}
Ejemplo n.º 5
0
/*!
  \brief General purpose handler to hide/show tps calibrate window
  \param widget is the pointer to the TPS caliobration window
  \param data is unused
 */
G_MODULE_EXPORT gboolean show_tps_calibrator_window(GtkWidget *widget, gpointer data)
{
	static GtkWidget *window = NULL;
	GtkWidget *item = NULL;
	GladeXML *main_xml = NULL;
	GladeXML *xml = NULL;
	Firmware_Details *firmware = NULL;
	GList ***ecu_widgets = NULL;
	void (*update_widget_f)(gpointer, gpointer) = NULL;

	ENTER();
	if (!update_widget_f)
		get_symbol_f("update_widget",(void **)&update_widget_f);


	ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets");
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	main_xml = (GladeXML *)DATA_GET(global_data,"main_xml");
	if ((!main_xml) || (DATA_GET(global_data,"leaving")))
	{
		EXIT();
		return TRUE;
	}

	if (!GTK_IS_WIDGET(window))
	{
		xml = glade_xml_new(main_xml->filename,"calibrate_tps_window",NULL);
		window = glade_xml_get_widget(xml,"calibrate_tps_window");
		glade_xml_signal_autoconnect(xml);

		item = glade_xml_get_widget(xml,"tpsMin_entry");
		register_widget_f("tpsMin_entry",item);
		OBJ_SET(item,"handler",GINT_TO_POINTER(GENERIC));
		OBJ_SET(item,"dl_type",GINT_TO_POINTER(IMMEDIATE));
		OBJ_SET(item,"last_value",GINT_TO_POINTER(-G_MAXINT));
		OBJ_SET(item,"page",GINT_TO_POINTER(0));
		if (firmware->capabilities & PIS)
			OBJ_SET(item,"offset",GINT_TO_POINTER(2676));
		else
			OBJ_SET(item,"offset",GINT_TO_POINTER(518));
		OBJ_SET(item,"size",GINT_TO_POINTER(MTX_S16));
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		if (firmware->capabilities & PIS)
		{
			OBJ_SET_FULL(item,"raw_upper",g_strdup("255"),g_free);
			OBJ_SET(item,"precision",GINT_TO_POINTER(0));
			ecu_widgets[0][2676] = g_list_prepend(
					ecu_widgets[0][2676],
					(gpointer)item);
		}
		else
		{
			OBJ_SET_FULL(item,"raw_upper",g_strdup("2047"),g_free);
			OBJ_SET(item,"precision",GINT_TO_POINTER(0));
			ecu_widgets[0][518] = g_list_prepend(
					ecu_widgets[0][518],
					(gpointer)item);
		}

		item = glade_xml_get_widget(xml,"tpsMax_entry");
		register_widget_f("tpsMax_entry",item);
		OBJ_SET(item,"handler",GINT_TO_POINTER(GENERIC));
		OBJ_SET(item,"dl_type",GINT_TO_POINTER(IMMEDIATE));
		OBJ_SET(item,"last_value",GINT_TO_POINTER(-G_MAXINT));
		OBJ_SET(item,"page",GINT_TO_POINTER(0));
		if (firmware->capabilities & PIS)
			OBJ_SET(item,"offset",GINT_TO_POINTER(2678));
		else
			OBJ_SET(item,"offset",GINT_TO_POINTER(520));
		OBJ_SET(item,"size",GINT_TO_POINTER(MTX_S16));
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		if (firmware->capabilities & PIS)
		{
			OBJ_SET_FULL(item,"raw_upper",g_strdup("255"),g_free);
			OBJ_SET(item,"precision",GINT_TO_POINTER(0));
			ecu_widgets[0][2678] = g_list_prepend(
					ecu_widgets[0][2678],
					(gpointer)item);

			/* Force them to update */
			g_list_foreach(ecu_widgets[0][2676],update_widget_f,NULL);
			g_list_foreach(ecu_widgets[0][2678],update_widget_f,NULL);

		}
		else
		{
			OBJ_SET_FULL(item,"raw_upper",g_strdup("2047"),g_free);
			OBJ_SET(item,"precision",GINT_TO_POINTER(0));
			ecu_widgets[0][520] = g_list_prepend(
					ecu_widgets[0][520],
					(gpointer)item);

			/* Force them to update */
			g_list_foreach(ecu_widgets[0][518],update_widget_f,NULL);
			g_list_foreach(ecu_widgets[0][520],update_widget_f,NULL);

		}

		item = glade_xml_get_widget(xml,"get_tps_button_min");
		OBJ_SET(item,"handler",GINT_TO_POINTER(GET_CURR_TPS));
		if (firmware->capabilities & PIS)
			OBJ_SET_FULL(item,"source",g_strdup("status_adc_tps"),g_free);
		else
			OBJ_SET_FULL(item,"source",g_strdup("tpsADC"),g_free);
		OBJ_SET_FULL(item,"dest_widget",g_strdup("tpsMin_entry"),g_free);

		item = glade_xml_get_widget(xml,"get_tps_button_max");
		OBJ_SET(item,"handler",GINT_TO_POINTER(GET_CURR_TPS));
		if (firmware->capabilities & PIS)
			OBJ_SET_FULL(item,"source",g_strdup("status_adc_tps"),g_free);
		else
			OBJ_SET_FULL(item,"source",g_strdup("tpsADC"),g_free);
		OBJ_SET_FULL(item,"dest_widget",g_strdup("tpsMax_entry"),g_free);
		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(lookup_widget_f("main_window")));
		gtk_widget_show(GTK_WIDGET(window));
		EXIT();
		return TRUE;
	}
#if GTK_MINOR_VERSION >=18
	if (gtk_widget_get_visible(GTK_WIDGET(window)))
#else
		if (GTK_WIDGET_VISIBLE(GTK_WIDGET(window)))
#endif
			gtk_widget_hide(GTK_WIDGET(window));
		else
			gtk_widget_show(GTK_WIDGET(window));
	EXIT();
	return TRUE;
}
Ejemplo n.º 6
0
/*!
 \brief General purpose handler to hide/show Battery calibrate window
 \param widget is a pointer to the widget clicked
 \param data is unused
 \returns TRUE
 */
G_MODULE_EXPORT gboolean show_battery_calibrator_window(GtkWidget *widget, gpointer data)
{
	static GtkWidget *window = NULL;
	GtkWidget *item = NULL;
	GladeXML *main_xml = NULL;
	GladeXML *xml = NULL;
	gfloat *tmpf = NULL;
	Firmware_Details *firmware = NULL;
	GList ***ecu_widgets;
	void (*update_widget_f)(gpointer, gpointer) = NULL;

	ENTER();
	if (!update_widget_f)
		get_symbol_f("update_widget",(void **)&update_widget_f);

	ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets");
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
	main_xml = (GladeXML *)DATA_GET(global_data,"main_xml");
	if ((!main_xml) || (DATA_GET(global_data,"leaving")))
	{
		EXIT();
		return TRUE;
	}

	if (!GTK_IS_WIDGET(window))
	{
		xml = glade_xml_new(main_xml->filename,"battery_calibration_window",NULL);
		window = glade_xml_get_widget(xml,"battery_calibration_window");
		glade_xml_signal_autoconnect(xml);

		item = glade_xml_get_widget(xml,"batt0_entry");
		register_widget_f("batt0_entry",item);
		OBJ_SET(item,"page",GINT_TO_POINTER(0));
		OBJ_SET(item,"offset",GINT_TO_POINTER(522));
		OBJ_SET(item,"handler",GINT_TO_POINTER(GENERIC));
		OBJ_SET(item,"dl_type",GINT_TO_POINTER(IMMEDIATE));
		OBJ_SET(item,"last_value",GINT_TO_POINTER(-G_MAXINT));
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));
		OBJ_SET(item,"size",GINT_TO_POINTER(MTX_S16));
		tmpf = g_new0(gfloat, 1);
		*tmpf = 0.1;
		OBJ_SET_FULL(item,"fromecu_mult",tmpf,g_free);
		ecu_widgets[0][522] = g_list_prepend(
				ecu_widgets[0][522],
				(gpointer)item);

		item = glade_xml_get_widget(xml,"battmax_entry");
		register_widget_f("battmax_entry",item);
		OBJ_SET(item,"page",GINT_TO_POINTER(0));
		OBJ_SET(item,"offset",GINT_TO_POINTER(524));
		OBJ_SET(item,"handler",GINT_TO_POINTER(GENERIC));
		OBJ_SET(item,"dl_type",GINT_TO_POINTER(IMMEDIATE));
		OBJ_SET(item,"last_value",GINT_TO_POINTER(-G_MAXINT));
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));
		OBJ_SET(item,"size",GINT_TO_POINTER(MTX_S16));
		tmpf = g_new0(gfloat, 1);
		*tmpf = 0.1;
		OBJ_SET_FULL(item,"fromecu_mult",tmpf,g_free);
		ecu_widgets[0][524] = g_list_prepend(
				ecu_widgets[0][524],
				(gpointer)item);

			/* Force them to update */
		g_list_foreach(ecu_widgets[0][522],update_widget_f,NULL);
		g_list_foreach(ecu_widgets[0][524],update_widget_f,NULL);

		item = glade_xml_get_widget(xml,"get_data_button");
		OBJ_SET(item,"handler",GINT_TO_POINTER(READ_VE_CONST));
		OBJ_SET_FULL(item,"bind_to_list",g_strdup("get_data_buttons"),g_free);

		item = glade_xml_get_widget(xml,"burn_data_button");
		OBJ_SET(item,"handler",GINT_TO_POINTER(BURN_FLASH));
		OBJ_SET_FULL(item,"bind_to_list",g_strdup("burners"),g_free);
		bind_to_lists_f(item,"burners");
		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(lookup_widget_f("main_window")));
		gtk_widget_show(GTK_WIDGET(window));

		EXIT();
		return TRUE;
	}
#if GTK_MINOR_VERSION >= 18
	if (gtk_widget_get_visible(GTK_WIDGET(window)))
#else
		if (GTK_WIDGET_VISIBLE(GTK_WIDGET(window)))
#endif
			gtk_widget_hide(GTK_WIDGET(window));
		else
			gtk_widget_show(GTK_WIDGET(window));
	EXIT();
	return TRUE;
}
Ejemplo n.º 7
0
/*!
 \brief General purpose handler to hide/show Sensor calibrate window
 \param widget is a pointer to the widget clicked
 \param data is unused
 \returns TRUE
 */
G_MODULE_EXPORT gboolean show_ms2_afr_calibrator_window(GtkWidget *widget, gpointer data)
{
	static GtkWidget *window = NULL;
	GtkWidget *item = NULL;
	GtkWidget *item2 = NULL;
	GladeXML *main_xml = NULL;
	GladeXML *xml = NULL;
	Firmware_Details *firmware = NULL;
	gboolean (*populate_afr_calibrator_combo_f)(GtkWidget *) = NULL;

	ENTER();
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	main_xml = (GladeXML *)DATA_GET(global_data,"main_xml");
	if ((!main_xml) || (DATA_GET(global_data,"leaving")))
	{
		EXIT();
		return TRUE;
	}

	if (!GTK_IS_WIDGET(window))
	{
		xml = glade_xml_new(main_xml->filename,"ms2_afr_calibrator_window",NULL);
		window = glade_xml_get_widget(xml,"ms2_afr_calibrator_window");
		glade_xml_signal_autoconnect(xml);

		item = glade_xml_get_widget(xml,"ego_sensor_combo");
		register_widget_f("afr_calibrate_ego_sensor_combo",item);
		if (get_symbol_f("populate_afr_calibrator_combo",(void **)&populate_afr_calibrator_combo_f))
			populate_afr_calibrator_combo_f(item);
		item2 = glade_xml_get_widget(xml,"generic_wideband_frame");
		OBJ_SET(item,"generic_controls",item2);

		item = glade_xml_get_widget(xml,"voltage1_entry");
		register_widget_f("voltage1_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("5"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"voltage2_entry");
		register_widget_f("voltage2_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("5"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"afr1_entry");
		register_widget_f("afr1_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("99"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"afr2_entry");
		register_widget_f("afr2_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("99"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(lookup_widget_f("main_window")));
		gtk_widget_show(GTK_WIDGET(window));
		EXIT();
		return TRUE;
	}
#if GTK_MINOR_VERSION >= 18
	if (gtk_widget_get_visible(GTK_WIDGET(window)))
#else
	if (GTK_WIDGET_VISIBLE(GTK_WIDGET(window)))
#endif
		gtk_widget_hide(GTK_WIDGET(window));
	else
		gtk_widget_show(GTK_WIDGET(window));
	EXIT();
	return TRUE;
}
Ejemplo n.º 8
0
/*!
   \brief General purpose handler to hide/show Sensor calibrate window
   \param widget is a pointer to the widget clicked
   \param data is unused
   \returns TRUE
    */
G_MODULE_EXPORT gboolean show_ms2_therm_table_generator_window(GtkWidget *widget, gpointer data)
{
	static GtkWidget *window = NULL;
	static GtkWidget *chooser = NULL;
	GtkWidget *item = NULL;
	GladeXML *main_xml = NULL;
	GladeXML *xml = NULL;
	Firmware_Details *firmware = NULL;

	ENTER();
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
	main_xml = (GladeXML *)DATA_GET(global_data,"main_xml");
	g_return_val_if_fail(firmware,FALSE);
	g_return_val_if_fail(main_xml,FALSE);
	
	if (DATA_GET(global_data,"leaving"))
	{
		EXIT();
		return TRUE;
	}

	if (!GTK_IS_WIDGET(window))
	{
		xml = glade_xml_new(main_xml->filename,"table_generator_window",NULL);
		window = glade_xml_get_widget(xml,"table_generator_window");
		glade_xml_signal_autoconnect(xml);

		/* Default to params not a file */
		chooser = glade_xml_get_widget(xml,"import_filechooser_button");
		register_widget_f("import_filechooser_button",chooser);
		item = glade_xml_get_widget(xml,"use_params_rbutton");
		register_widget_f("use_params_rbutton",item);
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item),TRUE);
		g_signal_emit_by_name(item,"toggled",NULL);

		item = glade_xml_get_widget(xml,"sensor_combo");
		gtk_combo_box_set_active(GTK_COMBO_BOX(item),0);
		register_widget_f("thermister_sensor_combo",item);
		item = glade_xml_get_widget(xml,"temp_label");
		register_widget_f("temp_label",item);
		if (firmware->capabilities & PIS)
			gtk_widget_destroy(glade_xml_get_widget(xml,"bias_resistor_table"));
		else
		{
			item = glade_xml_get_widget(xml,"bias_entry");
			register_widget_f("bias_entry",item);
			OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
			OBJ_SET_FULL(item,"raw_upper",g_strdup("100000"),g_free);
			OBJ_SET(item,"precision",GINT_TO_POINTER(1));
		}

		item = glade_xml_get_widget(xml,"temp1_entry");
		register_widget_f("temp1_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("-40"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("300"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"temp2_entry");
		register_widget_f("temp2_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("-40"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("300"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"temp3_entry");
		register_widget_f("temp3_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("-40"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("300"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"resistance1_entry");
		register_widget_f("resistance1_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("500000"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"resistance2_entry");
		register_widget_f("resistance2_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("500000"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"resistance3_entry");
		register_widget_f("resistance3_entry",item);
		OBJ_SET_FULL(item,"raw_lower",g_strdup("0"),g_free);
		OBJ_SET_FULL(item,"raw_upper",g_strdup("500000"),g_free);
		OBJ_SET(item,"precision",GINT_TO_POINTER(1));

		item = glade_xml_get_widget(xml,"celsius_rbutton");
		OBJ_SET_FULL(item,"temp_label",g_strdup("Temperature(\302\260 C)"),g_free);
		register_widget_f("thermister_celsius_rbutton",item);
		item = glade_xml_get_widget(xml,"fahrenheit_rbutton");
		OBJ_SET_FULL(item,"temp_label",g_strdup("Temperature(\302\260 F)"),g_free);
		register_widget_f("thermister_fahrenheit_rbutton",item);
		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(item),TRUE);
		g_signal_emit_by_name(item,"toggled",NULL);
		item = glade_xml_get_widget(xml,"kelvin_rbutton");
		OBJ_SET_FULL(item,"temp_label",g_strdup("Temperature(\302\260 K)"),g_free);
		register_widget_f("thermister_kelvin_rbutton",item);
		gtk_window_set_transient_for(GTK_WINDOW(window),GTK_WINDOW(lookup_widget_f("main_window")));
		gtk_widget_show(GTK_WIDGET(window));
		EXIT();
		return TRUE;
	}
#if GTK_MINOR_VERSION >= 18
	if (gtk_widget_get_visible(GTK_WIDGET(window)))
#else
		if (GTK_WIDGET_VISIBLE(GTK_WIDGET(window)))
#endif
			gtk_widget_hide(GTK_WIDGET(window));
		else
		{
			gtk_file_chooser_unselect_all(GTK_FILE_CHOOSER(chooser));
			gtk_widget_show(GTK_WIDGET(window));
		}
	EXIT();
	return TRUE;
}
Ejemplo n.º 9
0
/*!
  \brief Sets up a megatunix comboboxentry widget. Reads the data from the 
  passed ConfigFile *, and sets up the choices as well as the combo model
  and an entry completion/regex alloing textual based entry.
  \param object is the pointer to combo widget object
  \param cfgfile is the pointer to datamap file assocated with this widget
  \param section is the section within the cfgfile
  */
G_MODULE_EXPORT void combo_setup(GObject *object, ConfigFile *cfgfile, gchar * section)
{
	gchar *tmpbuf = NULL;
	gchar ** choices = NULL;
	gchar ** vector = NULL;
	gint num_choices = 0;
	gint num_bitvals = 0;
	gint i = 0;
	gchar *tmpstr = NULL;
	gchar *regex = NULL;
	const gchar *name = NULL;
	GtkListStore *store = NULL;
	GtkTreeIter iter;
	GtkEntryCompletion *completion = NULL;
	GtkWidget *entry = NULL;
	extern gconstpointer *global_data;

	cfg_read_string(cfgfile,section,"choices",&tmpbuf);

	choices = parse_keys(tmpbuf,&num_choices,",");
	tmpbuf = g_strdelimit(tmpbuf,",",'|');
	tmpstr = g_utf8_normalize(tmpbuf,-1,G_NORMALIZE_DEFAULT);
	regex = g_utf8_casefold(tmpbuf,-1);
	g_free(tmpbuf);
	g_free(tmpstr);

	if (!cfg_read_string(cfgfile,section,"bitvals",&tmpbuf))
	{
		MTXDBG(CRITICAL,_("\"bitvals\" key is MISSING, critical fault, not setting up control \n"));
		return;
	}
	vector = parse_keys(tmpbuf,&num_bitvals,",");
	g_free(tmpbuf);
	if (num_bitvals != num_choices)
	{
		name = glade_get_widget_name(GTK_WIDGET(object));
		MTXDBG(CRITICAL,_("\"bitvals\" BIG PROBLEM, combobox %s choices %i and bits %i don't match up\n"),(name == NULL ? "undefined" : name),num_choices,num_bitvals);
		return;
	}


	store = gtk_list_store_new(COMBO_COLS,G_TYPE_STRING,G_TYPE_UCHAR);

	for (i=0;i<num_choices;i++)
	{
		gtk_list_store_append(store,&iter);
		assert(choices[i]);
		assert(vector[i]);
		gtk_list_store_set(store,&iter,CHOICE_COL,choices[i],BITVAL_COL,(guchar)g_ascii_strtoull(vector[i],NULL,10),-1);

	}
	OBJ_SET_FULL(object,"model",store,gtk_list_store_clear);
	g_strfreev(vector);
	g_strfreev(choices);

	gtk_combo_box_set_model(GTK_COMBO_BOX(object),GTK_TREE_MODEL(store));
	if (GTK_IS_COMBO_BOX_ENTRY(object))
	{
		gint width = 0;
		gtk_combo_box_entry_set_text_column(GTK_COMBO_BOX_ENTRY(object),CHOICE_COL);
		entry = mask_entry_new_with_mask(regex);
		/* Nasty hack, but otherwise the entry is an obnoxious size.. */
		if ((width = (GINT)OBJ_GET((GtkWidget *)object,"max_chars")) > 0)
			gtk_entry_set_width_chars(GTK_ENTRY(entry),width);
		else
			gtk_entry_set_width_chars(GTK_ENTRY(entry),12);

		gtk_widget_set_size_request(GTK_WIDGET(object),-1,(3*(GINT)DATA_GET(global_data,"font_size")));

		gtk_container_remove (GTK_CONTAINER (object), gtk_bin_get_child(GTK_BIN (object)));
		gtk_container_add (GTK_CONTAINER (object), entry);

		completion = gtk_entry_completion_new();
		OBJ_SET_FULL(object,"completion",completion,g_object_unref);
		gtk_entry_set_completion(GTK_ENTRY(entry),completion);
		gtk_entry_completion_set_model(completion,GTK_TREE_MODEL(store));
		gtk_entry_completion_set_text_column(completion,CHOICE_COL);
		gtk_entry_completion_set_inline_completion(completion,TRUE);
		gtk_entry_completion_set_inline_selection(completion,TRUE);
		gtk_entry_completion_set_popup_single_match(completion,FALSE);
		OBJ_SET(object,"arrow-size",GINT_TO_POINTER(1));
	}
	g_free(regex);

}
Ejemplo n.º 10
0
/*!
  \brief bind_data() is a recursive function that is called for every container
  widget in a glade frame and it's purpose is to search the datamap file passed
  for the widget names in the glade file and if it's fond in the datamap to
  load all the attribues listed and bind them to the object using GTK+'s
  object model.
  \param widget is the widget passed to load attributes on
  \param user_data is the pointer to a BingGroup structure.
  */
G_MODULE_EXPORT void bind_data(GtkWidget *widget, gpointer user_data)
{
	BindGroup *bindgroup = (BindGroup *)user_data;
	ConfigFile *cfgfile = bindgroup->cfgfile;
	GHashTable *groups = bindgroup->groups;
	gchar * tmpbuf = NULL;
	gchar * section = NULL;
	gchar ** keys = NULL;
	gint num_keys = 0;
	gint offset = 0;
	gint page = 0;
	gint index = 0;
	gchar * initializer = NULL;
	GdkColor color;
	gchar *size = NULL;
	gint count = 0;
	gint tmpi = 0;
	gboolean hidden = FALSE;
	gchar *ptr = NULL;
	gchar **vector = NULL;
	gchar **vec2 = NULL;
	void (*func)(void) = NULL;
	GList *list = NULL;
	GList *list2 = NULL;
	const gchar *name = NULL;
	gboolean indexed = FALSE;
	Firmware_Details *firmware = NULL;
	GList ***ecu_widgets = NULL;
	GList *tab_widgets = NULL;
	void (*load_dep_obj)(GObject *, ConfigFile *,const gchar *,const gchar *) = NULL;

	ENTER();
	MTXDBG(TABLOADER,_("Entered"));
	ecu_widgets = (GList ***)DATA_GET(global_data,"ecu_widgets");
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");

	g_return_if_fail(ecu_widgets);
	g_return_if_fail(firmware);

	if (!GTK_IS_WIDGET(widget))
	{
		EXIT();
		return;
	}

	if (GTK_IS_WIDGET(widget))
		if (GTK_IS_CONTAINER(widget))
			gtk_container_foreach(GTK_CONTAINER(widget),bind_data,user_data);
	name = gtk_widget_get_name(widget);
	if (!name)
	{
		EXIT();
		return;
	}

	if (NULL != (ptr = g_strrstr_len(name,strlen(name),"_of_")))
	{
		indexed = TRUE;
		ptr = g_strrstr_len(name,ptr-name,"_");
		tmpbuf = g_strdelimit(g_strdup(ptr),"_",' ');
		section = g_strndup(name,ptr-name);
		/*printf("(indexed) section is %s\n",section);*/
		gint result = sscanf(tmpbuf,"%d of %d",&index,&count);
		/*printf("sscanf result %i\n",result);*
		* printf("Found indexed value for \"%s\", index %i, count %i\n",tmpbuf,index,count);
		*/
		g_free(tmpbuf);
	}
	else
		section = g_strdup(name);

	if(cfg_read_string(cfgfile, section, "keys", &tmpbuf))
	{
		keys = parse_keys(tmpbuf,&num_keys,",");
		MTXDBG(TABLOADER,_("Number of keys for %s is %i\n"),section,num_keys);
		g_free(tmpbuf);
	}
	else 
	{
		g_free(section);
		EXIT();
		return;
	}

	page = -1;
	/* Store ptr to self in qdata, needed for bind_to_lists from groups*/
	OBJ_SET(widget,"self",widget);
	/* Bind the data in the "defaults" group per tab to EVERY var in that
	 * tab
	 */
	page = bind_group_data(cfgfile, G_OBJECT(widget), groups, "defaults");

	if(cfg_read_string(cfgfile, section, "group", &tmpbuf))
	{
		page = bind_group_data(cfgfile,G_OBJECT(widget),groups,tmpbuf);
		g_free(tmpbuf);
	}

	if ((!cfg_read_int(cfgfile, section, "page", &page)) && (page == -1))
	{
		MTXDBG(TABLOADER|CRITICAL,_("Object %s doesn't have a page assigned!!!!\n"),section);	

	}
	/* Bind widgets to lists if they have the bind_to_list flag set...
	 */
	tmpbuf = NULL;
	if (cfg_read_string(cfgfile, section, "bind_to_list", &tmpbuf))
	{
		bind_to_lists(widget, tmpbuf);
		g_free(tmpbuf);
	}
	if (cfg_read_boolean(cfgfile,section,"ellipsize",&tmpi))
	{
		if ((GTK_IS_LABEL(widget)) && (tmpi))
		{
			OBJ_SET(widget,"ellipsize_preferred",GINT_TO_POINTER(TRUE));
			if (DATA_GET(global_data,"ellipsize_tabs"))
				gtk_label_set_ellipsize(GTK_LABEL(widget),PANGO_ELLIPSIZE_END);
		}
	}

	/* Color selections */
	if (cfg_read_string(cfgfile, section, "active_fg", &tmpbuf))
	{
		gdk_color_parse(tmpbuf, &color);
		gtk_widget_modify_fg(widget, GTK_STATE_NORMAL, &color);
		g_free(tmpbuf);
	}
	if (cfg_read_string(cfgfile, section, "inactive_fg", &tmpbuf))
	{
		gdk_color_parse(tmpbuf, &color);
		gtk_widget_modify_fg(widget, GTK_STATE_INSENSITIVE, &color);
		g_free(tmpbuf);
	}

	/* If this widget has a "depend_on" tag we need to load the dependancy
	 * information  and store it for use when needed...
	 */
	if (cfg_read_string(cfgfile,section,"depend_on",&tmpbuf))
	{
		if (get_symbol("load_dependencies_obj",(void **)&load_dep_obj))
			load_dep_obj(G_OBJECT(widget),cfgfile,section,"depend_on");
		g_free(tmpbuf);
	}

	/* If this widget (a textview) has "create_tags" we call a special
	 * handler just for that..
	 */
	if (cfg_read_string(cfgfile,section,"create_tags",&tmpbuf))
	{
		load_tags(G_OBJECT(widget),cfgfile,section);
		g_free(tmpbuf);
	}

	/* If this widget has "tooltip" set the tip on the widget */
	if (cfg_read_string(cfgfile,section,"tooltip",&tmpbuf))
	{
		gtk_widget_set_tooltip_text(widget,tmpbuf);
		g_free(tmpbuf);
	}

	/* If this widget (a label) has "set_label" we set the label on it
	 */
	if (cfg_read_string(cfgfile,section,"set_label",&tmpbuf))
	{
/*		printf("setting label on %s to \"%s\"\n",glade_get_widget_name(widget),tmpbuf);*/
		gtk_label_set_text(GTK_LABEL(widget),tmpbuf);
		g_free(tmpbuf);
	}

	/* If this widget is temp dependant, set the current units on it 
	 */
	if (cfg_read_string(cfgfile,section,"temp_dep",&tmpbuf))
	{
		OBJ_SET(widget,"widget_temp",DATA_GET(global_data,"mtx_temp_units"));
		g_free(tmpbuf);
	}

	/* If this widget has "register_as", register it with the supplied name
	 */
	if (cfg_read_string(cfgfile,section,"register_as",&tmpbuf))
	{
		register_widget(tmpbuf,widget);
		g_free(tmpbuf);
	}
	/* If this widget has visible_functions defined */
	if (cfg_read_string(cfgfile,section,"visible_functions",&tmpbuf))
	{
		vector = g_strsplit(tmpbuf,",",-1);
		g_free(tmpbuf);
		for (guint i=0;i<g_strv_length(vector);i++)
		{
			vec2 = g_strsplit(vector[i],":",2);
			if (g_strv_length(vec2) != 2)
			{
				printf("ERROR in %s, visible_functions param is missing the framerate parameter (func:fps)\n",cfgfile->filename);
				g_strfreev(vec2);
				continue;
			}
			gint fps = (GINT)g_strtod(vec2[1],NULL);
			get_symbol(vec2[0],(void **)&func);
			if (func)
			{
				list = g_list_prepend(list,(gpointer)func);
				list2 = g_list_prepend(list2,GINT_TO_POINTER(fps));
			}
			g_strfreev(vec2);
		}
		g_strfreev(vector);
		OBJ_SET_FULL(widget,"func_list",list,g_list_free);
		OBJ_SET_FULL(widget,"func_fps_list",list2,g_list_free);
	}

	/* If this widget has "initializer" there's a global variable 
	 * with it's name on it 
	 */
	if (cfg_read_string(cfgfile,section,"initializer",&initializer))
	{
		gint widget_type = 0;
		if (!cfg_read_string(cfgfile,section,"widget_type",&tmpbuf))
			MTXDBG(TABLOADER|CRITICAL,_("Object %s has initializer, but no widget_type!!!!\n"),section);
		else
			widget_type = translate_string(tmpbuf);
		g_free(tmpbuf);
		switch (widget_type)
		{
			case MTX_RANGE:
				gtk_range_set_value(GTK_RANGE(widget),(GINT)DATA_GET(global_data,initializer));
				break;

			case MTX_SPINBUTTON:
				gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget),(GINT)DATA_GET(global_data,initializer));
				break;
			case MTX_ENTRY:
				gtk_entry_set_text(GTK_ENTRY(widget),(gchar *)DATA_GET(global_data,initializer));

			default:
				break;

		}
		g_free(initializer);
	}
	/* Hidden widgets have special handlers and should NOT be updated normally */
	cfg_read_boolean(cfgfile,section, "hidden", &hidden);
	offset = -1;
	cfg_read_int(cfgfile,section, "offset", &offset);
	if (offset >= 0 && indexed)
	{
		/*printf("indexed widget %s\n",name); */
		if (cfg_read_string(cfgfile, section, "size", &size))
		{
			offset += index * get_multiplier ((DataSize)translate_string (size));
			g_free(size);
		}
		else
		{
			if(OBJ_GET(widget, "size"))
			{
				offset += index * get_multiplier ((DataSize)(GINT)OBJ_GET(widget, "size"));
			}
			else
			{
				MTXDBG(TABLOADER|CRITICAL,_("Indexed Object %s has index and offset, but no size!!!!\n"),section);
				g_free(section);
				EXIT();
				return;
			}
		}
		/*printf("widget %s, offset %i\n",name,offset);*/
		OBJ_SET(widget,"offset",GINT_TO_POINTER(offset));
	}
	if (offset >= 0)
	{
		/* The way we do it now is to STORE widgets in LISTS for each
		 * offset, thus we can have multiple on screen controls bound
		 * to single data offset in the ECU
		 */
		if (page < 0)
		{
			MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters,  there is a bug with this datamap widget %s, page %i, at offset %i...\n\n"),section,page,offset);
			g_free(section);
			EXIT();
			return;
		}
		if (page < firmware->total_pages)
		{
			if (offset >= firmware->page_params[page]->length)
				MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters,  there is a bug with this datamap widget %s, at offset %i...\n\n"),section,offset);
			else if (!hidden)
			{

				tab_widgets = OBJ_GET(bindgroup->topframe,"tab_widgets");
				tab_widgets = g_list_prepend(tab_widgets, widget);
				OBJ_SET(bindgroup->topframe,"tab_widgets",tab_widgets);
				ecu_widgets[page][offset] = g_list_prepend(
						ecu_widgets[page][offset],
						(gpointer)widget);
			}
		}
		else
			MTXDBG(TABLOADER|CRITICAL,_("Attempting to append widget beyond bounds of Firmware Parameters, there is a bug with this datamap for widget %s, at page %i offset %i...\n\n"),section,page,offset);
	}

	/* If there is a "group" key in a section it means that it gets the
	 * rest of it's setting from the groupname listed.  This reduces
	 * redundant keys all throughout the file...
	 */
	bind_keys(G_OBJECT(widget), cfgfile, section, keys, num_keys);
	g_strfreev(keys);

	/* If this widget has the "choices" key (combobox)
	 */
	if (cfg_read_string(cfgfile,section,"choices",&tmpbuf))
	{
		combo_setup(G_OBJECT(widget),cfgfile,section);
		g_free(tmpbuf);
	}

	if (cfg_read_string(cfgfile,section,"post_functions_with_arg",&tmpbuf))
	{
		run_post_functions_with_arg(tmpbuf,widget);
		g_free(tmpbuf);
	}
	if (cfg_read_string(cfgfile,section,"post_functions",&tmpbuf))
	{
		run_post_functions(tmpbuf);
		g_free(tmpbuf);
	}
	if (cfg_read_boolean(cfgfile,section,"show_widget",&tmpi))
	{
		if (tmpi)
			gtk_widget_show(widget);
		else
			gtk_widget_hide(widget);
	}
	if (cfg_read_string(cfgfile,section,"set_tab_labels",&tmpbuf))
	{
		if (GTK_IS_NOTEBOOK(widget))
		{
			vector=g_strsplit(tmpbuf,",",-1);
			if (gtk_notebook_get_n_pages(GTK_NOTEBOOK(widget)) == g_strv_length(vector))
			{
				for (int i=0;i<g_strv_length(vector);i++)
				{
					gtk_notebook_set_tab_label_text(GTK_NOTEBOOK(widget),
							gtk_notebook_get_nth_page(GTK_NOTEBOOK(widget),i),
							vector[i]);
				}
			}
			g_strfreev(vector);
		}
		g_free(tmpbuf);
	}
	g_free(section);
	MTXDBG(TABLOADER,_("Leaving"));
	EXIT();
	return;
}
Ejemplo n.º 11
0
/*!
  \brief load_gui_tabs_pf() is called after interrogation completes 
  successfully. It's purpose is to load all the glade files and 
  datamaps as specified in the interrogation profile of the detected firmware. 
  */
G_MODULE_EXPORT gboolean load_gui_tabs_pf(void)
{
	gint i = 0;
	gint cur = 0;
	ConfigFile *cfgfile = NULL;
	gchar * map_file = NULL;
	gchar * glade_file = NULL;
	gchar * tmpbuf = NULL;
	gchar * tab_name = NULL;
	gchar * tab_ident = NULL;
	gboolean tmpi = FALSE;
	GtkWidget *label = NULL;
	GtkWidget *container = NULL;
	GtkWidget *child = NULL;
	GtkWidget *notebook = NULL;
	GtkWidget *item = NULL;
	TabInfo *tabinfo = NULL;
	GPtrArray *tabinfos = NULL;
	extern GdkColor red;
	gboolean * hidden_list = NULL;
	Firmware_Details *firmware = NULL;
	CmdLineArgs *args = NULL;
	gchar * pathstub = NULL;

	ENTER();
	firmware = (Firmware_Details *)DATA_GET(global_data,"firmware");
	args = (CmdLineArgs *)DATA_GET(global_data,"args");

	if (DATA_GET(global_data,"tabs_loaded"))
	{
		EXIT();
		return FALSE;
	}
	if (!firmware)
	{
		EXIT();
		return FALSE;
	}
	if (!firmware->tab_list)
	{
		EXIT();
		return FALSE;
	}
	if (!firmware->tab_confs)
	{
		EXIT();
		return FALSE;
	}
	if (args->inhibit_tabs)
	{
		EXIT();
		return FALSE;
	}

	set_title(g_strdup(_("Loading Gui Tabs...")));
	notebook = lookup_widget("toplevel_notebook");
	hidden_list = (gboolean *)DATA_GET(global_data,"hidden_list");
	tabinfos = g_ptr_array_new();

	while (firmware->tab_list[i])
	{

		pathstub = g_build_filename(GUI_DATA_DIR,firmware->tab_list[i],NULL);
		glade_file = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"glade");
		g_free(pathstub);
		pathstub = g_build_filename(GUI_DATA_DIR,firmware->tab_confs[i],NULL);
		map_file = get_file((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"datamap");
		g_free(pathstub);
		if (!g_file_test(glade_file,G_FILE_TEST_EXISTS))
		{
			MTXDBG(TABLOADER|CRITICAL,_("GLADE FILE: \"%s.glade\" NOT FOUND\n"),firmware->tab_list[i]);
			update_logbar("interr_view","warning",g_strdup(_("Glade File: ")),FALSE,FALSE,TRUE);
			update_logbar("interr_view","info",g_strdup_printf("\"%s.glade\"",firmware->tab_list[i]),FALSE,FALSE,TRUE);
			update_logbar("interr_view","warning",g_strdup(_("  is MISSING!\n")),FALSE,FALSE,TRUE);
			i++;
			continue;
		}
		if (!g_file_test(map_file,G_FILE_TEST_EXISTS))
		{
			MTXDBG(TABLOADER|CRITICAL,_("DATAMAP: \"%s.datamap\" NOT FOUND\n"),firmware->tab_confs[i]);
			update_logbar("interr_view","warning",g_strdup(_("Datamap File: ")),FALSE,FALSE,TRUE);
			update_logbar("interr_view","info",g_strdup_printf("\"%s.datamap\"",firmware->tab_confs[i]),FALSE,FALSE,TRUE);
			update_logbar("interr_view","warning",g_strdup(_("  is MISSING!\n")),FALSE,FALSE,TRUE);
			i++;
			continue;
		}
		cfgfile = cfg_open_file(map_file);
		if (cfgfile)
		{
			tabinfo = g_new0(TabInfo, 1);
			tabinfo->glade_file = g_strdup(glade_file);
			tabinfo->datamap_file = g_strdup(map_file);

			cfg_read_string(cfgfile,"global","tab_name",&tab_name);

			label = gtk_label_new(NULL);
			tabinfo->tab_label = label;
			gtk_label_set_markup_with_mnemonic(GTK_LABEL(label),tab_name);
			if (cfg_read_boolean(cfgfile,"global","ellipsize",&tmpi))
			{
				if (tmpi)
				{
					OBJ_SET(label,"ellipsize_preferred",GINT_TO_POINTER(TRUE));
					if (DATA_GET(global_data,"ellipsize_tabs"))
						gtk_label_set_ellipsize(GTK_LABEL(label),PANGO_ELLIPSIZE_END);
				}
			}
			if (cfg_read_string(cfgfile,"global","bind_to_list",&tmpbuf))
			{
				OBJ_SET_FULL(label,"bind_to_list",g_strdup(tmpbuf),g_free);
				bind_to_lists(label,tmpbuf);
				g_free(tmpbuf);
				if (cfg_read_string(cfgfile,"global","match_type",&tmpbuf))
				{
					tmpi = translate_string(tmpbuf);
					g_free(tmpbuf);
					OBJ_SET(label,"match_type",GINT_TO_POINTER(tmpi));
				}
			}
			gtk_misc_set_alignment(GTK_MISC(label),0,0.5);
			container = gtk_vbox_new(1,0);
			if (cfg_read_string(cfgfile,"topframe","tab_ident",&tab_ident))
			{
				tmpi = translate_string(tab_ident);
				g_free(tab_ident);
				OBJ_SET(container,"tab_ident",GINT_TO_POINTER(tmpi));
			}
			g_free(tab_name);
			OBJ_SET_FULL(label,"glade_file",g_strdup(glade_file),cleanup);
			OBJ_SET_FULL(label,"datamap_file",g_strdup(map_file),cleanup);
			OBJ_SET(label,"not_rendered",GINT_TO_POINTER(TRUE));
			gtk_notebook_append_page(GTK_NOTEBOOK(notebook),container,label);
			gtk_notebook_set_tab_reorderable(GTK_NOTEBOOK(notebook),container,TRUE);
			gtk_widget_show(container);
			cur = gtk_notebook_get_n_pages(GTK_NOTEBOOK(notebook))-1;
			tabinfo->page_num = cur;
			tabinfo->notebook = GTK_NOTEBOOK(notebook);
			if (hidden_list[cur] == TRUE)
			{
				child = gtk_notebook_get_nth_page(GTK_NOTEBOOK(notebook),cur);
				label = gtk_notebook_get_tab_label(GTK_NOTEBOOK(notebook),child);
				gtk_widget_hide(child);
				gtk_widget_hide(label);
				item = lookup_widget("show_tab_visibility_menuitem");
				gtk_widget_modify_text(gtk_bin_get_child(GTK_BIN(item)),GTK_STATE_NORMAL,&red);
			}
			g_ptr_array_add(tabinfos,(gpointer)tabinfo);
		}
		cfg_free(cfgfile);
		g_free(map_file);
		g_free(glade_file);
		i++;

		if (!firmware)
			break;
	}
	preload_deps(tabinfos);
	DATA_SET_FULL(global_data,"tabinfos",tabinfos,dealloc_tabinfos);
	DATA_SET(global_data,"tabs_loaded",GINT_TO_POINTER(TRUE));
	MTXDBG(TABLOADER,_("All is well, leaving...\n\n"));
	set_title(g_strdup(_("Gui Tabs Loaded...")));
	gdk_flush();
	EXIT();
	return TRUE;
}
Ejemplo n.º 12
0
/*!
  \brief load_gui_tabs_pf() is called after interrogation completes 
  successfully. It's purpose is to load all the glade files and datamaps 
  as specified in the interrogation profile of the detected firmware. 
  \param notebook is the pointer to the notebook the new tab should be placed
  \param page is the page number to load
  \returns TRUE on success, FALSE on failure
  */
G_MODULE_EXPORT gboolean load_actual_tab(GtkNotebook *notebook, gint page)
{
	ConfigFile *cfgfile = NULL;
	gchar * map_file = NULL;
	gchar * glade_file = NULL;
	gchar * tmpbuf = NULL;
	GladeXML *xml = NULL;
	GtkWidget *label = NULL;
	GtkWidget *topframe = NULL;
	GtkWidget *placeholder = NULL;
	GHashTable *groups = NULL;
	GList *tab_widgets = NULL;
	BindGroup *bindgroup = NULL;
	extern GdkColor red;

	ENTER();
	placeholder =  gtk_notebook_get_nth_page(notebook,page);
	label = gtk_notebook_get_tab_label(notebook,placeholder);

	glade_file = (gchar *)OBJ_GET(label,"glade_file");
	map_file = (gchar *)OBJ_GET(label,"datamap_file");
	xml = glade_xml_new(glade_file,"topframe",NULL);
	g_return_val_if_fail(xml,FALSE);
	thread_update_logbar("interr_view",NULL,g_strdup(_("Load of tab: ")),FALSE,FALSE);
	thread_update_logbar("interr_view","info", g_strdup_printf("\"%s\"",glade_file),FALSE,FALSE);
	thread_update_logbar("interr_view",NULL,g_strdup(_(" completed.\n")),FALSE,FALSE);
	thread_update_logbar("interr_view",NULL,g_strdup(_("Load of tabconf: ")),FALSE,FALSE);
	thread_update_logbar("interr_view","info", g_strdup_printf("\"%s\"",map_file),FALSE,FALSE);
	cfgfile = cfg_open_file(map_file);
	if (cfgfile)
	{
		topframe = glade_xml_get_widget(xml,"topframe");
		if (topframe == NULL)
		{
			MTXDBG(TABLOADER|CRITICAL,_("\"topframe\" not found in xml, ABORTING!!\n"));
			set_title(g_strdup(_("ERROR Gui Tab XML problem, \"topframe\" element not found!!!")));
			EXIT();
			return FALSE;
		}
		OBJ_SET_FULL(topframe,"glade_xml",(gpointer)xml,g_object_unref);
		// bind_data() is recursive and will take 
		// care of all children

		bindgroup = g_new0(BindGroup,1);
		groups = load_groups(cfgfile);
		bindgroup->cfgfile = cfgfile;
		bindgroup->groups = groups;
		bindgroup->map_file = g_strdup(map_file);
/*		tab_widgets = g_list_prepend(tab_widgets,topframe);
		OBJ_SET(topframe,"tab_widgets",tab_widgets);
		*/
		bindgroup->topframe = topframe;
		bind_data(topframe,(gpointer)bindgroup);
		g_free(bindgroup->map_file);
		if (groups)
			g_hash_table_destroy(groups);
		groups = NULL;
		/* Clear not_rendered flag */
		OBJ_SET(label,"not_rendered",NULL);

		populate_master(topframe,(gpointer)cfgfile);

		gtk_box_pack_start(GTK_BOX(placeholder),topframe,TRUE,TRUE,0);
		OBJ_SET(placeholder,"topframe",topframe);
		glade_xml_signal_autoconnect(xml);
		g_free(bindgroup);
		if (cfg_read_string(cfgfile,"global","post_functions",&tmpbuf))
		{
			run_post_functions(tmpbuf);
			g_free(tmpbuf);
		}
		cfg_free(cfgfile);
		gtk_widget_show(topframe);
		/*printf("Current length of tab_widgets is %i\n",g_list_length(OBJ_GET(topframe,"tab_widgets")));*/
		thread_update_logbar("interr_view",NULL,g_strdup(_(" completed.\n")),FALSE,FALSE);
	}
	update_groups_pf();
	update_sources_pf();
	/* Allow gui to update as it should.... */
	gdk_flush();
	EXIT();
	return TRUE;
}
Ejemplo n.º 13
0
/*!
  \brief descends into a GladeWidgetInfo tree looking for special case 
  widgets to handle
  \param info is the pointer to a GladeWidgetInfo structure
  \param cfgfile is the pointer to the corresponding datamap file
  \returns TRUE, unless eat end of the tree
  */
gboolean descend_tree(GladeWidgetInfo *info,ConfigFile *cfgfile)
{
	static GHashTable *widget_2_tab_hash = NULL;
	static ConfigFile *last_cfgfile = NULL;
	static gchar * prefix = NULL;
	gchar *groups = NULL;
	gchar *bitvals = NULL;
	gchar *source_key = NULL;
	gchar *source_values = NULL;
	gint bitval = 0;
	gint bitmask = 0;
	gint offset = 0;
	gint page = 0;
	/*gint canID = 0;*/
	DataSize size = MTX_U08;
	GObject *object = NULL;
	GList *list = NULL;
	guint i = 0;

	ENTER();
	if (!widget_2_tab_hash)
	{
		widget_2_tab_hash = (GHashTable *)DATA_GET(global_data,"widget_2_tab_hash");
		g_return_val_if_fail(widget_2_tab_hash,FALSE);
	}
	/*
	   if (!info->parent)
	   printf("%s is a TOPLEVEL\n",info->name);
	   else if (info->n_children == 0)
	   {
	   printf("%s is a BOTTOM WIDGET\n",info->name);
	   EXIT();
	   return FALSE;
	   }
	   else
	   printf("%s\n",info->name);

	   printf("widget %s has %i children\n",info->name,info->n_children);
	 */
	for (i=0;i<info->n_children;i++)
		descend_tree(info->children[i].child,cfgfile);

	if (last_cfgfile != cfgfile)
	{
		if (prefix)
			cleanup(prefix);
		if(!cfg_read_string(cfgfile,"global","id_prefix", &prefix))
			prefix = NULL;
		last_cfgfile = cfgfile;
	}
	if (cfg_find_section(cfgfile,info->name)) // This widget exists 
	{
		if (prefix)
			g_hash_table_insert(widget_2_tab_hash,g_strdup_printf("%s%s",prefix,info->name),g_strdup(cfgfile->filename));
		else
			g_hash_table_insert(widget_2_tab_hash,g_strdup(info->name),g_strdup(cfgfile->filename));
	}

	if (cfg_read_string(cfgfile,info->name,"source_values",&source_values))
	{
		if (!cfg_read_string(cfgfile,info->name,"source_key",&source_key))
		{
			MTXDBG(TABLOADER|CRITICAL,_("%s needs source_key\n"),info->name);
			EXIT();
			return TRUE;
		}
		if (!cfg_read_int(cfgfile,info->name,"offset",&offset))
		{
			MTXDBG(TABLOADER|CRITICAL,_("%s needs offset\n"),info->name);
			EXIT();
			return TRUE;
		}
		if (!cfg_read_int(cfgfile,info->name,"bitmask",&bitmask))
		{
			MTXDBG(TABLOADER|CRITICAL,_("%s needs bitmask\n"),info->name);
			EXIT();
			return TRUE;
		}
		if (!cfg_read_string(cfgfile,info->name,"bitvals",&bitvals))
		{
			if (!cfg_read_int(cfgfile,info->name,"bitval",&bitval))
			{
				MTXDBG(TABLOADER|CRITICAL,_("%s needs bitvals or bitval\n"),info->name);
				EXIT();
				return TRUE;
			}
		}
		if (!cfg_read_int(cfgfile,info->name,"page",&page))
		{
			if (!cfg_read_int(cfgfile,"defaults","page",&page))
			{
				MTXDBG(TABLOADER|CRITICAL,_("%s has no page defined!\n"),info->name);
				EXIT();
				return TRUE;
			}
		}
		object = (GObject *)g_object_new(GTK_TYPE_INVISIBLE,NULL);
		g_object_ref_sink(object);
		/*OBJ_SET(object,"canID",GINT_TO_POINTER(canID));*/
		OBJ_SET(object,"page",GINT_TO_POINTER(page));
		OBJ_SET(object,"offset",GINT_TO_POINTER(offset));
		OBJ_SET(object,"size",GINT_TO_POINTER(size));
		OBJ_SET(object,"bitmask",GINT_TO_POINTER(bitmask));
		if (bitvals)
			OBJ_SET_FULL(object,"bitvals",g_strdup(bitvals),g_free);
		else
			OBJ_SET(object,"bitval",GINT_TO_POINTER(bitval));
		OBJ_SET_FULL(object,"source_key",g_strdup(source_key),g_free);
		OBJ_SET_FULL(object,"source_values",g_strdup(source_values),g_free);
		list = (GList *)DATA_GET(global_data,"source_list");
		list = g_list_prepend(list,object);
		DATA_SET(global_data,"source_list",(gpointer)list);
		cleanup(groups);
		cleanup(bitvals);
		cleanup(source_key);
		cleanup(source_values);

	}
	if (cfg_read_string(cfgfile,info->name,"toggle_groups",&groups))
	{
		if (!cfg_read_int(cfgfile,info->name,"offset",&offset))
		{
			MTXDBG(TABLOADER|CRITICAL,_("%s needs offset\n"),info->name);
			EXIT();
			return TRUE;
		}
		if (!cfg_read_int(cfgfile,info->name,"bitmask",&bitmask))
		{
			MTXDBG(TABLOADER|CRITICAL,_("%s needs bitmask\n"),info->name);
			EXIT();
			return TRUE;
		}
		if (!cfg_read_string(cfgfile,info->name,"bitvals",&bitvals))
		{
			if (!cfg_read_int(cfgfile,info->name,"bitval",&bitval))
			{
				MTXDBG(TABLOADER|CRITICAL,_("%s needs bitvals or bitval\n"),info->name);
				EXIT();
				return TRUE;
			}
		}
		if (!cfg_read_int(cfgfile,info->name,"page",&page))
		{
			if (!cfg_read_int(cfgfile,"defaults","page",&page))
			{
				MTXDBG(TABLOADER|CRITICAL,_("%s has no page defined!\n"),info->name);
				EXIT();
				return TRUE;
			}
		}
		/*
		   if (!cfg_read_int(cfgfile,info->name,"canID",&canID))
		   {
		   if (!cfg_read_int(cfgfile,"defaults","canID",&canID))
		   {
		   printf("%s has no canID defined!\n",info->name);
		   EXIT();
		   return TRUE;
		   }
		   }
		 */
		object = (GObject *)g_object_new(GTK_TYPE_INVISIBLE,NULL);
		g_object_ref_sink(object);
		/*OBJ_SET(object,"canID",GINT_TO_POINTER(canID));*/
		OBJ_SET(object,"page",GINT_TO_POINTER(page));
		OBJ_SET(object,"offset",GINT_TO_POINTER(offset));
		OBJ_SET(object,"size",GINT_TO_POINTER(size));
		OBJ_SET(object,"bitmask",GINT_TO_POINTER(bitmask));
		if (bitvals)
			OBJ_SET_FULL(object,"bitvals",g_strdup(bitvals),g_free);
		else
			OBJ_SET(object,"bitval",GINT_TO_POINTER(bitval));
		OBJ_SET_FULL(object,"toggle_groups",g_strdup(groups),g_free);
		list = (GList *)DATA_GET(global_data,"toggle_group_list");
		list = g_list_prepend(list,object);
		DATA_SET(global_data,"toggle_group_list",(gpointer)list);
		cleanup(groups);
		cleanup(bitvals);
		cleanup(source_key);
		cleanup(source_values);
	}
	EXIT();
	return TRUE;
}
Ejemplo n.º 14
0
/*!
  \brief Binds remaing keys in cfgfile to the object
  \param object is the pointer to object where we bind the data to
  \param cfgfile is the pointer to configfile  where we pull the data from
  \param section is the section name within cfgfile to gt the data from
  \param keys is the array of char *'s, list of keys to read and store
  \param num_keys is the number of elements in the keys array
  */
G_MODULE_EXPORT void bind_keys(GObject *object, ConfigFile *cfgfile, gchar *section, gchar ** keys, gint num_keys)
{
	gint i = 0;
	gint tmpi = 0;
	gfloat tmpf = 0.0;
	gfloat *newfloat = NULL;
	gchar * tmpbuf = NULL;
	gchar * tmpstr = NULL;
	DataType keytype = MTX_STRING;

	for (i=0;i<num_keys;i++)
	{
		keytype = translate_string(keys[i]);
		switch(keytype)
		{
			case MTX_INT:
				if (cfg_read_int(cfgfile,section,keys[i],&tmpi))
				{
					MTXDBG(KEYPARSER,_("Binding INT \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section);
					OBJ_SET(object,
							keys[i],
							GINT_TO_POINTER(tmpi));	
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_INT: read of key \"%s\" from section \"%s\"  of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;
			case MTX_ENUM:
				if (cfg_read_string(cfgfile,section,keys[i],&tmpbuf))
				{
					tmpi = translate_string(tmpbuf);
					MTXDBG(KEYPARSER,_("Binding ENUM \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section);
					OBJ_SET(object,
							keys[i],
							GINT_TO_POINTER(tmpi));	
					g_free(tmpbuf);
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_ENUM: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;
			case MTX_BOOL:
				if (cfg_read_boolean(cfgfile,section,keys[i],&tmpi))
				{
					MTXDBG(KEYPARSER,_("Binding BOOL \"%s\",\"%i\" to widget \"%s\"\n"),keys[i],tmpi,section);
					if (tmpi)
					{
						OBJ_SET(object,
								keys[i],
								GINT_TO_POINTER(tmpi));	
						if (strstr(keys[i],"fromecu_complex"))
							load_complex_params_obj(object,cfgfile,section);
					}
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_BOOL: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;
			case MTX_FLOAT:
				if (cfg_read_float(cfgfile,section,keys[i],&tmpf))
				{
					newfloat = NULL;
					newfloat = g_new0(gfloat, 1);
					*newfloat = tmpf;
					OBJ_SET_FULL(object,
							keys[i],
							(gpointer)newfloat,g_free);
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_FLOAT: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;

			case MTX_STRING:
				if(cfg_read_string(cfgfile,section,keys[i],&tmpbuf))
				{
					MTXDBG(KEYPARSER,_("Binding STRING key:\"%s\" value:\"%s\" to widget \"%s\"\n"),keys[i],tmpbuf,section);
					tmpstr = DATA_GET(object,keys[i]);
					/* If data already on widget, append
					 * new data and store */
					if ((tmpstr) && (g_strrstr(keys[i],"bind_to_list")!= NULL))
					{
						tmpstr = g_strconcat(tmpstr,",",tmpbuf,NULL);
						OBJ_SET_FULL(object,
								keys[i],
								g_strdup(tmpstr),
								g_free);
						g_free(tmpstr);
					}
					else
						OBJ_SET_FULL(object,keys[i],g_strdup(tmpbuf),g_free);
								
					g_free(tmpbuf);
				}
				else
					MTXDBG(KEYPARSER|CRITICAL,_("MTX_STRING: read of key \"%s\" from section \"%s\" of file \"%s\" failed\n"),keys[i],section,cfgfile->filename);
				break;
			default:
				break;

		}
	}

	return;
}
Ejemplo n.º 15
0
/*!
 \brief convert_after_upload() converts the ms-units data to the real world
 units for display on the GUI
 \param widget (GtkWidget *) to extract the conversion info from to perform
 the necessary math
 \returns the real world value for the GUI
 */
G_MODULE_EXPORT gfloat convert_after_upload(GtkWidget * widget)
{
	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
	static gint (*get_ecu_data_f)(gpointer);
	static void (*send_to_ecu_f)(gpointer, gint, gboolean) = NULL;
	gfloat return_value = 0.0;
	gchar * conv_expr = NULL;
	void *evaluator = NULL;
	gint tmpi = 0;
	DataSize size = 0;
	gfloat lower = 0.0;
	gfloat upper = 0.0;
	gboolean fromecu_complex = FALSE;
	guint i = 0;
	gint table_num = -1;
	GHashTable *mhash = NULL;
	GHashTable *ahash = NULL;
	gchar *key_list = NULL;
	gchar *mult_list = NULL;
	gchar *add_list = NULL;
	gchar **keys = NULL;
	gchar **mults = NULL;
	gchar **adds = NULL;
	gchar * tmpbuf = NULL;
	gchar * source_key = NULL;
	gchar * hash_key = NULL;
	gfloat *multiplier = NULL;
	gfloat *adder = NULL;
	gint *algorithm = NULL;
	GHashTable *sources_hash = NULL;
	extern gconstpointer *global_data;


	if (!get_ecu_data_f)
		get_symbol("get_ecu_data",(void *)&get_ecu_data_f);
	if (!send_to_ecu_f)
		get_symbol("send_to_ecu",(void *)&send_to_ecu_f);
	g_return_val_if_fail(get_ecu_data_f,0.0);
	g_return_val_if_fail(send_to_ecu_f,0.0);

	g_static_mutex_lock(&mutex);

	size = (DataSize)OBJ_GET(widget,"size");
	if (size == 0)
	{
		printf(_("BIG PROBLEM, size undefined! widget %s, default to U08 \n"),(gchar *)glade_get_widget_name(widget));
		size = MTX_U08;
	}

	if (OBJ_GET(widget,"raw_lower"))
		lower = (gfloat)strtol(OBJ_GET(widget,"raw_lower"),NULL,10);
	else
		lower = (gfloat)get_extreme_from_size(size,LOWER);
	if (OBJ_GET(widget,"raw_upper"))
		upper = (gfloat)strtol(OBJ_GET(widget,"raw_upper"),NULL,10);
	else
		upper = (gfloat)get_extreme_from_size(size,UPPER);

	fromecu_complex = (GBOOLEAN)OBJ_GET(widget,"fromecu_complex");
	if (fromecu_complex)
	{
		g_static_mutex_unlock(&mutex);
		/*printf("Complex upload conversion for widget at page %i, offset %i, name %s\n",(GINT)OBJ_GET(widget,"page"),(GINT)OBJ_GET(widget,"offset"),glade_get_widget_name(widget));
		  */
		return handle_complex_expr_obj(G_OBJECT(widget),NULL,UPLOAD);
	}

	if (OBJ_GET(widget,"lookuptable"))
		tmpi = lookup_data_obj(G_OBJECT(widget),get_ecu_data_f(widget));
	else
		tmpi = get_ecu_data_f(widget);
	if (tmpi < lower)
	{
		dbg_func(CONVERSIONS|CRITICAL,g_strdup_printf(__FILE__": convert_after_upload()\n\t WARNING RAW value  out of range for widget %s, clamped at %.1f (%.1f <- %i -> %.1f), updating ECU with valid value within limits!!\n",(gchar *)glade_get_widget_name(widget),lower,lower,tmpi,upper));
		tmpi = lower;
		send_to_ecu_f(widget,tmpi,TRUE);
	}
	if (tmpi > upper)
	{
		dbg_func(CONVERSIONS|CRITICAL,g_strdup_printf(__FILE__": convert_after_upload()\n\t WARNING RAW value out of range for widget %s, clamped at %.1f (%.1f <- %i -> %.1f), updating ECU with valid value within limits!!\n",(gchar *)glade_get_widget_name(widget),lower,lower,tmpi,upper));
		tmpi = upper;
		send_to_ecu_f(widget,tmpi,TRUE);
	}
	/* MULTI EXPRESSION ONLY! */
	if (OBJ_GET(widget,"multi_expr_keys"))
	{
		sources_hash = DATA_GET(global_data,"sources_hash");
		if ((!OBJ_GET(widget,"mhash")) && (!OBJ_GET(widget,"ahash")))
		{
			mhash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
			ahash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
			key_list = OBJ_GET(widget,"multi_expr_keys");
			mult_list = OBJ_GET(widget,"fromecu_mults");
			add_list = OBJ_GET(widget,"fromecu_adds");
			if (!mult_list)
				printf("BUG, widget %s is multi_expression but doesn't have fromecu_mults defined!\n",glade_get_widget_name(widget));
			if (!add_list)
				printf("BUG, widget %s is multi_expression but doesn't have fromecu_adds defined!\n",glade_get_widget_name(widget));
			keys = g_strsplit(key_list,",",-1);
			mults = g_strsplit(mult_list,",",-1);
			adds = g_strsplit(add_list,",",-1);
			for (i=0;i<MIN(g_strv_length(keys),g_strv_length(mults));i++)
			{
				multiplier = g_new0(gfloat, 1);
				*multiplier = (gfloat)g_strtod(mults[i],NULL);
				g_hash_table_insert(mhash,g_strdup(keys[i]),multiplier);
				adder = g_new0(gfloat, 1);
				*adder = (gfloat)g_strtod(adds[i],NULL);
				g_hash_table_insert(ahash,g_strdup(keys[i]),adder);
			}
			g_strfreev(keys);
			g_strfreev(mults);
			g_strfreev(adds);

			OBJ_SET_FULL(widget,"mhash",mhash,g_hash_table_destroy);
			OBJ_SET_FULL(widget,"ahash",ahash,g_hash_table_destroy);
		}
		mhash = OBJ_GET(widget,"mhash");
		ahash = OBJ_GET(widget,"ahash");
		source_key = OBJ_GET(widget,"source_key");
		if (!source_key)
			printf(_("big problem, source key is undefined!!\n"));
		hash_key = (gchar *)g_hash_table_lookup(sources_hash,source_key);
		tmpbuf = (gchar *)OBJ_GET(widget,"table_num");
		if (tmpbuf)
			table_num = (GINT)strtol(tmpbuf,NULL,10);
		if (table_num == -1)
		{
			if (!hash_key)
			{
				multiplier = g_hash_table_lookup(mhash,"DEFAULT");
				adder = g_hash_table_lookup(ahash,"DEFAULT");
			}
			else
			{
				multiplier = g_hash_table_lookup(mhash,(gchar *)hash_key);
				adder = g_hash_table_lookup(ahash,(gchar *)hash_key);
			}
		}
		else
		{
			algorithm = DATA_GET(global_data,"algorithm");
			switch (algorithm[table_num])
			{
				case SPEED_DENSITY:
					if (!hash_key)
					{
						multiplier = g_hash_table_lookup(mhash,"DEFAULT");
						adder = g_hash_table_lookup(ahash,"DEFAULT");
					}
					else
					{
						multiplier = g_hash_table_lookup(mhash,hash_key);
						adder = g_hash_table_lookup(ahash,hash_key);
					}
					break;
				case ALPHA_N:
					multiplier = g_hash_table_lookup(mhash,"DEFAULT");
					adder = g_hash_table_lookup(ahash,"DEFAULT");
					break;
				case MAF:
					multiplier = g_hash_table_lookup(mhash,"AFM_VOLTS");
					adder = g_hash_table_lookup(ahash,"AFM_VOLTS");
					break;
			}
		}
		if ((multiplier) && (adder))
			return_value = (((gfloat)tmpi * (*multiplier)) + (*adder));
		else if (multiplier)
			return_value = (gfloat)tmpi * (*multiplier);
		else
			return_value = (gfloat)tmpi;
	}
	else
	{
		conv_expr = (gchar *)OBJ_GET(widget,"fromecu_conv_expr");
		if (conv_expr)
		{
			evaluator = (void *)OBJ_GET(widget,"ul_evaluator");
			if (!evaluator)
			{
				evaluator = evaluator_create(conv_expr);
				assert(evaluator);
				OBJ_SET_FULL(widget,"ul_evaluator",(gpointer)evaluator,evaluator_destroy);
			}
			return_value = evaluator_evaluate_x(evaluator,tmpi);
		}
		else
		{
			multiplier = OBJ_GET(widget,"fromecu_mult");
			adder = OBJ_GET(widget,"fromecu_add");
			if ((multiplier) && (adder))
				return_value = (((gfloat)tmpi * (*multiplier)) + (*adder));
			else if (multiplier)
				return_value = (gfloat)tmpi * (*multiplier);
			else
				return_value = (gfloat)tmpi;
			/*dbg_func(CONVERSIONS,g_strdup_printf(__FILE__": convert_after_ul():\n\tNo/Fast CONVERSION defined for  widget %s, value %f\n",(gchar *)glade_get_widget_name(widget), return_value));*/
		}

	}
//	dbg_func(CONVERSIONS,g_strdup_printf(__FILE__": convert_after_ul()\n\t page %i,offset %i, raw %i, val %f\n",page,offset,tmpi,return_value));
	g_static_mutex_unlock(&mutex);
	return (return_value);
}
Ejemplo n.º 16
0
G_MODULE_EXPORT void load_status(xmlNode *node,GtkWidget *parent)
{
	gchar *txt = NULL;
	gchar *active_fg = NULL;
	gchar *inactive_fg = NULL;
	gchar *bind_to_list = NULL;
	gchar *source = NULL;
	gint bitval = -1;
	gint bitmask = -1;
	GtkWidget *label = NULL;
	GtkWidget *frame = NULL;
	GdkColor color;
	xmlNode *cur_node = NULL;

	if (!node->children)
	{
		printf(_("ERROR, load_potential_args, xml node is empty!!\n"));
		return;
	}
	cur_node = node->children;
	while (cur_node->next)
	{
		if (cur_node->type == XML_ELEMENT_NODE)
		{
			if (g_strcasecmp((gchar *)cur_node->name,"label") == 0)
				generic_xml_gchar_import(cur_node,&txt);
			if (g_strcasecmp((gchar *)cur_node->name,"active_fg") == 0)
				generic_xml_gchar_import(cur_node,&active_fg);
			if (g_strcasecmp((gchar *)cur_node->name,"inactive_fg") == 0)
				generic_xml_gchar_import(cur_node,&inactive_fg);
			if (g_strcasecmp((gchar *)cur_node->name,"source") == 0)
				generic_xml_gchar_import(cur_node,&source);
			if (g_strcasecmp((gchar *)cur_node->name,"bind_to_list") == 0)
				generic_xml_gchar_import(cur_node,&bind_to_list);
			if (g_strcasecmp((gchar *)cur_node->name,"bitval") == 0)
				generic_xml_gint_import(cur_node,&bitval);
			if (g_strcasecmp((gchar *)cur_node->name,"bitmask") == 0)
				generic_xml_gint_import(cur_node,&bitmask);
		}
		cur_node = cur_node->next;
	}
	/* Minimum requirements */
	if ((txt) && (active_fg) && (inactive_fg) && (bind_to_list))
	{
		frame = gtk_frame_new(NULL);
		gtk_frame_set_shadow_type(GTK_FRAME(frame),GTK_SHADOW_ETCHED_IN);
		label = gtk_label_new(NULL);
		gtk_label_set_markup(GTK_LABEL(label),_(txt));
		gtk_container_add(GTK_CONTAINER(frame),label);
		gtk_widget_set_sensitive(GTK_WIDGET(label),FALSE);
		gdk_color_parse(active_fg,&color);
		gtk_widget_modify_fg(label,GTK_STATE_NORMAL,&color);
		gdk_color_parse(inactive_fg,&color);
		gtk_widget_modify_fg(label,GTK_STATE_INSENSITIVE,&color);
		g_free(txt);
		g_free(active_fg);
		g_free(inactive_fg);
		/* For controls based on ECU data */
		if ((bitval >= 0) && (bitmask >= 0) && (source))
		{
			OBJ_SET(label,"bitval",GINT_TO_POINTER(bitval));
			OBJ_SET(label,"bitmask",GINT_TO_POINTER(bitmask));
			OBJ_SET_FULL(label,"source",g_strdup(source),g_free);
			g_free(source);
		}
		if (bind_to_list)
		{
			bind_to_lists(label, bind_to_list);
			g_free(bind_to_list);
		}
		gtk_box_pack_start(GTK_BOX(parent),frame,TRUE,TRUE,0);
	}
}
Ejemplo n.º 17
0
/*!
 \brief convert_before_download() converts the value passed using the
 conversions bound to the widget
 \param widget (GtkWidget *) widget to extract the conversion info from
 \param value (gfloat *) the "real world" value from the tuning gui before
 translation to MS-units
 \returns the integere ms-units form after conversion
 */
G_MODULE_EXPORT gint convert_before_download(GtkWidget *widget, gfloat value)
{
	static GStaticMutex mutex = G_STATIC_MUTEX_INIT;
	gint return_value = 0;
	gint tmpi = 0;
	gchar * conv_expr = NULL;
	void *evaluator = NULL;
	DataSize size = MTX_U08;
	float lower = 0.0;
	float upper = 0.0;
	gfloat *multiplier = NULL;
	gfloat *adder = NULL;
	guint i = 0;
	GHashTable *mhash = NULL;
	GHashTable *ahash = NULL;
	gchar *key_list = NULL;
	gchar *mult_list = NULL;
	gchar *add_list = NULL;
	gchar **keys = NULL;
	gchar **mults = NULL;
	gchar **adds = NULL;
	gint table_num = 0;
	gchar *tmpbuf = NULL;
	gchar * source_key = NULL;
	gchar * hash_key = NULL;
	gint *algorithm = NULL;
	GHashTable *sources_hash = NULL;

	sources_hash = DATA_GET(global_data,"sources_hash");
	algorithm = DATA_GET(global_data,"algorithm");

	g_static_mutex_lock(&mutex);


	if (!OBJ_GET(widget,"size"))
		printf(__FILE__"%s %s\n",_(": convert_before_download, FATAL ERROR, size undefined for widget %s "),glade_get_widget_name(widget));

	size = (DataSize)OBJ_GET(widget,"size");
	if (OBJ_GET(widget,"raw_lower"))
		lower = (gfloat)strtol(OBJ_GET(widget,"raw_lower"),NULL,10);
	else
		lower = (gfloat)get_extreme_from_size(size,LOWER);
	if (OBJ_GET(widget,"raw_upper"))
		upper = (gfloat)strtol(OBJ_GET(widget,"raw_upper"),NULL,10);
	else
		upper = (gfloat)get_extreme_from_size(size,UPPER);

	/* MULTI EXPRESSION ONLY! */
	if (OBJ_GET(widget,"multi_expr_keys"))
	{
		if ((!OBJ_GET(widget,"mhash")) && (!OBJ_GET(widget,"ahash")))
		{
			mhash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
			ahash = g_hash_table_new_full(g_str_hash,g_str_equal,g_free,g_free);
			key_list = OBJ_GET(widget,"multi_expr_keys");
			mult_list = OBJ_GET(widget,"fromecu_mults");
			add_list = OBJ_GET(widget,"fromecu_addds");
			keys = g_strsplit(key_list,",",-1);
			mults = g_strsplit(mult_list,",",-1);
			adds = g_strsplit(add_list,",",-1);
			for (i=0;i<MIN(g_strv_length(keys),g_strv_length(mults));i++)
			{
				multiplier = g_new0(gfloat, 1);
				*multiplier = (gfloat)g_strtod(mults[i],NULL);
				g_hash_table_insert(mhash,g_strdup(keys[i]),multiplier);
				adder = g_new0(gfloat, 1);
				*adder = (gfloat)g_strtod(adds[i],NULL);
				g_hash_table_insert(ahash,g_strdup(keys[i]),adder);
			}
			g_strfreev(keys);
			g_strfreev(mults);
			g_strfreev(adds);

			OBJ_SET_FULL(widget,"mhash",mhash,g_hash_table_destroy);
			OBJ_SET_FULL(widget,"ahash",ahash,g_hash_table_destroy);
		}
		mhash = OBJ_GET(widget,"mhash");
		ahash = OBJ_GET(widget,"ahash");
		source_key = OBJ_GET(widget,"source_key");
		if (!source_key)
			printf(_("big problem, source key is undefined!!\n"));
		hash_key = (gchar *)g_hash_table_lookup(sources_hash,source_key);
		tmpbuf = (gchar *)OBJ_GET(widget,"table_num");
		if (tmpbuf)
			table_num = (GINT)strtol(tmpbuf,NULL,10);
		if (table_num == -1) /* Not a table */
		{
			if (!hash_key)
			{
				multiplier = g_hash_table_lookup(mhash,"DEFAULT");
				adder = g_hash_table_lookup(ahash,"DEFAULT");
			}
			else
			{
				multiplier = g_hash_table_lookup(mhash,(gchar *)hash_key);
				adder = g_hash_table_lookup(ahash,(gchar *)hash_key);
			}
		}
		else /* This is a 3d table */
		{
			switch (algorithm[table_num])
			{
				case SPEED_DENSITY:
					if (!hash_key)
					{
						multiplier = g_hash_table_lookup(mhash,"DEFAULT");
						adder = g_hash_table_lookup(ahash,"DEFAULT");
					}
					else
					{
						multiplier = g_hash_table_lookup(mhash,hash_key);
						adder = g_hash_table_lookup(ahash,hash_key);
					}
					break;
				case ALPHA_N:
					multiplier = g_hash_table_lookup(mhash,"DEFAULT");
					adder = g_hash_table_lookup(ahash,"DEFAULT");
					break;
				case MAF:
					multiplier = g_hash_table_lookup(mhash,"AFM_VOLTS");
					adder = g_hash_table_lookup(ahash,"AFM_VOLTS");
					break;
			}
		}
		/* Reverse calc due to this being TO the ecu */
		if ((multiplier) && (adder))
			return_value = (GINT)((value - (*adder))/(*multiplier));
		else if (multiplier)
			return_value = (GINT)(value/(*multiplier));
		else
			return_value = (GINT)value;
	}
	else /* NON Multi Expression */
	{
		conv_expr = (gchar *)OBJ_GET(widget,"toecu_conv_expr");

		/* Expression is NOT multi expression but has more complex math*/
		if (conv_expr)
		{
			evaluator = (void *)OBJ_GET(widget,"dl_evaluator");
			if (!evaluator)
			{
				evaluator = evaluator_create(conv_expr);
				assert(evaluator);
				OBJ_SET_FULL(widget,"dl_evaluator",(gpointer)evaluator,evaluator_destroy);
			}
			return_value = (GINT)evaluator_evaluate_x(evaluator,value); 
		}
		else
		{
			multiplier = (gfloat *)OBJ_GET(widget,"fromecu_mult");
			adder = (gfloat *)OBJ_GET(widget,"fromecu_add");
			/* Handle all cases of with or without multiplier/adder*/
			if ((multiplier) && (adder))
				return_value = (GINT)((value - (*adder))/(*multiplier));
			else if (multiplier)
				return_value = (GINT)(value/(*multiplier));
			else
				return_value = (GINT)value;
		}
	}
	dbg_func(CONVERSIONS,g_strdup_printf(__FILE__": convert_before_dl():\n\t widget %s raw %.2f, sent %i\n",glade_get_widget_name(widget),value,return_value));
	if (return_value > upper) 
	{
		dbg_func(CONVERSIONS|CRITICAL,g_strdup_printf(__FILE__": convert_before_download()\n\t WARNING value clamped at %f (%f <- %f -> %f)!!\n",upper,lower,value,upper));
		return_value = upper;
	}
	if (return_value < lower)
	{
		dbg_func(CONVERSIONS|CRITICAL,g_strdup_printf(__FILE__": convert_before_download()\n\t WARNING value clamped at %f (%f <- %f -> %f)!!\n",lower,lower,value,upper));
		return_value = lower;
	}

	tmpi = return_value;
	if (OBJ_GET(widget,"lookuptable"))
		return_value = (GINT)reverse_lookup_obj(G_OBJECT(widget),tmpi);

	g_static_mutex_unlock(&mutex);
	return (return_value);
}
Ejemplo n.º 18
0
/*!
  \brief present_firmware_choices() presents a dialog box with the firmware
  choices.
  \returns the name of the chosen firmware
  */
G_MODULE_EXPORT gchar * present_firmware_choices(void)
{
	gchar ** filenames = NULL;
	GtkWidget *dialog = NULL;
	GtkWidget *vbox = NULL;
	GtkWidget *hbox = NULL;
	GtkWidget *ebox = NULL;
	GtkWidget *sep = NULL;
	GtkWidget *dummybutton = NULL;
	GtkWidget *button = NULL;
	GtkWidget *label = NULL;
	ListElement *element = NULL;
	gchar *tmpbuf = NULL;
	GArray *classes = NULL;
	GSList *group = NULL;
	GList *p_list = NULL;
	GList *s_list = NULL;
	ConfigFile *cfgfile = NULL;
	const gchar * last_file = NULL;
	gint major = 0;
	gint minor = 0;
	guint i = 0;
	gint result = 0;
	extern gconstpointer *global_data;
	gchar * pathstub = NULL;

	ENTER();
	pathstub = g_build_filename(INTERROGATOR_DATA_DIR,"Profiles",DATA_GET(global_data,"ecu_family"),NULL);
	filenames = get_files((const gchar *)DATA_GET(global_data,"project_name"),pathstub,"prof",&classes);
	g_free(pathstub);
	if (!filenames)
	{
		MTXDBG(CRITICAL,_("NO Interrogation profiles found, was MegaTunix installed properly?\n"));
		EXIT();
		return NULL;
	}
	i = 0;
	while (filenames[i]) 
	{
		cfgfile = cfg_open_file(filenames[i]);
		if (!cfgfile)
		{
			MTXDBG(CRITICAL,_("Interrogation profile damaged!, was MegaTunix installed properly?\n"));
			i++;
			continue;
		}
		get_file_api(cfgfile,&major,&minor);
		if ((major != INTERROGATE_MAJOR_API) || (minor != INTERROGATE_MINOR_API))
		{
			thread_update_logbar("interr_view","warning",g_strdup_printf(_("Interrogation profile API mismatch (%i.%i != %i.%i):\n\tFile %s will be skipped\n"),major,minor,INTERROGATE_MAJOR_API,INTERROGATE_MINOR_API,cfgfile->filename),FALSE,FALSE);
			i++;
			cfg_free(cfgfile);
			continue;
		}
		cfg_read_string(cfgfile,"interrogation_profile","name",&tmpbuf);
		cfg_free(cfgfile);
		last_file = (gchar *)DATA_GET(global_data,"last_offline_profile");

		if (g_array_index(classes,FileClass,i) == PERSONAL)
		{
			element = g_new0(ListElement, 1);
			element->filename = g_strdup(filenames[i]);
			if (g_ascii_strcasecmp(element->filename,last_file) == 0)
				element->def = TRUE;

			element->name = g_strdup(tmpbuf);
			p_list = g_list_append(p_list,(gpointer)element);
		}
		if (g_array_index(classes,FileClass,i) == SYSTEM)
		{
			element = g_new0(ListElement, 1);
			element->filename = g_strdup(filenames[i]);
			if (g_ascii_strcasecmp(element->filename,last_file) == 0)
				element->def = TRUE;
			element->name = g_strdup(tmpbuf);
			s_list = g_list_append(s_list,(gpointer)element);
		}
		g_free(tmpbuf);
		i++;
	}
	p_list = g_list_sort(p_list,list_sort);
	s_list = g_list_sort(s_list,list_sort);


	dialog = gtk_dialog_new_with_buttons("Select Firmware",
			GTK_WINDOW(lookup_widget("main_window")),
			GTK_DIALOG_DESTROY_WITH_PARENT,
			"Abort",
			GTK_RESPONSE_CANCEL,
			"Load",
			GTK_RESPONSE_OK,
			NULL);

	vbox = gtk_vbox_new(TRUE,2);
	gtk_container_set_border_width(GTK_CONTAINER(vbox),5);
	gtk_box_pack_start(GTK_BOX(gtk_dialog_get_content_area(GTK_DIALOG(dialog))),vbox,TRUE,TRUE,0);
	/* Dummies */
	dummybutton = gtk_radio_button_new(NULL);
	g_object_ref_sink(dummybutton);
	group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(dummybutton));
	if (g_list_length(p_list) > 0)
	{
		label = gtk_label_new("Custom (personal) Profiles");
		gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);

		/* Cycle list for PERSONAL interogation files */
		for (i=0;i<g_list_length(p_list);i++)
		{
			element = (ListElement *)g_list_nth_data(p_list,i);

			ebox = gtk_event_box_new();
			gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0);
			hbox = gtk_hbox_new(FALSE,10);
			gtk_container_add(GTK_CONTAINER(ebox),hbox);
			label = gtk_label_new(element->name);
			gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0);
			button = gtk_radio_button_new(group);
			g_free(OBJ_GET(button,"filename"));
			OBJ_SET_FULL(button,"filename",g_strdup(element->filename),g_free);
			OBJ_SET(button,"handler",
					GINT_TO_POINTER(OFFLINE_FIRMWARE_CHOICE));
			g_signal_connect(button,
					"toggled",
					G_CALLBACK(toggle_button_handler),
					NULL);
			gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0);
			if (element->def)
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),TRUE);
			else
				gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),FALSE);
			group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button));
		}

		sep = gtk_hseparator_new();
		gtk_box_pack_start(GTK_BOX(vbox),sep,TRUE,TRUE,0);
	}
	label = gtk_label_new("System Wide ECU Profiles");
	gtk_box_pack_start(GTK_BOX(vbox),label,TRUE,TRUE,0);
	/* Cycle list for System interogation files */
	for (i=0;i<g_list_length(s_list);i++)
	{
		element = (ListElement *)g_list_nth_data(s_list,i);
		ebox = gtk_event_box_new();
		gtk_box_pack_start(GTK_BOX(vbox),ebox,TRUE,TRUE,0);
		hbox = gtk_hbox_new(FALSE,10);
		gtk_container_add(GTK_CONTAINER(ebox),hbox);
		label = gtk_label_new(element->name);
		gtk_box_pack_start(GTK_BOX(hbox),label,FALSE,TRUE,0);
		button = gtk_radio_button_new(group);
		g_free(OBJ_GET(button,"filename"));
		OBJ_SET_FULL(button,"filename",g_strdup(element->filename),g_free);
		OBJ_SET(button,"handler",
				GINT_TO_POINTER(OFFLINE_FIRMWARE_CHOICE));
		g_signal_connect(button,
				"toggled",
				G_CALLBACK(toggle_button_handler),
				NULL);
		gtk_box_pack_end(GTK_BOX(hbox),button,FALSE,TRUE,0);
		if (element->def)
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),TRUE);
		else
			gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),FALSE);
		group = gtk_radio_button_get_group(GTK_RADIO_BUTTON(button));
	}
	/*
	   if (i==1)
	   gtk_toggle_button_toggled(GTK_TOGGLE_BUTTON(button));
	   else
	   gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button),TRUE);
	   */

	g_strfreev(filenames);
	g_array_free(classes,TRUE);

	gtk_widget_show_all(dialog);
	gtk_window_set_transient_for(GTK_WINDOW(gtk_widget_get_toplevel(dialog)),GTK_WINDOW(lookup_widget("main_window")));

	result = gtk_dialog_run(GTK_DIALOG(dialog));
	gtk_widget_destroy(dialog);
	g_object_unref(dummybutton);
	g_list_foreach(p_list,free_element,NULL);
	g_list_foreach(s_list,free_element,NULL);
	g_list_free(p_list);
	g_list_free(s_list);
	switch (result)
	{
		case GTK_RESPONSE_ACCEPT:
		case GTK_RESPONSE_OK:
			EXIT();
			return (gchar *)DATA_GET(global_data,"offline_firmware_choice");
			break;
		case GTK_RESPONSE_CANCEL:
		default:
			EXIT();
			return NULL;
	}
	EXIT();
	return NULL;
}