Example #1
0
        public static void OnBleDidInitialize(string message)
        {
            string errorMessage = message != "Success" ? message : null;

#if UNITY_IOS
            Debug.Log("calling scanning peripherals.");
            InitBLE.ScanForPeripherals();
#else
            OnBleDidInitializeEvent?.Invoke(errorMessage);
#endif
        }
Example #2
0
    private void InitiateMatConnection()
    {
        //Initiate the connection with the mat.
#if UNITY_IOS
        // connection part for ios
        InitBLE.InitBLEFramework(currentYipliConfig.matInfo?.macAddress ?? "", 0, currentYipliConfig.matInfo?.matAdvertisingName ?? LibConsts.MatTempAdvertisingNameOnlyForNonIOS);
#elif UNITY_ANDROID
        InitBLE.InitBLEFramework(currentYipliConfig.matInfo?.macAddress ?? "", 0, currentYipliConfig.matInfo?.matAdvertisingName ?? LibConsts.MatTempAdvertisingNameOnlyForNonIOS, currentYipliConfig.isDeviceAndroidTV);
#else
        InitBLE.InitBLEFramework(currentYipliConfig.matInfo?.macAddress ?? "", 0);
#endif
    }
Example #3
0
 public void Update()
 {
     if (bIsMatFlowInitialized)
     {
         //LoadGameScene if mat connection is established
         if (InitBLE.getMatConnectionStatus().Equals("connected", StringComparison.OrdinalIgnoreCase))
         {
             if (true != bIsGameMainSceneLoading)
             {
                 StartCoroutine(LoadMainGameScene());
             }
         }
     }
 }
Example #4
0
    // This function is to be called before Mat tutorial.
    // Mat tutorial requires the mat connection to be established.
    public void EstablishMatConnection()
    {
        Debug.Log("Starting Mat connection flow");
        NoMatPanel.SetActive(false);
        newMatInputController.MakeSortLayerTen();
        //newUIManager.TurnOffMainCommonButton();

#if UNITY_ANDROID
        /*
         * if (currentYipliConfig.matInfo == null && !currentYipliConfig.isDeviceAndroidTV)
         * {
         *  Debug.Log("Filling te current mat Info from Device saved MAT");
         *  currentYipliConfig.matInfo = UserDataPersistence.GetSavedMat();
         * }
         */

        if (currentYipliConfig.matInfo != null || currentYipliConfig.isDeviceAndroidTV)
        {
            //Debug.Log("Mac Address : " + currentYipliConfig.matInfo.macAddress);
            //Load Game scene if the mat is already connected.
            if (!InitBLE.getMatConnectionStatus().Equals("connected", StringComparison.OrdinalIgnoreCase))
            {
                StartCoroutine(ConnectMat());
            }
        }
        else //Current Mat not found in Db.
        {
            loadingPanel.SetActive(false);
            Debug.Log("No Mat found in cache.");
            noMatText.text = ProductMessages.Err_mat_connection_android_phone_register;
            newUIManager.UpdateButtonDisplay(NoMatPanel.tag);
            NoMatPanel.SetActive(true);
            newMatInputController.MakeSortLayerZero();
            FindObjectOfType <YipliAudioManager>().Play("BLE_failure");
        }
#elif UNITY_STANDALONE_WIN
        if (!InitBLE.getMatConnectionStatus().Equals("connected", StringComparison.OrdinalIgnoreCase))
        {
            StartCoroutine(ConnectMat());
        }
#elif UNITY_IOS
        if (!InitBLE.getMatConnectionStatus().Equals("connected", StringComparison.OrdinalIgnoreCase))
        {
            StartCoroutine(ConnectMat());
        }
#endif

        StartCoroutine(MatConnectionCheck());
    }
    private void MenuControlSystem()
    {
        string fmActionData = InitBLE.GetFMResponse();

        Debug.Log("Json Data from Fmdriver : " + fmActionData);

        if (fmActionData == null || fmActionData == "Make action")
        {
            return;
        }

        FmDriverResponseInfo singlePlayerResponse = JsonUtility.FromJson <FmDriverResponseInfo>(fmActionData);

        if (singlePlayerResponse == null)
        {
            return;
        }

        if (PlayerSession.Instance.currentYipliConfig.oldFMResponseCount != singlePlayerResponse.count)
        {
            //Debug.Log("FMResponse " + fmActionData);
            PlayerSession.Instance.currentYipliConfig.oldFMResponseCount = singlePlayerResponse.count;

            YipliUtils.PlayerActions providedAction = ActionAndGameInfoManager.GetActionEnumFromActionID(singlePlayerResponse.playerdata[0].fmresponse.action_id);

            switch (providedAction)
            {
            case YipliUtils.PlayerActions.LEFT:
                ProcessMatInputs(LEFT);
                break;

            case YipliUtils.PlayerActions.RIGHT:
                ProcessMatInputs(RIGHT);
                break;

            case YipliUtils.PlayerActions.ENTER:
                ProcessMatInputs(ENTER);
                break;
            }
        }
    }
Example #6
0
        public static void OnBleDidCompletePeripheralScan(string message)
        {
            string errorMessage       = message != "Success" ? message : null;
            string peripheralJsonList = (errorMessage == null) ? InitBLE.GetListOfDevices() : null;

            /*
             * if (peripheralJsonList != null)
             * {
             *  Dictionary<string, object> dictObject = Json.Deserialize(peripheralJsonList) as Dictionary<string, object>;
             * ​
             *  object receivedByteDataArray;
             *  if (dictObject.TryGetValue("deviceList", out receivedByteDataArray))
             *  {
             *      peripheralsList = (List<object>)receivedByteDataArray;
             *  }
             * }
             */

            Debug.LogError("peripheralJsonList from ble controller : " + peripheralJsonList);

            OnBleDidCompletePeripheralScanEvent?.Invoke(peripheralJsonList, errorMessage);
        }
