fix displaying bluetooth state and add waiting for elm327 connection

This commit is contained in:
Sem van der Hoeven
2024-01-21 13:17:31 +01:00
parent e464d0cdfe
commit 3f19ab4b7d
3 changed files with 29 additions and 32 deletions

View File

@@ -190,8 +190,8 @@ void on_init_run()
display.setColor(VGA_BLACK); display.setColor(VGA_BLACK);
display.print("Bluetooth ", (display.getDisplayXSize() / 2) - (11 * display.getFontXsize()), initialization_y + 50); display.print("Bluetooth ", (display.getDisplayXSize() / 2) - (11 * display.getFontXsize()), initialization_y + 50);
char current_bt_state[BT_STATE_LENGTH]; char current_bt_state[BT_STATE_LENGTH] = "poep";
obd2_elm327_get_state(&elm327, (char *)current_bt_state); obd2_elm327_get_state(&elm327, current_bt_state);
display.print(current_bt_state, (display.getDisplayXSize() / 2) + display.getFontXsize(), initialization_y + 50); display.print(current_bt_state, (display.getDisplayXSize() / 2) + display.getFontXsize(), initialization_y + 50);
display.setBackColor(VGA_BLACK); display.setBackColor(VGA_BLACK);
@@ -423,7 +423,7 @@ void setup()
/* Init display */ /* Init display */
display.InitLCD(); display.InitLCD();
display.setFont(OCR_A_Extended_M); // display.setFont(OCR_A_Extended_M);
#if (DEBUG == 1) #if (DEBUG == 1)
Serial.println("Starting"); Serial.println("Starting");
@@ -435,9 +435,17 @@ void setup()
statemachine_register_state(&main_state, STATE_CAR_INFO); statemachine_register_state(&main_state, STATE_CAR_INFO);
statemachine_init(); statemachine_init();
/* Serial1 is bluetooth module, pin 18 and 19. */ display.setFont(BigFont);
Serial1.begin(BT_BAUD); display.setColor(VGA_AQUA);
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);
obd2_elm327_init(&elm327); obd2_elm327_init(&elm327);
display.clrScr();
display.setFont(OCR_A_Extended_M);
} }
void loop() void loop()

View File

@@ -3,39 +3,27 @@
#include "obd2_elm327.h" #include "obd2_elm327.h"
ELM327 myELM327; ELM327 elm327_obj;
void obd2_elm327_init(obd2_elm327_t *elm327) char bt_states[3][BT_STATE_LENGTH] = {"Initializing", "Connecting ", "Connected "};
char obd2_elm327_init(obd2_elm327_t *elm327)
{ {
ELM327_SERIAL.begin(ELM327_BAUD);
elm327->bt_state = BT_INITIALISING; elm327->bt_state = BT_INITIALISING;
if (!elm327_obj.begin(ELM327_SERIAL, false, 5000))
{
return 0;
}
return 1;
} }
void obd2_elm327_get_state(obd2_elm327_t *elm327, char *state) void obd2_elm327_get_state(obd2_elm327_t *elm327, char *state)
{ {
// char bt_states[3][13] = {"Initializing", "Connecting ", "Connected "}; strcpy(state, bt_states[elm327->bt_state]);
// char bt_states;
// (void) bt_states;
if (sizeof(state) != BT_STATE_LENGTH)
{
/* result string must be of size 13 */
return;
}
switch (elm327->bt_state)
{
case BT_INITIALISING:
strcpy(state, "Initializing");
break;
case BT_CONNECTING:
strcpy(state, "Connecting ");
break;
case BT_CONNECTED:
strcpy(state, "Connected ");
break;
default:
strcpy(state, "Unknown ");
break;
}
} }
void obd2_elm327_process(obd2_elm327_t *elm327) void obd2_elm327_process(obd2_elm327_t *elm327)

View File

@@ -76,8 +76,9 @@ typedef struct obt2_elm327_tag
* @brief initializes the bluetooth module driver * @brief initializes the bluetooth module driver
* *
* @param elm327 pointer to struct holding bluetooth driver data * @param elm327 pointer to struct holding bluetooth driver data
* @returns 1 if successfully initialized, 0 if not.
*/ */
void obd2_elm327_init(obd2_elm327_t *elm327); char obd2_elm327_init(obd2_elm327_t *elm327);
/** /**
* @brief processes the bluetooth module communication with the OBD2 reader * @brief processes the bluetooth module communication with the OBD2 reader