Compare commits

..

1 Commits

Author SHA1 Message Date
d259e862ba Version 2.6.7 2024-01-12 22:33:08 +01:00
2 changed files with 21 additions and 59 deletions

View File

@ -1 +1 @@
__version__ = '2.6.6' __version__ = '2.6.7'

View File

@ -31,7 +31,6 @@ import os
import logging import logging
import sys import sys
import time import time
import subprocess
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
@ -46,48 +45,16 @@ class RaspberryPi:
def __init__(self): def __init__(self):
import spidev import spidev
import gpiozero import RPi.GPIO
self.GPIO = RPi.GPIO
self.SPI = spidev.SpiDev() self.SPI = spidev.SpiDev()
self.GPIO_RST_PIN = gpiozero.LED(self.RST_PIN)
self.GPIO_DC_PIN = gpiozero.LED(self.DC_PIN)
# self.GPIO_CS_PIN = gpiozero.LED(self.CS_PIN)
self.GPIO_PWR_PIN = gpiozero.LED(self.PWR_PIN)
self.GPIO_BUSY_PIN = gpiozero.Button(self.BUSY_PIN, pull_up=False)
def digital_write(self, pin, value): def digital_write(self, pin, value):
if pin == self.RST_PIN: self.GPIO.output(pin, value)
if value:
self.GPIO_RST_PIN.on()
else:
self.GPIO_RST_PIN.off()
elif pin == self.DC_PIN:
if value:
self.GPIO_DC_PIN.on()
else:
self.GPIO_DC_PIN.off()
# elif pin == self.CS_PIN:
# if value:
# self.GPIO_CS_PIN.on()
# else:
# self.GPIO_CS_PIN.off()
elif pin == self.PWR_PIN:
if value:
self.GPIO_PWR_PIN.on()
else:
self.GPIO_PWR_PIN.off()
def digital_read(self, pin): def digital_read(self, pin):
if pin == self.BUSY_PIN: return self.GPIO.input(pin)
return self.GPIO_BUSY_PIN.value
elif pin == self.RST_PIN:
return self.RST_PIN.value
elif pin == self.DC_PIN:
return self.DC_PIN.value
# elif pin == self.CS_PIN:
# return self.CS_PIN.value
elif pin == self.PWR_PIN:
return self.PWR_PIN.value
def delay_ms(self, delaytime): def delay_ms(self, delaytime):
time.sleep(delaytime / 1000.0) time.sleep(delaytime / 1000.0)
@ -99,7 +66,15 @@ class RaspberryPi:
self.SPI.writebytes2(data) self.SPI.writebytes2(data)
def module_init(self): def module_init(self):
self.GPIO_PWR_PIN.on() self.GPIO.setmode(self.GPIO.BCM)
self.GPIO.setwarnings(False)
self.GPIO.setup(self.RST_PIN, self.GPIO.OUT)
self.GPIO.setup(self.DC_PIN, self.GPIO.OUT)
self.GPIO.setup(self.CS_PIN, self.GPIO.OUT)
self.GPIO.setup(self.PWR_PIN, self.GPIO.OUT)
self.GPIO.setup(self.BUSY_PIN, self.GPIO.IN)
self.GPIO.output(self.PWR_PIN, 1)
# SPI device, bus = 0, device = 0 # SPI device, bus = 0, device = 0
self.SPI.open(0, 0) self.SPI.open(0, 0)
@ -107,21 +82,16 @@ class RaspberryPi:
self.SPI.mode = 0b00 self.SPI.mode = 0b00
return 0 return 0
def module_exit(self, cleanup=False): def module_exit(self):
logger.debug("spi end") logger.debug("spi end")
self.SPI.close() self.SPI.close()
self.GPIO_RST_PIN.off()
self.GPIO_DC_PIN.off()
self.GPIO_PWR_PIN.off()
logger.debug("close 5V, Module enters 0 power consumption ...") logger.debug("close 5V, Module enters 0 power consumption ...")
self.GPIO.output(self.RST_PIN, 0)
self.GPIO.output(self.DC_PIN, 0)
self.GPIO.output(self.PWR_PIN, 0)
if cleanup: self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN, self.PWR_PIN])
self.GPIO_RST_PIN.close()
self.GPIO_DC_PIN.close()
# self.GPIO_CS_PIN.close()
self.GPIO_PWR_PIN.close()
self.GPIO_BUSY_PIN.close()
class JetsonNano: class JetsonNano:
@ -260,20 +230,12 @@ class SunriseX3:
self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN], self.PWR_PIN) self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN], self.PWR_PIN)
if sys.version_info[0] == 2: if os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'):
process = subprocess.Popen("cat /proc/cpuinfo | grep Raspberry", shell=True, stdout=subprocess.PIPE)
else:
process = subprocess.Popen("cat /proc/cpuinfo | grep Raspberry", shell=True, stdout=subprocess.PIPE, text=True)
output, _ = process.communicate()
if sys.version_info[0] == 2:
output = output.decode(sys.stdout.encoding)
if "Raspberry" in output:
implementation = RaspberryPi() implementation = RaspberryPi()
elif os.path.exists('/sys/bus/platform/drivers/gpio-x3'): elif os.path.exists('/sys/bus/platform/drivers/gpio-x3'):
implementation = SunriseX3() implementation = SunriseX3()
else: else:
implementation = JetsonNano() implementation = RaspberryPi()
for func in [x for x in dir(implementation) if not x.startswith('_')]: for func in [x for x in dir(implementation) if not x.startswith('_')]:
setattr(sys.modules[__name__], func, getattr(implementation, func)) setattr(sys.modules[__name__], func, getattr(implementation, func))