void Update() { time_ms += Time.deltaTime; deadzoneTime_ms += Time.deltaTime; Debug.Log("sequenceState: " + System.Enum.GetName(typeof(SequenceState), sequenceState)); if (sequenceState == SequenceState.Playing) { sequenceWindowClosure = SequenceWindowClosure.Open; sequenceTime_ms += Time.deltaTime; timeSinceLastPress_ms += Time.deltaTime; // If we have enough keys to assess whether the sequence can be validated, do so. if (currentKeySequenceLogs["Event"].Count == keysToPress.GetLength(0)) { sequenceWindowClosure = SequenceWindowClosure.ClosedByInputThreshold; SequenceData sequenceData = CheckCapturedKeys(); InputData inputData = new InputData(); inputData.validity = InputValidity.Rejected; inputData.confidence = 0; inputData.inputNumber = sequenceData.sequenceNumber; inputData.type = InputType.KeySequence; if (sequenceData.sequenceValidity == SequenceValidity.Accepted) { inputData.validity = InputValidity.Accepted; inputData.confidence = 1; } //if (state == SequenceValidity.Accepted) { onKeySequenceFinished.Invoke(sequenceData, inputData); onInputFinished.Invoke(inputData); //} sequenceState = SequenceState.Stopped; } else if (deadzoneTime_ms > deadzoneTimeLimit_ms) { sequenceWindowClosure = SequenceWindowClosure.ClosedByDeadzone; Debug.Log("No key pressed for " + deadzoneTimeLimit_ms + "seconds, sequence stopped."); SequenceData sequenceData = CheckCapturedKeys(); InputData inputData = new InputData(); inputData.validity = InputValidity.Rejected; inputData.confidence = 0; inputData.inputNumber = sequenceData.sequenceNumber; inputData.type = InputType.KeySequence; //if (state == SequenceValidity.Accepted) { onKeySequenceFinished.Invoke(sequenceData, inputData); onInputFinished.Invoke(inputData); //} sequenceState = SequenceState.Stopped; } } else { sequenceTime_ms = 0f; timeSinceLastPress_ms = 0f; } }
void Update() { if (bciState == BCIState.Disconnected) { return; } confidence = ((float)ReadSocket()); if (confidence == -1f) { // No Stream available. return; } // Update() runs faster (1/60) than our input data (1/16) arrives. // The code below is only run whenever a new value comes in from the BCI side. LogSample("Sample"); InputData inputData = new InputData(); inputData.confidence = 1 - confidence; inputData.type = InputType.MotorImagery; MotorImageryEvent newClassification = MotorImageryEvent.Rest; inputData.validity = InputValidity.Rejected; if (bciProcessingMode == BCIProcessingMode.SingleThreshold) { newClassification = ProcessSingleThreshold(confidence); } else if (bciProcessingMode == BCIProcessingMode.ConsecutiveThreshold) { newClassification = ProcessConsecutiveThreshold(confidence); } if (newClassification != classification) { if (newClassification == MotorImageryEvent.MotorImagery) { inputData.validity = InputValidity.Accepted; inputNumber++; } inputData.inputNumber = inputNumber; LogMotorImageryEvent(newClassification, confidence); onBCIMotorImagery.Invoke(newClassification); onInputFinished.Invoke(inputData); classification = newClassification; } if (confidence != 0f) { onBCIEvent.Invoke(confidence); } }
void FixedUpdate() { if (bciState == BCIState.Disconnected) { return; } float confidence = ((float)ReadSocket()); if (confidence == -1f) { // No Stream available. return; } InputData inputData = new InputData(); inputData.confidence = 1 - confidence; inputData.type = InputType.MotorImagery; MotorImageryEvent newClassification = MotorImageryEvent.Rest; inputData.validity = InputValidity.Rejected; if (confidence > classificationThreshold) { newClassification = MotorImageryEvent.MotorImagery; inputData.validity = InputValidity.Accepted; } if (newClassification != classification) { inputNumber++; inputData.inputNumber = inputNumber; onBCIMotorImagery.Invoke(newClassification); onInputFinished.Invoke(inputData); classification = newClassification; } if (classification != 0f) { onBCIEvent.Invoke(confidence); } }