Skip to content

Commit

Permalink
Merge pull request #101 from weberbox/dev_displays
Browse files Browse the repository at this point in the history
@weberbox Added 240x320 ST7789 display modules with no input, button input and adjusted encoder support. Added a display rotation setting to ILI9341 and ST7789 displays in the wizard setup. Removed endswith('b') for display buttons modules and added buttonslevel and rotation variables to all displays. Updated wizard to convert number strings to int or float. A couple bugfixes in display modules (missing network in pygame, self._display_canvas(img) outside of menuactive, Added spidev back to ili9341_em module, missing socket in ssd1306).
  • Loading branch information
nebhead authored May 20, 2022
2 parents c249f89 + d3d531b commit 8c2474a
Show file tree
Hide file tree
Showing 23 changed files with 1,742 additions and 124 deletions.
1 change: 1 addition & 0 deletions common.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ def DefaultSettings():
'page_theme' : 'light',
'triggerlevel' : 'LOW',
'buttonslevel' : 'HIGH',
'disp_rotation' : 0,
'shutdown_timer' : 60,
'startup_timer' : 240,
'auto_power_off' : False,
Expand Down
8 changes: 3 additions & 5 deletions control.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
inpins = settings['inpins']
triggerlevel = settings['globals']['triggerlevel']
buttonslevel = settings['globals']['buttonslevel']
disp_rotation = settings['globals']['disp_rotation']
units = settings['globals']['units']

if triggerlevel == 'LOW':
Expand Down Expand Up @@ -177,13 +178,10 @@
raise

try:
if str(settings['modules']['display']).endswith('b'):
display_device = DisplayModule.Display(buttonslevel=buttonslevel, units=units)
else:
display_device = DisplayModule.Display(units=units)
display_device = DisplayModule.Display(buttonslevel=buttonslevel, rotation=disp_rotation, units=units)
except:
from display_none import Display # Simulated Library for controlling the grill platform
display_device = Display(units=units)
display_device = Display(buttonslevel=buttonslevel, rotation=disp_rotation, units=units)
error_event = f'An error occured configuring the [{settings["modules"]["display"]}] display object. The "display_none" module has been loaded instead. This sometimes means that the hardware is not connected properly, or the module is not configured. Please run the configuration wizard again from the admin panel to fix this issue.'
errors.append(error_event)
WriteErrors(errors)
Expand Down
5 changes: 3 additions & 2 deletions display_ili9341.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@
'''
class Display:

def __init__(self, units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.rotation = rotation
self.units = units
self.displayactive = False
self.in_data = None
Expand All @@ -55,7 +56,7 @@ def _init_globals(self):
def _init_display_device(self):
# Init Device
self.serial = spi(port=0, device=0, gpio_DC=24, gpio_RST=25, bus_speed_hz=32000000, reset_hold_time=0.2, reset_release_time=0.2)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=5)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=5, rotate=self.rotation)

# Setup & Start Display Loop Thread
display_thread = threading.Thread(target=self._display_loop)
Expand Down
7 changes: 4 additions & 3 deletions display_ili9341b.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
'''
class Display:

def __init__(self, buttonslevel='HIGH', units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.buttonslevel = buttonslevel
self.rotation = rotation
self.units = units
self.displayactive = False
self.in_data = None
Expand All @@ -60,7 +61,7 @@ def _init_globals(self):
def _init_display_device(self):
# Init Device
self.serial = spi(port=0, device=0, gpio_DC=24, gpio_RST=25, bus_speed_hz=32000000, reset_hold_time=0.2, reset_release_time=0.2)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=5)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=5, rotate=self.rotation)

# Setup & Start Display Loop Thread
display_thread = threading.Thread(target=self._display_loop)
Expand Down Expand Up @@ -626,7 +627,7 @@ def _display_current(self, in_data, status_data):
draw.text((self.WIDTH // 2 - font_width // 2, self.HEIGHT - font_height - 6), text, font=font,
fill=(0, 0, 0))

self._display_canvas(img)
self._display_canvas(img)

'''
====================== Input & Menu Code ========================
Expand Down
6 changes: 3 additions & 3 deletions display_ili9341e.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import time
import socket
import qrcode
import spidev
import threading
from luma.core.interface.serial import spi
from luma.lcd.device import ili9341
Expand All @@ -33,8 +32,9 @@
'''
class Display:

def __init__(self, units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.rotation = rotation
self.units = units
self.displayactive = False
self.in_data = None
Expand All @@ -60,7 +60,7 @@ def _init_globals(self):
def _init_display_device(self):
# Init Device
self.serial = spi(port=0, device=0, gpio_DC=24, gpio_RST=25, bus_speed_hz=32000000, reset_hold_time=0.2, reset_release_time=0.2)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=5)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=5, rotate=self.rotation)

