136 lines
5.1 KiB
C#
136 lines
5.1 KiB
C#
using System.Collections;
|
||
using System.Collections.Generic;
|
||
using Kill.Bluetooth;
|
||
using Kill.Core;
|
||
using Kill.Managers;
|
||
using Kill.UI.Components;
|
||
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using ZXing.Datamatrix;
|
||
namespace Kill.UI.Pages
|
||
{
|
||
public class AboutDevicePage : MonoBehaviour
|
||
{
|
||
public Text[] infoTexts; // 0:设备型号 1:id 2:sn 3:mac 4:固件版本 5:wifi
|
||
public Button backButton;
|
||
public Button wifiButton;
|
||
public SetWifiPage setWifiPage;
|
||
public Button firmwareUpdateButton;
|
||
public FirmwareUpdatePage firmwareUpdatePage;
|
||
void Start()
|
||
{
|
||
UIManager.Instance.RegisterBackAction(Back);
|
||
backButton.onClick.RemoveAllListeners();
|
||
backButton.onClick.AddListener(Back);
|
||
wifiButton.onClick.RemoveAllListeners();
|
||
wifiButton.onClick.AddListener(OnWifiButtonClick);
|
||
firmwareUpdateButton.onClick.RemoveAllListeners();
|
||
firmwareUpdateButton.onClick.AddListener(OnFirmwareUpdateButtonClick);
|
||
if (BluetoothManager.Instance.IsConnected)
|
||
{
|
||
StartCoroutine(GetAllInfoByBlueTooth());
|
||
}
|
||
else
|
||
{
|
||
infoTexts[0].text = DataManager.Instance.selectedDevice.device_model;
|
||
infoTexts[1].text = DataManager.Instance.selectedDevice.product_id;
|
||
infoTexts[2].text = DataManager.Instance.selectedDevice.device_sn;;
|
||
infoTexts[3].text = DataManager.Instance.selectedDevice.ble_mac;
|
||
infoTexts[4].text = DataManager.Instance.selectedDevice.firmware_version;
|
||
// WiFi模式:从设备配置获取WiFi名称
|
||
var config = DataManager.Instance.deviceConfig;
|
||
infoTexts[5].text = config?.wifi_ssid ?? "";
|
||
}
|
||
|
||
|
||
}
|
||
bool deviceInfoReceived = false;
|
||
bool wifiInfoReceived = false;
|
||
IEnumerator GetAllInfoByBlueTooth()
|
||
{
|
||
deviceInfoReceived = false;
|
||
wifiInfoReceived = false;
|
||
LoadingUI.Show();
|
||
|
||
GetDeviceInfoByBlueTooth();
|
||
while (!deviceInfoReceived)
|
||
{
|
||
yield return new WaitForEndOfFrame();
|
||
}
|
||
yield return new WaitForSeconds(0.2f); // 等待0.5秒再请求WiFi信息,确保蓝牙通信稳定
|
||
GetWifiInfoByBlueTooth();
|
||
while (!wifiInfoReceived)
|
||
{
|
||
yield return new WaitForEndOfFrame();
|
||
}
|
||
LoadingUI.Hide();
|
||
}
|
||
|
||
public void GetDeviceInfoByBlueTooth()
|
||
{
|
||
BLECommunicationManager.Instance.ReadDeviceInfo((info) =>
|
||
{
|
||
Loom.QueueOnMainThread(() =>
|
||
{
|
||
deviceInfoReceived = true;
|
||
infoTexts[0].text = info.GetDeviceModelString();
|
||
infoTexts[1].text = info.GetDeviceIdString();
|
||
infoTexts[2].text = info.GetSerialNumberString();
|
||
infoTexts[3].text = info.GetBleMacAddressString();
|
||
infoTexts[4].text = info.GetFirmwareVersionString();
|
||
DataManager.Instance.selectedDevice.firmware_version = info.GetFirmwareVersionString();
|
||
});
|
||
});
|
||
}
|
||
public void GetWifiInfoByBlueTooth()
|
||
{
|
||
BLECommunicationManager.Instance.ReadWIFIControl((info) =>
|
||
{
|
||
Loom.QueueOnMainThread(() =>
|
||
{
|
||
wifiInfoReceived = true;
|
||
infoTexts[5].text = info.SSID;
|
||
infoTexts[5].GetComponentInParent<Button>().interactable = true;
|
||
});
|
||
});
|
||
}
|
||
|
||
public void InitInfoByOnlineData()
|
||
{
|
||
infoTexts[0].text = DataManager.Instance.selectedDevice.device_model;
|
||
infoTexts[1].text = DataManager.Instance.selectedDevice.product_id;
|
||
infoTexts[2].text = DataManager.Instance.selectedDevice.device_sn;
|
||
infoTexts[3].text = DataManager.Instance.selectedDevice.ble_mac;
|
||
infoTexts[4].text = DataManager.Instance.selectedDevice.firmware_version;
|
||
infoTexts[5].text ="";
|
||
}
|
||
public void Back()
|
||
{
|
||
UIManager.Instance.RegisterBackAction(GetComponentInParent<DeviceInfoPage>().Back);
|
||
Destroy(gameObject);
|
||
}
|
||
public void OnWifiButtonClick()
|
||
{
|
||
// WiFi模式下不支持设置WiFi
|
||
if (DataManager.Instance.hasWifi && !DataManager.Instance.hasBluetooth)
|
||
{
|
||
ToastUI.Show("100293");
|
||
return;
|
||
}
|
||
SetWifiPage wifiPage=Instantiate(setWifiPage, transform);
|
||
wifiPage.gameObject.SetActive(true);
|
||
wifiPage.Init(WIfiCallback);
|
||
}
|
||
public void WIfiCallback(string ssid)
|
||
{
|
||
infoTexts[5].text = ssid;
|
||
}
|
||
public void OnFirmwareUpdateButtonClick()
|
||
{
|
||
FirmwareUpdatePage page = Instantiate(firmwareUpdatePage, transform);
|
||
page.gameObject.SetActive(true);
|
||
}
|
||
}
|
||
|
||
}
|