public void DoUpdate() { float value = 0f; if (isSetup) { if (++currIndex == dataLength) { currIndex = 0; } try { value = (float.Parse(eegData [1, currIndex]) - yOffset) / MAX_AMPLITUDE; SomaxisReading reading = new SomaxisReading(int.Parse(eegData [0, currIndex]), value); owner.PublishReading(reading, this); } catch (Exception e) { Debug.LogError("Could not generate csv reading data!"); } if (currIndex % 120 == 0) { Debug.Log("Csv reading data " + currIndex + ": " + eegData [0, currIndex] + ", " + value); } } }
private void PublishReading(ANT_Response response) { Debug.Log("Publishing BROADCAST_DATA_0x4E !!!"); byte[] payload = response.getDataPayload(); // What the heck is going on here?! ushort[] dataArray1 = new ushort[4] { (ushort)(((int)payload [3] & (int)byte.MaxValue) << 2 | (int)payload [4] >> 6), (ushort)(((int)payload [4] & 63) << 4 | (int)payload [5] >> 4), (ushort)(((int)payload [5] & 15) << 6 | (int)payload [6] >> 2), (ushort)((uint)(((int)payload [6] & 3) << 8) | (uint)payload [7]) }; // Why are there 4 readings per sample? for (int index = 0; index < 4; index++) { /* logic to hanle sample history * this._gSampleHistorySum -= (uint)this._gSampleHistory [this._gBufferIndex]; * this._gSampleHistory [this._gBufferIndex] = dataArray1 [index]; * this._gSampleHistorySum += (uint)this._gSampleHistory [this._gBufferIndex]; * this._gSampleAverageHistory [this._gBufferIndex] = (ushort)(this._gSampleHistorySum / this._gNumTaps); * this._gSampleAverageDifferenceSquaredHistory [this._gBufferIndex] = * (uint)Math.Pow ((double)((int)this._gSampleHistory [this._gBufferIndex] * - (int)this._gSampleAverageHistory [this._gBufferIndex]), 2.0); * uint num1 = 0U; * foreach (uint num2 in this._gSampleAverageDifferenceSquaredHistory) * num1 += num2; * this._gPseudoStandardDeviationHistory [index] = (ushort)Math.Sqrt ((double)num1 / (double)(this._gNumTaps - 1U)); * this._gBufferIndex = ++this._gBufferIndex % this._gNumTaps; */ SomaxisReading reading = new SomaxisReading(payload [0], dataArray1 [index]); owner.PublishReading(reading, this); } }
public void PublishReading(SomaxisReading reading, ISomaxisTracker tracker) { if (tracker != currentTracker) { Debug.LogWarning("Warning: PublishReading cannot be called from a ISomaxisTracker who is not the current tracker."); return; } foreach (ISomaxisReadingListener listener in listeners) { listener.HandleReading(reading); } }
public void HandleReading(SomaxisReading reading) { if (player == reading.GetPlayer()) { for (int i = 1; i < currentResolution; i++) { // shift arrays rawData [i - 1] = rawData [i]; rawTimestamps [i - 1] = rawTimestamps [i]; } rawData [currentResolution - 1] = reading.GetReading(); rawTimestamps [currentResolution - 1] = reading.GetTimestamp(); //fftTime = Time.deltaTime - lastDt; } }