mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-15 20:21:03 +00:00
finished state machine
This commit is contained in:
@@ -28,32 +28,112 @@ extern uint8_t SmallFont[];
|
||||
char should_clear = 1;
|
||||
char led_state = LOW;
|
||||
char flag = 0;
|
||||
char counter_temp = 0;
|
||||
char main_color = 0;
|
||||
char init_text_i = 0;
|
||||
int init_text_x = 100;
|
||||
char init_text[] = "Initialising...";
|
||||
char text_temp[2] = {'a','\0'};
|
||||
|
||||
void on_init_enter();
|
||||
void on_init_run();
|
||||
void on_init_exit();
|
||||
void on_main_enter();
|
||||
void on_main_run();
|
||||
void __state_none(){ /* do nothing */}
|
||||
|
||||
state_t init_state =
|
||||
{
|
||||
.id = STATE_INIT,
|
||||
.next = STATE_CAR_INFO,
|
||||
.on_enter = &on_init_enter,
|
||||
.on_run = &on_init_run,
|
||||
.on_exit = &on_init_exit};
|
||||
|
||||
state_t main_state =
|
||||
{
|
||||
.id = STATE_CAR_INFO,
|
||||
.next = STATE_CAR_INFO,
|
||||
.on_enter = &on_main_enter,
|
||||
.on_run = &on_main_run,
|
||||
.on_exit = &__state_none};
|
||||
|
||||
/* Set the pins for the display and dev board */
|
||||
/* Standard Arduino Mega/Due shield : <display model>,38,39,40,41 */
|
||||
UTFT display(ILI9486,38,39,40,41);
|
||||
UTFT display(ILI9486, 38, 39, 40, 41);
|
||||
|
||||
void setup() {
|
||||
randomSeed(analogRead(0));
|
||||
void on_init_enter()
|
||||
{
|
||||
display.clrScr();
|
||||
Serial.println("Entering init state!");
|
||||
}
|
||||
|
||||
#if (DEBUG == 1)
|
||||
Serial.begin(9600);
|
||||
#endif
|
||||
/* Serial1 is bluetooth module, pin 18 and 19. */
|
||||
Serial1.begin(115200);
|
||||
void on_init_run()
|
||||
{
|
||||
Serial.println("Running!");
|
||||
if (!flag)
|
||||
{
|
||||
flag = 1;
|
||||
main_color = ~main_color;
|
||||
// display.clrScr();
|
||||
if (main_color)
|
||||
{
|
||||
display.setColor(VGA_RED);
|
||||
display.fillCircle(10,20,100);
|
||||
} else
|
||||
{
|
||||
display.setColor(VGA_TEAL);
|
||||
display.fillCircle(30,50,131);
|
||||
}
|
||||
display.setColor(VGA_AQUA);
|
||||
display.setBackColor(0,0,0);
|
||||
text_temp[0] = init_text[init_text_i];
|
||||
display.print(text_temp, init_text_x, LCD_H / 2);
|
||||
init_text_x += display.getFontXsize();
|
||||
init_text_i++;
|
||||
if (init_text_i > 14)
|
||||
{
|
||||
init_text_i = 0;
|
||||
display.clrScr();
|
||||
}
|
||||
}
|
||||
|
||||
/* Init display */
|
||||
display.InitLCD();
|
||||
display.setFont(BigFont);
|
||||
}
|
||||
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("Starting");
|
||||
#endif
|
||||
void on_init_exit()
|
||||
{
|
||||
Serial.println("Exiting init state!");
|
||||
flag = 0;
|
||||
main_color = 0;
|
||||
display.clrScr();
|
||||
}
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
obd2_timer_init();
|
||||
void on_main_enter()
|
||||
{
|
||||
obd2_timer_reset();
|
||||
Serial.println("Entering main loop");
|
||||
obd2_timer_set_period(800);
|
||||
}
|
||||
|
||||
void on_main_run()
|
||||
{
|
||||
if (!flag)
|
||||
{
|
||||
led_state = ~led_state;
|
||||
digitalWrite(LED_BUILTIN, led_state);
|
||||
flag = 1;
|
||||
main_color = ~main_color;
|
||||
if (main_color)
|
||||
display.setColor(255, 0, 166);
|
||||
else
|
||||
display.setColor(78, 181, 72);
|
||||
display.fillRect(LCD_W / 2 - 200, LCD_H / 2 - 100, LCD_W / 2 + 200, LCD_H / 2 + 100);
|
||||
display.setColor(0, 247, 255);
|
||||
display.print("OBD2 display yeet", CENTER, LCD_H / 2);
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("switching led");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void RTT_Handler()
|
||||
@@ -62,33 +142,60 @@ void RTT_Handler()
|
||||
obd2_timer_reset();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
while (Serial1.available()) {
|
||||
char rec = Serial1.read();
|
||||
#if (DEBUG == 1)
|
||||
Serial.println(rec);
|
||||
#endif
|
||||
}
|
||||
void setup()
|
||||
{
|
||||
randomSeed(analogRead(0));
|
||||
|
||||
if (should_clear)
|
||||
{
|
||||
display.clrScr();
|
||||
display.setColor(255, 0, 166);
|
||||
display.fillRect(LCD_W/2-200,LCD_H/2-100,LCD_W/2+200,LCD_H/2+100);
|
||||
display.setColor(0, 247, 255);
|
||||
display.print("OBD2 display yeet",CENTER,LCD_H/2);
|
||||
delay(10);
|
||||
should_clear = 0;
|
||||
}
|
||||
#if (DEBUG == 1)
|
||||
Serial.begin(9600);
|
||||
#endif
|
||||
/* Serial1 is bluetooth module, pin 18 and 19. */
|
||||
Serial1.begin(115200);
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
led_state = ~led_state;
|
||||
digitalWrite(LED_BUILTIN, led_state);
|
||||
flag = 1;
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("switching led");
|
||||
#endif
|
||||
}
|
||||
/* Init display */
|
||||
display.InitLCD();
|
||||
display.setFont(BigFont);
|
||||
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("Starting");
|
||||
#endif
|
||||
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
obd2_timer_init();
|
||||
statemachine_register_state(&init_state, STATE_INIT);
|
||||
statemachine_register_state(&main_state, STATE_CAR_INFO);
|
||||
statemachine_init();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
statemachine_loop();
|
||||
|
||||
counter_temp++;
|
||||
if (counter_temp == 50)
|
||||
{
|
||||
statemachine_next();
|
||||
}
|
||||
|
||||
delay(100);
|
||||
// while (Serial1.available())
|
||||
// {
|
||||
// char rec = Serial1.read();
|
||||
// #if (DEBUG == 1)
|
||||
// Serial.println(rec);
|
||||
// #endif
|
||||
// }
|
||||
|
||||
// if (should_clear)
|
||||
// {
|
||||
// display.clrScr();
|
||||
// display.setColor(255, 0, 166);
|
||||
// display.fillRect(LCD_W / 2 - 200, LCD_H / 2 - 100, LCD_W / 2 + 200, LCD_H / 2 + 100);
|
||||
// display.setColor(0, 247, 255);
|
||||
// display.print("OBD2 display yeet", CENTER, LCD_H / 2);
|
||||
// delay(10);
|
||||
// should_clear = 0;
|
||||
// }
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user