mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-16 04:31:04 +00:00
tested ELM327 connection and refactored bt driver to include elm327
This commit is contained in:
62
due_obd2/obd2_elm327.cpp
Normal file
62
due_obd2/obd2_elm327.cpp
Normal file
@@ -0,0 +1,62 @@
|
||||
#include <string.h>
|
||||
#include "ELMduino.h"
|
||||
|
||||
#include "obd2_elm327.h"
|
||||
|
||||
ELM327 myELM327;
|
||||
|
||||
void obd2_elm327_init(obd2_elm327_t *elm327)
|
||||
{
|
||||
elm327->bt_state = BT_INITIALISING;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
void obd2_elm327_process(obd2_elm327_t *elm327)
|
||||
{
|
||||
if (elm327->bt_state != BT_CONNECTED)
|
||||
{
|
||||
__UINT32_TYPE__ bt_state = digitalRead(BT_STATE_PIN);
|
||||
|
||||
if (bt_state != elm327->bt_state)
|
||||
{
|
||||
if (bt_state)
|
||||
{
|
||||
elm327->bt_state = BT_CONNECTED;
|
||||
}
|
||||
else
|
||||
{
|
||||
elm327->bt_state = BT_INITIALISING;
|
||||
}
|
||||
elm327->on_state_change();
|
||||
}
|
||||
}
|
||||
|
||||
/* TODO read from Serial2 to read OBD2 data */
|
||||
}
|
||||
Reference in New Issue
Block a user