test displaying values in main state

This commit is contained in:
Sem van der Hoeven
2024-01-22 23:52:17 +01:00
parent 0da353338e
commit 50fd4c813d
4 changed files with 202 additions and 63 deletions

View File

@@ -141,10 +141,6 @@ void on_init_enter()
Timer2.attachInterrupt(update_device_info);
Timer2.start(MS(100));
// TODO change to update when initializing bluetooth..
// Timer1.attachInterrupt(update_percent_test);
// Timer1.start(MS(60));
Timer3.attachInterrupt(update_ram_kb);
logo_flag |= (1 << FLAG_LOGO_UPDATE);
@@ -162,6 +158,10 @@ void on_init_run()
display.setColor(VGA_BLACK);
/*clear only initializing text*/
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 initialization text */
if (init_flag & (1 << FLAG_INIT_UPDATE_TEXT_POS))
@@ -193,6 +193,8 @@ void on_init_run()
display.setColor(COLOR_ORANGE);
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);
/* update bluetooth state */
display.setBackColor(VGA_FUCHSIA);
display.setColor(VGA_BLACK);
@@ -274,6 +276,11 @@ void on_init_run()
display.print(logo_text, CENTER, logo_pos_y);
}
}
if (init_percent == 100)
{
statemachine_next();
}
}
void on_init_exit()
@@ -297,14 +304,29 @@ void on_main_enter()
#if (DEBUG == 1)
Serial.println("Entering main loop");
#endif
display.setColor(VGA_AQUA);
}
void on_main_run()
{
delay(500);
#if (DEBUG == 1)
Serial.println("main!");
#endif
obd2_elm327_process(&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
}
if (elm327.value_updates & (1 << UPDATE_THROTTLE_POS))
{
display.printNumI(elm327.throttle_percent,100,20,3,'0');
elm327.value_updates &= ~(1 << UPDATE_THROTTLE_POS);
}
}
void update_init_text()
@@ -421,7 +443,7 @@ void setup()
randomSeed(analogRead(0));
#if (DEBUG == 1)
Serial.begin(9600);
Serial.begin(115200);
#endif
/* Init display */
@@ -436,6 +458,9 @@ void setup()
statemachine_register_state(&init_state, STATE_INIT);
statemachine_register_state(&main_state, STATE_CAR_INFO);
// TODO remove
//statemachine_register_state(&main_state, 0);
statemachine_init();
display.clrScr();
@@ -448,7 +473,15 @@ void setup()
display.setColor(COLOR_ORANGE);
display.print("Waiting for ELM327", (display.getDisplayXSize() / 2) - ((18 * display.getFontXsize()) / 2), 160);
obd2_elm327_init(&elm327);
#if (DEBUG == 1)
Serial.println("checking for bt");
#endif
if (!obd2_elm327_init(&elm327))
{
#if (DEBUG == 1)
Serial.println("Shit man its fucked");
#endif
}
elm327.on_state_change = &bt_state_changed;
#if (DEBUG == 1)
Serial.println("done with elm327 init");