mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-15 20:21:03 +00:00
add waiting for ELM327 before init state
This commit is contained in:
@@ -30,6 +30,7 @@ Program to create a car monitor display using:
|
||||
#define FLAG_DEVICE_LABEL_UPDATE_POS 0x04
|
||||
#define FLAG_DEVICE_LABEL_SHOULD_UPDATE_POS 0x05 /* 0 if label should be updated, 1 if valyue should be updated */
|
||||
#define FLAG_DEVICE_LABEL_UPDATE_KB_POS 0x06 /* count KB up */
|
||||
#define FLAG_INIT_ELM327_DONE_POS 0x07 /* elm327 done initializing */
|
||||
|
||||
#define LOGO_MIN_STEP 20
|
||||
#define LOGO_MAX_POS_Y 124
|
||||
@@ -100,7 +101,7 @@ void __state_none()
|
||||
state_t init_state =
|
||||
{
|
||||
.id = STATE_INIT,
|
||||
.next = STATE_INIT,
|
||||
.next = STATE_CAR_INFO,
|
||||
.on_enter = &on_init_enter,
|
||||
.on_run = &on_init_run,
|
||||
.on_exit = &on_init_exit};
|
||||
@@ -123,6 +124,9 @@ UTFT display(ILI9486, 38, 39, 40, 41);
|
||||
|
||||
void on_init_enter()
|
||||
{
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("Entering init state!");
|
||||
#endif
|
||||
display.clrScr();
|
||||
|
||||
Timer0.attachInterrupt(update_init_text);
|
||||
@@ -138,9 +142,6 @@ void on_init_enter()
|
||||
Timer3.attachInterrupt(update_ram_kb);
|
||||
|
||||
logo_flag |= (1 << FLAG_LOGO_UPDATE);
|
||||
#if (DEBUG == 1)
|
||||
Serial.println("Entering init state!");
|
||||
#endif
|
||||
}
|
||||
|
||||
void on_init_run()
|
||||
@@ -435,13 +436,21 @@ void setup()
|
||||
statemachine_register_state(&main_state, STATE_CAR_INFO);
|
||||
statemachine_init();
|
||||
|
||||
display.clrScr();
|
||||
|
||||
display.setFont(BigFont);
|
||||
display.setColor(VGA_AQUA);
|
||||
display.print("Welcome Sem",(display.getDisplayXSize()/2) - ((11 * display.getFontXsize())/2),120);
|
||||
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.print("Just a moment...", (display.getDisplayXSize() / 2) - ((16 * display.getFontXsize()) / 2), 140);
|
||||
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("done with elm327 init");
|
||||
Serial.println(elm327.elm327->connected);
|
||||
#endif
|
||||
|
||||
display.clrScr();
|
||||
|
||||
@@ -452,7 +461,6 @@ void loop()
|
||||
{
|
||||
|
||||
statemachine_loop();
|
||||
// Serial.println("Running");
|
||||
// delay(10);
|
||||
// while (Serial1.available())
|
||||
// {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#include <string.h>
|
||||
#include "ELMduino.h"
|
||||
|
||||
|
||||
#include "obd2_elm327.h"
|
||||
|
||||
@@ -13,6 +13,7 @@ char obd2_elm327_init(obd2_elm327_t *elm327)
|
||||
ELM327_SERIAL.begin(ELM327_BAUD);
|
||||
|
||||
elm327->bt_state = BT_INITIALISING;
|
||||
elm327->elm327 = &elm327_obj;
|
||||
|
||||
if (!elm327_obj.begin(ELM327_SERIAL, false, 5000))
|
||||
{
|
||||
|
||||
@@ -33,6 +33,8 @@ Be sure to disconnect the TX and RX pins from the BT module when programming the
|
||||
#ifndef OBD2_ELM327_H
|
||||
#define OBD2_ELM327_H
|
||||
|
||||
#include "ELMduino.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -68,6 +70,7 @@ enum BluetoothState
|
||||
*/
|
||||
typedef struct obt2_elm327_tag
|
||||
{
|
||||
ELM327 *elm327;
|
||||
enum BluetoothState bt_state;
|
||||
void (*on_state_change)();
|
||||
} obd2_elm327_t;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
int current_state_id = 0;
|
||||
state_t states[STATE_AMOUNT] = {NULL, NULL};
|
||||
__UINT8_TYPE__ next = 0;
|
||||
static char has_init = 0;
|
||||
|
||||
__UINT8_TYPE__ statemachine_register_state(state_t *state, int index)
|
||||
{
|
||||
@@ -28,11 +29,17 @@ __UINT8_TYPE__ statemachine_init()
|
||||
}
|
||||
}
|
||||
current_state_id = 0;
|
||||
states[current_state_id].on_enter();
|
||||
}
|
||||
|
||||
void statemachine_loop()
|
||||
{
|
||||
|
||||
if (has_init == 0)
|
||||
{
|
||||
has_init = 1;
|
||||
states[current_state_id].on_enter();
|
||||
}
|
||||
|
||||
if (states[current_state_id].next == current_state_id)
|
||||
{
|
||||
next = 0;
|
||||
|
||||
@@ -10,7 +10,7 @@ extern "C"
|
||||
#define STATE_INIT 0
|
||||
#define STATE_CAR_INFO 1
|
||||
|
||||
#define STATE_AMOUNT 2 /* change when more states are added */
|
||||
#define STATE_AMOUNT 3 /* change when more states are added */
|
||||
|
||||
/* two displays:
|
||||
- initialisation display, shows the state of booting up
|
||||
|
||||
Reference in New Issue
Block a user