Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions src/boot_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@
i2c.unlock()

if tlv320_present:
if "audio" in launcher_config.data and "volume" in launcher_config.data["audio"]:
volume_level = launcher_config.audio_volume
else:
volume_level = 0.7
fjPeriphs = adafruit_fruitjam.peripherals.Peripherals(
audio_output=launcher_config.audio_output,
audio_output=launcher_config.audio_output,
safe_volume_limit=launcher_config.audio_volume_override_danger
)

fjPeriphs.volume = launcher_config.audio_volume
fjPeriphs.volume = volume_level

wave_file = "/boot_animation_assets/ada_fruitjam_boot_jingle.wav"

Expand Down
56 changes: 28 additions & 28 deletions src/launcher_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,98 +19,98 @@ def __init__(self):
@property
def data(self) -> dict:
return self._data

@data.setter
def data(self, value: dict) -> None:
self._data = value

@property
def use_mouse(self) -> bool:
return "use_mouse" in self._data and self._data["use_mouse"]

@use_mouse.setter
def use_mouse(self, value: bool) -> None:
self._data["use_mouse"] = value

@property
def favorites(self) -> list:
return list(self._data["favorites"]) if "favorites" in self._data else []

@favorites.setter
def favorites(self, value: list) -> None:
self._data["favorites"] = value

@property
def palette_bg(self) -> int:
return int(self._data["palette"].get("bg", "0x222222"), 16)

@palette_bg.setter
def palette_bg(self, value: int) -> None:
self._data["palette"]["bg"] = "0x{:06x}".format(value)

@property
def palette_fg(self) -> int:
return int(self._data["palette"].get("fg", "0xffffff"), 16)

@palette_fg.setter
def palette_fg(self, value: int) -> None:
self._data["palette"]["fg"] = "0x{:06x}".format(value)

@property
def palette_arrow(self) -> int:
return int(self._data["palette"].get("arrow", "0x004abe"), 16)

@palette_arrow.setter
def palette_arrow(self, value: int) -> None:
self._data["palette"]["arrow"] = "0x{:06x}".format(value)

@property
def palette_accent(self) -> int:
return int(self._data["palette"].get("accent", "0x008800"), 16)

@palette_accent.setter
def palette_accent(self, value: int) -> None:
self._data["palette"]["accent"] = "0x{:06x}".format(value)

@property
def audio_output(self) -> str:
return self._data["audio"].get("output", "headphone")

@audio_output.setter
def audio_output(self, value: str) -> None:
self._data["audio"]["output"] = value

@property
def audio_output_speaker(self) -> bool:
return self.audio_output == "speaker"

@property
def audio_output_headphones(self) -> bool:
return not self.audio_output_speaker

@property
def audio_volume(self) -> int:
return min(max(int(self._data["audio"].get("volume", 7)), 1), 20)
def audio_volume(self) -> float:
return min(max(float(self._data["audio"].get("volume", 0.35)), 0.0), 1.0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any thoughts on specifying the default volume in the constructor and using it here? Same goes for audio_volume_override_danger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I prefer not to have another place that the default volume and limits can be set.

I do see how it could be convenient in some situations for instance the changes in the PR to boot_animation.py that increase the volume if it isn't specified in the launcher config could be made a little bit simpler.

But personally I think it also adds an extra source of potential confusion if someone is does something like launcher_config = LauncherConfig(audio_volume=0.6) expecting that it alone will have an impact on the volume level.

And it would mean that the default volume level inside of launcher config could then differ from the default value inside of fruit jam library here: https://github.com/FoamyGuy/Adafruit_CircuitPython_FruitJam/blob/volume_api_floats/adafruit_fruitjam/peripherals.py#L197.

In my mind any user code that wants to have a different default value for any of the configurations could instead use the data dictionary directly instead of the property, something like launcher_config.data["audio"].get("volume", 0.6)

Part of me was tempted to make these return None instead of a default value if they aren't set in the file. That way this class is solely accessing information from the config file, not providing any of it's own values for anything. Code using it would need to check for None and act accordingly if we did make that change though.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your argument here makes sense, although appending default_ to the constructor parameters would clear it up a little.

To follow on your None idea, one solution would be to allow assigning None within adafruit_fruitjam.peripherals.Peripherals.volume which it would recognize and reset the volume to the default... but at that point, I think it's better just to handle it how you're doing here. 👍


@audio_volume.setter
def audio_volume(self, value: int) -> None:
self._data["audio"]["volume"] = min(max(value, 1), 20)
def audio_volume(self, value: float) -> None:
self._data["audio"]["volume"] = min(max(value, 0.0), 1.0)

@property
def audio_volume_override_danger(self) -> int:
return int(self._data["audio"].get("volume_override_danger", 12))
def audio_volume_override_danger(self) -> float:
return float(self._data["audio"].get("volume_override_danger", 0.75))

@audio_volume_override_danger.setter
def audio_volume_override_danger(self, value: int) -> None:
self._data["audio"]["volume_override_danger"] = min(max(value, 1), 20)
def audio_volume_override_danger(self, value: float) -> None:
self._data["audio"]["volume_override_danger"] = min(max(value, 0.0), 1.0)

@property
def boot_animation(self) -> str:
value = self._data["boot_animation"] if "boot_animation" in self._data else ""
if not value.endswith(".py") or not pathlib.Path(value).exists():
return "/boot_animation.py"
return value

@boot_animation.setter
def boot_animation(self, value: str) -> None:
if value.endswith(".py") and pathlib.Path(value).exists():
Expand Down