Skip to content

Commit

Permalink
Change from using (unstable) spi device numbers to spidev path.
Browse files Browse the repository at this point in the history
See: doceme/py-spidev#130 for explanation.
  • Loading branch information
tim-seoss committed Jun 13, 2023
1 parent 8799d55 commit 0c41a87
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 45 deletions.
47 changes: 14 additions & 33 deletions src/scs_core/particulate/opc_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,14 @@ def construct_from_jdict(cls, jdict, name=None, skeleton=False):
restart_on_zeroes = jdict.get('restart-on-zeroes', True)
power_saving = jdict.get('power-saving')

bus = jdict.get('bus')
address = jdict.get('address')
dev_path = jdict.get('dev_path')

return cls(model, sample_period, restart_on_zeroes, power_saving, bus, address, name=name)
return cls(model, sample_period, restart_on_zeroes, power_saving, dev_path, name=name)


# ----------------------------------------------------------------------------------------------------------------

def __init__(self, model, sample_period, restart_on_zeroes, power_saving, bus, address, name=None):
def __init__(self, model, sample_period, restart_on_zeroes, power_saving, dev_path, name=None):
"""
Constructor
"""
Expand All @@ -61,15 +60,14 @@ def __init__(self, model, sample_period, restart_on_zeroes, power_saving, bus, a
self.__restart_on_zeroes = bool(restart_on_zeroes) # bool
self.__power_saving = bool(power_saving) # bool

self.__bus = bus # int
self.__address = address # int
self.__dev_path = dev_path # string


def __eq__(self, other): # ignore name
try:
return self.model == other.model and self.sample_period == other.sample_period and \
self.restart_on_zeroes == other.restart_on_zeroes and self.power_saving == other.power_saving and \
self.bus == other.bus and self.address == other.address
self.dev_path == other.dev_path

except (TypeError, AttributeError):
return False
Expand All @@ -91,21 +89,12 @@ def opc(self, interface, host):
def uses_spi(self):
return True


def opc_bus(self, host):
try:
return int(self.__bus)

except TypeError:
return host.opc_spi_bus()


def opc_address(self, host):
def opc_dev_path(self, host):
try:
return int(self.__address)
return int(self.__dev_path)

except TypeError:
return host.opc_spi_device()
return host.opc_spi_dev_path()


# ----------------------------------------------------------------------------------------------------------------
Expand All @@ -131,13 +120,8 @@ def restart_on_zeroes(self):


@property
def bus(self):
return self.__bus


@property
def address(self):
return self.__address
def dev_path(self):
return self.__dev_path


# ----------------------------------------------------------------------------------------------------------------
Expand All @@ -150,11 +134,8 @@ def as_json(self):
jdict['restart-on-zeroes'] = self.restart_on_zeroes
jdict['power-saving'] = self.power_saving

if self.__bus is not None:
jdict['bus'] = self.bus

if self.__address is not None:
jdict['address'] = self.address
if self.__dev_path is not None:
jdict['dev_path'] = self.dev_path

return jdict

Expand All @@ -163,6 +144,6 @@ def as_json(self):

def __str__(self, *args, **kwargs):
return "OPCConf(core):{name:%s, model:%s, sample_period:%s, restart_on_zeroes:%s, power_saving:%s, " \
"bus:%s, address:%s}" % \
"dev_path:%s}" % \
(self.name, self.model, self.sample_period, self.restart_on_zeroes, self.power_saving,
self.bus, self.address)
self.dev_path)
14 changes: 2 additions & 12 deletions src/scs_core/sys/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,22 +195,12 @@ def sim(cls):
# SPI...

@abstractmethod
def ndir_spi_bus(self):
def ndir_spi_dev_path(self):
pass


@abstractmethod
def ndir_spi_device(self):
pass


@abstractmethod
def opc_spi_bus(self):
pass


@abstractmethod
def opc_spi_device(self):
def opc_spi_dev_path(self):
pass


Expand Down

0 comments on commit 0c41a87

Please sign in to comment.