mirror of
https://github.com/SemvdH/OBD2-car-display.git
synced 2025-12-14 19:51:04 +00:00
90 lines
2.0 KiB
C
90 lines
2.0 KiB
C
/*
|
|
BT module settings (AT mode):
|
|
+NAME=OBD2_BT
|
|
+VER=8.0.2,FSC-BT836B
|
|
+MAC=DC0D30000FA9
|
|
+BAUD=115200
|
|
+PIN=1189
|
|
|
|
HC-05 bluetooth module:
|
|
address: 5856:00:017A39
|
|
IAC: 9E8B33
|
|
|
|
AT Commands to connect permanently to the OBD2 module:
|
|
AT+RESET
|
|
AT+ORGL (Set to original)
|
|
AT+ROLE=1 (Set to Master)
|
|
AT+CMODE=0 (Set connect to a specific address)
|
|
AT+BIND=dc0d,30,000fa9
|
|
AT+INIT (Need to connect)
|
|
AT+PAIR=dc0d,30,000fa9,30 (,30 means 30 second timeout)
|
|
AT+LINK=dc0d,30,000fa9
|
|
|
|
Be sure to disconnect the TX and RX pins from the BT module when programming the arduino.
|
|
*/
|
|
#ifndef OBD2_BT_H
|
|
#define OBD2_BT_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
// #include <Arduino.h>
|
|
// #include "obd2_util.h"
|
|
|
|
/* pins */
|
|
#define PIN_BT_RX 19
|
|
#define PIN_BT_TX 18
|
|
|
|
#define BT_STATE_PIN 3 /* state connection pin from bluetooth module -> level high on connected */
|
|
|
|
#define BT_BAUD 115200
|
|
|
|
#define BT_STATE_LENGTH 13 /* length of the string identifier used for the states */
|
|
|
|
enum BluetoothState
|
|
{
|
|
BT_INITIALISING = 0,
|
|
BT_CONNECTING = 1,
|
|
BT_CONNECTED = 2
|
|
};
|
|
|
|
/**
|
|
* @brief struct to hold bluetooth module data
|
|
*
|
|
* @param state the current state of the bluetooth module
|
|
* @param on_state_change function pointer to the function to be called when the state changes
|
|
*/
|
|
typedef struct obt2_bt_tag
|
|
{
|
|
enum BluetoothState state;
|
|
void (*on_state_change)();
|
|
} obd2_bt_t;
|
|
|
|
/**
|
|
* @brief initializes the bluetooth module driver
|
|
*
|
|
* @param bt pointer to struct holding bluetooth driver data
|
|
*/
|
|
void obd2_bt_init(obd2_bt_t *bt);
|
|
|
|
/**
|
|
* @brief processes the bluetooth module communication with the OBD2 reader
|
|
*
|
|
* @param bt pointer to struct holding bluetooth driver data
|
|
*/
|
|
void obd2_bt_process(obd2_bt_t *bt);
|
|
|
|
/**
|
|
* @brief copies the current state of the bluetooth module to the state string
|
|
*
|
|
* @param bt pointer to struct holding bluetooth driver data
|
|
* @param state resulting string to hold the text representation of the state
|
|
*/
|
|
void obd2_bt_get_state(obd2_bt_t *bt, char *state);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // OBD2_BT_H
|