def __init__(self, device_addr, adapter_addr=None): """ Initialization of an instance of a remote micro:bit :param device_addr: Discovered microbit device with this address :param adapter_addr: Optional unless you have more than one adapter on your machine """ self.ubit = central.Central(adapter_addr=adapter_addr, device_addr=device_addr) self.user_pin_callback = None # Micro:bit Characteristics self._accel_data = self.ubit.add_characteristic(ACCEL_SRV, ACCEL_DATA) self._accel_period = self.ubit.add_characteristic( ACCEL_SRV, ACCEL_PERIOD) self._magneto_data = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_DATA) self._magneto_period = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_PERIOD) self._magneto_bearing = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_BEARING) self._btn_a_state = self.ubit.add_characteristic(BTN_SRV, BTN_A_STATE) self._btn_b_state = self.ubit.add_characteristic(BTN_SRV, BTN_B_STATE) self._io_pin_data = self.ubit.add_characteristic( IO_PIN_SRV, IO_PIN_DATA) self._io_ad_config = self.ubit.add_characteristic( IO_PIN_SRV, IO_AD_CONFIG) self._io_pin_config = self.ubit.add_characteristic( IO_PIN_SRV, IO_PIN_CONFIG) self._io_pin_pwm = self.ubit.add_characteristic(IO_PIN_SRV, IO_PIN_PWM) self._led_state = self.ubit.add_characteristic(LED_SRV, LED_STATE) self._led_text = self.ubit.add_characteristic(LED_SRV, LED_TEXT) self._led_scroll = self.ubit.add_characteristic(LED_SRV, LED_SCROLL) self._temp_data = self.ubit.add_characteristic(TEMP_SRV, TEMP_DATA) self._temp_period = self.ubit.add_characteristic(TEMP_SRV, TEMP_PERIOD)
def __init__(self, device_addr, adapter_addr=dongle.address): self._guitar = central.Central(adapter_addr=adapter_addr, device_addr=device_addr) self._guitar_rx = self._guitar.add_characteristic( BLEGuitar.BLE_GUITAR_SERVICE, BLEGuitar.BLE_GUITAR_CHAR) self.on_connect = lambda x: None self.on_guitar_message = lambda x: None self.last_dict = {}
def __init__(self, device_addr, adapter_addr=SELF): self.remote_device = central.Central(adapter_addr=adapter_addr, device_addr=device_addr) try: self._id_char = self.remote_device.add_characteristic( SVC_UUID, DEV_IDS_CHRC) self._attr_char = self.remote_device.add_characteristic( SVC_UUID, DEV_ATTR_CHRC) except Exception as e: logging.error(e)
def __init__(self, device_addr, adapter_addr=None, accelerometer_service=True, button_service=True, led_service=True, magnetometer_service=False, pin_service=False, temperature_service=True, uart_service=False): """ Initialization of an instance of a remote micro:bit :param device_addr: Discovered microbit device with this address :param adapter_addr: Optional unless you have more than one adapter on your machine """ self.ubit = central.Central(adapter_addr=adapter_addr, device_addr=device_addr) self.user_pin_callback = None self.user_calibrate_cb = None self.uart_tx_cb = None # Micro:bit Characteristics if accelerometer_service: self._accel_data = self.ubit.add_characteristic( ACCEL_SRV, ACCEL_DATA) self._accel_period = self.ubit.add_characteristic( ACCEL_SRV, ACCEL_PERIOD) if button_service: self._btn_a_state = self.ubit.add_characteristic( BTN_SRV, BTN_A_STATE) self._btn_b_state = self.ubit.add_characteristic( BTN_SRV, BTN_B_STATE) if led_service: self._led_state = self.ubit.add_characteristic(LED_SRV, LED_STATE) self._led_text = self.ubit.add_characteristic(LED_SRV, LED_TEXT) self._led_scroll = self.ubit.add_characteristic( LED_SRV, LED_SCROLL) if magnetometer_service: self._magneto_data = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_DATA) self._magneto_period = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_PERIOD) self._magneto_bearing = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_BEARING) self._magneto_calibrate = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_CALIBRATE) if pin_service: self._io_pin_data = self.ubit.add_characteristic( IO_PIN_SRV, IO_PIN_DATA) self._io_ad_config = self.ubit.add_characteristic( IO_PIN_SRV, IO_AD_CONFIG) self._io_pin_config = self.ubit.add_characteristic( IO_PIN_SRV, IO_PIN_CONFIG) self._io_pin_pwm = self.ubit.add_characteristic( IO_PIN_SRV, IO_PIN_PWM) if temperature_service: self._temp_data = self.ubit.add_characteristic(TEMP_SRV, TEMP_DATA) self._temp_period = self.ubit.add_characteristic( TEMP_SRV, TEMP_PERIOD) if uart_service: self._uart_tx = self.ubit.add_characteristic(UART_SRV, UART_TX) self._uart_rx = self.ubit.add_characteristic(UART_SRV, UART_RX)
def __init__(self, device_addr, adapter_addr): self.remote_device = central.Central(adapter_addr=adapter_addr, device_addr=device_addr) self._remote_charac = self.remote_device.add_characteristic( MY_SRVC, DEV_IDS_CHRC)
def __init__(self, device_addr, adapter_addr=None, **kwargs): """ Initialization of an instance of a remote micro:bit :param device_addr: Discovered microbit device with this address :param adapter_addr: Optional unless you have more than one adapter on your machine """ legacy_params = [ 'accelerometer_service', 'button_service', 'led_service', 'magnetometer_service', 'pin_service', 'temperature_service', 'uart_service' ] for kwarg in kwargs: if kwarg in legacy_params: logger.warning('The parameter %s has been deprecated. There ' 'is no longer a requirement to specify which ' 'services the micro:bit has.\nYou will get an ' 'Error in the log if you access a ' 'characteristic that does not exist on ' 'micro:bit') self.ubit = central.Central(adapter_addr=adapter_addr, device_addr=device_addr) self.user_pin_callback = None self.user_btn_a_callback = None self.user_btn_b_callback = None self.user_calibrate_cb = None self.uart_tx_cb = None # Micro:bit Characteristics # if accelerometer_service: self._accel_data = self.ubit.add_characteristic(ACCEL_SRV, ACCEL_DATA) self._accel_period = self.ubit.add_characteristic( ACCEL_SRV, ACCEL_PERIOD) # if button_service: self._btn_a_state = self.ubit.add_characteristic(BTN_SRV, BTN_A_STATE) self._btn_b_state = self.ubit.add_characteristic(BTN_SRV, BTN_B_STATE) # if led_service: self._led_state = self.ubit.add_characteristic(LED_SRV, LED_STATE) self._led_text = self.ubit.add_characteristic(LED_SRV, LED_TEXT) self._led_scroll = self.ubit.add_characteristic(LED_SRV, LED_SCROLL) # if magnetometer_service: self._magneto_data = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_DATA) self._magneto_period = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_PERIOD) self._magneto_bearing = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_BEARING) self._magneto_calibrate = self.ubit.add_characteristic( MAGNETO_SRV, MAGNETO_CALIBRATE) # if pin_service: self._io_pin_data = self.ubit.add_characteristic( IO_PIN_SRV, IO_PIN_DATA) self._io_ad_config = self.ubit.add_characteristic( IO_PIN_SRV, IO_AD_CONFIG) self._io_pin_config = self.ubit.add_characteristic( IO_PIN_SRV, IO_PIN_CONFIG) self._io_pin_pwm = self.ubit.add_characteristic(IO_PIN_SRV, IO_PIN_PWM) # if temperature_service: self._temp_data = self.ubit.add_characteristic(TEMP_SRV, TEMP_DATA) self._temp_period = self.ubit.add_characteristic(TEMP_SRV, TEMP_PERIOD) # if uart_service: self._uart_tx = self.ubit.add_characteristic(UART_SRV, UART_TX) self._uart_rx = self.ubit.add_characteristic(UART_SRV, UART_RX)