import time from adafruit_hid.keyboard import Keyboard from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS import adafruit_ble from adafruit_ble.advertising import Advertisement from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.standard.hid import HIDService from adafruit_ble.services.standard.device_info import DeviceInfoService # Use default HID descriptor hid = HIDService() device_info = DeviceInfoService( software_revision=adafruit_ble.__version__, manufacturer="Adafruit Industries" ) advertisement = ProvideServicesAdvertisement(hid) advertisement.appearance = 961 scan_response = Advertisement() ble = adafruit_ble.BLERadio() if ble.connected: for c in ble.connections: c.disconnect() print("advertising") ble.start_advertising(advertisement, scan_response) k = Keyboard(hid.devices) kl = KeyboardLayoutUS(k)
for i in range(KEYCOUNT): # activate rising edge events on all keys trellis.activate_key(i, NeoTrellis.EDGE_RISING) # activate falling edge events on all keys trellis.activate_key(i, NeoTrellis.EDGE_FALLING) # set all keys to trigger the blink callback trellis.callbacks[i] = send # cycle the LEDs on startup trellis.pixels[i] = GREEN time.sleep(0.05) for i in range(KEYCOUNT): trellis.pixels[i] = BLUE device_info = DeviceInfoService(software_revision=adafruit_ble.__version__, manufacturer="Stonehippo") advertisement = ProvideServicesAdvertisement(hid) advertisement.appearance = 961 scan_response = Advertisement() scan_response.complete_name = "ZoomKeys HID" ble = adafruit_ble.BLERadio() if not ble.connected: print("advertising") ble.start_advertising(advertisement, scan_response) else: print("connected") print(ble.connections) while True: while not ble.connected:
# onboard blue LED blue_led = DigitalInOut(board.BLUE_LED) blue_led.direction = Direction.OUTPUT # setup for BLE ble = BLERadio() ble.name = "CoDi" if ble.connected: for c in ble.connections: c.disconnect() advertisement = ProvideServicesAdvertisement() # add device info service and UART service for BLE to advertise device_info_service = DeviceInfoService(manufacturer="CoDi Co.") uart_service = UARTService() advertisement.services.append(device_info_service) advertisement.services.append(uart_service) # function for haptic motor vibration # num: # of times to vibrate # duration: duration of vibration # delay: time between vibrations def vibrate(num, duration, delay): # 16 is the vibration effect being used for the haptic motor drv.sequence[0] = adafruit_drv2605.Effect(16) for _ in range(0, num): drv.play() # start vibration time.sleep(duration)
''' import time from adafruit_ble import BLERadio from adafruit_ble.advertising.standard import ProvideServicesAdvertisement from adafruit_ble.services.standard.device_info import DeviceInfoService #构建BLE对象 ble = BLERadio() #定义广播名称 ble.name = '01Studio' #定义设备信息 dev_info = DeviceInfoService(manufacturer='01Studio', software_revision='v1.0', model_number='pyBLE-NRF52840', serial_number=None, firmware_revision=None, hardware_revision='v1.0', service=None) #广播添加设备信息服务 advertisement = ProvideServicesAdvertisement(dev_info) #发起广播 ble.start_advertising(advertisement) while True: pass