Example #7
0
    private IEnumerator ConnectMat(bool bIsReconnectMatNeeded = false)
    {
        int iTryCount = 0;

        //Initiate the connection with the mat.
        try
        {
            if (bIsReconnectMatNeeded)
            {
                RetryMatConnectionOnPC();
            }
            else
            {
                InitiateMatConnection();
            }
        }
        catch (Exception e)
        {
            Debug.LogError("mat connection failed : " + e.Message);

            loadingPanel.SetActive(false);
            newUIManager.UpdateButtonDisplay(NoMatPanel.tag);
            NoMatPanel.SetActive(true);
            newMatInputController.MakeSortLayerZero();
            yield break;
        }

        yield return(new WaitForSecondsRealtime(0.1f));

        //Turn on the Mat Find Panel, and animate
        loadingPanel.gameObject.GetComponentInChildren <TextMeshProUGUI>().text = "Finding your mat..";
        loadingPanel.SetActive(true);//Show msg till mat connection is confirmed.

        while (!InitBLE.getMatConnectionStatus().Equals("connected", StringComparison.OrdinalIgnoreCase) &&
               iTryCount < MaxBleCheckCount)
        {
#if UNITY_IOS
            yield return(new WaitForSecondsRealtime(1f));
#else
            yield return(new WaitForSecondsRealtime(0.25f));
#endif
            iTryCount++;
        }

        //Turn off the Mat Find Panel
        loadingPanel.SetActive(false);
        loadingPanel.gameObject.GetComponentInChildren <TextMeshProUGUI>().text = "Fetching player details...";

        if (!InitBLE.getMatConnectionStatus().Equals("connected", StringComparison.OrdinalIgnoreCase))
        {
            FindObjectOfType <YipliAudioManager>().Play("BLE_failure");
            Debug.Log("Mat not reachable.");

#if UNITY_ANDROID || UNITY_IOS
            noMatText.text = ProductMessages.Err_mat_connection_mat_off;
#elif UNITY_STANDALONE_WIN && UNITY_EDITOR
            if (PortTestings.CheckAvailableComPorts() == 0)
            {
                noMatText.text = ProductMessages.Err_mat_connection_no_ports;
            }
            else
            {
                noMatText.text = ProductMessages.Err_mat_connection_mat_off;
            }
#endif
            newUIManager.UpdateButtonDisplay(NoMatPanel.tag);
            NoMatPanel.SetActive(true);
            newMatInputController.MakeSortLayerZero();
        }
    }
Example #8
0
        static void HandleOnBleDidCompletePeripheralScanEvent(string peripherals, string errorMessage)
        {
            if (errorMessage == null)
            {
                if (InitBLE.isInitActive)
                {
                    /*********************************************************************
                     *   Received String
                     *   A4:DA:32:4F:C2:54|YIPLI,F4:BF:80:63:E3:7A|honor Band 4-37A,F5:FB:4A:55:76:22|Mi Smart Band 4
                     **********************************************************************/
                    string[] allBleDevices = peripherals.Split(',');
                    for (int i = 0; i < allBleDevices.Length; i++)
                    {
                        string[] tempSplits = allBleDevices[i].Split('|');

                        Debug.Log("Mac : " + tempSplits[0] + " Device Name:" + tempSplits[1]);
                        if (tempSplits[1].Contains("YIPLI") && tempSplits[1].Length > 5)
                        {
                            string[] matID = tempSplits[1].Split('-');

                            /***********************************
                            *  // FOR Batch of 250
                            *  // MAT NAME - YIPLI-001
                            *  /**********************************/

                            //Check for the Mat name you want to connect against the scanned list
                            if (tempSplits[1] == InitBLE.MAT_NAME)
                            {
                                InitBLE.ConnectPeripheral(tempSplits[0]);
                            }
                        }
                        else if (tempSplits[1].Contains("YIPLI") && tempSplits[1].Length == 5)
                        {
                            /***********************************
                            *  // FOR NRF Boards and Batch 1 boards
                            *  // MAT NAME - YIPLI
                            *  /**********************************/

                            //----------
                            // Directly connect to MAT ID if valid mac address
                            // FOR BATCH-1 BOARDS
                            //----------
                            string macAddress = tempSplits[0];

                            //----------
                            // Get MacAddress from GATT
                            // FOR NRF BOARDS
                            //----------
                            // ~ TODO ~​


                            Debug.Log(macAddress + " " + InitBLE.MAC_ADDRESS);
                            if (InitBLE.MAC_ADDRESS == macAddress)
                            {
                                InitBLE.ConnectPeripheral(tempSplits[0]);
                            }
                        }
                    }
                }
            }
        }
Example #9
0
 public static void SetGameMode(int gameMode)
 {
     Debug.Log("GameMode: " + gameMode);
     InitBLE.setGameMode(gameMode);
 }
Example #10
0
 // for 2 players
 public static void SetGameClusterId(int p1gameClusterId, int p2gameClusterId)
 {
     InitBLE.setGameClusterID(p1gameClusterId, p2gameClusterId);
 }
Example #11
0
 public static void SetGameClusterId(int gameClusterId)
 {
     InitBLE.setGameClusterID(gameClusterId);
 }
Example #12
0
 public static string GetFMDriverVersion()
 {
     return(InitBLE.getFMDriverVersion());
 }
Example #13
0
 // based on player
 public static int GetGameClusterId(int playerID)
 {
     return(InitBLE.getGameClusterID(playerID));
 }
Example #14
0
 public static int GetGameClusterId()
 {
     return(InitBLE.getGameClusterID());
 }