Skip to content

Commit b2eb083

Browse files
committed
Support writing audio board firmware from Service Menu
1 parent 3688fcc commit b2eb083

File tree

2 files changed

+30
-16
lines changed

2 files changed

+30
-16
lines changed

mpf/modes/service/code/service.py

+26-16
Original file line numberDiff line numberDiff line change
@@ -456,14 +456,6 @@ async def _light_test_menu(self):
456456

457457
self.machine.events.post("service_light_test_stop")
458458

459-
# VOLUME Menu
460-
def _load_software_sound_menu_entries(self) -> List[ServiceMenuEntry]:
461-
"""Return the software sound menu items with label and callback."""
462-
return [
463-
ServiceMenuEntry("%s Volume" % config.get('label', track), partial(self._sound_track_menu, track))
464-
for track, config in self.machine.config["sound_system"]["tracks"].items()
465-
]
466-
467459
async def _volume_menu(self, platform=None):
468460
position = 0
469461
if platform:
@@ -488,6 +480,16 @@ async def _volume_menu(self, platform=None):
488480
if isinstance(item['value'], float):
489481
item['value'] = int(item['value'] * 100)
490482

483+
# If supported on hardware platform, add option to write to firmware
484+
if platform and hasattr(platform.audio_interface, "save_settings_to_firmware"):
485+
items.append({
486+
"name": "write_to_firmware",
487+
"label": "Write Settings",
488+
"is_platform": True,
489+
"value": "Confirm",
490+
"levels_list": ["Confirm", "Saved"]
491+
})
492+
491493
self._update_volume_slide(items, position)
492494

493495
while True:
@@ -506,7 +508,7 @@ async def _volume_menu(self, platform=None):
506508
self._update_volume_slide(items, position)
507509
elif key == 'ENTER':
508510
# change setting
509-
await self._volume_change(items, position, focus_change="enter")
511+
await self._volume_change(items, position, platform, focus_change="enter")
510512

511513
self.machine.events.post("service_volume_stop")
512514

@@ -523,7 +525,7 @@ def _update_volume_slide(self, items, position, is_change=False, focus_change=No
523525
is_platform=config["is_platform"],
524526
focus_change=focus_change)
525527

526-
async def _volume_change(self, items, position, focus_change=None):
528+
async def _volume_change(self, items, position, platform, focus_change=None):
527529
self._update_volume_slide(items, position, focus_change=focus_change)
528530
if items[position].get("levels_list"):
529531
values = items[position]["levels_list"]
@@ -551,12 +553,20 @@ async def _volume_change(self, items, position, focus_change=None):
551553
new_value = values[value_position]
552554
if new_value is not None:
553555
items[position]['value'] = new_value
554-
# Internally tracked values divide by 100 to store a float.
555-
# External (hardware) values, use the value units provided
556-
# TODO: Create an Amp/Track class to internalize this method.
557-
if not items[position].get("levels_list"):
558-
new_value = new_value / 100
559-
self.machine.variables.set_machine_var(f"{items[position]['name']}_volume", new_value, persist=True)
556+
# Check for a firmware update
557+
if items[position]['name'] == "write_to_firmware":
558+
if new_value == "Saved":
559+
platform.audio_interface.save_settings_to_firmware()
560+
# Remove the options from the list
561+
values = ['Saved']
562+
items[position]['levels_list'] = values
563+
else:
564+
# Internally tracked values divide by 100 to store a float.
565+
# External (hardware) values, use the value units provided
566+
# TODO: Create an Amp/Track class to internalize this method.
567+
if not items[position].get("levels_list"):
568+
new_value = new_value / 100
569+
self.machine.variables.set_machine_var(f"{items[position]['name']}_volume", new_value, persist=True)
560570
self._update_volume_slide(items, position, is_change=True)
561571

562572
# AUDIT Menu

mpf/platforms/fast/fast_audio.py

+4
Original file line numberDiff line numberDiff line change
@@ -193,3 +193,7 @@ def pulse_reset_pin(self, ms=None, **kwargs):
193193
if not ms:
194194
ms = self.control_pin_pulse_times[7]
195195
self.communicator.pulse_control_pin(7, ms)
196+
197+
def save_settings_to_firmware(self, **kwargs):
198+
del kwargs
199+
self.communicator.save_settings_to_firmware()

0 commit comments

Comments
 (0)