This commit is contained in:
Sem van der Hoeven
2024-07-14 21:44:26 +02:00
parent 50fd4c813d
commit f9cef163b9
4 changed files with 307 additions and 153 deletions

View File

@@ -86,6 +86,7 @@ uint32_t ram_b_amount = 0; /* counts up to 96 to show the KB of ram */
char device_label_i = -1; /* counter in the current device label */
char bt_state = BT_INITIALISING;
char update_slow = 0;
obd2_elm327_t elm327;
@@ -160,7 +161,7 @@ void on_init_run()
display.print(" ", (display.getDisplayXSize() / 2) - (INIT_TEXT_WIDTH * display.getFontXsize() / 2) - (INIT_PERCENTAGE_WIDTH / 2), display.getDisplayYSize() / 2 + 50);
if (init_percent > 90)
{
update_percent(8);
update_percent(8);
}
}
/* update initialization text */
@@ -279,7 +280,7 @@ void on_init_run()
if (init_percent == 100)
{
statemachine_next();
statemachine_next();
}
}
@@ -304,29 +305,91 @@ void on_main_enter()
#if (DEBUG == 1)
Serial.println("Entering main loop");
#endif
display.setColor(VGA_AQUA);
Timer0.attachInterrupt(query_slow_obd2_values);
Timer0.start(MS(5000));
display.setColor(VGA_AQUA);
}
void on_main_run()
{
obd2_elm327_process(&elm327);
if (update_slow)
{
update_slow = 0;
} else {
obd2_elm327_process_fast(&elm327);
}
if (elm327.value_updates & (1 << UPDATE_RPM_POS))
{
display.print("rpm ",0,100);
display.printNumI(elm327.rpm,100,100,4,'0');
elm327.value_updates &= ~(1 << UPDATE_RPM_POS);
#if (DEBUG == 1)
Serial.println("rpm");
Serial.println(elm327.rpm);
#endif
int width = (int)(display.getDisplayXSize() * ((float)elm327.rpm / 7000.0));
display.fillRect(0,20,width,20);
display.setColor(VGA_FUCHSIA);
display.print("rpm", 0, 20);
display.printNumI(elm327.engine_load, 30, 20, 4, '0');
display.setColor(VGA_AQUA);
}
if (elm327.value_updates & (1 << UPDATE_THROTTLE_POS))
if (elm327.value_updates & (1 << UPDATE_COOLANT_TEMP_POS))
{
display.printNumI(elm327.throttle_percent,100,20,3,'0');
elm327.value_updates &= ~(1 << UPDATE_THROTTLE_POS);
}
elm327.value_updates &= ~(1 << UPDATE_COOLANT_TEMP_POS);
display.print("coolant temp", 0, 100);
display.printNumI(elm327.engine_coolant_temp, 200, 100, 4, '0');
}
if (elm327.value_updates & (1 << UPDATE_FUEL_PRESSURE_POS))
{
elm327.value_updates &= ~(1 << UPDATE_FUEL_PRESSURE_POS);
display.print("fuel pressure", 0, 120);
display.printNumF(elm327.fuel_pressure, 200, 120, 4, '0');
}
if (elm327.value_updates & (1 << UPDATE_FUEL_LEVEL_POS))
{
elm327.value_updates &= ~(1 << UPDATE_FUEL_LEVEL_POS);
display.print("fuel level", 0, 140);
display.printNumF(elm327.fuel_level, 200, 140, 4, '0');
}
// if (elm327.value_updates & (1 << UPDATE_INTAKE_AIR_TEMP_POS))
// {
// elm327.value_updates &= ~(1 << UPDATE_INTAKE_AIR_TEMP_POS);
// display.print("intake air temp", 0, 160);
// display.printNumI(elm327.intake_air_temp, 200, 160, 4, '0');
// }
// if (elm327.value_updates & (1 << UPDATE_AMBIENT_AIR_TEMP_POS))
// {
// elm327.value_updates &= ~(1 << UPDATE_AMBIENT_AIR_TEMP_POS);
// display.print("ambient air temp", 0, 180);
// display.printNumI(elm327.ambient_air_temp, 200, 180, 4, '0');
// }
// if (elm327.value_updates & (1 << UPDATE_OIL_TEMP_POS))
// {
// elm327.value_updates &= ~(1 << UPDATE_OIL_TEMP_POS);
// display.print("oil temp", 0, 200);
// display.printNumF(elm327.engine_oil_temp, 200, 200, 4, '0');
// }
if (elm327.value_updates & (1 << UPDATE_ENGINE_LOAD_POS))
{
elm327.value_updates &= ~(1 << UPDATE_ENGINE_LOAD_POS);
int width = (int)(display.getDisplayXSize() * ((float)elm327.engine_load / 100.0));
display.fillRect(0,50,width,50);
display.setColor(VGA_FUCHSIA);
display.print("el", 0, 50);
display.printNumI(elm327.engine_load, 20, 50, 4, '0');
display.setColor(VGA_AQUA);
}
// if (elm327.value_updates & (1 << UPDATE_MANIFOLD_PRESSURE_POS))
// {
// elm327.value_updates &= ~(1 << UPDATE_MANIFOLD_PRESSURE_POS);
// display.print("manifold pressure", 0, 240);
// display.printNumI(elm327.manifold_pressure, 200, 240, 4, '0');
// }
}
void update_init_text()
@@ -432,7 +495,12 @@ void update_ram_kb()
void bt_state_changed()
{
update_percent(10);
update_percent(10);
}
void query_slow_obd2_values()
{
update_slow = 1;
}
void setup()
@@ -460,7 +528,7 @@ void setup()
statemachine_register_state(&main_state, STATE_CAR_INFO);
// TODO remove
//statemachine_register_state(&main_state, 0);
// statemachine_register_state(&main_state, 0);
statemachine_init();
display.clrScr();
@@ -473,14 +541,14 @@ void setup()
display.setColor(COLOR_ORANGE);
display.print("Waiting for ELM327", (display.getDisplayXSize() / 2) - ((18 * display.getFontXsize()) / 2), 160);
#if (DEBUG == 1)
Serial.println("checking for bt");
#endif
#if (DEBUG == 1)
Serial.println("checking for bt");
#endif
if (!obd2_elm327_init(&elm327))
{
#if (DEBUG == 1)
Serial.println("Shit man its fucked");
#endif
#if (DEBUG == 1)
Serial.println("Shit man its fucked");
#endif
}
elm327.on_state_change = &bt_state_changed;
#if (DEBUG == 1)