Skip to content

Commit

Permalink
constant: Add SpinValue
Browse files Browse the repository at this point in the history
SpinValue acts as a type definition for values to and from Spin Devices
  • Loading branch information
m-laniakea committed Nov 19, 2019
1 parent 2b185f6 commit 29b0af1
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
7 changes: 6 additions & 1 deletion stspin/constants/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
from .command import Command
from .constant import Constant

from .constant import (
Constant,
SpinValue,
)

from .register import Register

from .status import (
Expand Down
34 changes: 34 additions & 0 deletions stspin/constants/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 29b0af1

Please sign in to comment.