1
0

MultipleDeviceSearch.cs 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. public class MultipleDeviceSearch : MonoBehaviour {
  6. // scan filter
  7. public bool speedCadence;
  8. public bool cadence;
  9. public bool hr;
  10. public bool speed;
  11. public bool power;
  12. public bool fec;
  13. public bool podometer;
  14. public List<int> foundSpeedCadenceIDList;
  15. public List<int> foundCadenceIDList;
  16. public List<int> foundHrIDList;
  17. public List<int> foundSpeedIDList;
  18. public List<int> foundPowerIDList;
  19. public List<int> foundFecIDList;
  20. public Text debugText;
  21. public SpeedCadenceDisplay spcadDisplay;
  22. // Use this for initialization
  23. public void Start() {
  24. StartScan();
  25. }
  26. public void StartScan () {
  27. //in order to start a multipleDevice scan on Android
  28. // call start_multiple_device_search, gameobject, bool speedCadence, bool hr, bool cadence, bool speed, bool power, bool fec as search filters
  29. foundSpeedCadenceIDList = new List<int>();
  30. foundCadenceIDList = new List<int>();
  31. foundHrIDList = new List<int>();
  32. foundSpeedIDList = new List<int>();
  33. foundPowerIDList = new List<int>();
  34. foundFecIDList = new List<int>();
  35. #if UNITY_ANDROID && !UNITY_EDITOR
  36. Debug.Log("starting android multi device scan");
  37. AndroidJNI.AttachCurrentThread();
  38. using (AndroidJavaClass javaClass = new AndroidJavaClass("com.ant.plugin.Ant_Connector")) {
  39. using (AndroidJavaObject activity = javaClass.GetStatic<AndroidJavaObject>("mContext")) {
  40. activity.Call("start_multiple_device_search",this.gameObject.name,speedCadence,hr,cadence,speed,power,fec);
  41. }
  42. }
  43. #endif
  44. }
  45. void ANTPLUG_foundSpeedCadence(string s) {
  46. foundSpeedCadenceIDList.Add(int.Parse(s));
  47. Debug.Log("scan found s&c device " + s);
  48. debugText.text += s+"-";
  49. //found the speedCadence, set the ID and look for it
  50. spcadDisplay.deviceID = int.Parse(s);
  51. spcadDisplay.StartScan();
  52. }
  53. void ANTPLUG_foundCadence(string s) {
  54. foundCadenceIDList.Add(int.Parse(s));
  55. Debug.Log("scan found cadence device " + s);
  56. debugText.text += s + "-";
  57. }
  58. void ANTPLUG_foundHr(string s) {
  59. foundHrIDList.Add(int.Parse(s));
  60. Debug.Log("scan found device hr " + s);
  61. debugText.text += s + "-";
  62. }
  63. void ANTPLUG_foundSpeed(string s) {
  64. foundSpeedIDList.Add(int.Parse(s));
  65. Debug.Log("scan found speed device " + s);
  66. debugText.text += s + "-";
  67. }
  68. void ANTPLUG_foundPower(string s) {
  69. foundPowerIDList.Add(int.Parse(s));
  70. Debug.Log("scan found power device " + s);
  71. debugText.text += s;
  72. }
  73. void ANTPLUG_foundFec(string s) {
  74. foundFecIDList.Add(int.Parse(s));
  75. Debug.Log("scan found trainer device " + s);
  76. debugText.text += s + "-";
  77. }
  78. }