From 879e0b97a05a71a22eeba34e0f90f498c9ec7fa7 Mon Sep 17 00:00:00 2001 From: Adrian Granados Date: Tue, 2 Apr 2024 17:31:21 -0400 Subject: [PATCH] Experimental support for the 240x240 1.3in display hat --- debian/changelog | 6 ++++ fpms/modules/constants.py | 21 ++++++-------- fpms/modules/display.py | 9 ++++++ fpms/modules/env_utils.py | 18 +++++++++++- fpms/modules/wlanpi_oled.py | 56 +++++++++++++++++-------------------- 5 files changed, 67 insertions(+), 43 deletions(-) create mode 100644 fpms/modules/display.py diff --git a/debian/changelog b/debian/changelog index 02fe9c3..b3493fd 100644 --- a/debian/changelog +++ b/debian/changelog @@ -1,3 +1,9 @@ +wlanpi-fpms (1.3.7) unstable; urgency=medium + + * Experimental support for the 240x240 1.3in display hat + + -- Adrian Granados Tue, 02 Apr 2024 00:00:00 -0500 + wlanpi-fpms (1.3.6) unstable; urgency=medium * Add option to set regulatory domain to NL diff --git a/fpms/modules/constants.py b/fpms/modules/constants.py index ee0ff0d..59d72c5 100644 --- a/fpms/modules/constants.py +++ b/fpms/modules/constants.py @@ -9,32 +9,29 @@ import pathlib from fpms.modules.env_utils import EnvUtils from fpms.modules.platform import * +from fpms.modules.display import * __version__ = "2.0.3" __author__ = "wifinigel@gmail.com" env_util = EnvUtils() PLATFORM = env_util.get_platform() +DISPLAY_TYPE = env_util.get_display_type() +# Uncomment the line below to force a display type +#DISPLAY_TYPE = DISPLAY_TYPE_ST7789 -# set misc vars depending on platform type -#HEIGHT_OFFSET = 0 -#IMAGE_DIR = "images/128x64" -#MAX_TABLE_LINES = 4 -#MAX_PAGE_LINES = 3 -#DISPLAY_MODE = '1' - -HEIGHT_OFFSET = 64 IMAGE_DIR = "images/128x128" MAX_TABLE_LINES = 9 MAX_PAGE_LINES = 8 DISPLAY_MODE = 'RGB' -PAGE_SLEEP = 300 # Time in secs before sleep -PAGE_WIDTH = 128 # Pixel size of screen width -PAGE_HEIGHT = 64 + HEIGHT_OFFSET # Pixel size of screen height -NAV_BAR_TOP = 54 + HEIGHT_OFFSET # Top pixel number of nav bar +PAGE_SLEEP = 300 # Time in secs before sleep +PAGE_WIDTH = 128 # Pixel size of screen width +PAGE_HEIGHT = 128 # Pixel size of screen height +NAV_BAR_TOP = PAGE_HEIGHT - 10 # Top pixel number of nav bar STATUS_BAR_HEIGHT = 16 SYSTEM_BAR_HEIGHT = 15 + MENU_VERSION = __version__ # fpms version # figure out the script path diff --git a/fpms/modules/display.py b/fpms/modules/display.py new file mode 100644 index 0000000..e2b1d9c --- /dev/null +++ b/fpms/modules/display.py @@ -0,0 +1,9 @@ +# -*- coding: utf-8 -*- +# +""" +display.py - display types +""" + +DISPLAY_TYPE_SSD1351 = "ssd1351" +DISPLAY_TYPE_ST7735 = "st7735" +DISPLAY_TYPE_ST7789 = "st7789" diff --git a/fpms/modules/env_utils.py b/fpms/modules/env_utils.py index 91c0199..5bd039a 100644 --- a/fpms/modules/env_utils.py +++ b/fpms/modules/env_utils.py @@ -14,11 +14,11 @@ from PIL import Image from fpms.modules.platform import * +from fpms.modules.display import * class EnvUtils(object): def __init__(self): - pass def get_platform(self): @@ -51,6 +51,7 @@ def get_platform(self): return platform + def get_platform_name(self): platform = self.get_platform() @@ -60,6 +61,17 @@ def get_platform_name(self): else: return PLATFORM_NAME_GENERIC + " " + platform + + def get_display_type(self): + + platform = self.get_platform() + + if platform == PLATFORM_PRO: + return DISPLAY_TYPE_SSD1351 + else: + return DISPLAY_TYPE_ST7735 + + def get_mode(self, MODE_FILE): valid_modes = ['classic', 'wconsole', 'hotspot', 'wiperf', 'server', 'bridge'] @@ -81,6 +93,7 @@ def get_mode(self, MODE_FILE): return current_mode + def get_image_ver(self, WLANPI_IMAGE_FILE): wlanpi_ver = "unknown" @@ -98,6 +111,7 @@ def get_image_ver(self, WLANPI_IMAGE_FILE): return wlanpi_ver + def get_hostname(self): try: @@ -117,6 +131,7 @@ def get_hostname(self): return None + def get_wifi_qrcode_for_hostapd(self): ''' Generates and returns the path to a WiFi QR code for the current Hostapd config. @@ -133,6 +148,7 @@ def get_wifi_qrcode_for_hostapd(self): return None + def get_wifi_qrcode(self, ssid, passphrase): qrcode_spec = "WIFI:S:{};T:WPA;P:{};;".format(ssid, passphrase) qrcode_hash = hashlib.sha1(qrcode_spec.encode()).hexdigest() diff --git a/fpms/modules/wlanpi_oled.py b/fpms/modules/wlanpi_oled.py index 2890f81..084eaba 100644 --- a/fpms/modules/wlanpi_oled.py +++ b/fpms/modules/wlanpi_oled.py @@ -5,18 +5,18 @@ from PIL import Image import sys import logging -from fpms.modules.constants import PLATFORM +from fpms.modules.constants import PLATFORM, DISPLAY_TYPE +from fpms.modules.display import * from fpms.modules.platform import * # set possible vars to None -DISPLAY_TYPE = None I2C_PORT = None SPI_BUS_SPEED = None I2C_ADDRESS = None INTERFACE_TYPE = None WIDTH = None HEIGHT = None -COLOR_ORDER_BGR = False +COLOR_ORDER_BGR = True GPIO_DATA_COMMAND = None GPIO_RESET = None GPIO_BACKLIGHT = None @@ -25,21 +25,17 @@ H_OFFSET = None V_OFFSET = None -if PLATFORM == PLATFORM_PRO: +if DISPLAY_TYPE == DISPLAY_TYPE_SSD1351: # ssd1351 128 x 128 - DISPLAY_TYPE = "ssd1351" INTERFACE_TYPE = "spi" WIDTH = "128" HEIGHT = "128" - COLOR_ORDER_BGR = True -else: - # 1.44 in LCD Display HAT settings - DISPLAY_TYPE = "st7735" +elif DISPLAY_TYPE == DISPLAY_TYPE_ST7735: + # 128x128 1.44 in LCD Display HAT INTERFACE_TYPE = "gpio_cs_spi" SPI_BUS_SPEED = "2000000" WIDTH = "128" HEIGHT = "128" - COLOR_ORDER_BGR = True GPIO_DATA_COMMAND = "25" GPIO_RESET = "27" GPIO_BACKLIGHT = "24" @@ -47,24 +43,17 @@ BACKLIGHT_ACTIVE = "high" H_OFFSET = "1" V_OFFSET = "2" - -# Sapphire HAT OLED settings -#DISPLAY_TYPE = "sh1106" -#I2C_PORT = "0" -#WIDTH = "128" -#HEIGHT = "64" - -### Legacy settings here for other displays ### -# Neo 2 OLED settings -#DISPLAY_TYPE = "ssd1306" -#I2C_PORT = 0 - -# ssd1327 128 x 128 -#DISPLAY_TYPE = "ssd1327" -#I2C_ADDRESS = "0x3d" -#WIDTH = "128" -#HEIGHT = "128" - +elif DISPLAY_TYPE == DISPLAY_TYPE_ST7789: + # 240x240 1.3 in LCD Display HAT + INTERFACE_TYPE = "gpio_cs_spi" + SPI_BUS_SPEED = "52000000" + WIDTH = "240" + HEIGHT = "240" + GPIO_DATA_COMMAND = "25" + GPIO_RESET = "27" + GPIO_BACKLIGHT = "24" + GPIO_CS = "8" + BACKLIGHT_ACTIVE = "high" ''' ### This code is borrowed from https://github.com/rm-hull/luma.examples/blob/master/examples/demo_opts.py @@ -78,6 +67,9 @@ # ignore PIL debug messages logging.getLogger('PIL').setLevel(logging.ERROR) +DISPLAY_WIDTH = int(WIDTH) +DISPLAY_HEIGHT = int(HEIGHT) + def display_settings(device, args): """ Display a short summary of the settings. @@ -205,8 +197,12 @@ def setHorizontalMode(): return True def drawImage(image): - device.display(image.convert(device.mode)) - #device.display(image) + img = image.convert(device.mode) + width, height = img.size + if DISPLAY_WIDTH != width or DISPLAY_HEIGHT != height: + img = img.resize((DISPLAY_WIDTH, DISPLAY_HEIGHT), Image.LANCZOS) + + device.display(img) def clear(): #blank = Image.new("RGBA", device.size, "black")