Add local development to SPI
This commit is contained in:
parent
881f8ddbf8
commit
eafad7ccdb
1 changed files with 14 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
||||||
import spidev
|
import importlib
|
||||||
from threading import Thread, Lock
|
from threading import Thread, Lock
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
import time
|
import time
|
||||||
|
@ -12,13 +12,17 @@ SPI_SPEED = 1000000
|
||||||
SPI_BUFFER_SIZE = 32
|
SPI_BUFFER_SIZE = 32
|
||||||
SPI_HEALTH = True
|
SPI_HEALTH = True
|
||||||
|
|
||||||
spi = spidev.SpiDev()
|
# For development purposes
|
||||||
spi.open(SPI_BUS, SPI_DEVICE)
|
spi_found = importlib.util.find_spec("spidev") is not None
|
||||||
spi.max_speed_hz = SPI_SPEED
|
spi = None
|
||||||
spi.mode = 0
|
if spi_found:
|
||||||
spi.bits_per_word = 8
|
spi = spidev.SpiDev()
|
||||||
|
spi.open(SPI_BUS, SPI_DEVICE)
|
||||||
|
spi.max_speed_hz = SPI_SPEED
|
||||||
|
spi.mode = 0
|
||||||
|
spi.bits_per_word = 8
|
||||||
|
|
||||||
spi_mutex = Lock()
|
spi_mutex = Lock()
|
||||||
|
|
||||||
class Register(IntEnum):
|
class Register(IntEnum):
|
||||||
IDENTIFICATION_MODEL_ID = 1,
|
IDENTIFICATION_MODEL_ID = 1,
|
||||||
|
@ -106,6 +110,9 @@ class Spi(object):
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def transfer(tx_buffer: list):
|
def transfer(tx_buffer: list):
|
||||||
|
if not spi_found:
|
||||||
|
return [] * SPI_BUFFER_SIZE
|
||||||
|
|
||||||
write_reg = tx_buffer[1]
|
write_reg = tx_buffer[1]
|
||||||
|
|
||||||
spi.xfer(tx_buffer)
|
spi.xfer(tx_buffer)
|
||||||
|
|
Reference in a new issue