mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-16 12:41:05 +00:00
fix displaying bluetooth state and add waiting for elm327 connection
This commit is contained in:
@@ -3,39 +3,27 @@
|
||||
|
||||
#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;
|
||||
|
||||
if (!elm327_obj.begin(ELM327_SERIAL, false, 5000))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
void obd2_elm327_get_state(obd2_elm327_t *elm327, char *state)
|
||||
{
|
||||
// char bt_states[3][13] = {"Initializing", "Connecting ", "Connected "};
|
||||
// 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;
|
||||
}
|
||||
strcpy(state, bt_states[elm327->bt_state]);
|
||||
}
|
||||
|
||||
void obd2_elm327_process(obd2_elm327_t *elm327)
|
||||
|
||||
Reference in New Issue
Block a user