📄 sensors.c
字号:
if (system_of_measurements == METRIC)
sprintf(buf, "%i km/h", data);
else // if the system is IMPERIAL
sprintf(buf, "%i mph", (int)(data/1.609));
}
void intake_pressure_formula(int data, char *buf)
{
if (system_of_measurements == METRIC)
sprintf(buf, "%i kPa", data);
else
sprintf(buf, "%.1f inHg", data/3.386389);
}
void timing_advance_formula(int data, char *buf)
{
sprintf(buf, "%.1f%c", ((float)data-128)/2, 0xB0);
}
void intake_air_temp_formula(int data, char *buf)
{
if (system_of_measurements == METRIC)
sprintf(buf, "%i%c C", data-40, 0xB0);
else // if the system is IMPERIAL
sprintf(buf, "%i%c F", (int)(((float)data-40)*9/5 + 32), 0xB0);
}
void air_flow_rate_formula(int data, char *buf)
{
if (system_of_measurements == METRIC)
sprintf(buf, "%.2f g/s", data*0.01);
else
sprintf(buf, "%.1f lb/min", data*0.0013227736);
}
void throttle_position_formula(int data, char *buf)
{
sprintf(buf, "%.1f%%", (float)data*100/255);
}
// **** New formulae added 3/11/2003: ****
// Fuel Pressure (guage): PID 0A
void fuel_pressure_formula(int data, char *buf)
{
if (system_of_measurements == METRIC)
sprintf(buf, "%i kPa", data*3);
else // if the system is IMPERIAL
sprintf(buf, "%.1f psi", data*3*0.145037738);
}
// Fuel Trim statuses: PID 06-09
void short_term_fuel_trim_formula(int data, char *buf)
{
if (data > 0xFF) // we're only showing bank 1 and 2 FT
data >>= 8;
sprintf(buf, (data == 128) ? "0.0%%" : "%+.1f%%", ((float)data - 128)*100/128);
}
void long_term_fuel_trim_formula(int data, char *buf)
{
if (data > 0xFF) // we're only showing bank 1 and 2 FT
data >>= 8;
sprintf(buf, (data == 128) ? "0.0%%" : "%+.1f%%", ((float)data - 128)*100/128);
}
// Commanded secondary air status: PID 12
void secondary_air_status_formula(int data, char *buf)
{
data = data & 0x0700; // mask bits 0, 1, and 2
if (data == 0x0100)
sprintf(buf, "upstream of 1st cat. conv.");
else if (data == 0x0200)
sprintf(buf, "downstream of 1st cat. conv.");
else if (data == 0x0400)
sprintf(buf, "atmosphere / off");
else
sprintf(buf, "Not supported");
}
// Oxygen sensor voltages & short term fuel trims: PID 14-1B
// Format is bankX_sensor
void o2_sensor_formula(int data, char *buf)
{
if ((data & 0xFF) == 0xFF) // if the sensor is not used in fuel trim calculation,
sprintf(buf, "%.3f V", (data >> 8)*0.005);
else
sprintf(buf, ((data & 0xFF) == 128) ? "%.3f V @ 0.0%% s.t. fuel trim" : "%.3f V @ %+.1f%% s.t. fuel trim", (data >> 8)*0.005, ((float)(data & 0xFF) - 128)*100/128);
}
//Power Take-Off Status: PID 1E
void pto_status_formula(int data, char *buf)
{
if ((data & 0x01) == 0x01)
sprintf(buf, "active");
else
sprintf(buf, "not active");
}
// OBD requirement to which vehicle is designed: PID 1C
void obd_requirements_formula(int data, char *buf)
{
switch (data)
{
case 0x01:
sprintf(buf, "OBD-II (California ARB)");
break;
case 0x02:
sprintf(buf, "OBD (Federal EPA)");
break;
case 0x03:
sprintf(buf, "OBD and OBD-II");
break;
case 0x04:
sprintf(buf, "OBD-I");
break;
case 0x05:
sprintf(buf, "Not OBD compliant");
break;
case 0x06:
sprintf(buf, "EOBD (Europe)");
break;
case 0x07:
sprintf(buf, "EOBD and OBD-II");
break;
case 0x08:
sprintf(buf, "EOBD and OBD");
break;
case 0x09:
sprintf(buf, "EOBD, OBD and OBD-II");
break;
case 0x0A:
sprintf(buf, "JOBD (Japan)");
break;
case 0x0B:
sprintf(buf, "JOBD and OBD-II");
break;
case 0x0C:
sprintf(buf, "JOBD and EOBD");
break;
case 0x0D:
sprintf(buf, "JOBD, EOBD, and OBD-II");
break;
default:
sprintf(buf, "Unknown: 0x%02X", data);
}
}
/* Sensors added 1/2/2003: */
void engine_run_time_formula(int data, char *buf)
{
int sec, min, hrs;
hrs = data / 3600; // get hours
min = (data % 3600) / 60; // get minutes
sec = data % 60; // get seconds
sprintf(buf, "%02i:%02i:%02i", hrs, min, sec);
}
void mil_distance_formula(int data, char *buf)
{
if (system_of_measurements == METRIC)
sprintf(buf, "%i km", data);
else // if the system is IMPERIAL
sprintf(buf, "%i miles", (int)(data/1.609));
}
void frp_relative_formula(int data, char *buf)
{
float kpa, psi;
kpa = data*0.079;
psi = kpa*0.145037738;
if (system_of_measurements == METRIC)
sprintf(buf, "%.3f kPa", kpa);
else // if the system is IMPERIAL
sprintf(buf, "%.1f PSI", psi);
}
void frp_widerange_formula(int data, char *buf)
{
int kpa;
float psi;
kpa = data*10;
psi = kpa*0.145037738;
if (system_of_measurements == METRIC)
sprintf(buf, "%i kPa", kpa);
else
sprintf(buf, "%.1f PSI", psi);
}
void o2_sensor_wrv_formula(int data, char *buf)
{
float eq_ratio, o2_voltage; // equivalence ratio and sensor voltage
eq_ratio = (float)(data >> 16)*0.0000305; // data bytes A,B
o2_voltage = (float)(data & 0xFFFF)*0.000122; // data bytes C,D
sprintf(buf, "%.3f V, Eq. ratio: %.3f", o2_voltage, eq_ratio);
}
//Commanded EGR status: PID 2C
void commanded_egr_formula(int data, char *buf)
{
sprintf(buf, "%.1f%%", (float)data*100/255);
}
//EGR error: PID 2D
void egr_error_formula(int data, char *buf)
{
sprintf(buf, (data == 128) ? "0.0%%" : "%+.1f%%", (float)(data-128)/255*100);
}
void evap_pct_formula(int data, char *buf)
{
sprintf(buf, "%.1f%%", (float)data/255*100);
}
void fuel_level_formula(int data, char *buf)
{
sprintf(buf, "%.1f%%", (float)data/255*100);
}
void warm_ups_formula(int data, char *buf)
{
sprintf(buf, "%i", data);
}
void clr_distance_formula(int data, char *buf)
{
if (system_of_measurements == METRIC)
sprintf(buf, "%i km", data);
else
sprintf(buf, "%i miles", (int)(data/1.609));
}
void evap_vp_formula(int data, char *buf)
{
if (system_of_measurements == METRIC)
sprintf(buf, "%.2f Pa", data*0.25);
else
sprintf(buf, "%.3f in H2O", data*0.25/249.088908);
}
void baro_pressure_formula(int data, char *buf)
{
if (system_of_measurements == METRIC)
sprintf(buf, "%i kPa", data);
else
sprintf(buf, "%.1f inHg", data*0.2953);
}
void o2_sensor_wrc_formula(int data, char *buf)
{
float eq_ratio, o2_ma; // equivalence ratio and sensor current
eq_ratio = (float)(data >> 16)*0.0000305; // data bytes A,B
o2_ma = ((float)(data & 0xFFFF) - 0x8000)*0.00390625; // data bytes C,D
sprintf(buf, "%.3f mA, Eq. ratio: %.3f", o2_ma, eq_ratio);
}
void cat_temp_formula(int data, char *buf)
{
float c, f;
c = data*0.1 - 40; // degrees Celcius
f = c*9/5 + 32; // degrees Fahrenheit
if (system_of_measurements == METRIC)
sprintf(buf, "%.1f%c C", c, 0xB0);
else
sprintf(buf, "%.1f%c F", f, 0xB0);
}
void ecu_voltage_formula(int data, char *buf)
{
sprintf(buf, "%.3f V", data*0.001);
}
void abs_load_formula(int data, char *buf)
{
sprintf(buf, "%.1f%%", (float)data*100/255);
}
void eq_ratio_formula(int data, char *buf)
{
sprintf(buf, "%.3f", data*0.0000305);
}
void relative_tp_formula(int data, char *buf)
{
sprintf(buf, "%.1f%%", (float)data*100/255);
}
void amb_air_temp_formula(int data, char *buf)
{
int c, f;
c = data-40; // degrees Celcius
f = (float)c*9/5 + 32; // degrees Fahrenheit
if (system_of_measurements == METRIC)
sprintf(buf, "%i%c C", c, 0xB0);
else
sprintf(buf, "%i%c F", f, 0xB0);
}
void abs_tp_formula(int data, char *buf)
{
sprintf(buf, "%.1f%%", (float)data*100/255);
}
void tac_pct_formula(int data, char *buf)
{
sprintf(buf, "%.1f%%", (float)data*100/255);
}
void mil_time_formula(int data, char *buf)
{
sprintf(buf, "%i hrs %i min", data/60, data%60);
}
void clr_time_formula(int data, char *buf)
{
sprintf(buf, "%i hrs %i min", data/60, data%60);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -