Skip to content

Commit

Permalink
Version 2.6.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jayofelony committed Jan 12, 2024
1 parent 5844e51 commit d259e86
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 59 deletions.
2 changes: 1 addition & 1 deletion pwnagotchi/_version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '2.6.6'
__version__ = '2.6.7'
78 changes: 20 additions & 58 deletions pwnagotchi/ui/hw/libs/waveshare/epdconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import logging
import sys
import time
import subprocess

logger = logging.getLogger(__name__)

Expand All @@ -46,48 +45,16 @@ class RaspberryPi:

def __init__(self):
import spidev
import gpiozero
import RPi.GPIO

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):
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()
self.GPIO.output(pin, value)

def digital_read(self, 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
return self.GPIO.input(pin)

def delay_ms(self, delaytime):
time.sleep(delaytime / 1000.0)
Expand All @@ -99,29 +66,32 @@ def spi_writebyte2(self, data):
self.SPI.writebytes2(data)

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
self.SPI.open(0, 0)
self.SPI.max_speed_hz = 4000000
self.SPI.mode = 0b00
return 0

def module_exit(self, cleanup=False):
def module_exit(self):
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)

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()
self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN, self.PWR_PIN])


class JetsonNano:
Expand Down Expand Up @@ -260,20 +230,12 @@ def module_exit(self):
self.GPIO.cleanup([self.RST_PIN, self.DC_PIN, self.CS_PIN, self.BUSY_PIN], self.PWR_PIN)


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:
if os.path.exists('/sys/bus/platform/drivers/gpiomem-bcm2835'):
implementation = RaspberryPi()
elif os.path.exists('/sys/bus/platform/drivers/gpio-x3'):
implementation = SunriseX3()
else:
implementation = JetsonNano()
implementation = RaspberryPi()

for func in [x for x in dir(implementation) if not x.startswith('_')]:
setattr(sys.modules[__name__], func, getattr(implementation, func))
Expand Down

0 comments on commit d259e86

Please sign in to comment.