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 rationale and
pre-requisite changes to py-spidev.
  • Loading branch information
tim-seoss committed Jun 13, 2023
1 parent 92628ce commit cbaecee
Show file tree
Hide file tree
Showing 12 changed files with 26 additions and 36 deletions.
13 changes: 4 additions & 9 deletions src/scs_dfe/particulate/alphasense_opc.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ def datum_class(cls):

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

def __init__(self, interface, spi_bus, spi_device, spi_mode, spi_clock):
def __init__(self, interface, spi_dev_path, spi_mode, spi_clock):
"""
Constructor
"""
super().__init__(interface)

self._spi = SPI(spi_bus, spi_device, spi_mode, spi_clock)
self._spi = SPI(spi_dev_path, spi_mode, spi_clock)


# ----------------------------------------------------------------------------------------------------------------
Expand Down Expand Up @@ -71,13 +71,8 @@ def data_ready(self):
# ----------------------------------------------------------------------------------------------------------------

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


@property
def address(self):
return self._spi.device
def dev_path(self):
return self._spi.dev_path


# ----------------------------------------------------------------------------------------------------------------
Expand Down
8 changes: 1 addition & 7 deletions src/scs_dfe/particulate/opc.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,13 +167,7 @@ def interface(self):

@property
@abstractmethod
def bus(self):
pass


@property
@abstractmethod
def address(self):
def dev_path(self):
pass


Expand Down
17 changes: 9 additions & 8 deletions src/scs_dfe/particulate/opc_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ def is_valid_model(cls, model):

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

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
"""
super().__init__(model, sample_period, restart_on_zeroes, power_saving, bus, address, name=name)
super().__init__(model, sample_period, restart_on_zeroes, power_saving, dev_path, name=name)


# ----------------------------------------------------------------------------------------------------------------
Expand All @@ -53,16 +53,17 @@ def opc_monitor(self, interface, host):

def opc(self, interface, host):
if self.model == OPCN2.source():
return OPCN2(interface, self.opc_bus(host), self.opc_address(host))
return OPCN2(interface, self.opc_dev_path(host))

elif self.model == OPCN3.source():
return OPCN3(interface, self.opc_bus(host), self.opc_address(host))
return OPCN3(interface, self.opc_dev_path(host))

elif self.model == OPCR1.source():
return OPCR1(interface, self.opc_bus(host), self.opc_address(host))
return OPCR1(interface, self.opc_dev_path(host))

elif self.model == SPS30.source():
return SPS30(interface, self.opc_bus(host), SPS30.DEFAULT_ADDR)
# FIXME SPS30 is i2c so should probably pass dev_path (e.g. /dev/i2c-X) ?
#elif self.model == SPS30.source():
# return SPS30(interface, self.opc_dev_path(host), SPS30.DEFAULT_ADDR)

raise ValueError('unknown model: %s' % self.model)

Expand All @@ -89,4 +90,4 @@ def __str__(self, *args, **kwargs):
return "OPCConf(dfe):{name:%s, model:%s, sample_period:%s, restart_on_zeroes:%s, power_saving:%s, " \
"bus:%s, address:%s}" % \
(self.name, self.model, self.sample_period, self.restart_on_zeroes, self.power_saving,
self.bus, self.address)
self.dev_path)
4 changes: 2 additions & 2 deletions src/scs_dfe/particulate/opc_n2/opc_n2.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ def max_permitted_zero_readings(cls):

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

def __init__(self, interface, spi_bus, spi_device):
def __init__(self, interface, spi_dev_path):
"""
Constructor
"""
super().__init__(interface, spi_bus, spi_device, self.__SPI_MODE, self.__SPI_CLOCK)
super().__init__(interface, spi_dev_path, self.__SPI_MODE, self.__SPI_CLOCK)


# ----------------------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/scs_dfe/particulate/opc_n3/opc_n3.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,11 @@ def max_permitted_zero_readings(cls):

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

def __init__(self, interface, spi_bus, spi_device):
def __init__(self, interface, spi_dev_path):
"""
Constructor
"""
super().__init__(interface, spi_bus, spi_device, self.__SPI_MODE, self.__SPI_CLOCK)
super().__init__(interface, spi_dev_path, self.__SPI_MODE, self.__SPI_CLOCK)


# ----------------------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions src/scs_dfe/particulate/opc_r1/opc_r1.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,11 @@ def max_permitted_zero_readings(cls):

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

def __init__(self, interface, spi_bus, spi_device):
def __init__(self, interface, spi_dev_path):
"""
Constructor
"""
super().__init__(interface, spi_bus, spi_device, self.__SPI_MODE, self.__SPI_CLOCK)
super().__init__(interface, spi_dev_path, self.__SPI_MODE, self.__SPI_CLOCK)


# ----------------------------------------------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/particulate/opc_monitor_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
try:
I2C.Sensors.open()

monitor = OPCMonitor(OPCN2(False, Host.opc_spi_bus(), Host.opc_spi_device()), conf)
monitor = OPCMonitor(OPCN2(False, Host.opc_spi_dev_path()), conf)
print(monitor)
print("-")

Expand Down
2 changes: 1 addition & 1 deletion tests/particulate/opc_n2_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
interface = interface_conf.interface()

# OPC...
opc = OPCN2(interface, Host.opc_spi_bus(), Host.opc_spi_device())
opc = OPCN2(interface, Host.opc_spi_dev_path())
print(opc)
print("-")

Expand Down
2 changes: 1 addition & 1 deletion tests/particulate/opc_n3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
interface = interface_conf.interface()

# OPC...
opc = OPCN3(interface, Host.opc_spi_bus(), Host.opc_spi_device())
opc = OPCN3(interface, Host.opc_spi_dev_path())
print(opc)
print("-")

Expand Down
2 changes: 1 addition & 1 deletion tests/particulate/opc_off.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
try:
I2C.Sensors.open()

opc = OPCN3(False, Host.opc_spi_bus(), Host.opc_spi_device())
opc = OPCN3(False, Host.opc_spi_dev_path())
print(opc)
print("-")

Expand Down
2 changes: 1 addition & 1 deletion tests/particulate/opc_on.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
try:
I2C.Sensors.open()

opc = OPCN3(False, Host.opc_spi_bus(), Host.opc_spi_device())
opc = OPCN3(False, Host.opc_spi_dev_path())
print(opc)
print("-")

Expand Down
2 changes: 1 addition & 1 deletion tests/particulate/opcube_n3_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
interface = interface_conf.interface()

# OPC...
opc = OPCN3(interface, Host.opc_spi_bus(), Host.opc_spi_device())
opc = OPCN3(interface, Host.opc_spi_dev_path())
print(opc)
print("-")

Expand Down

0 comments on commit cbaecee

Please sign in to comment.