Skip to content

Commit

Permalink
Experimental support for the 240x240 1.3in display hat
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangranados committed Apr 2, 2024
1 parent c649211 commit 879e0b9
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 43 deletions.
6 changes: 6 additions & 0 deletions debian/changelog
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
wlanpi-fpms (1.3.7) unstable; urgency=medium

* Experimental support for the 240x240 1.3in display hat

-- Adrian Granados <[email protected]> Tue, 02 Apr 2024 00:00:00 -0500

wlanpi-fpms (1.3.6) unstable; urgency=medium

* Add option to set regulatory domain to NL
Expand Down
21 changes: 9 additions & 12 deletions fpms/modules/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__ = "[email protected]"

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
Expand Down
9 changes: 9 additions & 0 deletions fpms/modules/display.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# -*- coding: utf-8 -*-
#
"""
display.py - display types
"""

DISPLAY_TYPE_SSD1351 = "ssd1351"
DISPLAY_TYPE_ST7735 = "st7735"
DISPLAY_TYPE_ST7789 = "st7789"
18 changes: 17 additions & 1 deletion fpms/modules/env_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -51,6 +51,7 @@ def get_platform(self):

return platform


def get_platform_name(self):

platform = self.get_platform()
Expand All @@ -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']
Expand All @@ -81,6 +93,7 @@ def get_mode(self, MODE_FILE):

return current_mode


def get_image_ver(self, WLANPI_IMAGE_FILE):

wlanpi_ver = "unknown"
Expand All @@ -98,6 +111,7 @@ def get_image_ver(self, WLANPI_IMAGE_FILE):

return wlanpi_ver


def get_hostname(self):

try:
Expand All @@ -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.
Expand All @@ -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()
Expand Down
56 changes: 26 additions & 30 deletions fpms/modules/wlanpi_oled.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -25,46 +25,35 @@
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"
GPIO_CS = "8"
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
Expand All @@ -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.
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 879e0b9

Please sign in to comment.