use available constants instead of testing errors for length
This commit is contained in:
parent
50a9beda04
commit
5ca6d8953d
@ -106,6 +106,9 @@ void common_hal_bleio_adapter_set_enabled(bleio_adapter_obj_t *self, bool enable
|
||||
char ble_name[32];
|
||||
name_len = dotenv_get_key("/.env", "CIRCUITPY_BLE_NAME", ble_name, sizeof(ble_name) - 1);
|
||||
if (name_len > 0) {
|
||||
if (name_len > MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH) {
|
||||
name_len = MYNEWT_VAL_BLE_SVC_GAP_DEVICE_NAME_MAX_LENGTH;
|
||||
}
|
||||
ble_name[name_len] = '\0';
|
||||
ble_svc_gap_device_name_set(ble_name);
|
||||
} else {
|
||||
|
@ -464,17 +464,11 @@ void common_hal_bleio_adapter_set_name(bleio_adapter_obj_t *self, const char *na
|
||||
ble_gap_conn_sec_mode_t sec;
|
||||
sec.lv = 0;
|
||||
sec.sm = 0;
|
||||
int result;
|
||||
result = sd_ble_gap_device_name_set(&sec, (const uint8_t *)name, strlen(name));
|
||||
for (int name_len = strlen(name); name_len > 0; --name_len) {
|
||||
result = sd_ble_gap_device_name_set(&sec, (const uint8_t *)name, name_len);
|
||||
// expecting NRF_ERROR_DATA_SIZE when name too long
|
||||
if (result == NRF_SUCCESS) {
|
||||
return;
|
||||
}
|
||||
uint16_t len = strlen(name);
|
||||
if (len > BLE_GAP_DEVNAME_MAX_LEN) {
|
||||
len = BLE_GAP_DEVNAME_MAX_LEN;
|
||||
}
|
||||
// default back to default if all fails
|
||||
sd_ble_gap_device_name_set(&sec, (const uint8_t *)default_ble_name, sizeof(default_ble_name) - 1);
|
||||
sd_ble_gap_device_name_set(&sec, (const uint8_t *)name, len);
|
||||
}
|
||||
|
||||
STATIC uint32_t _update_identities(bool is_central) {
|
||||
|
Loading…
Reference in New Issue
Block a user