Fixes for temp display and start defines for engine load

This commit is contained in:
SemvdH
2025-05-04 22:08:24 +02:00
parent 48933e2bab
commit 34b287f871
4 changed files with 118 additions and 32 deletions

View File

@@ -66,9 +66,10 @@ char update_slow = 0;
obd2_elm327_t elm327;
int bar_1_x = 0;
int bar_2_x = 10;
int bar_3_y = 50;
uint16_t last_coolant_temp = 0;
uint16_t last_intake_air_temp = 0;
uint16_t last_ambient_air_temp = 0;
uint16_t last_engine_oil_temp = 0;
void on_init_enter();
void on_init_run();
@@ -171,7 +172,7 @@ void on_init_run()
}
/* update initialization progress bar */
display.setColor(COLOR_ORANGE);
display.setColor(COLOR_LIGHT_GRAY);
display.fillRect(0, initialization_y + display.getFontYsize() + 3, ((float)init_percent / 100.0) * display.getDisplayXSize(), initialization_y + display.getFontYsize() + 13);
obd2_elm327_check_connection(&elm327);
@@ -292,9 +293,17 @@ void on_main_enter()
display.setColor(TEMP_BOX_COLOR);
display.drawRect(TEMP_BOX_X_START, TEMP_BOX_Y_START, TEMP_BOX_X_START + TEMP_BOX_WIDTH, TEMP_BOX_Y_START + TEMP_BOX_HEIGHT);
// draw T for title
display.setBackColor(VGA_TEAL);
display.setColor(VGA_BLACK);
display.print("T", TEMP_BOX_X_START + TEMP_BOX_WIDTH - display.getFontXsize(), TEMP_BOX_Y_START);
// reset colors
display.setColor(VGA_AQUA);
display.setBackColor(VGA_BLACK);
// update slow values so we don't have to wait for the first time the timer fires
// TODO do this while initializing
query_slow_obd2_values();
}
@@ -323,15 +332,22 @@ void on_main_run()
display.print("coo ", TEMP_BOX_CONTENT_X_START, TEMP_BOX_COOLANT_TEXT_Y_START);
display.setColor(VGA_AQUA);
display.printNumI(elm327.engine_coolant_temp, TEMP_BOX_CONTENT_X_START + (4 * display.getFontXsize()), TEMP_BOX_COOLANT_TEXT_Y_START, 4, '0');
bar_draw_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_COOLANT_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.engine_coolant_temp, COOLANT_TEMP_MAX, COLOR_ORANGE, 1, &display);
#if (DEBUG == 1)
Serial.print("bar height ");
Serial.println(TEMP_BOX_BAR_HEIGHT);
// if the current temp is lower than the last temp (bar dropped) remove part of the drawn bar instead of drawing a new one
if (last_coolant_temp > elm327.engine_coolant_temp)
{
bar_clear_part_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_COOLANT_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.engine_coolant_temp, COOLANT_TEMP_MAX, VGA_BLACK, 1, &display);
}
else
{
bar_draw_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_COOLANT_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.engine_coolant_temp, COOLANT_TEMP_MAX, COLOR_LIGHT_GRAY, 1, &display);
}
last_coolant_temp = elm327.engine_coolant_temp;
#if (DEBUG == 1)
Serial.print("coolant temp: ");
Serial.println(elm327.engine_coolant_temp);
#endif
#endif // DEBUG
}
if (elm327.value_updates & (1 << UPDATE_FUEL_PRESSURE_POS))
@@ -355,12 +371,22 @@ void on_main_run()
display.print("int ", TEMP_BOX_CONTENT_X_START, TEMP_BOX_INTAKE_AIR_TEXT_Y_START);
display.setColor(VGA_AQUA);
display.printNumI(elm327.intake_air_temp, TEMP_BOX_CONTENT_X_START + (4 * display.getFontXsize()), TEMP_BOX_INTAKE_AIR_TEXT_Y_START, 4, '0');
bar_draw_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_INTAKE_AIR_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.intake_air_temp, INTAKE_AIR_TEMP_MAX, COLOR_ORANGE, 1, &display);
#if (DEBUG == 1)
// if the current temp is lower than the last temp (bar dropped) remove part of the drawn bar instead of drawing a new one
if (last_intake_air_temp > elm327.intake_air_temp)
{
bar_clear_part_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_INTAKE_AIR_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.intake_air_temp, INTAKE_AIR_TEMP_MAX, VGA_BLACK, 1, &display);
}
else
{
bar_draw_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_INTAKE_AIR_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.intake_air_temp, INTAKE_AIR_TEMP_MAX, COLOR_LIGHT_GRAY, 1, &display);
}
last_intake_air_temp = elm327.intake_air_temp;
#if (DEBUG == 1)
Serial.print("intake air temp: ");
Serial.println(elm327.intake_air_temp);
#endif
#endif
}
if (elm327.value_updates & (1 << UPDATE_AMBIENT_AIR_TEMP_POS))
@@ -370,12 +396,22 @@ void on_main_run()
display.print("amb ", TEMP_BOX_CONTENT_X_START, TEMP_BOX_AMBIENT_AIR_TEXT_Y_START);
display.setColor(VGA_AQUA);
display.printNumI(elm327.ambient_air_temp, TEMP_BOX_CONTENT_X_START + (4 * display.getFontXsize()), TEMP_BOX_AMBIENT_AIR_TEXT_Y_START, 4, '0');
bar_draw_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_AMBIENT_AIR_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.ambient_air_temp, AMBIENT_AIR_TEMP_MAX, COLOR_ORANGE, 1, &display);
#if (DEBUG == 1)
// if the current temp is lower than the last temp (bar dropped) remove part of the drawn bar instead of drawing a new one
if (last_ambient_air_temp > elm327.ambient_air_temp)
{
bar_clear_part_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_AMBIENT_AIR_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.ambient_air_temp, AMBIENT_AIR_TEMP_MAX, VGA_BLACK, 1, &display);
}
else
{
bar_draw_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_AMBIENT_AIR_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.ambient_air_temp, AMBIENT_AIR_TEMP_MAX, COLOR_LIGHT_GRAY, 1, &display);
}
last_ambient_air_temp = elm327.ambient_air_temp;
#if (DEBUG == 1)
Serial.print("ambient air temp: ");
Serial.println(elm327.ambient_air_temp);
#endif
#endif
}
if (elm327.value_updates & (1 << UPDATE_OIL_TEMP_POS))
@@ -385,12 +421,23 @@ void on_main_run()
display.print("oil ", TEMP_BOX_CONTENT_X_START, TEMP_BOX_OIL_TEXT_Y_START);
display.setColor(VGA_AQUA);
display.printNumI(elm327.engine_oil_temp, TEMP_BOX_CONTENT_X_START + (4 * display.getFontXsize()), TEMP_BOX_OIL_TEXT_Y_START, 4, '0');
bar_draw_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_OIL_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.engine_oil_temp, OIL_TEMP_MAX, COLOR_ORANGE, 1, &display);
#if (DEBUG == 1)
// if the current temp is lower than the last temp (bar dropped) remove part of the drawn bar instead of drawing a new one
if (last_engine_oil_temp > elm327.engine_oil_temp)
{
bar_clear_part_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_OIL_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.engine_oil_temp, OIL_TEMP_MAX, VGA_BLACK, 1, &display);
}
else
{
bar_draw_horizontal(TEMP_BOX_CONTENT_X_START, TEMP_BOX_OIL_BAR_Y_START, TEMP_BOX_BAR_WIDTH, TEMP_BOX_BAR_HEIGHT, elm327.engine_oil_temp, OIL_TEMP_MAX, COLOR_LIGHT_GRAY, 1, &display);
}
last_engine_oil_temp = elm327.engine_oil_temp;
#if (DEBUG == 1)
Serial.print("oil temp: ");
Serial.println(elm327.engine_oil_temp);
#endif
#endif
}
if (elm327.value_updates & (1 << UPDATE_ENGINE_LOAD_POS))
@@ -555,7 +602,7 @@ void setup()
display.print("Welcome Sem", (display.getDisplayXSize() / 2) - ((11 * display.getFontXsize()) / 2), 120);
display.setColor(VGA_FUCHSIA);
display.print("Just a moment...", (display.getDisplayXSize() / 2) - ((16 * display.getFontXsize()) / 2), 140);
display.setColor(COLOR_ORANGE);
display.setColor(COLOR_LIGHT_GRAY);
display.print("Waiting for ELM327", (display.getDisplayXSize() / 2) - ((18 * display.getFontXsize()) / 2), 160);
#if (DEBUG == 1)
@@ -563,16 +610,16 @@ void setup()
#endif
if (!obd2_elm327_init(&elm327))
{
#if (DEBUG == 1)
#if (DEBUG == 1)
Serial.println("Shit man its fucked");
#endif
#endif
}
elm327.on_state_change = &bt_state_changed;
#if (DEBUG == 1)
#if (DEBUG == 1)
Serial.println("done with elm327 init");
Serial.println(elm327.elm327->connected);
#endif
#endif
#if (SKIP_BT_CHECK == 1)
update_percent(10);
#endif