/*! \brief Updates the runtime sliders on whichever tab is active, by calling rt_update_values for each element of the hashtable \param data is unused */ G_MODULE_EXPORT gboolean update_rtsliders(gpointer data) { gfloat coolant = 0.0; static gfloat last_coolant = 0.0; GHashTable **ve3d_sliders; GHashTable *hash; TabIdent active_page; Firmware_Details *firmware = NULL; firmware = (Firmware_Details *)DATA_GET(global_data,"firmware"); ve3d_sliders = (GHashTable **)DATA_GET(global_data,"ve3d_sliders"); if (DATA_GET(global_data,"leaving")) return FALSE; active_page = (TabIdent)(GINT)DATA_GET(global_data,"active_page"); /* Update all the dynamic RT Sliders */ if (active_page == RUNTIME_TAB) /* Runtime display is visible */ if ((hash = (GHashTable *)DATA_GET(global_data,"rt_sliders"))) g_hash_table_foreach(hash,rt_update_values,NULL); if (active_page == ENRICHMENTS_TAB) /* Enrichments display is up */ if ((hash = (GHashTable *)DATA_GET(global_data,"enr_sliders"))) g_hash_table_foreach(hash,rt_update_values,NULL); if (active_page == ACCEL_WIZ_TAB) /* Enrichments display is up */ if ((hash = (GHashTable *)DATA_GET(global_data,"aw_sliders"))) g_hash_table_foreach(hash,rt_update_values,NULL); if (active_page == WARMUP_WIZ_TAB) /* Warmup wizard is visible */ { if ((hash = (GHashTable *)DATA_GET(global_data,"ww_sliders"))) g_hash_table_foreach(hash,rt_update_values,NULL); if (!lookup_current_value("cltdeg",&coolant)) MTXDBG(CRITICAL,_("Error getting current value of \"cltdeg\" from datasource\n")); if ((coolant != last_coolant) || (DATA_GET(global_data,"rt_forced_update"))) warmwizard_update_status(coolant); last_coolant = coolant; } if (ve3d_sliders) { for (gint i=0;i<firmware->total_tables;i++) { if (ve3d_sliders[i]) g_hash_table_foreach(ve3d_sliders[i],rt_update_values,NULL); } } return TRUE; }
void _crunch_trigtooth_data(gint page) { extern Firmware_Details *firmware; gint canID = firmware->canID; DataSize size = MTX_U08; gint i = 0; gint tmp = 0; gint min = -1; gint max = -1; gint cap_idx = 0; gfloat ratio = 0.0; gfloat suggested_sample_time= 0.0; gint min_sampling_time = 0; extern gint toothmon_id; gint lower = 0; gint upper = 0; gushort total = 0; gint position = get_ecu_data(canID,page,CTR,size); gint index = 0; /* g_printf("Counter position on page %i is %i\n",page,position); if (position > 0) g_printf("data block from position %i to 185, then wrapping to 0 to %i\n",position,position-1); else g_printf("data block from position 0 to 185 (93 words)\n"); */ /*printf("position is %i\n",position);*/ index=0; for (i=0;i<93;i++) ttm_data->last[i] = ttm_data->current[i]; for (i=position;i<185;i+=2) { /*total = (get_ecu_data(canID,page,i,size)*256)+get_ecu_data(canID,page,i+1,size);*/ total = get_ecu_data(canID,page,i,MTX_U16); ttm_data->current[index] = total; index++; } if (position != 0) { for (i=0;i<position;i+=2) { /*total = (get_ecu_data(canID,page,i,size)*256)+get_ecu_data(canID,page,i+1,size);*/ total = get_ecu_data(canID,page,i,MTX_U16); ttm_data->current[index] = total; index++; } } /*g_printf("\n");*/ if (get_ecu_data(canID,page,UNITS,size) == 1) { /*g_printf("0.1 ms units\n");*/ ttm_data->units=100; } else { /*g_printf("1uS units\n");*/ ttm_data->units=1; } min = 65535; max = 1; for (i=0;i<93;i++) { if ((ttm_data->current[i] < min) && (ttm_data->current[i] != 0)) min = ttm_data->current[i]; if (ttm_data->current[i] > max) max = ttm_data->current[i]; } ttm_data->min_time = min; ttm_data->max_time = max; /* Ratio of min to max, may not work for complex wheel * patterns */ ratio = (float)max/(float)min; lookup_current_value("rpm",&ttm_data->rpm); /*printf("Current RPM %f\n",ttm_data->rpm);*/ if (page == 9) /* TOOTH logger, we should search for min/max's */ { /* ttm_data->current is the array containing the entire * sample of data organized so the beginning of the array * corresponds to the wrap point in the ECU. Thus we should * search from here to find then number of "max" pips to see * how many wheel rotations we captured, and then try and * count the minor pips between those maxes and crunch on them * to determine the "quality" of the signal. */ /* Problems, the wheel styles can be very complex, not just * n-m styles.. */ cap_idx = 0; for (i=0;i<93;i++) { ttm_data->captures[i] = 0; /* Crude test, ok for m-n wheels, but not complex*/ if ((ttm_data->current[i] > (1.5*min)) && (min != 0)) ttm_data->captures[cap_idx++] = i; } upper = (gint)ceil(ratio); lower = (gint)floor(ratio); if ((ratio-lower) < 0.5) ttm_data->missing = lower - 1; else ttm_data->missing = upper - 1; /* for (i=1;i<cap_idx;i++) printf("read %i trigger times followed by %i missing, thus %i-%i wheel\n",ttm_data->captures[i]-ttm_data->captures[i-1],ttm_data->missing,ttm_data->missing+ttm_data->captures[i]-ttm_data->captures[i-1],ttm_data->missing); for (i=0;i<cap_idx;i++) printf("Missing teeth at index %i\n",ttm_data->captures[i]); */ /*printf("max/min is %f\n ceil %f. floor %f",ratio,ceil(ratio),floor(ratio) );*/ /*printf("wheel is a missing %i style\n",ttm_data->missing);*/ /* printf("Minimum tooth time: %i, max tooth time %i\n",min,max); printf ("Teeth per second is %f\n",1.0/(((float)min*ttm_data->units)/1000000.0)); */ suggested_sample_time = 186000/((1.0/(((float)min*ttm_data->units)/1000000.0))); if (suggested_sample_time < 0) suggested_sample_time = 0; min_sampling_time = 500; /* milliseconds */ ttm_data->sample_time = suggested_sample_time < min_sampling_time ? min_sampling_time : suggested_sample_time; /* printf("Suggested Sampling time is %f ms.\n",suggested_sample_time); printf("Sampling time set to %i ms.\n",ttm_data->sample_time); */ if (toothmon_id != 0) { g_source_remove(toothmon_id); toothmon_id = g_timeout_add(ttm_data->sample_time,(GtkFunction)signal_toothtrig_read,GINT_TO_POINTER(TOOTHMON_TICKLER)); } } /* printf("Data for this block\n"); for (i=0;i<93;i++) { printf("%.4x ", ttm_data->current[i]); if (!((i+1)%16)) printf("\n"); } printf("\n"); */ /* vertical scale calcs: * PROBLEM: max_time can be anywhere from 0-65535, need to * develop a way to have nice even scale along the Y axis so you * know what the values are * for values of 0-100000 */ ttm_data->peak = ttm_data->max_time *1.25; /* Add 25% padding */ tmp = ttm_data->peak; if (tmp < 750) ttm_data->vdivisor = 100; else if ((tmp >= 750) && (tmp < 1500)) ttm_data->vdivisor = 250; else if ((tmp >= 1500) && (tmp < 3000)) ttm_data->vdivisor = 500; else if ((tmp >= 3000) && (tmp < 6000)) ttm_data->vdivisor = 1000; else if ((tmp >= 6000) && (tmp < 12000)) ttm_data->vdivisor = 1500; else if ((tmp >= 12000) && (tmp < 24000)) ttm_data->vdivisor = 3000; else if ((tmp >= 24000) && (tmp < 48000)) ttm_data->vdivisor = 6000; else if (tmp >= 48000) ttm_data->vdivisor = 12000; }