1+ import json
2+ import os
13from pathlib import Path
24import threading
35from audio .audio_player_delegate_sdl2 import AudioPlayerDelegateSdl2
911from devices .miyoo .system_config import SystemConfig
1012from devices .miyoo_trim_common import MiyooTrimCommon
1113from devices .trimui .trim_ui_device import TrimUIDevice
14+ from devices .utils .file_watcher import FileWatcher
15+ from display .display import Display
1216from utils import throttle
1317from utils .config_copier import ConfigCopier
1418
1519from utils .ffmpeg_image_utils import FfmpegImageUtils
20+ from utils .logger import PyUiLogger
1621from utils .py_ui_config import PyUiConfig
1722
1823class TrimUISmartProS (TrimUIDevice ):
@@ -24,12 +29,17 @@ def __init__(self, device_name,main_ui_mode):
2429
2530 script_dir = Path (__file__ ).resolve ().parent
2631 source = script_dir / 'brick-system.json'
27- ConfigCopier .ensure_config ("/mnt/SDCARD/Saves/brick-system.json" , source )
28- self .system_config = SystemConfig ("/mnt/SDCARD/Saves/brick-system.json" )
32+ ConfigCopier .ensure_config ("/mnt/SDCARD/Saves/trim-ui-smart-pro-s-system.json" , source )
33+ self .system_config = SystemConfig ("/mnt/SDCARD/Saves/trim-ui-smart-pro-s-system.json" )
34+ self .mainui_volume = 0
35+
2936 if (main_ui_mode ):
37+ self .on_mainui_config_change ()
3038 trim_stock_json_file = script_dir / 'stock/brick.json'
3139 ConfigCopier .ensure_config (TrimUISmartProS .TRIMUI_STOCK_CONFIG_LOCATION , trim_stock_json_file )
3240
41+ self .mainui_config_thread , self .mainui_config_thread_stop_event = FileWatcher ().start_file_watcher (
42+ TrimUISmartProS .TRIMUI_STOCK_CONFIG_LOCATION , self .on_mainui_config_change , interval = 0.2 , repeat_trigger_for_mtime_granularity_issues = True )
3343
3444 self .miyoo_games_file_parser = MiyooGamesFileParser ()
3545 self .ensure_wpa_supplicant_conf ()
@@ -60,6 +70,10 @@ def startup_init(self, include_wifi=True):
6070 config_volume = self .system_config .get_volume ()
6171 self ._set_volume (config_volume )
6272
73+ def _set_volume (self , user_volume ):
74+ # Investigate sending volume key
75+ pass
76+
6377 #Untested
6478 @throttle .limit_refresh (5 )
6579 def is_hdmi_connected (self ):
@@ -159,6 +173,27 @@ def get_audio_system(self):
159173 def get_core_name_overrides (self , core_name ):
160174 return [core_name , core_name + "-64" ]
161175
162- def _set_lumination_to_config (self ):
163- with open ("/sys/class/backlight/backlight0/brightness" , "w" ) as f :
164- f .write (str ((self .system_config .brightness * 255 ) // 20 ))
176+ def get_volume (self ):
177+ try :
178+ return self .mainui_volume * 5
179+ except :
180+ return 0
181+
182+ def on_mainui_config_change (self ):
183+ path = TrimUISmartProS .TRIMUI_STOCK_CONFIG_LOCATION
184+ if not os .path .exists (path ):
185+ PyUiLogger .get_logger ().warning (f"File not found: { path } " )
186+ return
187+
188+ try :
189+ with open (path , "r" , encoding = "utf-8" ) as f :
190+ data = json .load (f )
191+
192+ old_volume = self .mainui_volume
193+ self .mainui_volume = data .get ("vol" )
194+ if (old_volume != self .mainui_volume ):
195+ Display .volume_changed (self .mainui_volume * 5 )
196+
197+ except Exception as e :
198+ PyUiLogger .get_logger ().warning (f"Error reading { path } : { e } " )
199+ return None
0 commit comments