Skip to content

Commit 0215fce

Browse files
committed
improve fallback logic with deinit and reusable display init
1 parent 0d38659 commit 0215fce

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

Fruit_Jam/Larsio_Paint_Music/display_manager.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import picodvi
1212
import framebufferio
1313
import board
14+
from adafruit_fruitjam.peripherals import request_display_config
1415

1516

1617

@@ -26,20 +27,13 @@ def __init__(self, width=320, height=240):
2627

2728
def initialize_display(self):
2829
"""Initialize the DVI display"""
29-
# Release any existing displays
30-
displayio.release_displays()
30+
# Use the Fruit Jam library to set up display, that way on DAC fallback
31+
# the display doesn't attempt to be re-initialized
3132

32-
# Initialize the DVI framebuffer
33-
fb = picodvi.Framebuffer(self.SCREEN_WIDTH, self.SCREEN_HEIGHT,
34-
clk_dp=board.CKP, clk_dn=board.CKN,
35-
red_dp=board.D0P, red_dn=board.D0N,
36-
green_dp=board.D1P, green_dn=board.D1N,
37-
blue_dp=board.D2P, blue_dn=board.D2N,
38-
color_depth=16)
33+
request_display_config(self.SCREEN_WIDTH, self.SCREEN_HEIGHT,color_depth=16)
3934

4035
# Create the display
41-
self.display = framebufferio.FramebufferDisplay(fb)
42-
supervisor.runtime.display = self.display # Keep display on in runtime info
36+
self.display = supervisor.runtime.display
4337

4438
# Create main group
4539
self.main_group = displayio.Group()

Fruit_Jam/Larsio_Paint_Music/input_handler.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(self, screen_width, screen_height, staff_y_start, staff_height):
3535
self.mouse_y = (screen_height // 2) * self.sensitivity
3636

3737
def find_mouse(self):
38-
self.mouse = find_and_init_boot_mouse()
38+
self.mouse = find_and_init_boot_mouse(cursor_image="sprites/lars_note.bmp")
3939
if self.mouse is None:
4040
print("Failed to find a working mouse after multiple attempts")
4141
return False

Fruit_Jam/Larsio_Paint_Music/sound_manager.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ def __init__(self, audio_output="pwm", seconds_per_eighth=0.25):
126126
except Exception as e:
127127
print(f"Error initializing TLV320 DAC: {e}")
128128
print("Falling back to PWM audio output")
129+
fjPeriphs.deinit()
129130
# Fallback to PWM if I2S initialization fails
130131
self.audio = audiopwmio.PWMAudioOut(board.D10)
131132

0 commit comments

Comments
 (0)