added model change detection, recompiles bluetooth if so

This commit is contained in:
dekunukem
2022-02-15 01:22:12 +00:00
parent 6c3877d09e
commit 96de5f95e1
4 changed files with 65 additions and 3 deletions

View File

@@ -8,6 +8,54 @@ import subprocess
# usb4vc_ui.reset_pboard()
def get_current_rpi_model():
current_model = 'Unknown'
try:
current_model = subprocess.getoutput("cat /proc/device-tree/model").replace('\n', '').replace('\r', '').strip()
except Exception as e:
print('get_current_rpi_model:', e)
return current_model
rpi_model_save_file = '/home/pi/rpi_model.txt'
def get_stored_rpi_model():
stored_model = 'Unknown'
try:
with open(rpi_model_save_file, 'r') as file:
stored_model = file.read().replace('\n', '').replace('\r', '').strip()
except Exception as e:
print('get_stored_rpi_model:', e)
return stored_model
def save_rpi_model(model_str):
try:
with open(rpi_model_save_file, 'w') as file:
file.write(model_str)
except Exception as e:
print('save_rpi_model:', e)
def check_rpi_model():
current_model = get_current_rpi_model()
stored_model = get_stored_rpi_model()
print('current_model', current_model)
print('stored_model', stored_model)
if current_model != stored_model:
usb4vc_ui.oled_print_model_changed()
for x in range(50):
print("!!!!!!!!!! DO NOT UNPLUG UNTIL I REBOOT !!!!!!!!!!")
print("!!!!!!!!!! DO NOT UNPLUG UNTIL I REBOOT !!!!!!!!!!")
print("!!!!!!!!!! DO NOT UNPLUG UNTIL I REBOOT !!!!!!!!!!")
time.sleep(0.1)
os.system("cd /home/pi/xpadneo/; sudo ./uninstall.sh")
usb4vc_ui.oled_print_oneline("Recompiling...")
os.system("cd /home/pi/xpadneo/; sudo ./install.sh")
usb4vc_ui.oled_print_oneline("Done! Rebooting..")
save_rpi_model(current_model)
time.sleep(2)
os.system('sudo reboot')
check_rpi_model()
usb4vc_ui.ui_init()
usb4vc_ui.ui_thread.start()

View File

@@ -1,4 +1,4 @@
RPI_APP_VERSION_TUPLE = (0, 0, 2)
RPI_APP_VERSION_TUPLE = (0, 0, 3)
code_name_to_value_lookup = {
'KEY_RESERVED':(0, 'kb_key'),

View File

@@ -947,4 +947,14 @@ def get_gamepad_protocol():
def get_joystick_curve():
return joystick_curve_list[my_menu.current_joystick_curve_index]
def oled_print_model_changed():
with canvas(oled_device) as draw:
oled_print_centered("RPi Model Changed!", font_regular, 0, draw)
oled_print_centered("Recompiling BT Driver", font_regular, 10, draw)
oled_print_centered("Might take a while...", font_regular, 20, draw)
def oled_print_oneline(msg):
with canvas(oled_device) as draw:
oled_print_centered(msg, font_medium, 10, draw)
ui_thread = threading.Thread(target=ui_worker, daemon=True)