void Update() //DEBUG INPUT SPOOFING { if (Input.GetKey(KeyCode.Q)) { confirmedInput newConfirmed = new confirmedInput(); newConfirmed.fingerIndex = 3; newConfirmed.intensity = UnityEngine.Random.Range(0, 1023); confirmedInputs.Add(newConfirmed); } if (Input.GetKey(KeyCode.W)) { confirmedInput newConfirmed = new confirmedInput(); newConfirmed.fingerIndex = 2; newConfirmed.intensity = UnityEngine.Random.Range(0, 1023); confirmedInputs.Add(newConfirmed); } if (Input.GetKey(KeyCode.E)) { confirmedInput newConfirmed = new confirmedInput(); newConfirmed.fingerIndex = 1; newConfirmed.intensity = UnityEngine.Random.Range(0, 1023); confirmedInputs.Add(newConfirmed); } if (Input.GetKey(KeyCode.R)) { confirmedInput newConfirmed = new confirmedInput(); newConfirmed.fingerIndex = 0; newConfirmed.intensity = UnityEngine.Random.Range(0, 1023); confirmedInputs.Add(newConfirmed); } if (Input.GetKey(KeyCode.T)) //DEBUG RANDOM ASSET CHANGE { changeAsset(inputCombinations [UnityEngine.Random.Range(0, inputCombinations.Length)].affiliatedObject, new float[] { UnityEngine.Random.Range(512, 768) }); } }
IEnumerator readPins() { while (true) { for (int index = 0; index < 4; index++) //Reset font styles. { textArray [index].fontStyle = FontStyle.Normal; } int comboIndex = 99; //Dummy combination index. Replaced if combination made. float[] signals = new float[4]; confirmedInputs = new List <confirmedInput>(); //SEND READ REQUESTS, STORE RESPONSE sendString("R0"); //Send out a call to read pin A0. Sent as string over USB. StartCoroutine(readString((string result) => { signals[0] = float.Parse(result); }, 10f)); sendString("R1"); //^ The coroutine is readString. StartCoroutine(readString((string result) => { signals[1] = float.Parse(result); }, 10f)); sendString("R2"); //^ A miniature namespace. Sets result as output. StartCoroutine(readString((string result) => { signals[2] = float.Parse(result); }, 10f)); sendString("R3"); //^ What to do StartCoroutine(readString((string result) => { signals[3] = float.Parse(result); }, 10f)); _index.text = "Index signal: " + signals[0].ToString(); //Update UI. middle.text = "Middle signal: " + signals[1].ToString(); ring.text = "Ring signal: " + signals[2].ToString(); pinkie.text = "Pinkie signal: " + signals[3].ToString(); //FILTER RESPONSES for (int index = 0; index < 4; index++) //For each finger, { //Perform a signal threshold check. If it passes, add to the input time counter. if (signals [index] > signalThreshold) { candidateInputTimes [index]++; } else { candidateInputTimes [index] = 0; } //If it fails, reset the counter. if (candidateInputTimes [index] > signalTimeThreshold) //If the counter passes the time threshold test, { confirmedInput newConfirmed = new confirmedInput(); //Confirm a new input. newConfirmed.fingerIndex = index; newConfirmed.intensity = signals [index]; //Promote signal data to confirmed input. confirmedInputs.Add(newConfirmed); //Add it to the list of confirmed inputs. } } if (confirmedInputs.Count > 0) //If any outputs were confirmed this cycle... { for (int index = 0; index < confirmedInputs.Count; index++) //Run through the confirmed inputs. { textArray [confirmedInputs[index].fingerIndex].fontStyle = FontStyle.Bold; } //Bold their UI displays. //COMPARE WITH DEFINED COMBINATIONS for (int index = 0; index < inputCombinations.Length; index++) { for (int fingerIndex = 0; fingerIndex < inputCombinations [index].fingerIndices.Length; fingerIndex++) { for (int matchIndex = 0; matchIndex < confirmedInputs.Count; matchIndex++) { if (confirmedInputs [matchIndex].fingerIndex != inputCombinations [index].fingerIndices [fingerIndex]) { comboIndex = 99; break; } //Break if non-match if (matchIndex == confirmedInputs.Count - 1) { comboIndex = index; break; } //If we get to the end, } } } /*//TRANSFER PRESS INTENSITY -- broken, spoofed instead * if ( comboIndex != 14 ) * { * inputCombinations [ comboIndex ].intensities = new float [ inputCombinations [ comboIndex ].fingerIndices.Length ]; * for ( int index = 0; index < inputCombinations [ comboIndex ].fingerIndices.Length; index++ ) * { * inputCombinations [ comboIndex ].intensities [ index ] = confirmedInputs [ index ].intensity; * } * }*/ //DETECT HOLD if (previousComboIndex == comboIndex && comboIndex != 99) //If the last detected combination and the current combination are the same, and the current combination is not a null value... { growAsset(inputCombinations [comboIndex].affiliatedObject, new float[1]); } //This is a hold event. Grow the associated asset. else if (previousComboIndex != comboIndex && comboIndex != 99) //If the last detected combination i bsn't the current combination, and the current combination is not a null value... { changeAsset(inputCombinations [comboIndex].affiliatedObject, new float[1]); } //This is a press event. Change the associated asset. } previousComboIndex = comboIndex; yield return(new WaitForSeconds(0.16f)); } }