From 96de5f95e1431a0eb7aca7939c299115d054a779 Mon Sep 17 00:00:00 2001 From: dekunukem Date: Tue, 15 Feb 2022 01:22:12 +0000 Subject: [PATCH] added model change detection, recompiles bluetooth if so --- getting_started.md | 8 ++++-- user_program/usb4vc_main.py | 48 +++++++++++++++++++++++++++++++++++ user_program/usb4vc_shared.py | 2 +- user_program/usb4vc_ui.py | 10 ++++++++ 4 files changed, 65 insertions(+), 3 deletions(-) diff --git a/getting_started.md b/getting_started.md index 28997ca..6c6cbfe 100644 --- a/getting_started.md +++ b/getting_started.md @@ -42,11 +42,15 @@ USB4VC is designed for **Raspberry Pi 1/2/3/4 Model B**. Insert SD card in Raspberry Pi, and hook it up to a monitor. No need for anything else. -Power on, and it should boot and execute the program, showing a bunch of information: +Power on, and it should boot and execute the program, showing a bunch of information. + +If you see `!!!!!!!!!! DO NOT UNPLUG UNTIL I REBOOT !!!!!!!!!!` on screen, **don't touch anything until it reboots**! ![Alt text](photos/rpitest.jpeg) -If so, congrats! Power off and continue. If not, make sure the power supply is sufficient, and the SD card image is burned properly. +If it works, congrats! Wait until nothing is scrolling on screen and unplug. + +If not, make sure the power supply is sufficient, and the SD card image is burned properly. ## Kit Assembly diff --git a/user_program/usb4vc_main.py b/user_program/usb4vc_main.py index a5706bc..4ec5c9a 100644 --- a/user_program/usb4vc_main.py +++ b/user_program/usb4vc_main.py @@ -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() diff --git a/user_program/usb4vc_shared.py b/user_program/usb4vc_shared.py index d299913..c9331f9 100644 --- a/user_program/usb4vc_shared.py +++ b/user_program/usb4vc_shared.py @@ -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'), diff --git a/user_program/usb4vc_ui.py b/user_program/usb4vc_ui.py index 37d7b99..e36c740 100644 --- a/user_program/usb4vc_ui.py +++ b/user_program/usb4vc_ui.py @@ -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)