mirror of
https://github.com/markqvist/OpenModem.git
synced 2024-12-12 17:34:26 -05:00
60 lines
1.2 KiB
C
60 lines
1.2 KiB
C
#include "Bluetooth.h"
|
|
#include <avr/pgmspace.h>
|
|
|
|
bool bluetooth_installed = false;
|
|
|
|
#define BT_AT_DELAY 100
|
|
void bluetooth_init(void) {
|
|
BT_DDR &= ~(_BV(BT_MODE) | _BV(BT_RTS));
|
|
BT_PORT |= _BV(BT_RTS);
|
|
|
|
// Check module is in command mode
|
|
if (BT_INPUT & _BV(BT_MODE)) {
|
|
// Check module RTS pin is pulled low
|
|
if (!(BT_INPUT &_BV(BT_RTS))) {
|
|
// Reconfigure UART to 9600 baud and issue reset
|
|
serial_setbaudrate_9600(0);
|
|
delay_ms(BT_AT_DELAY*2);
|
|
printf(PSTR("AT"));
|
|
printf(PSTR("AT+FACTORYRESET\r\n"));
|
|
delay_ms(BT_AT_DELAY);
|
|
|
|
printf(PSTR("AT+GAPDEVNAME=OpenModem\r\n"));
|
|
delay_ms(BT_AT_DELAY);
|
|
|
|
printf(PSTR("AT+MODESWITCHEN=ble,0\r\n"));
|
|
delay_ms(BT_AT_DELAY);
|
|
|
|
printf(PSTR("AT+MODESWITCHEN=local,0\r\n"));
|
|
delay_ms(BT_AT_DELAY);
|
|
|
|
printf(PSTR("AT+HWMODELED=0\r\n"));
|
|
delay_ms(BT_AT_DELAY);
|
|
|
|
printf(PSTR("AT+BLEPOWERLEVEL=4\r\n"));
|
|
delay_ms(BT_AT_DELAY);
|
|
|
|
printf(PSTR("ATZ\r\n"));
|
|
delay_ms(BT_AT_DELAY);
|
|
|
|
// Reconfigure mode pin to output
|
|
BT_DDR |= _BV(BT_MODE);
|
|
|
|
// Enable DATA mode
|
|
BT_PORT &= ~_BV(BT_MODE);
|
|
|
|
bluetooth_installed = true;
|
|
}
|
|
}
|
|
|
|
if (bluetooth_installed) {
|
|
|
|
} else {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bool bluetooth_enabled() {
|
|
return bluetooth_installed;
|
|
} |