From 0c41a87bbf168bf8d170c006c42d713b0612d042 Mon Sep 17 00:00:00 2001 From: Tim Small Date: Tue, 13 Jun 2023 09:44:49 +0100 Subject: [PATCH] Change from using (unstable) spi device numbers to spidev path. See: https://github.com/doceme/py-spidev/pull/130 for explanation. --- src/scs_core/particulate/opc_conf.py | 47 +++++++++------------------- src/scs_core/sys/node.py | 14 ++------- 2 files changed, 16 insertions(+), 45 deletions(-) diff --git a/src/scs_core/particulate/opc_conf.py b/src/scs_core/particulate/opc_conf.py index 2ad45faeb..abdf34dcc 100644 --- a/src/scs_core/particulate/opc_conf.py +++ b/src/scs_core/particulate/opc_conf.py @@ -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 """ @@ -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 @@ -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() # ---------------------------------------------------------------------------------------------------------------- @@ -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 # ---------------------------------------------------------------------------------------------------------------- @@ -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 @@ -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) diff --git a/src/scs_core/sys/node.py b/src/scs_core/sys/node.py index b20a022ef..52820f6cb 100644 --- a/src/scs_core/sys/node.py +++ b/src/scs_core/sys/node.py @@ -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