Skip to content

Commit

Permalink
improve (st7789)
Browse files Browse the repository at this point in the history
  • Loading branch information
hishizuka committed Feb 13, 2024
1 parent 60e3fc5 commit 14f0eff
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
8 changes: 5 additions & 3 deletions modules/button_config.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import copy

class Button_Config:
config = None

Expand Down Expand Up @@ -177,9 +179,9 @@ class Button_Config:
"Pirate_Audio_old": {},
"Display_HAT_Mini": {},
}
# copy button definition
G_BUTTON_DEF["Display_HAT_Mini"] = G_BUTTON_DEF["Pirate_Audio"]
G_BUTTON_DEF["Pirate_Audio_old"] = G_BUTTON_DEF["Pirate_Audio"]
# copy button definition
G_BUTTON_DEF["Display_HAT_Mini"] = copy.deepcopy(G_BUTTON_DEF["Pirate_Audio"])
G_BUTTON_DEF["Pirate_Audio_old"] = copy.deepcopy(G_BUTTON_DEF["Pirate_Audio"])
for k in G_BUTTON_DEF["Pirate_Audio_old"]:
# Y key is GPIO 20, not 24
G_BUTTON_DEF["Pirate_Audio_old"][k][20] = G_BUTTON_DEF["Pirate_Audio_old"][k].pop(24)
Expand Down
27 changes: 18 additions & 9 deletions modules/display/st7789_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
_SENSOR_DISPLAY = False
try:
from ST7789 import ST7789
import pigpio
#import pigpio

_SENSOR_DISPLAY = True
except ImportError:
Expand All @@ -19,6 +19,7 @@

class ST7789Display(Display):
st7789 = None
rotation = 90
blank_buffer = None
blank_draw = None
# backlight = None
Expand All @@ -30,7 +31,8 @@ class ST7789Display(Display):
send = True

brightness = 100
brightness_table = [0, 1, 2, 3, 4, 5, 10, 50, 100]
#brightness_table = [0, 1, 2, 3, 4, 5, 10, 50, 100]
brightness_table = [0, 100]
brightness_index = len(brightness_table)-1

size = (240, 240)
Expand All @@ -40,24 +42,27 @@ def __init__(self, config, size=None):

if size:
self.size = size
self.rotation = 180

self.st7789 = ST7789(
height=self.size[0],
height=self.size[1],
width=self.size[0],
rotation=self.rotation,
port=0,
cs=1,
dc=9,
backlight=None,
spi_speed_hz=80 * 1000 * 1000,
#backlight=None,
backlight=13,
spi_speed_hz=120 * 1000 * 1000,
offset_left=0,
offset_top=0,
)
self.st7789.begin()

# backlight
self.pi = pigpio.pi()
self.pi.set_mode(GPIO_BACKLIGHT, pigpio.OUTPUT)
self.pi.hardware_PWM(GPIO_BACKLIGHT, GPIO_BACKLIGHT_FREQ, 100 * 10000)
#self.pi = pigpio.pi()
#self.pi.set_mode(GPIO_BACKLIGHT, pigpio.OUTPUT)
#self.pi.hardware_PWM(GPIO_BACKLIGHT, GPIO_BACKLIGHT_FREQ, 100 * 10000)

self.blank_buffer = Image.new("RGB", self.size)
self.blank_draw = ImageDraw.Draw(self.blank_buffer)
Expand All @@ -78,5 +83,9 @@ def update(self, im_array, direct_update=False):
def set_brightness(self, b):
if b == self.brightness:
return
self.pi.hardware_PWM(GPIO_BACKLIGHT, GPIO_BACKLIGHT_FREQ, b * 10000)
#self.pi.hardware_PWM(GPIO_BACKLIGHT, GPIO_BACKLIGHT_FREQ, b * 10000)
if b == 0:
self.st7789.set_backlight(False)
else:
self.st7789.set_backlight(True)
self.brightness = b

0 comments on commit 14f0eff

Please sign in to comment.