Skip to content

Commit

Permalink
Merge pull request #19 from kattni/read-only-unary
Browse files Browse the repository at this point in the history
Add read-only UnaryStruct
  • Loading branch information
tannewt committed Feb 7, 2019
2 parents 37f83e4 + 614668a commit 13e8165
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions adafruit_register/i2c_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
__version__ = "0.0.0-auto.0"
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_Register.git"


class Struct:
"""
Arbitrary structure register that is readable and writeable.
Expand All @@ -63,6 +64,7 @@ def __set__(self, obj, value):
with obj.i2c_device:
obj.i2c_device.write(self.buffer)


class UnaryStruct:
"""
Arbitrary single value structure register that is readable and writeable.
Expand Down Expand Up @@ -91,3 +93,17 @@ def __set__(self, obj, value):
struct.pack_into(self.format, buf, 1, value)
with obj.i2c_device:
obj.i2c_device.write(buf)


class ROUnaryStruct(UnaryStruct):
"""
Arbitrary single value structure register that is read-only.
Values map to the first value in the defined struct. See struct
module documentation for struct format string and its possible value types.
:param int register_address: The register address to read the bit from
:param type struct_format: The struct format string for this register.
"""
def __set__(self, obj, value):
raise AttributeError()

0 comments on commit 13e8165

Please sign in to comment.