|
| 1 | +import time |
| 2 | +from audiocore import WaveFile |
| 3 | +import audiobusio |
| 4 | +import board |
| 5 | +import supervisor |
| 6 | +from displayio import Group, TileGrid, OnDiskBitmap |
| 7 | +import adafruit_tlv320 |
| 8 | +from adafruit_fruitjam.peripherals import request_display_config |
| 9 | +from adafruit_progressbar.horizontalprogressbar import ( |
| 10 | + HorizontalFillDirection, |
| 11 | + HorizontalProgressBar, |
| 12 | +) |
| 13 | + |
| 14 | +# DAC setup |
| 15 | +i2c = board.I2C() |
| 16 | +dac = adafruit_tlv320.TLV320DAC3100(i2c) |
| 17 | +dac.configure_clocks(sample_rate=44100, bit_depth=16) |
| 18 | + |
| 19 | +# for headphone jack ouput |
| 20 | +dac.headphone_output = True |
| 21 | +dac.headphone_volume = -15 # dB |
| 22 | +# for speaker JST output |
| 23 | +# dac.speaker_output = True |
| 24 | +# dac.speaker_volume = -15 # dB |
| 25 | + |
| 26 | +# Chime audio setup |
| 27 | +wave_file = open( # pylint: disable=consider-using-with |
| 28 | + "mac_startup/mac_chime.wav", "rb" |
| 29 | +) |
| 30 | +wave = WaveFile(wave_file) |
| 31 | +audio = audiobusio.I2SOut(board.I2S_BCLK, board.I2S_WS, board.I2S_DIN) |
| 32 | + |
| 33 | +# Display setup |
| 34 | +request_display_config(640, 480) |
| 35 | +display = supervisor.runtime.display |
| 36 | +display.auto_refresh = False |
| 37 | + |
| 38 | +# group to hold visual all elements |
| 39 | +main_group = Group() |
| 40 | +display.root_group = main_group |
| 41 | +display.refresh() |
| 42 | + |
| 43 | +# background image |
| 44 | +bg_bmp = OnDiskBitmap("mac_startup/mac_startup_bg.bmp") |
| 45 | +bg_tg = TileGrid(bg_bmp, pixel_shader=bg_bmp.pixel_shader) |
| 46 | +main_group.append(bg_tg) |
| 47 | + |
| 48 | +# Icons for bottom left |
| 49 | +icons = [] |
| 50 | +for i in range(6): |
| 51 | + odb = OnDiskBitmap("mac_startup/mac_startup_icon{0}.bmp".format(i)) |
| 52 | + tg = TileGrid(odb, pixel_shader=odb.pixel_shader) |
| 53 | + icons.append( |
| 54 | + { |
| 55 | + "bmp": odb, |
| 56 | + "tg": tg, |
| 57 | + } |
| 58 | + ) |
| 59 | + tg.x = 10 + ((33 + 8) * i) |
| 60 | + tg.y = display.height - tg.tile_height - 10 |
| 61 | + tg.hidden = True |
| 62 | + if i < 5: |
| 63 | + odb.pixel_shader.make_transparent(0) |
| 64 | + main_group.append(tg) |
| 65 | + |
| 66 | +# progress bar in the welcome box |
| 67 | +progress_bar = HorizontalProgressBar( |
| 68 | + (147, 138), |
| 69 | + (346, 7), |
| 70 | + direction=HorizontalFillDirection.LEFT_TO_RIGHT, |
| 71 | + min_value=0, |
| 72 | + max_value=800, |
| 73 | + fill_color=0xC7BEFD, |
| 74 | + outline_color=0x000000, |
| 75 | + bar_color=0x3F3F3F, |
| 76 | + margin_size=0, |
| 77 | +) |
| 78 | +main_group.append(progress_bar) |
| 79 | + |
| 80 | +# play the chime sound |
| 81 | +audio.play(wave) |
| 82 | +while audio.playing: |
| 83 | + pass |
| 84 | + |
| 85 | +# start drawing the visual elements |
| 86 | +display.auto_refresh = True |
| 87 | +time.sleep(1) |
| 88 | +start_time = time.monotonic() |
| 89 | + |
| 90 | +while True: |
| 91 | + elapsed = time.monotonic() - start_time |
| 92 | + |
| 93 | + # if we haven't reached the end yet |
| 94 | + if elapsed * 100 <= 800: |
| 95 | + # update the progress bar |
| 96 | + progress_bar.value = elapsed * 100 |
| 97 | + |
| 98 | + else: # reached the end animation |
| 99 | + # set progress bar to max value |
| 100 | + progress_bar.value = 800 |
| 101 | + |
| 102 | + # loop over all icons |
| 103 | + for index, icon in enumerate(icons): |
| 104 | + # if it's time for the current icon to show, and it's still hidden |
| 105 | + if (elapsed - 1) > index and icon["tg"].hidden: |
| 106 | + # make the current icon visible |
| 107 | + icon["tg"].hidden = False |
0 commit comments