Try another fix
This commit is contained in:
parent
2c0f05dd77
commit
34e68e2a9e
1 changed files with 10 additions and 4 deletions
|
@ -4,6 +4,7 @@ import multiprocessing
|
||||||
from enum import IntEnum
|
from enum import IntEnum
|
||||||
import time
|
import time
|
||||||
import sys
|
import sys
|
||||||
|
import random
|
||||||
|
|
||||||
from compLib.LogstashLogging import Logging
|
from compLib.LogstashLogging import Logging
|
||||||
|
|
||||||
|
@ -17,6 +18,7 @@ SPI_HEALTH = True
|
||||||
spi_found = importlib.util.find_spec("spidev") is not None
|
spi_found = importlib.util.find_spec("spidev") is not None
|
||||||
spi = None
|
spi = None
|
||||||
spi_lock = multiprocessing.Lock()
|
spi_lock = multiprocessing.Lock()
|
||||||
|
last_spi_call = time.time()
|
||||||
if spi_found:
|
if spi_found:
|
||||||
import spidev
|
import spidev
|
||||||
spi = spidev.SpiDev()
|
spi = spidev.SpiDev()
|
||||||
|
@ -123,9 +125,12 @@ class Spi(object):
|
||||||
|
|
||||||
if rx_buffer[1] != write_reg:
|
if rx_buffer[1] != write_reg:
|
||||||
Logging.get_logger().error(f"Warning! SPI error during read/write of register {write_reg}! Retrying automagically")
|
Logging.get_logger().error(f"Warning! SPI error during read/write of register {write_reg}! Retrying automagically")
|
||||||
time.sleep(0.01)
|
time.sleep(random.uniform(0.0, 0.1))
|
||||||
return Spi.transfer(tx_buffer_copy)
|
return Spi.transfer(tx_buffer_copy)
|
||||||
|
|
||||||
|
global last_spi_call
|
||||||
|
last_spi_call = time.time()
|
||||||
|
|
||||||
return rx_buffer
|
return rx_buffer
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
|
@ -204,8 +209,9 @@ class Spi(object):
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def health_check_loop():
|
def health_check_loop():
|
||||||
while SPI_HEALTH:
|
while SPI_HEALTH:
|
||||||
Spi.health_check()
|
if last_spi_call + 0.75 < time.time():
|
||||||
time.sleep(0.75)
|
Spi.health_check()
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_version():
|
def get_version():
|
||||||
|
|
Reference in a new issue