This commit is contained in:
Sem van der Hoeven
2024-11-12 00:14:45 +01:00
parent ac2c2d6643
commit cf24296f63
6 changed files with 168 additions and 40 deletions

View File

@@ -3,6 +3,8 @@
#include "obd2_elm327.h"
#define DEBUG 1
#define KM_IN_MILES 1.6093440
#define RPM_MAX 7000
#define THROTTLE_MAX 100
@@ -86,24 +88,14 @@ void obd2_elm327_process_fast(obd2_elm327_t *elm327)
{
switch (current_value_fast)
{
case RPM_V:
{
float rpm = elm327->elm327->rpm();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
elm327->rpm = (uint16_t)rpm;
elm327->value_updates |= (1 << UPDATE_RPM_POS);
current_value_fast = ENGINE_LOAD_V;
}
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
{
// elm327->elm327->printError();
current_value_fast = ENGINE_LOAD_V;
}
break;
}
case ENGINE_LOAD_V:
{
#if (DEBUG == 1)
float engine_load = 50;
current_value_fast = FUEL_PRESSURE_V;
elm327->engine_load = (uint8_t)engine_load;
elm327->value_updates |= (1 << UPDATE_ENGINE_LOAD_POS);
#else
float engine_load = elm327->elm327->engineLoad();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
@@ -116,10 +108,17 @@ void obd2_elm327_process_fast(obd2_elm327_t *elm327)
// elm327->elm327->printError();
current_value_fast = FUEL_PRESSURE_V;
}
#endif
break;
}
case FUEL_PRESSURE_V:
{
#if (DEBUG == 1)
float fuel_pressure = 8;
elm327->fuel_pressure = (uint16_t)fuel_pressure;
elm327->value_updates |= (1 << UPDATE_FUEL_PRESSURE_POS);
current_value_fast = MANIFOLD_PRESSURE_V;
#else
float fuel_pressure = elm327->elm327->fuelPressure();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
@@ -132,22 +131,30 @@ void obd2_elm327_process_fast(obd2_elm327_t *elm327)
// elm327->elm327->printError();
current_value_fast = MANIFOLD_PRESSURE_V;
}
#endif
break;
}
case MANIFOLD_PRESSURE_V:
{
#if (DEBUG == 1)
float manifold_pressure = 8;
elm327->manifold_pressure = (uint8_t)manifold_pressure;
elm327->value_updates |= (1 << UPDATE_MANIFOLD_PRESSURE_POS);
current_value_fast = ENGINE_LOAD_V;
#else
float manifold_pressure = elm327->elm327->manifoldPressure();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
elm327->manifold_pressure = (uint8_t)manifold_pressure;
elm327->value_updates |= (1 << UPDATE_MANIFOLD_PRESSURE_POS);
current_value_fast = RPM_V;
current_value_fast = ENGINE_LOAD_V;
}
else if (elm327->elm327->nb_rx_state != ELM_GETTING_MSG)
{
// elm327->elm327->printError();
current_value_fast = RPM_V;
current_value_fast = ENGINE_LOAD_V;
}
#endif
break;
}
}
@@ -160,6 +167,11 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
{
case COOLANT_TEMP_V:
{
#if (DEBUG == 1)
elm327->engine_coolant_temp = 102;
elm327->value_updates |= (1 << UPDATE_COOLANT_TEMP_POS);
current_value_slow = INTAKE_AIR_TEMP_V;
#else
float coolant_temp = elm327->elm327->engineCoolantTemp();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
@@ -172,10 +184,16 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
// elm327->elm327->printError();
current_value_slow = INTAKE_AIR_TEMP_V;
}
#endif
break;
}
case INTAKE_AIR_TEMP_V:
{
#if (DEBUG == 1)
elm327->intake_air_temp = 40;
elm327->value_updates |= (1 << UPDATE_INTAKE_AIR_TEMP_POS);
current_value_slow = AMBIENT_AIR_TEMP_V;
#else
float intake_air_temp = elm327->elm327->intakeAirTemp();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
@@ -188,10 +206,16 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
// elm327->elm327->printError();
current_value_slow = AMBIENT_AIR_TEMP_V;
}
#endif
break;
}
case AMBIENT_AIR_TEMP_V:
{
#if (DEBUG == 1)
elm327->ambient_air_temp = 20;
elm327->value_updates |= (1 << UPDATE_AMBIENT_AIR_TEMP_POS);
current_value_slow = OIL_TEMP_V;
#else
float ambient_air_temp = elm327->elm327->ambientAirTemp();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
@@ -204,10 +228,16 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
// elm327->elm327->printError();
current_value_slow = OIL_TEMP_V;
}
#endif
break;
}
case OIL_TEMP_V:
{
#if (DEBUG == 1)
elm327->engine_oil_temp = 80;
elm327->value_updates |= (1 << UPDATE_OIL_TEMP_POS);
current_value_slow = FUEL_LEVEL_V;
#else
float engine_oil_temp = elm327->elm327->oilTemp();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
@@ -220,10 +250,16 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
// elm327->elm327->printError();
current_value_slow = FUEL_LEVEL_V;
}
#endif
break;
}
case FUEL_LEVEL_V:
{
#if (DEBUG == 1)
elm327->fuel_level = 50;
elm327->value_updates |= (1 << UPDATE_FUEL_LEVEL_POS);
current_value_slow = COOLANT_TEMP_V;
#else
float fuel_level = elm327->elm327->fuelLevel();
if (elm327->elm327->nb_rx_state == ELM_SUCCESS)
{
@@ -236,6 +272,7 @@ void obd2_elm327_process_slow(obd2_elm327_t *elm327)
// elm327->elm327->printError();
current_value_slow = COOLANT_TEMP_V;
}
#endif
break;
}
default: