mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2025-01-15 17:27:15 -05:00
Cleanup
This commit is contained in:
parent
c51335a1df
commit
7a8a1b5dee
37
Bluetooth.h
37
Bluetooth.h
@ -387,7 +387,8 @@ char bt_devname[11];
|
|||||||
bt_ssp_pin = 0;
|
bt_ssp_pin = 0;
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
}
|
}
|
||||||
void bt_pairing_complete(uint16_t conn_handle, uint8_t auth_status) {
|
|
||||||
|
void bt_pairing_complete(uint16_t conn_handle, uint8_t auth_status) {
|
||||||
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
|
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
|
||||||
BLEConnection* connection = Bluefruit.Connection(conn_handle);
|
BLEConnection* connection = Bluefruit.Connection(conn_handle);
|
||||||
|
|
||||||
@ -420,9 +421,9 @@ void bt_pairing_complete(uint16_t conn_handle, uint8_t auth_status) {
|
|||||||
} else {
|
} else {
|
||||||
bt_ssp_pin = 0;
|
bt_ssp_pin = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool match_request) {
|
bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool match_request) {
|
||||||
for (int i = 0; i < 6; i++) {
|
for (int i = 0; i < 6; i++) {
|
||||||
// multiply by tens however many times needed to make numbers appear in order
|
// multiply by tens however many times needed to make numbers appear in order
|
||||||
bt_ssp_pin += ((int)passkey[i] - 48) * pow(10, 5-i);
|
bt_ssp_pin += ((int)passkey[i] - 48) * pow(10, 5-i);
|
||||||
@ -432,9 +433,9 @@ bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool ma
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_connect_callback(uint16_t conn_handle) {
|
void bt_connect_callback(uint16_t conn_handle) {
|
||||||
bt_state = BT_STATE_CONNECTED;
|
bt_state = BT_STATE_CONNECTED;
|
||||||
cable_state = CABLE_STATE_DISCONNECTED;
|
cable_state = CABLE_STATE_DISCONNECTED;
|
||||||
|
|
||||||
@ -442,15 +443,15 @@ void bt_connect_callback(uint16_t conn_handle) {
|
|||||||
conn->requestPHY(BLE_GAP_PHY_2MBPS);
|
conn->requestPHY(BLE_GAP_PHY_2MBPS);
|
||||||
conn->requestMtuExchange(512+3);
|
conn->requestMtuExchange(512+3);
|
||||||
conn->requestDataLengthUpdate();
|
conn->requestDataLengthUpdate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||||
if (reason != BLE_GAP_SEC_STATUS_SUCCESS) {
|
if (reason != BLE_GAP_SEC_STATUS_SUCCESS) {
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_setup_hw() {
|
bool bt_setup_hw() {
|
||||||
if (!bt_ready) {
|
if (!bt_ready) {
|
||||||
#if HAS_EEPROM
|
#if HAS_EEPROM
|
||||||
if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) {
|
if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) {
|
||||||
@ -497,9 +498,9 @@ bool bt_setup_hw() {
|
|||||||
|
|
||||||
} else { return false; }
|
} else { return false; }
|
||||||
} else { return false; }
|
} else { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_start() {
|
void bt_start() {
|
||||||
if (bt_state == BT_STATE_OFF) {
|
if (bt_state == BT_STATE_OFF) {
|
||||||
Bluefruit.setName(bt_devname);
|
Bluefruit.setName(bt_devname);
|
||||||
bledis.setManufacturer(BLE_MANUFACTURER);
|
bledis.setManufacturer(BLE_MANUFACTURER);
|
||||||
@ -528,9 +529,9 @@ void bt_start() {
|
|||||||
|
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_init() {
|
bool bt_init() {
|
||||||
bt_state = BT_STATE_OFF;
|
bt_state = BT_STATE_OFF;
|
||||||
if (bt_setup_hw()) {
|
if (bt_setup_hw()) {
|
||||||
if (bt_enabled && !console_active) bt_start();
|
if (bt_enabled && !console_active) bt_start();
|
||||||
@ -538,18 +539,18 @@ bool bt_init() {
|
|||||||
} else {
|
} else {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_enable_pairing() {
|
void bt_enable_pairing() {
|
||||||
if (bt_state == BT_STATE_OFF) bt_start();
|
if (bt_state == BT_STATE_OFF) bt_start();
|
||||||
bt_allow_pairing = true;
|
bt_allow_pairing = true;
|
||||||
bt_pairing_started = millis();
|
bt_pairing_started = millis();
|
||||||
bt_state = BT_STATE_PAIRING;
|
bt_state = BT_STATE_PAIRING;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_bt() {
|
void update_bt() {
|
||||||
if (bt_allow_pairing && millis()-bt_pairing_started >= BT_PAIRING_TIMEOUT) {
|
if (bt_allow_pairing && millis()-bt_pairing_started >= BT_PAIRING_TIMEOUT) {
|
||||||
bt_disable_pairing();
|
bt_disable_pairing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user