diff --git a/stspin/constants/__init__.py b/stspin/constants/__init__.py index ae7274d..d87abf4 100644 --- a/stspin/constants/__init__.py +++ b/stspin/constants/__init__.py @@ -1,5 +1,10 @@ from .command import Command -from .constant import Constant + +from .constant import ( + Constant, + SpinValue, +) + from .register import Register from .status import ( diff --git a/stspin/constants/constant.py b/stspin/constants/constant.py index c8e3773..15c5870 100644 --- a/stspin/constants/constant.py +++ b/stspin/constants/constant.py @@ -3,6 +3,40 @@ ) +class SpinValue: + """Class representing values sent to and from Spin Devices + :Value: Exclusively unsigned integers representing one or more bytes + + """ + Value: Final[int] + Type: Final = 'SpinValue' + + def __init__(self, value: int) -> None: + assert(value >= 0) + self.Value = value + + def __eq__(self, other: object) -> bool: + if isinstance(other, int): + return self.Value == other + + if not isinstance(other, SpinValue): + return NotImplemented + + return self.Value == other.Value + + def __or__(self, other: object) -> object: + if isinstance(other, int): + return SpinValue(self.Value | other) + + if not isinstance(other, SpinValue): + return NotImplemented + + return SpinValue(self.Value | other.Value) + + def __repr__(self) -> str: + return f'{self.Value}' + + class Constant: DirReverse: Final = 0 DirForward: Final = 1