[ble] Add support to change ble name from KMKKeyboard.go
This commit is contained in:
		
				
					committed by
					
						
						Kyle Brown
					
				
			
			
				
	
			
			
			
						parent
						
							18eeb4eadc
						
					
				
				
					commit
					e5700eeb5f
				
			
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							@@ -125,3 +125,4 @@ mnt2/
 | 
			
		||||
kmk/release_info.py
 | 
			
		||||
kmk/release_info.mpy
 | 
			
		||||
*.mpy
 | 
			
		||||
.vscode
 | 
			
		||||
 
 | 
			
		||||
@@ -14,19 +14,20 @@ BLE_APPEARANCE_HID_KEYBOARD = 961
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class BLEHID(AbstractHID):
 | 
			
		||||
    def post_init(self):
 | 
			
		||||
    def post_init(self, ble_name='KMK Keyboard', **kwargs):
 | 
			
		||||
        self.devices = {}
 | 
			
		||||
 | 
			
		||||
        hid = HIDService()
 | 
			
		||||
 | 
			
		||||
        advertisement = ProvideServicesAdvertisement(hid)
 | 
			
		||||
        advertisement.appearance = BLE_APPEARANCE_HID_KEYBOARD
 | 
			
		||||
        scan_response = Advertisement()
 | 
			
		||||
        scan_response.complete_name = 'KMK Keyboard'
 | 
			
		||||
 | 
			
		||||
        ble = BLERadio()
 | 
			
		||||
        ble.name = ble_name
 | 
			
		||||
        # ble.tx_power = 2
 | 
			
		||||
 | 
			
		||||
        if not ble.connected:
 | 
			
		||||
            ble.start_advertising(advertisement, scan_response)
 | 
			
		||||
            ble.start_advertising(advertisement)
 | 
			
		||||
            while not ble.connected:
 | 
			
		||||
                pass
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -41,7 +41,7 @@ HID_REPORT_SIZES = {
 | 
			
		||||
class AbstractHID:
 | 
			
		||||
    REPORT_BYTES = 8
 | 
			
		||||
 | 
			
		||||
    def __init__(self):
 | 
			
		||||
    def __init__(self, **kwargs):
 | 
			
		||||
        self._evt = bytearray(self.REPORT_BYTES)
 | 
			
		||||
        self.report_device = memoryview(self._evt)[0:1]
 | 
			
		||||
        self.report_device[0] = HIDReportTypes.KEYBOARD
 | 
			
		||||
@@ -55,7 +55,7 @@ class AbstractHID:
 | 
			
		||||
        self.report_mods = memoryview(self._evt)[1:2]
 | 
			
		||||
        self.report_non_mods = memoryview(self._evt)[3:]
 | 
			
		||||
 | 
			
		||||
        self.post_init()
 | 
			
		||||
        self.post_init(**kwargs)
 | 
			
		||||
 | 
			
		||||
    def __repr__(self):
 | 
			
		||||
        return '{}(REPORT_BYTES={})'.format(self.__class__.__name__, self.REPORT_BYTES)
 | 
			
		||||
@@ -191,7 +191,7 @@ class AbstractHID:
 | 
			
		||||
class USBHID(AbstractHID):
 | 
			
		||||
    REPORT_BYTES = 9
 | 
			
		||||
 | 
			
		||||
    def post_init(self):
 | 
			
		||||
    def post_init(self, **kwargs):
 | 
			
		||||
        self.devices = {}
 | 
			
		||||
 | 
			
		||||
        for device in usb_hid.devices:
 | 
			
		||||
 
 | 
			
		||||
@@ -191,7 +191,7 @@ class KMKKeyboard:
 | 
			
		||||
        else:
 | 
			
		||||
            return busio.UART(tx=pin, rx=None, timeout=timeout)
 | 
			
		||||
 | 
			
		||||
    def go(self, hid_type=HIDModes.USB):
 | 
			
		||||
    def go(self, hid_type=HIDModes.USB, **kwargs):
 | 
			
		||||
        assert self.keymap, 'must define a keymap with at least one row'
 | 
			
		||||
        assert self.row_pins, 'no GPIO pins defined for matrix rows'
 | 
			
		||||
        assert self.col_pins, 'no GPIO pins defined for matrix columns'
 | 
			
		||||
@@ -225,7 +225,7 @@ class KMKKeyboard:
 | 
			
		||||
        elif hid_type == HIDModes.BLE:
 | 
			
		||||
            self.hid_helper = BLEHID
 | 
			
		||||
 | 
			
		||||
        self._hid_helper_inst = self.hid_helper()
 | 
			
		||||
        self._hid_helper_inst = self.hid_helper(**kwargs)
 | 
			
		||||
 | 
			
		||||
        # Split keyboard Init
 | 
			
		||||
        if self.split_type is not None:
 | 
			
		||||
 
 | 
			
		||||
@@ -70,4 +70,4 @@ keyboard.keymap = [
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
if __name__ == '__main__':
 | 
			
		||||
    keyboard.go(hid_type=HIDModes.BLE)
 | 
			
		||||
    keyboard.go(hid_type=HIDModes.BLE, ble_name='Lab68')
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user