mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-16 04:31:04 +00:00
progress
This commit is contained in:
@@ -9,22 +9,24 @@
|
||||
|
||||
typedef enum elm327_current_value_e
|
||||
{
|
||||
RPM_V,
|
||||
THROTTLE_V,
|
||||
COOLANT_TEMP_V,
|
||||
INTAKE_AIR_TEMP_V,
|
||||
AMBIENT_AIR_TEMP_V,
|
||||
OIL_TEMP_V,
|
||||
ENGINE_LOAD_V,
|
||||
BATTERY_VOLTAGE_V,
|
||||
FUEL_PRESSURE_V,
|
||||
SPEED_V,
|
||||
MANIFOLD_PRESSURE_V
|
||||
RPM_V, // fast
|
||||
// THROTTLE_V,
|
||||
COOLANT_TEMP_V, // slow
|
||||
INTAKE_AIR_TEMP_V, // slow
|
||||
AMBIENT_AIR_TEMP_V, // slow
|
||||
OIL_TEMP_V, // slow
|
||||
ENGINE_LOAD_V, // fast
|
||||
// BATTERY_VOLTAGE_V,
|
||||
FUEL_PRESSURE_V, // fast?
|
||||
// SPEED_V,
|
||||
MANIFOLD_PRESSURE_V, // fast?
|
||||
FUEL_LEVEL_V // slow
|
||||
|
||||
} elm327_current_value;
|
||||
|
||||
ELM327 elm327_obj;
|
||||
elm327_current_value current_value;
|
||||
elm327_current_value current_value_fast;
|
||||
elm327_current_value current_value_slow;
|
||||
|
||||
char bt_states[2][BT_STATE_LENGTH] = {"Initializing", "Connected"};
|
||||
|
||||
@@ -65,81 +67,24 @@ void obd2_elm327_check_connection(obd2_elm327_t *elm327)
|
||||
}
|
||||
}
|
||||
|
||||
void obd2_elm327_process(obd2_elm327_t *elm327)
|
||||
void obd2_elm327_process_fast(obd2_elm327_t *elm327)
|
||||
{
|
||||
|
||||
switch (current_value)
|
||||
switch (current_value_fast)
|
||||
{
|
||||
case RPM_V:
|
||||
{
|
||||
float rpm = elm327->elm327->rpm();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
if (rpm > 0 && rpm < RPM_MAX)
|
||||
elm327->rpm = (uint16_t)rpm;
|
||||
elm327->value_updates |= (1 << UPDATE_RPM_POS);
|
||||
current_value_fast = ENGINE_LOAD_V;
|
||||
}
|
||||
current_value = THROTTLE_V;
|
||||
break;
|
||||
}
|
||||
case THROTTLE_V:
|
||||
{
|
||||
float throttle = elm327->elm327->throttle();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
if (throttle > 0 && throttle <= THROTTLE_MAX)
|
||||
{
|
||||
elm327->throttle_percent = (uint8_t)throttle;
|
||||
elm327->value_updates |= (1 << UPDATE_THROTTLE_POS);
|
||||
}
|
||||
// elm327->elm327->printError();
|
||||
current_value_fast = ENGINE_LOAD_V;
|
||||
}
|
||||
// current_value = COOLANT_TEMP_V;
|
||||
//TODO remove
|
||||
current_value = RPM_V;
|
||||
break;
|
||||
}
|
||||
case COOLANT_TEMP_V:
|
||||
{
|
||||
float coolant_temp = elm327->elm327->engineCoolantTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->engine_coolant_temp = (uint8_t)coolant_temp;
|
||||
elm327->value_updates |= (1 << UPDATE_COOLANT_TEMP_POS);
|
||||
}
|
||||
current_value = INTAKE_AIR_TEMP_V;
|
||||
break;
|
||||
}
|
||||
case INTAKE_AIR_TEMP_V:
|
||||
{
|
||||
float intake_air_temp = elm327->elm327->intakeAirTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->intake_air_temp = (uint8_t)intake_air_temp;
|
||||
elm327->value_updates |= (1 << UPDATE_INTAKE_AIR_TEMP_POS);
|
||||
}
|
||||
current_value = AMBIENT_AIR_TEMP_V;
|
||||
break;
|
||||
}
|
||||
case AMBIENT_AIR_TEMP_V:
|
||||
{
|
||||
float ambient_air_temp = elm327->elm327->ambientAirTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->ambient_air_temp = (uint8_t)ambient_air_temp;
|
||||
elm327->value_updates |= (1 << UPDATE_AMBIENT_AIR_TEMP_POS);
|
||||
}
|
||||
current_value = OIL_TEMP_V;
|
||||
break;
|
||||
}
|
||||
case OIL_TEMP_V:
|
||||
{
|
||||
float engine_oil_temp = elm327->elm327->oilTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->engine_oil_temp = engine_oil_temp;
|
||||
elm327->value_updates |= (1 << UPDATE_OIL_TEMP_POS);
|
||||
}
|
||||
current_value = ENGINE_LOAD_V;
|
||||
break;
|
||||
}
|
||||
case ENGINE_LOAD_V:
|
||||
@@ -149,19 +94,13 @@ void obd2_elm327_process(obd2_elm327_t *elm327)
|
||||
{
|
||||
elm327->engine_load = (uint8_t)engine_load;
|
||||
elm327->value_updates |= (1 << UPDATE_ENGINE_LOAD_POS);
|
||||
current_value_fast = FUEL_PRESSURE_V;
|
||||
}
|
||||
current_value = BATTERY_VOLTAGE_V;
|
||||
break;
|
||||
}
|
||||
case BATTERY_VOLTAGE_V:
|
||||
{
|
||||
float battery_voltage = elm327->elm327->batteryVoltage();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
elm327->battery_voltage = battery_voltage;
|
||||
elm327->value_updates |= (1 << UPDATE_BATTERY_VOLTAGE_POS);
|
||||
// elm327->elm327->printError();
|
||||
current_value_fast = FUEL_PRESSURE_V;
|
||||
}
|
||||
current_value = FUEL_PRESSURE_V;
|
||||
break;
|
||||
}
|
||||
case FUEL_PRESSURE_V:
|
||||
@@ -169,21 +108,15 @@ void obd2_elm327_process(obd2_elm327_t *elm327)
|
||||
float fuel_pressure = elm327->elm327->fuelPressure();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->fuel_pressure = fuel_pressure;
|
||||
elm327->fuel_pressure = (uint16_t)fuel_pressure;
|
||||
elm327->value_updates |= (1 << UPDATE_FUEL_PRESSURE_POS);
|
||||
current_value_fast = MANIFOLD_PRESSURE_V;
|
||||
}
|
||||
current_value = SPEED_V;
|
||||
break;
|
||||
}
|
||||
case SPEED_V:
|
||||
{
|
||||
float speed = elm327->elm327->mph();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
elm327->speed = (uint8_t)(speed * KM_IN_MILES);
|
||||
elm327->value_updates |= (1 << UPDATE_SPEED_POS);
|
||||
// elm327->elm327->printError();
|
||||
current_value_fast = MANIFOLD_PRESSURE_V;
|
||||
}
|
||||
current_value = MANIFOLD_PRESSURE_V;
|
||||
break;
|
||||
}
|
||||
case MANIFOLD_PRESSURE_V:
|
||||
@@ -193,8 +126,101 @@ void obd2_elm327_process(obd2_elm327_t *elm327)
|
||||
{
|
||||
elm327->manifold_pressure = (uint8_t)manifold_pressure;
|
||||
elm327->value_updates |= (1 << UPDATE_MANIFOLD_PRESSURE_POS);
|
||||
current_value_fast = RPM_V;
|
||||
}
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
// elm327->elm327->printError();
|
||||
current_value_fast = RPM_V;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void obd2_elm327_process_slow(obd2_elm327_t *elm327)
|
||||
{
|
||||
|
||||
switch (current_value_slow)
|
||||
{
|
||||
case COOLANT_TEMP_V:
|
||||
{
|
||||
float coolant_temp = elm327->elm327->engineCoolantTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->engine_coolant_temp = (uint8_t)coolant_temp;
|
||||
elm327->value_updates |= (1 << UPDATE_COOLANT_TEMP_POS);
|
||||
current_value_slow = INTAKE_AIR_TEMP_V;
|
||||
}
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
// elm327->elm327->printError();
|
||||
current_value_slow = INTAKE_AIR_TEMP_V;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case INTAKE_AIR_TEMP_V:
|
||||
{
|
||||
float intake_air_temp = elm327->elm327->intakeAirTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->intake_air_temp = (uint8_t)intake_air_temp;
|
||||
elm327->value_updates |= (1 << UPDATE_INTAKE_AIR_TEMP_POS);
|
||||
current_value_slow = AMBIENT_AIR_TEMP_V;
|
||||
}
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
// elm327->elm327->printError();
|
||||
current_value_slow = AMBIENT_AIR_TEMP_V;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case AMBIENT_AIR_TEMP_V:
|
||||
{
|
||||
float ambient_air_temp = elm327->elm327->ambientAirTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->ambient_air_temp = (uint8_t)ambient_air_temp;
|
||||
elm327->value_updates |= (1 << UPDATE_AMBIENT_AIR_TEMP_POS);
|
||||
current_value_slow = OIL_TEMP_V;
|
||||
}
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
// elm327->elm327->printError();
|
||||
current_value_slow = OIL_TEMP_V;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case OIL_TEMP_V:
|
||||
{
|
||||
float engine_oil_temp = elm327->elm327->oilTemp();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->engine_oil_temp = (uint16_t)engine_oil_temp;
|
||||
elm327->value_updates |= (1 << UPDATE_OIL_TEMP_POS);
|
||||
current_value_slow = FUEL_LEVEL_V;
|
||||
}
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
// elm327->elm327->printError();
|
||||
current_value_slow = FUEL_LEVEL_V;
|
||||
}
|
||||
break;
|
||||
}
|
||||
case FUEL_LEVEL_V:
|
||||
{
|
||||
float fuel_level = elm327->elm327->fuelLevel();
|
||||
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
|
||||
{
|
||||
elm327->fuel_level = (uint16_t)fuel_level;
|
||||
elm327->value_updates |= (1 << UPDATE_FUEL_LEVEL_POS);
|
||||
current_value_slow = COOLANT_TEMP_V;
|
||||
}
|
||||
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
|
||||
{
|
||||
// elm327->elm327->printError();
|
||||
current_value_slow = COOLANT_TEMP_V;
|
||||
}
|
||||
current_value = RPM_V;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
Reference in New Issue
Block a user