1+ import math
12from pathlib import Path
3+ import subprocess
24import threading
35from audio .audio_player_delegate_sdl2 import AudioPlayerDelegateSdl2
46from controller .controller_inputs import ControllerInput
1012from devices .miyoo .system_config import SystemConfig
1113from devices .miyoo_trim_common import MiyooTrimCommon
1214from devices .trimui .trim_ui_device import TrimUIDevice
15+ from devices .utils .file_watcher import FileWatcher
16+ from devices .utils .process_runner import ProcessRunner
17+ from display .display import Display
1318from utils import throttle
1419
1520from utils .config_copier import ConfigCopier
1621from utils .ffmpeg_image_utils import FfmpegImageUtils
22+ from utils .logger import PyUiLogger
1723from utils .py_ui_config import PyUiConfig
1824
1925class TrimUIBrick (TrimUIDevice ):
@@ -25,8 +31,7 @@ def __init__(self, device_name, main_ui_mode):
2531 self .audio_player = AudioPlayerDelegateSdl2 ()
2632 script_dir = Path (__file__ ).resolve ().parent
2733 source = script_dir / 'brick-system.json'
28- ConfigCopier .ensure_config ("/mnt/SDCARD/Saves/trim-ui-brick-system.json" , source )
29- self .system_config = SystemConfig ("/mnt/SDCARD/Saves/trim-ui-brick-system.json" )
34+ self ._load_system_config ("/mnt/SDCARD/Saves/trim-ui-brick-system.json" , source )
3035
3136 if (main_ui_mode ):
3237 trim_stock_json_file = script_dir / 'stock/brick.json'
@@ -37,6 +42,8 @@ def __init__(self, device_name, main_ui_mode):
3742 self .ensure_wpa_supplicant_conf ()
3843 threading .Thread (target = self .monitor_wifi , daemon = True ).start ()
3944 threading .Thread (target = self .startup_init , daemon = True ).start ()
45+ self .config_watcher_thread , self .config_watcher_thread_stop_event = FileWatcher ().start_file_watcher (
46+ "/mnt/SDCARD/Saves/trim-ui-brick-system.json" , self .on_system_config_changed , interval = 0.2 , repeat_trigger_for_mtime_granularity_issues = True )
4047 if (PyUiConfig .enable_button_watchers ()):
4148 from controller .controller import Controller
4249 #/dev/miyooio if we want to get rid of miyoo_inputd
@@ -48,6 +55,7 @@ def __init__(self, device_name, main_ui_mode):
4855 self .power_key_watcher = KeyWatcher ("/dev/input/event1" )
4956 power_key_polling_thread = threading .Thread (target = self .power_key_watcher .poll_keyboard , daemon = True )
5057 power_key_polling_thread .start ()
58+ # Done to try to account for external systems editting the config file
5159
5260 super ().__init__ ()
5361
@@ -60,7 +68,7 @@ def startup_init(self, include_wifi=True):
6068 self ._set_hue_to_config ()
6169 config_volume = self .system_config .get_volume ()
6270 self ._set_volume (config_volume )
63-
71+
6472 #Untested
6573 @throttle .limit_refresh (5 )
6674 def is_hdmi_connected (self ):
@@ -157,3 +165,31 @@ def get_audio_system(self):
157165
158166 def get_core_name_overrides (self , core_name ):
159167 return [core_name , core_name + "-64" ]
168+
169+ def _set_volume (self , user_volume ):
170+ from display .display import Display
171+ if (user_volume < 0 ):
172+ user_volume = 0
173+ elif (user_volume > 100 ):
174+ user_volume = 100
175+ volume = math .ceil (user_volume * 255 // 100 )
176+
177+ try :
178+
179+ ProcessRunner .run (
180+ ["amixer" , "cset" , f"numid=17" , str (int (volume ))],
181+ check = True
182+ )
183+
184+ except Exception as e :
185+ PyUiLogger .get_logger ().error (f"Failed to set volume: { e } " )
186+
187+ self .system_config .reload_config ()
188+ self .system_config .set_volume (user_volume )
189+ self .system_config .save_config ()
190+ Display .volume_changed (user_volume )
191+ return user_volume
192+
193+
194+ def might_require_surface_format_conversion (self ):
195+ return True # RA save state images don't seem to load w/o conversion?
0 commit comments