mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-15 20:21:03 +00:00
51 lines
1.0 KiB
C++
51 lines
1.0 KiB
C++
#include <string.h>
|
|
|
|
|
|
#include "obd2_elm327.h"
|
|
|
|
ELM327 elm327_obj;
|
|
|
|
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->elm327 = &elm327_obj;
|
|
|
|
if (!elm327_obj.begin(ELM327_SERIAL, false, 5000))
|
|
{
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|
|
|
|
void obd2_elm327_get_state(obd2_elm327_t *elm327, char *state)
|
|
{
|
|
strcpy(state, bt_states[elm327->bt_state]);
|
|
}
|
|
|
|
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 */
|
|
} |