You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
3.3 KiB
84 lines
3.3 KiB
using System; |
|
using System.Collections; |
|
using System.Security.Cryptography; |
|
using System.Threading; |
|
using UnityEngine; |
|
using UnityEngine.UI; |
|
using static UDESDK.UDE_SDK; |
|
|
|
public class BleDevice : MonoBehaviour |
|
{ |
|
//[HideInInspector] |
|
public string DeviceName; |
|
[HideInInspector] |
|
public bool IsConnected; |
|
public string Msg; |
|
|
|
private Text DeviceNameTxt; |
|
private Text ConnectStateTxt; |
|
private Action<string, bool> DeviceListener; |
|
|
|
private Button ConnectBtn; |
|
private Button DisconnectBtn; |
|
|
|
private Button StartABtn; |
|
private Button StartBBtn; |
|
private Button StartCBtn; |
|
private Button StopABtn; |
|
private Button StopBBtn; |
|
private Button StopCBtn; |
|
|
|
public void CreateBleDevice(GameObject go, string deviceName, string msg, Action<string, bool> action) |
|
{ |
|
DeviceName = deviceName; |
|
IsConnected = Sample._SDK.UDE_CheckDeviceIsConnect(deviceName); |
|
Msg = msg; |
|
DeviceListener = action; |
|
ConnectBtn = go.transform.Find("ConnectBtn").GetComponent<Button>(); |
|
DisconnectBtn = go.transform.Find("DisconnectBtn").GetComponent<Button>(); |
|
DeviceNameTxt = go.transform.Find("DeviceName_txt").GetComponent<Text>(); |
|
ConnectStateTxt = go.transform.Find("ConnectState_txt").GetComponent<Text>(); |
|
|
|
StartABtn = go.transform.Find("CaliStartA").GetComponent<Button>(); |
|
StartBBtn = go.transform.Find("CaliStartB").GetComponent<Button>(); |
|
StartCBtn = go.transform.Find("CaliStartC").GetComponent<Button>(); |
|
StopABtn = go.transform.Find("CaliStopA").GetComponent<Button>(); |
|
StopBBtn = go.transform.Find("CaliStopB").GetComponent<Button>(); |
|
StopCBtn = go.transform.Find("CaliStopC").GetComponent<Button>(); |
|
|
|
DeviceNameTxt.text = DeviceName; |
|
ConnectStateTxt.text = IsConnected ? "Connected" : "Not Connected "; |
|
ConnectStateTxt.color = IsConnected ? Color.green : Color.red; |
|
|
|
ConnectBtn.onClick.AddListener(() => |
|
{ |
|
if(Sample._SDK.UDE_ConnectCertainDevice(DeviceName, action)) |
|
{ |
|
ConnectStateTxt.text = "Connected"; |
|
ConnectStateTxt.color = Color.green; |
|
IsConnected = true; |
|
} |
|
}); |
|
|
|
DisconnectBtn.onClick.AddListener(() => |
|
{ |
|
if(Sample._SDK.UDE_DisconnectDevice(DeviceName)) |
|
{ |
|
ConnectStateTxt.text = "Not Connected"; |
|
ConnectStateTxt.color = Color.red; |
|
IsConnected = false; |
|
} |
|
}); |
|
|
|
|
|
StartABtn.onClick.AddListener(() => { Sample._SDK.UDE_CalibrationMotionController(deviceName, CalibrationType.Fist, true); }); |
|
StartBBtn.onClick.AddListener(() => { Sample._SDK.UDE_CalibrationMotionController(deviceName, CalibrationType.Adduct, true); }); |
|
StartCBtn.onClick.AddListener(() => { Sample._SDK.UDE_CalibrationMotionController(deviceName, CalibrationType.Stretch, true); }); |
|
StopABtn.onClick.AddListener(() => { Sample._SDK.UDE_CalibrationMotionController(deviceName, CalibrationType.Fist, false); }); |
|
StopBBtn.onClick.AddListener(() => { Sample._SDK.UDE_CalibrationMotionController(deviceName, CalibrationType.Adduct, false); }); |
|
StopCBtn.onClick.AddListener(() => { Sample._SDK.UDE_CalibrationMotionController(deviceName, CalibrationType.Stretch, false); }); |
|
} |
|
|
|
|
|
|
|
}
|
|
|