mirror of
https://github.com/dekuNukem/USB4VC.git
synced 2025-10-31 11:26:46 -07:00
added setting wifi info from config file
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import os
|
||||
import sys
|
||||
import time
|
||||
import json
|
||||
import RPi.GPIO as GPIO
|
||||
import usb4vc_usb_scan
|
||||
import usb4vc_ui
|
||||
@@ -55,8 +56,53 @@ def check_rpi_model():
|
||||
os.system('sudo reboot')
|
||||
time.sleep(10)
|
||||
|
||||
def update_wifi_credentials():
|
||||
config_file_path = '/etc/wpa_supplicant/wpa_supplicant.conf'
|
||||
if os.path.isfile(config_file_path) is False:
|
||||
print('update_wifi_credentials: system config file not found')
|
||||
return
|
||||
new_wifi_info_path = "/home/pi/usb4vc/config/wifi_info.json"
|
||||
if os.path.isfile(new_wifi_info_path) is False:
|
||||
print('update_wifi_credentials: user wifi info file not found')
|
||||
return
|
||||
|
||||
with open(new_wifi_info_path) as json_file:
|
||||
wifi_dict = json.load(json_file)
|
||||
|
||||
config_str = f"""
|
||||
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||
update_config=1
|
||||
country={wifi_dict['wifi_country_code']}
|
||||
|
||||
network={{
|
||||
ssid="{wifi_dict['wifi_name']}"
|
||||
psk="{wifi_dict['wifi_password']}"
|
||||
}}
|
||||
"""
|
||||
|
||||
config_str_unsecured = f"""
|
||||
ctrl_interface=DIR=/var/run/wpa_supplicant GROUP=netdev
|
||||
update_config=1
|
||||
country={wifi_dict['wifi_country_code']}
|
||||
|
||||
network={{
|
||||
ssid="{wifi_dict['wifi_name']}"
|
||||
key_mgmt=NONE
|
||||
}}
|
||||
"""
|
||||
to_write = config_str
|
||||
if len(wifi_dict['wifi_password']) > 0:
|
||||
to_write = config_str_unsecured
|
||||
with open(config_file_path, 'w') as wifi_config_file:
|
||||
wifi_config_file.write(to_write)
|
||||
|
||||
check_rpi_model()
|
||||
|
||||
try:
|
||||
update_wifi_credentials()
|
||||
except Exception as e:
|
||||
print('update_wifi_credentials exception:', e)
|
||||
|
||||
usb4vc_ui.ui_init()
|
||||
usb4vc_ui.ui_thread.start()
|
||||
|
||||
|
||||
@@ -192,7 +192,7 @@ def translate_dict(old_mapping_dict, lookup_dict):
|
||||
return translated_map_dict
|
||||
|
||||
def find_keycode_in_mapping(source_code, mapping_dict, usb_gamepad_type):
|
||||
print(source_code, mapping_dict, usb_gamepad_type)
|
||||
# print(source_code, mapping_dict, usb_gamepad_type)
|
||||
map_dict_copy = dict(mapping_dict)
|
||||
if 'DualSense' in usb_gamepad_type and map_dict_copy.get("MAPPING_TYPE") == "DEFAULT_15PIN":
|
||||
map_dict_copy = usb4vc_gamepads.PS5_DEFAULT_MAPPING
|
||||
|
||||
Reference in New Issue
Block a user