diff --git a/python_payload/st3m/processors.py b/python_payload/st3m/processors.py index 9ff75199ca348e304d3d64be2f53ce4bec377ca5..be45fd771ec5022dad715d3b97794e60d06b21a0 100644 --- a/python_payload/st3m/processors.py +++ b/python_payload/st3m/processors.py @@ -1,6 +1,6 @@ from ctx import Context -from st3m import Responder +from st3m import Responder, settings from st3m.input import InputState, InputController from st3m.goose import ABCBase, abstractmethod, List @@ -30,14 +30,13 @@ class AudioProcessor(Processor): def __init__(self) -> None: super().__init__() self.input = InputController() - self.volume_step = 1.5 def think(self, ins: InputState, delta_ms: int) -> None: self.input.think(ins, delta_ms) if self.input.buttons.os.left.pressed: - audio.adjust_volume_dB(-self.volume_step) + audio.adjust_volume_dB(-settings.num_volume_step_db.value) if self.input.buttons.os.right.pressed: - audio.adjust_volume_dB(self.volume_step) + audio.adjust_volume_dB(settings.num_volume_step_db.value) class ProcessorMidldeware(Responder): diff --git a/python_payload/st3m/run.py b/python_payload/st3m/run.py index bde74b88c3442cca9678b00f9252159f4b346639..885cd6578a21b9fb20c361ac1a021da3e33eac0a 100644 --- a/python_payload/st3m/run.py +++ b/python_payload/st3m/run.py @@ -145,10 +145,12 @@ def run_main() -> None: log.info(f"free memory: {gc.mem_free()}") captouch.calibration_request() - # defaults, maybe expose in a config file someday - audio.set_volume_dB(-10) - audio.headphones_set_minimum_volume_dB(-30) - audio.speaker_set_minimum_volume_dB(-30) + + audio.set_volume_dB(settings.num_startup_volume_db.value) + audio.headphones_set_minimum_volume_dB(settings.num_headphones_min_db.value) + audio.speaker_set_minimum_volume_dB(settings.num_speakers_min_db.value) + audio.headphones_set_maximum_volume_dB(settings.num_headphones_max_db.value) + audio.speaker_set_maximum_volume_dB(settings.num_speakers_max_db.value) leds.set_rgb(0, 255, 0, 0) leds.update() diff --git a/python_payload/st3m/settings.py b/python_payload/st3m/settings.py index 4277174de981b2f345c844d1340fe2a43665c403..e73510cb1006ea0181fbbe3e53c3f0e9e031fa99 100644 --- a/python_payload/st3m/settings.py +++ b/python_payload/st3m/settings.py @@ -161,6 +161,19 @@ class StringTunable(UnaryTunable): pass +class NumberTunable(UnaryTunable): + """ + NumberTunable is a UnaryTunable that has a numeric value + """ + + def __init__(self, name: str, key: int | float, default: Optional[str]) -> None: + super().__init__(name, key, default) + + def press(self, vm: Optional["ViewManager"]) -> None: + # Number adjustment not supported at the moment + pass + + # TODO: invert Tunable <-> Widget dependency to be able to define multiple different widget renderings for the same underlying tunable type class ObfuscatedStringTunable(UnaryTunable): """ @@ -189,6 +202,24 @@ onoff_wifi_preference = OnOffTunable( str_wifi_ssid = StringTunable("WiFi SSID", "system.wifi.ssid", "Camp2023-open") str_wifi_psk = ObfuscatedStringTunable("WiFi Password", "system.wifi.psk", None) str_hostname = StringTunable("Hostname", "system.hostname", "flow3r") +num_volume_step_db = StringTunable( + "Volume Change dB", "system.audio.volume_step_db", 2.5 +) +num_startup_volume_db = StringTunable( + "Startup Volume dB", "system.audio.startup_volume_db", -10 +) +num_headphones_min_db = StringTunable( + "Min Headphone Volume dB", "system.audio.headphones_min_db", -30 +) +num_speakers_min_db = StringTunable( + "Min Speakers Volume dB", "system.audio.speakers_min_db", -30 +) +num_headphones_max_db = StringTunable( + "Max Headphone Volume dB", "system.audio.headphones_max_db", 3 +) +num_speakers_max_db = StringTunable( + "Max Speakers Volume dB", "system.audio.speakers_max_db", 14 +) # List of all settings to be loaded/saved load_save_settings: List[UnaryTunable] = [ @@ -203,6 +234,12 @@ load_save_settings: List[UnaryTunable] = [ str_wifi_ssid, str_wifi_psk, str_hostname, + num_volume_step_db, + num_startup_volume_db, + num_headphones_min_db, + num_speakers_min_db, + num_headphones_max_db, + num_speakers_max_db, ] diff --git a/python_payload/st3m/settings_menu.py b/python_payload/st3m/settings_menu.py index 6996cdbf14e15c327298d063c43665ada3c0b51e..cc9a0b617b63cd7961c893a4d588dcf9b5022e32 100644 --- a/python_payload/st3m/settings_menu.py +++ b/python_payload/st3m/settings_menu.py @@ -154,6 +154,7 @@ tunable_widget_map = { Tunable: TunableWidget, OnOffTunable: OnOffWidget, StringTunable: StringWidget, + NumberTunable: StringWidget, # temporary until an editable one is added ObfuscatedStringTunable: ObfuscatedValueWidget, }