Skip to content

Fix a couple of Characteristic bugs and add FloatCharacteristic #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 10, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions adafruit_ble/characteristics/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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)
47 changes: 47 additions & 0 deletions adafruit_ble/characteristics/float.py
Original file line number Diff line number Diff line change
@@ -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__("<f", **kwargs)

def __get__(self, obj, cls=None):
return super().__get__(obj)[0]

def __set__(self, obj, value):
super().__set__(obj, (value,))