Bluetooth HC-05 draft
This commit is contained in:
parent
28eab796d8
commit
96f0624c36
|
@ -15,7 +15,8 @@ static const char *commands[5];
|
||||||
static int numCommands = 0;
|
static int numCommands = 0;
|
||||||
static int setBaudIdx = -1;
|
static int setBaudIdx = -1;
|
||||||
|
|
||||||
static char cmdBaud[10];
|
static char cmdHello[5];
|
||||||
|
static char cmdBaud[25];
|
||||||
static char cmdName[30];
|
static char cmdName[30];
|
||||||
static char cmdPin[16];
|
static char cmdPin[16];
|
||||||
|
|
||||||
|
@ -166,12 +167,6 @@ void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const c
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// todo: add support for other BT module types
|
|
||||||
if (moduleType != BLUETOOTH_HC_06) {
|
|
||||||
scheduleMsg(&btLogger, "This Bluetooth module is currently not supported!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
numCommands = 0;
|
numCommands = 0;
|
||||||
|
|
||||||
// now check the arguments and add other commands:
|
// now check the arguments and add other commands:
|
||||||
|
@ -221,12 +216,30 @@ void bluetoothStart(ts_channel_s *tsChan, bluetooth_module_e moduleType, const c
|
||||||
}
|
}
|
||||||
|
|
||||||
// ok, add commands!
|
// ok, add commands!
|
||||||
commands[numCommands++] = "AT"; // this command is added to test a connection
|
switch (moduleType) {
|
||||||
|
case BLUETOOTH_HC_05:
|
||||||
|
chsnprintf(cmdHello, sizeof(cmdHello), "AT\r\n");
|
||||||
|
chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+UART=%d,0,0\r\n", baud); // baud rate, 0=(1 stop bit), 0=(no parity bits)
|
||||||
|
chsnprintf(cmdName, sizeof(cmdName), "AT+NAME=%s\r\n", name);
|
||||||
|
chsnprintf(cmdPin, sizeof(cmdPin), "AT+PSWD=%s\r\n", pinCode);
|
||||||
|
// todo: add more commands?
|
||||||
|
// AT+RMAAD
|
||||||
|
// AT+ROLE=0
|
||||||
|
break;
|
||||||
|
case BLUETOOTH_HC_06:
|
||||||
|
chsnprintf(cmdHello, sizeof(cmdHello), "AT");
|
||||||
chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+BAUD%c", '0' + setBaudIdx);
|
chsnprintf(cmdBaud, sizeof(cmdBaud), "AT+BAUD%c", '0' + setBaudIdx);
|
||||||
commands[numCommands++] = cmdBaud;
|
|
||||||
chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s", name);
|
chsnprintf(cmdName, sizeof(cmdName), "AT+NAME%s", name);
|
||||||
commands[numCommands++] = cmdName;
|
|
||||||
chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s", pinCode);
|
chsnprintf(cmdPin, sizeof(cmdPin), "AT+PIN%s", pinCode);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
// todo: add support for other BT module types
|
||||||
|
scheduleMsg(&btLogger, "This Bluetooth module is currently not supported!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
commands[numCommands++] = cmdHello; // this command is added to test a connection
|
||||||
|
commands[numCommands++] = cmdBaud;
|
||||||
|
commands[numCommands++] = cmdName;
|
||||||
commands[numCommands++] = cmdPin;
|
commands[numCommands++] = cmdPin;
|
||||||
|
|
||||||
// create a thread to execute these commands later
|
// create a thread to execute these commands later
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
|
|
||||||
// Supported Bluetooth module types
|
// Supported Bluetooth module types
|
||||||
typedef enum {
|
typedef enum {
|
||||||
|
BLUETOOTH_HC_05,
|
||||||
BLUETOOTH_HC_06,
|
BLUETOOTH_HC_06,
|
||||||
} bluetooth_module_e;
|
} bluetooth_module_e;
|
||||||
|
|
||||||
|
|
|
@ -169,6 +169,10 @@ static void setTsSpeed(int value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__)
|
#if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__)
|
||||||
|
// Bluetooth HC-05 module initialization start (it waits for disconnect and then communicates to the module)
|
||||||
|
static void bluetoothHC05(const char *baudRate, const char *name, const char *pinCode) {
|
||||||
|
bluetoothStart(&tsChannel, BLUETOOTH_HC_05, baudRate, name, pinCode);
|
||||||
|
}
|
||||||
// Bluetooth HC-06 module initialization start (it waits for disconnect and then communicates to the module)
|
// Bluetooth HC-06 module initialization start (it waits for disconnect and then communicates to the module)
|
||||||
static void bluetoothHC06(const char *baudRate, const char *name, const char *pinCode) {
|
static void bluetoothHC06(const char *baudRate, const char *name, const char *pinCode) {
|
||||||
bluetoothStart(&tsChannel, BLUETOOTH_HC_06, baudRate, name, pinCode);
|
bluetoothStart(&tsChannel, BLUETOOTH_HC_06, baudRate, name, pinCode);
|
||||||
|
@ -844,6 +848,7 @@ void startTunerStudioConnectivity(void) {
|
||||||
#if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__)
|
#if EFI_BLUETOOTH_SETUP || defined(__DOXYGEN__)
|
||||||
// Usage: "bluetooth_hc06 <baud> <name> <pincode>"
|
// Usage: "bluetooth_hc06 <baud> <name> <pincode>"
|
||||||
// Example: "bluetooth_hc06 38400 rusefi 1234"
|
// Example: "bluetooth_hc06 38400 rusefi 1234"
|
||||||
|
addConsoleActionSSS("bluetooth_hc05", bluetoothHC05);
|
||||||
addConsoleActionSSS("bluetooth_hc06", bluetoothHC06);
|
addConsoleActionSSS("bluetooth_hc06", bluetoothHC06);
|
||||||
addConsoleAction("bluetooth_cancel", bluetoothCancel);
|
addConsoleAction("bluetooth_cancel", bluetoothCancel);
|
||||||
#endif /* EFI_BLUETOOTH_SETUP */
|
#endif /* EFI_BLUETOOTH_SETUP */
|
||||||
|
|
Loading…
Reference in New Issue