change default BLE name
This commit is contained in:
@@ -6,6 +6,7 @@ from kmk.extensions import Extension
|
|||||||
from kmk.hid import HIDModes
|
from kmk.hid import HIDModes
|
||||||
from kmk.kmktime import ticks_diff, ticks_ms
|
from kmk.kmktime import ticks_diff, ticks_ms
|
||||||
from kmk.matrix import intify_coordinate
|
from kmk.matrix import intify_coordinate
|
||||||
|
from storage import getmount
|
||||||
|
|
||||||
|
|
||||||
class BLE_Split(Extension):
|
class BLE_Split(Extension):
|
||||||
@@ -47,6 +48,14 @@ class BLE_Split(Extension):
|
|||||||
return
|
return
|
||||||
|
|
||||||
def during_bootup(self, keyboard):
|
def during_bootup(self, keyboard):
|
||||||
|
self._ble.name = str(getmount('/').label)
|
||||||
|
if self._ble.name.endswith('L'):
|
||||||
|
# If name ends in 'L' assume left and strip from name
|
||||||
|
self._is_target = True
|
||||||
|
elif self._ble.name.endswith('R'):
|
||||||
|
# If name ends in 'R' assume right and strip from name
|
||||||
|
self._is_target = False
|
||||||
|
else:
|
||||||
self._is_target = bool(self.split_side == 'Left')
|
self._is_target = bool(self.split_side == 'Left')
|
||||||
|
|
||||||
if self.split_flip and not self._is_target:
|
if self.split_flip and not self._is_target:
|
||||||
@@ -108,7 +117,7 @@ class BLE_Split(Extension):
|
|||||||
self._ble.stop_scan()
|
self._ble.stop_scan()
|
||||||
for adv in self._ble.start_scan(ProvideServicesAdvertisement, timeout=20):
|
for adv in self._ble.start_scan(ProvideServicesAdvertisement, timeout=20):
|
||||||
print('Scanning')
|
print('Scanning')
|
||||||
if UARTService in adv.services:
|
if UARTService in adv.services and adv.rssi > -70:
|
||||||
self._uart_connection = self._ble.connect(adv)
|
self._uart_connection = self._ble.connect(adv)
|
||||||
self._uart_connection.connection_interval = 11.25
|
self._uart_connection.connection_interval = 11.25
|
||||||
self._uart = self._uart_connection[UARTService]
|
self._uart = self._uart_connection[UARTService]
|
||||||
@@ -126,7 +135,6 @@ class BLE_Split(Extension):
|
|||||||
self._uart = UARTService()
|
self._uart = UARTService()
|
||||||
advertisement = ProvideServicesAdvertisement(self._uart)
|
advertisement = ProvideServicesAdvertisement(self._uart)
|
||||||
|
|
||||||
self._ble.stop_advertising()
|
|
||||||
self._ble.start_advertising(advertisement)
|
self._ble.start_advertising(advertisement)
|
||||||
|
|
||||||
self.ble_time_reset()
|
self.ble_time_reset()
|
||||||
|
@@ -230,12 +230,13 @@ class BLEHID(AbstractHID):
|
|||||||
from adafruit_ble import BLERadio
|
from adafruit_ble import BLERadio
|
||||||
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
|
from adafruit_ble.advertising.standard import ProvideServicesAdvertisement
|
||||||
from adafruit_ble.services.standard.hid import HIDService
|
from adafruit_ble.services.standard.hid import HIDService
|
||||||
|
from storage import getmount
|
||||||
|
|
||||||
BLE_APPEARANCE_HID_KEYBOARD = const(961)
|
BLE_APPEARANCE_HID_KEYBOARD = const(961)
|
||||||
# Hardcoded in CPy
|
# Hardcoded in CPy
|
||||||
MAX_CONNECTIONS = const(2)
|
MAX_CONNECTIONS = const(2)
|
||||||
|
|
||||||
def post_init(self, ble_name='KMK Keyboard', **kwargs):
|
def post_init(self, ble_name=str(getmount('/').label), **kwargs):
|
||||||
self.conn_id = -1
|
self.conn_id = -1
|
||||||
|
|
||||||
self.ble = self.BLERadio()
|
self.ble = self.BLERadio()
|
||||||
|
Reference in New Issue
Block a user