# Setup & Start Display Loop Thread
display_thread = threading.Thread(target=self._display_loop)
Expand Down
7 changes: 4 additions & 3 deletions display_ili9341em.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
'''
class Display:

def __init__(self, units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.rotation = rotation
self.units = units
self.displayactive = False
self.in_data = None
Expand All @@ -60,8 +61,8 @@ def _init_globals(self):

def _init_display_device(self):
# Init Device
self.serial = spi(port=0, device=0, gpio_DC=16, gpio_RST=20, bus_speed_hz=32000000, reset_hold_time=0.2, reset_release_time=0.2)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=12)
self.serial = spi(spi=spidev.SpiDev(), port=0, device=0, gpio_DC=16, gpio_RST=20, bus_speed_hz=32000000, reset_hold_time=0.2, reset_release_time=0.2)
self.device = ili9341(self.serial, active_low=False, width=self.WIDTH, height=self.HEIGHT, gpio_LIGHT=12, rotate=self.rotation)

# Setup & Start Display Loop Thread
display_thread = threading.Thread(target=self._display_loop)
Expand Down
2 changes: 1 addition & 1 deletion display_none.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

class Display:

def __init__(self, units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
self.display_splash()

def display_status(self, in_data, status_data):
Expand Down
2 changes: 1 addition & 1 deletion display_prototype.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

class Display:

def __init__(self, units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
self.display_splash()
self.units = units

Expand Down
2 changes: 1 addition & 1 deletion display_pygame_240x320.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'''
class Display:

def __init__(self, units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.units = units
self.displayactive = False
Expand Down
2 changes: 1 addition & 1 deletion display_pygame_240x320b.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
'''
class Display:

def __init__(self, buttonslevel='HIGH', units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.buttonslevel = buttonslevel
self.units = units
Expand Down
28 changes: 26 additions & 2 deletions display_pygame_64x128.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
'''
class Display:

def __init__(self, units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.units = units
self.displayactive = False
Expand Down Expand Up @@ -174,7 +174,31 @@ def _display_text(self):
self.display_surface.fill((255,255,255))
self.display_surface.blit(self.display_image, (0, 0))

pygame.display.update()
pygame.display.update()

def _display_network(self, networkip):
# Create canvas
img = Image.new('RGB', (self.WIDTH, self.HEIGHT), color=(255, 255, 255))
img_qr = qrcode.make('http://' + networkip)
img_qr_width, img_qr_height = img_qr.size
img_qr_width *= 2
img_qr_height *= 2
w = min(self.WIDTH, self.HEIGHT)
new_image = img_qr.resize((w, w))
position = (int((self.WIDTH/2)-(w/2)), 0)
img.paste(new_image, position)

# Convert to PyGame and Display
strFormat = img.mode
size = img.size
raw_str = img.tobytes("raw", strFormat)

self.display_image = pygame.image.fromstring(raw_str, size, strFormat)

self.display_surface.fill((255,255,255))
self.display_surface.blit(self.display_image, (0, 0))

pygame.display.update()

def _display_current(self, in_data, status_data):
self.units = status_data['units']
Expand Down
3 changes: 2 additions & 1 deletion display_ssd1306.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'''
import time
import threading
import socket
from luma.core.interface.serial import i2c
from luma.core.render import canvas
from luma.oled.device import ssd1306
Expand All @@ -28,7 +29,7 @@
'''
class Display:

def __init__(self, units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.units = units
self.displayactive = False
Expand Down
2 changes: 1 addition & 1 deletion display_ssd1306b.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
'''
class Display:

def __init__(self, buttonslevel='HIGH', units='F'):
def __init__(self, buttonslevel='HIGH', rotation=0, units='F'):
# Init Global Variables and Constants
self.buttonslevel = buttonslevel
self.units = units
Expand Down
Loading

0 comments on commit 8c2474a

Please sign in to comment.