From 5844e51cf849041ee5b3bece6594f611adf00f84 Mon Sep 17 00:00:00 2001 From: Jeroen Oudshoorn Date: Fri, 12 Jan 2024 21:22:49 +0100 Subject: [PATCH] Version 2.6.6 --- pwnagotchi/_version.py | 2 +- pwnagotchi/ui/hw/libs/waveshare/epdconfig.py | 78 +++++++++++++++----- 2 files changed, 59 insertions(+), 21 deletions(-) diff --git a/pwnagotchi/_version.py b/pwnagotchi/_version.py index 5341d43a..4ebf01eb 100644 --- a/pwnagotchi/_version.py +++ b/pwnagotchi/_version.py @@ -1 +1 @@ -__version__ = '2.6.5' +__version__ = '2.6.6' diff --git a/pwnagotchi/ui/hw/libs/waveshare/epdconfig.py b/pwnagotchi/ui/hw/libs/waveshare/epdconfig.py index 72dfd076..9f317df8 100644 --- a/pwnagotchi/ui/hw/libs/waveshare/epdconfig.py +++ b/pwnagotchi/ui/hw/libs/waveshare/epdconfig.py @@ -31,6 +31,7 @@ import os import logging import sys import time +import subprocess logger = logging.getLogger(__name__) @@ -45,16 +46,48 @@ class RaspberryPi: def __init__(self): import spidev - import RPi.GPIO + import gpiozero - self.GPIO = RPi.GPIO 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): - self.GPIO.output(pin, value) + if pin == self.RST_PIN: + 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): - return self.GPIO.input(pin) + if pin == self.BUSY_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): time.sleep(delaytime / 1000.0) @@ -66,15 +99,7 @@ class RaspberryPi: self.SPI.writebytes2(data) def module_init(self): - 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) + self.GPIO_PWR_PIN.on() # SPI device, bus = 0, device = 0 self.SPI.open(0, 0) @@ -82,16 +107,21 @@ class RaspberryPi: self.SPI.mode = 0b00 return 0 - def module_exit(self): + def module_exit(self, cleanup=False): logger.debug("spi end") 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 ...") - self.GPIO.output(self.RST_PIN, 0) - self.GPIO.output(self.DC_PIN, 0) - self.GPIO.output(self.PWR_PIN, 0) - self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN, self.PWR_PIN]) + if cleanup: + 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: @@ -230,12 +260,20 @@ class SunriseX3: self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN], self.PWR_PIN) -if os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'): +if sys.version_info[0] == 2: + 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() elif os.path.exists('/sys/bus/platform/drivers/gpio-x3'): implementation = SunriseX3() else: - implementation = RaspberryPi() + implementation = JetsonNano() for func in [x for x in dir(implementation) if not x.startswith('_')]: setattr(sys.modules[__name__], func, getattr(implementation, func))