diff --git a/adafruit_ble/characteristics/__init__.py b/adafruit_ble/characteristics/__init__.py index fb2b3f3..78daf3e 100644 --- a/adafruit_ble/characteristics/__init__.py +++ b/adafruit_ble/characteristics/__init__.py @@ -74,7 +74,7 @@ def __bind_locally(self, service, initial_value): if max_length is None: max_length = len(initial_value) return _bleio.Characteristic.add_to_service( - service, + service.bleio_service, self.uuid.bleio_uuid, initial_value=initial_value, max_length=max_length, @@ -138,4 +138,4 @@ def __get__(self, obj, cls=None): def __set__(self, obj, value): encoded = struct.pack(self._struct_format, *value) - super.__set__(obj, encoded) + super().__set__(obj, encoded) diff --git a/adafruit_ble/characteristics/float.py b/adafruit_ble/characteristics/float.py new file mode 100644 index 0000000..d33903e --- /dev/null +++ b/adafruit_ble/characteristics/float.py @@ -0,0 +1,47 @@ +# The MIT License (MIT) +# +# Copyright (c) 2019 Scott Shawcroft for Adafruit Industries +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to deal +# in the Software without restriction, including without limitation the rights +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +# copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +# THE SOFTWARE. +""" +`float` +==================================================== + +This module provides float characteristics that are usable directly as attributes. + +""" + +from . import StructCharacteristic + +__version__ = "0.0.0-auto.0" +__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_BLE.git" + +class FloatCharacteristic(StructCharacteristic): + """32-bit float""" + # TODO: Valid set values as within range. + def __init__(self, **kwargs): + if "initial_value" in kwargs: + kwargs["initial_value"] = (kwargs["initial_value"],) + super().__init__("