From f92bf501fca10927d3c13705283913b764a9e3fa Mon Sep 17 00:00:00 2001 From: Philip Pitts <84428015+philippitts@users.noreply.github.com> Date: Thu, 19 Oct 2023 11:56:29 -0400 Subject: [PATCH] Assign square wave values on all synthetic mode updates --- OpenBCI_Ganglion_Library.cpp | 40 +++++++++++++++++------------------- OpenBCI_Ganglion_Library.h | 8 ++++---- 2 files changed, 23 insertions(+), 25 deletions(-) diff --git a/OpenBCI_Ganglion_Library.cpp b/OpenBCI_Ganglion_Library.cpp index ca7a35a..47f4c42 100644 --- a/OpenBCI_Ganglion_Library.cpp +++ b/OpenBCI_Ganglion_Library.cpp @@ -163,7 +163,7 @@ void OpenBCI_Ganglion::processData() { wifi.storeByteBufTx(sampleCounter); } if (streamSynthetic) { - incrementSyntheticChannelData(); + updateSyntheticChannelData(); } else { updateMCPdata(); if (useAccel){ @@ -229,22 +229,20 @@ void OpenBCI_Ganglion::initSyntheticData() { } void OpenBCI_Ganglion::startRunningSynthetic() { - thatTime = millis(); + previousTime = millis(); startRunning(); } -void OpenBCI_Ganglion::incrementSyntheticChannelData() { - thisTime = millis(); - if (thisTime - thatTime > syntheticFrequency) { - thatTime = thisTime; - for (int i = 0; i < 4; i++) { - rising[i] = !rising[i]; - if (rising[i]) { - channelData[i] = 8000000; - } else { - channelData[i] = -8000000; - } - } +void OpenBCI_Ganglion::updateSyntheticChannelData() { + currentTime = millis(); + + if (currentTime - previousTime > syntheticFrequency) { + previousTime = currentTime; + syntheticValue = -syntheticValue; + } + + for (int i = 0; i < 4; i++) { + channelData[i] = syntheticValue; } } @@ -411,22 +409,22 @@ void OpenBCI_Ganglion::testImpedance() { } else { - thisTime = micros(); // time critical activities! - if (thisTime - halfPeriodTimer > HALF_PERIOD) { - halfPeriodTimer = thisTime; + currentTime = micros(); // time critical activities! + if (currentTime - halfPeriodTimer > HALF_PERIOD) { + halfPeriodTimer = currentTime; if (ACrising) { updateDAC(realZeroPosition - HALF_WAVE); ACrising = false; edge = true; - uAsampleTimer = thisTime; + uAsampleTimer = currentTime; } else { updateDAC(realZeroPosition + HALF_WAVE); ACrising = true; edge = true; - uAsampleTimer = thisTime; + uAsampleTimer = currentTime; } } - if (thisTime - uAsampleTimer > UA_SAMPLE_TIME) { + if (currentTime - uAsampleTimer > UA_SAMPLE_TIME) { if (uAsampleCounter > UA_SAMPLE_LIMIT) { updateDAC(realZeroPosition); ACwaveTest = false; @@ -477,7 +475,7 @@ void OpenBCI_Ganglion::testImpedance() { } else { if(currentCounts < minNegCurrentCounts){ minNegCurrentCounts = currentCounts; } } - uAsampleTimer = thisTime; + uAsampleTimer = currentTime; uAsampleCounter++; } } diff --git a/OpenBCI_Ganglion_Library.h b/OpenBCI_Ganglion_Library.h index bf4a73a..2cb7c27 100644 --- a/OpenBCI_Ganglion_Library.h +++ b/OpenBCI_Ganglion_Library.h @@ -58,7 +58,7 @@ class OpenBCI_Ganglion { int changeChannelState_maintainRunningState(int, int); void initSyntheticData(void); void startRunningSynthetic(void); - void incrementSyntheticChannelData(void); + void updateSyntheticChannelData(void); void buildRawPacket(void); void sendRawPacket(void); void compressData18(void); @@ -198,12 +198,12 @@ class OpenBCI_Ganglion { unsigned long gain = GAIN_1; // unsigned long sps = SAMPLE_200; boolean requestToStartRunning = false; - unsigned long thisTime; - unsigned long thatTime; + unsigned long currentTime; + unsigned long previousTime; unsigned long thisStampTime; unsigned long thatStampTime; int timeDifference; - boolean rising[4] = {true,true,true,true}; + int syntheticValue = 8000000; unsigned long regVal;