mirror of
https://github.com/liberatedsystems/RNode_Firmware_CE.git
synced 2025-06-07 14:22:51 -04:00
Cleanup
This commit is contained in:
parent
59e1836975
commit
fe9538de7e
1 changed files with 135 additions and 135 deletions
50
Bluetooth.h
50
Bluetooth.h
|
@ -28,8 +28,8 @@
|
||||||
#elif HAS_BLE == true
|
#elif HAS_BLE == true
|
||||||
#include "esp_bt_main.h"
|
#include "esp_bt_main.h"
|
||||||
#include "esp_bt_device.h"
|
#include "esp_bt_device.h"
|
||||||
// TODO: Remove
|
#include "BleSerial.h"
|
||||||
#define SerialBT Serial
|
BleSerial SerialBT;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif MCU_VARIANT == MCU_NRF52
|
#elif MCU_VARIANT == MCU_NRF52
|
||||||
|
@ -260,30 +260,30 @@ char bt_devname[11];
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#elif MCU_VARIANT == MCU_NRF52
|
#elif MCU_VARIANT == MCU_NRF52
|
||||||
uint8_t eeprom_read(uint32_t mapped_addr);
|
uint8_t eeprom_read(uint32_t mapped_addr);
|
||||||
|
|
||||||
void bt_stop() {
|
void bt_stop() {
|
||||||
if (bt_state != BT_STATE_OFF) {
|
if (bt_state != BT_STATE_OFF) {
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
bt_state = BT_STATE_OFF;
|
bt_state = BT_STATE_OFF;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_disable_pairing() {
|
void bt_disable_pairing() {
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
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) {
|
||||||
bt_disable_pairing();
|
bt_disable_pairing();
|
||||||
} 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);
|
||||||
|
@ -295,18 +295,18 @@ bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool ma
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||||
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) {
|
||||||
|
@ -346,9 +346,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);
|
||||||
|
@ -375,9 +375,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();
|
||||||
|
@ -385,18 +385,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…
Add table
Add a link
Reference in a new issue