mirror of
https://github.com/markqvist/RNode_Firmware.git
synced 2025-01-13 16:29:39 -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_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) {
|
||||
BLEConnection* connection = Bluefruit.Connection(conn_handle);
|
||||
|
||||
@ -420,9 +421,9 @@ void bt_pairing_complete(uint16_t conn_handle, uint8_t auth_status) {
|
||||
} else {
|
||||
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++) {
|
||||
// multiply by tens however many times needed to make numbers appear in order
|
||||
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 false;
|
||||
}
|
||||
}
|
||||
|
||||
void bt_connect_callback(uint16_t conn_handle) {
|
||||
void bt_connect_callback(uint16_t conn_handle) {
|
||||
bt_state = BT_STATE_CONNECTED;
|
||||
cable_state = CABLE_STATE_DISCONNECTED;
|
||||
|
||||
@ -442,15 +443,15 @@ void bt_connect_callback(uint16_t conn_handle) {
|
||||
conn->requestPHY(BLE_GAP_PHY_2MBPS);
|
||||
conn->requestMtuExchange(512+3);
|
||||
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) {
|
||||
bt_state = BT_STATE_ON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool bt_setup_hw() {
|
||||
bool bt_setup_hw() {
|
||||
if (!bt_ready) {
|
||||
#if HAS_EEPROM
|
||||
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; }
|
||||
}
|
||||
}
|
||||
|
||||
void bt_start() {
|
||||
void bt_start() {
|
||||
if (bt_state == BT_STATE_OFF) {
|
||||
Bluefruit.setName(bt_devname);
|
||||
bledis.setManufacturer(BLE_MANUFACTURER);
|
||||
@ -528,9 +529,9 @@ void bt_start() {
|
||||
|
||||
bt_state = BT_STATE_ON;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool bt_init() {
|
||||
bool bt_init() {
|
||||
bt_state = BT_STATE_OFF;
|
||||
if (bt_setup_hw()) {
|
||||
if (bt_enabled && !console_active) bt_start();
|
||||
@ -538,18 +539,18 @@ bool bt_init() {
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bt_enable_pairing() {
|
||||
void bt_enable_pairing() {
|
||||
if (bt_state == BT_STATE_OFF) bt_start();
|
||||
bt_allow_pairing = true;
|
||||
bt_pairing_started = millis();
|
||||
bt_state = BT_STATE_PAIRING;
|
||||
}
|
||||
}
|
||||
|
||||
void update_bt() {
|
||||
void update_bt() {
|
||||
if (bt_allow_pairing && millis()-bt_pairing_started >= BT_PAIRING_TIMEOUT) {
|
||||
bt_disable_pairing();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user