From 4a3f85c559ec994aaaf5538e5ad6a25f6c108e6b Mon Sep 17 00:00:00 2001 From: Andrew Date: Sat, 10 Aug 2024 21:33:16 +0100 Subject: [PATCH] Added flicker filtering, and support for expert --- Hardware/OSRTT_Expert/file2.ino | 353 +++------ Hardware/OSRTT_Expert/file3.ino | 732 ++++-------------- Hardware/OSRTT_Expert/file4.ino | 687 ++++++++++++++++ Hardware/OSRTT_Pro_Code/file3.ino | 59 +- OSRTT Launcher/OSRTT Launcher/App.config | 3 + OSRTT Launcher/OSRTT Launcher/LiveView.cs | 10 +- .../OSRTT Launcher/Main.Designer.cs | 26 +- OSRTT Launcher/OSRTT Launcher/Main.cs | 119 ++- OSRTT Launcher/OSRTT Launcher/Main.resx | 3 - OSRTT Launcher/OSRTT Launcher/ProcessData.cs | 117 ++- .../Properties/Settings.Designer.cs | 12 + .../Properties/Settings.settings | 3 + .../ResultsSettings.Designer.cs | 48 +- .../OSRTT Launcher/ResultsSettings.cs | 37 +- OSRTT Launcher/OSRTT Launcher/ResultsView.cs | 2 +- 15 files changed, 1282 insertions(+), 929 deletions(-) create mode 100644 Hardware/OSRTT_Expert/file4.ino diff --git a/Hardware/OSRTT_Expert/file2.ino b/Hardware/OSRTT_Expert/file2.ino index d92d6d4..f2d638c 100644 --- a/Hardware/OSRTT_Expert/file2.ino +++ b/Hardware/OSRTT_Expert/file2.ino @@ -1,6 +1,5 @@ #include #include -#include #include #define INPUT_SIZE 8 @@ -20,18 +19,18 @@ char extGammaKeys[] = {'q', 'y', 'h', 'z', 'n', 'u', 's', 'j', 'm', 'e', 'i', 'k //ADC values unsigned long curr_time = micros(); -uint32_t sample_count = 0; //50ms sample time default -unsigned long samplingTime = 150000; -uint16_t adcBuff[32000]; + +#define ArraySize 76000 +uint16_t adcBuff[ArraySize]; + //Button values int buttonState = 0; const int buttonPin = 10; //Digital Potentiometer values (SPI) -byte address = 0x00; -int CS = 0; +int CS = 1; SPISettings settingsA(60000000, MSBFIRST, SPI_MODE0); //Serial connection values @@ -41,6 +40,9 @@ int testRuns = 4; bool vsync = true; bool extendedGamma = true; int fpsLimit = 49; +int GlobalSampleCount = 36651; +int GlobalSampleDelay = 0; +int GlobalStartDelay = 0; unsigned long loopTimer = millis(); @@ -49,7 +51,7 @@ char input[INPUT_SIZE + 1]; void Delay600ns() { digitalWrite(CS, HIGH); - for (int i = 0; i < 10; i++) + for (int i = 0; i < 12; i++) { __asm__("nop"); } @@ -60,19 +62,86 @@ int getADCValue(int count) { uint32_t value = 0; int localCounter = 0; + SPI.beginTransaction(settingsA); while (localCounter < count) { - // Pulse CS to trigger ADC conversion start Delay600ns(); // SPI transaction - SPI.beginTransaction(settingsA); - value += SPI.transfer16(0xFFFF); - SPI.endTransaction(); + __asm__("nop"); + __asm__("nop"); + uint8_t highByte = SPI.transfer(0xFF); + uint8_t lowByte = SPI.transfer(0xFF); + value += (highByte << 8) + lowByte; localCounter++; } + SPI.endTransaction(); value /= count; return value; } +#ifdef __arm__ +// should use uinstd.h to define sbrk but Due causes a conflict +extern "C" char* sbrk(int incr); +#else // __ARM__ +extern char *__brkval; +#endif // __arm__ + +int freeMemory() { + char top; +#ifdef __arm__ + return &top - reinterpret_cast(sbrk(0)); +#elif defined(CORE_TEENSY) || (ARDUINO > 103 && ARDUINO != 151) + return &top - __brkval; +#else // __arm__ + return __brkval ? &top - __brkval : &top - __malloc_heap_start; +#endif // __arm__ +} +/// Fills ADC Buffer, either at native 2.78us per sample, or with delay +/// Triple loops needed to fill all three buffers, plus logic to handle differing sample counts +long fillADCBuffer(int sampleCount = 10000, int delayTime = 0) +{ + int count = sampleCount; + if (count >= ArraySize) + { + count = ArraySize - 1; + } + long tStart = 0; + long tEnd = 0; + SPI.beginTransaction(settingsA); + if (delayTime != 0) + { + tStart = micros(); + for (int i = 0; i < count; i++) + { + Delay600ns(); + // SPI transaction + __asm__("nop"); + __asm__("nop"); + uint8_t highByte = SPI.transfer(0xFF); + uint8_t lowByte = SPI.transfer(0xFF); + adcBuff[i] = (highByte << 8) + lowByte; + delayMicroseconds(delayTime); + } + tEnd = micros(); + } + else + { + tStart = micros(); + for (int i = 0; i < count; i++) + { + Delay600ns(); + // SPI transaction + __asm__("nop"); + __asm__("nop"); + uint8_t highByte = SPI.transfer(0xFF); + uint8_t lowByte = SPI.transfer(0xFF); + adcBuff[i] = (highByte << 8) + lowByte; + } + tEnd = micros(); + } + SPI.endTransaction(); + long tTaken = tEnd - tStart; + return tTaken; +} int getSingleADCValue() { @@ -168,33 +237,21 @@ int checkLightLevel() // Check light level & modulate potentiometer value return 1; } -void runADC(int curr, int nxt, char key, String type) // Run test, press key and print results +void runADC(int curr, int nxt, char key, String type, int samples = 36650, int sampleDelay = 0, int startDelay = 0) // Run test, press key and print results { - //digitalWrite(3, HIGH); + if (samples > ArraySize) + { + samples = ArraySize - 1; + } // Set next colour Keyboard.print(key); - curr_time = micros(); //need to run this in case board is left connected for long period as first run won't read any samples - unsigned long start_time = micros(); - - ///////////////////////////////////////////////////////////// - // Take ADC Readings // - ///////////////////////////////////////////////////////////// - // Loop for samplingTime microseconds - while (curr_time <= (start_time + (samplingTime - 1))) + if (startDelay != 0) { - - adcBuff[sample_count] = getSingleADCValue(); - sample_count++; //Increment sample count - curr_time = micros(); //update current time + delay(startDelay); } - //digitalWrite(3, LOW); - ///////////////////////////////////////////////////////////// - // Print Readings // - ///////////////////////////////////////////////////////////// - // Get how long the samples took to capture in microseconds - int timeTaken = curr_time - start_time; + int timeTaken = fillADCBuffer(samples, sampleDelay); //Print from & to RGB values, time taken, sample count and all captured results Serial.print(type); Serial.print(curr); @@ -203,247 +260,17 @@ void runADC(int curr, int nxt, char key, String type) // Run test, press key and Serial.print(","); Serial.print(timeTaken); Serial.print(","); - Serial.print(sample_count); + Serial.print(samples); Serial.print(","); - for (int i = 0; i < sample_count; i++) + for (int i = 0; i < samples; i++) { Serial.print(adcBuff[i]); Serial.print(","); } Serial.println(); - sample_count = 0; //reset sample count //As using Serial slows the adc down, we take the time after Serial was used. curr_time = micros(); } -bool isBitSet(int var, int pos) -{ - return var & (1 << pos) ? true : false; -} - -void digitalPotWrite(int value) -{ - // 5K D2, 10K D3, 24K D7, 51K D8, 100K D9, 150K D11, 390K D12, 470K D13 - if (isBitSet(value, 0)) { digitalWrite(4, HIGH); } else { digitalWrite(4, LOW); } - if (isBitSet(value, 1)) { digitalWrite(5, HIGH); } else { digitalWrite(5, LOW); } - if (isBitSet(value, 2)) { digitalWrite(6, HIGH); } else { digitalWrite(6, LOW); } - if (isBitSet(value, 3)) { digitalWrite(8, HIGH); } else { digitalWrite(8, LOW); } - if (isBitSet(value, 4)) { digitalWrite(9, HIGH); } else { digitalWrite(9, LOW); } - if (isBitSet(value, 5)) { digitalWrite(11, HIGH); } else { digitalWrite(11, LOW); } - if (isBitSet(value, 6)) { digitalWrite(12, HIGH); } else { digitalWrite(12, LOW); } - if (isBitSet(value, 7)) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); } -} - -void runGammaTest() -{ - Serial.println("G Test Starting"); - if (extendedGamma) - { - int arrSize = sizeof(extGammaArr) / sizeof(int); - for (int i = 0; i < arrSize; i++) - { - Keyboard.print(extGammaKeys[i]); - delay(200); - runADC(extGammaArr[i], extGammaArr[i], extGammaKeys[i], "Gamma: "); - delay(200); - } - } - else - { - int arrSize = sizeof(RGBArr) / sizeof(int); - for (int i = 0; i < arrSize; i++) - { - Keyboard.print(Keys[i]); - delay(200); - runADC(RGBArr[i], RGBArr[i], Keys[i], "Gamma: "); - delay(200); - } - } - Serial.println("G Test Complete"); -} - -void runInputLagTest(int timeBetween) -{ - //Keyboard.print('1'); - //Keyboard.print('Q'); - delay(50); - int sampleTime = 200000; - if (timeBetween == 100) - { - sampleTime = 100000; - } - curr_time = micros(); - unsigned long clickTime = micros(); - //Mouse.click(MOUSE_LEFT); - //Mouse.click(MOUSE_LEFT); - Keyboard.print('6'); - unsigned long start_time = micros(); - while(curr_time <= (start_time + (sampleTime - 1))) - { - adcBuff[sample_count] = getSingleADCValue(); - sample_count++; - curr_time = micros(); - } - ADC0->SWTRIG.bit.START = 0; - int timeTaken = curr_time - start_time; - Keyboard.print('1'); - - Serial.print("IL:"); - Serial.print(start_time - clickTime); - Serial.print(","); - Serial.print(timeTaken); - Serial.print(","); - Serial.print(sample_count); - Serial.print(","); - for (int i = 0; i < sample_count; i++) - { - Serial.print(adcBuff[i]); - Serial.print(","); - } - Serial.println(); - Keyboard.print('1'); - Keyboard.print('1'); - sample_count = 0; //reset sample count - - curr_time = micros(); -} - -void checkLatency() { - delay(100); - Keyboard.print('Q'); - delay(100); - runADC(1000, 1000, 'F', "TL:"); - unsigned long startTime = micros(); - while (curr_time < (startTime + 3000)) - { - curr_time = micros(); - getSerialChars(); - if (input[0] == 'X') - { - break; - } - else if (input[0] == 'S') - { - int t = input[1] - '0'; - t++; - samplingTime = 50000 * t; - break; - } - } -} - -int convertHexToDec(char c) { - if (c <= 57) { - return c - '0'; // Convert char to int - } else { - return c - 55; - } -} - -void getSerialChars() { - for (int i = 0; i < INPUT_SIZE + 1; i++) { - input[i] = ' '; - } - byte size = Serial.readBytes(input, INPUT_SIZE); - input[size] = 0; -} - -void adctest() -{ - //digitalPotWrite(128); - SPI.beginTransaction(settingsA); - int samples = 10000; - long tStart = micros(); - for (int i = 0; i < samples; i++) - { - Delay600ns(); - // SPI transaction - __asm__("nop"); // testing to see if adding no-op will make msb valid - __asm__("nop"); - uint8_t highByte = SPI.transfer(0xFF); - uint8_t lowByte = SPI.transfer(0xFF); - adcBuff[i] = (highByte << 8) + lowByte; - //adcBuff[i] = SPI.transfer16(0xFFFF); - } - long tEnd = micros(); - SPI.endTransaction(); - float tTaken = tEnd - tStart; - tTaken /= samples; - Serial.print(tTaken); - Serial.println(" us per sample"); - long adcAvg = 0; - int min = 65535; - int max = 0; - for (int i = 0; i < samples; i++) - { - Serial.print(adcBuff[i]); - Serial.print(","); - adcAvg += adcBuff[i]; - if (adcBuff[i] < min) - { - min = adcBuff[i]; - } - else if (adcBuff[i] > max) - { - max = adcBuff[i]; - } - } - Serial.println(); - Serial.print("ADC Value average: "); - Serial.print(adcAvg / samples); - Serial.print(", Min = "); - Serial.print(min); - Serial.print(", Max = "); - Serial.println(max); -} - - -void setup() { - pinMode(buttonPin, INPUT_PULLUP); //Button input on pin 2 - if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { - Serial.println(F("SSD1306 allocation failed")); - for (;;); - } - drawSplashScreen(); - - pinMode (4, OUTPUT); //D2, SW1 - pinMode (5, OUTPUT); //D3, SW2 - pinMode (6, OUTPUT); //D4, SW3 - pinMode (8, OUTPUT); //D7, SW4 - pinMode (9, OUTPUT); //D9, SW5 - pinMode (11, OUTPUT); //D11, SW6 - pinMode (12, OUTPUT); //D12, SW7 - pinMode (13, OUTPUT); //D13, SW8 - - pinMode(CS, OUTPUT); // D0, CS - digitalWrite(CS, LOW); - digitalPotWrite(0x00); - - Serial.begin(115200); //Open Serial connection at 115200 baud - long timer = millis(); - while (!Serial) - { - if (millis() > (timer + 180000)) - { - clearDisplayBuffer(); - } - buttonState = digitalRead(buttonPin); - if (buttonState == HIGH) - { - oledAwaitingSerial("CONNECTION"); - } - } - Keyboard.begin(); //Open keyboard connection over USB - pinMode(buttonPin, INPUT_PULLUP); //Button input on pin 2 - //pinMode(13, OUTPUT); //Onboard LED - - SPI.begin(); - - Serial.println("Begin..."); - Serial.println("EXPERT"); - - adctest(); - -} diff --git a/Hardware/OSRTT_Expert/file3.ino b/Hardware/OSRTT_Expert/file3.ino index 5eec3c8..8011db5 100644 --- a/Hardware/OSRTT_Expert/file3.ino +++ b/Hardware/OSRTT_Expert/file3.ino @@ -1,632 +1,160 @@ -void loop() { - //Delay600ns(); - Serial.setTimeout(1000); - getSerialChars(); - if (millis() == (loopTimer + 180000)) - { - clearDisplayBuffer(); - loopTimer = millis(); - } - buttonState = digitalRead(buttonPin); - if (buttonState == HIGH) - { - oledFourLines("CONNECTED", "TO", "DESKTOP", "APP"); - adctest(); +bool isBitSet(int var, int pos) +{ + return var & (1 << pos) ? true : false; +} - } - if (input[0] == 'A') +void digitalPotWrite(int value) +{ + // 5K D2, 10K D3, 24K D7, 51K D8, 100K D9, 150K D11, 390K D12, 470K D13 + if (isBitSet(value, 0)) { digitalWrite(4, HIGH); } else { digitalWrite(4, LOW); } + if (isBitSet(value, 1)) { digitalWrite(5, HIGH); } else { digitalWrite(5, LOW); } + if (isBitSet(value, 2)) { digitalWrite(6, HIGH); } else { digitalWrite(6, LOW); } + if (isBitSet(value, 3)) { digitalWrite(8, HIGH); } else { digitalWrite(8, LOW); } + if (isBitSet(value, 4)) { digitalWrite(9, HIGH); } else { digitalWrite(9, LOW); } + if (isBitSet(value, 5)) { digitalWrite(11, HIGH); } else { digitalWrite(11, LOW); } + if (isBitSet(value, 6)) { digitalWrite(12, HIGH); } else { digitalWrite(12, LOW); } + if (isBitSet(value, 7)) { digitalWrite(13, HIGH); } else { digitalWrite(13, LOW); } +} + +void runGammaTest() +{ + Serial.println("G Test Starting"); + if (extendedGamma) { - int arrSize = sizeof(RGBArr) / sizeof(int); - Serial.print("RGB Array : "); + int arrSize = sizeof(extGammaArr) / sizeof(int); for (int i = 0; i < arrSize; i++) { - Serial.print(RGBArr[i]); - Serial.print(","); - } - Serial.println(); - } - else if (input[0] == 'B') - { - // Brightness Calibration screen - Serial.setTimeout(200); - int mod = input[1] - '0'; - int potVal = 1 + mod; - digitalPotWrite(potVal); - Serial.println("BRIGHTNESS CHECK"); - delay(500); - int sample_count = 0; - while (sample_count < 1000) - { - adcBuff[sample_count] = getSingleADCValue(); //save new ADC value to buffer @ sample_count position - sample_count++; //Increment sample count - } - Serial.print("Stability:"); - for (int i = 0; i < sample_count; i++) - { - Serial.print(adcBuff[i]); - Serial.print(","); - } - Serial.println(); - sample_count = 0; - - while (input[0] != 'X') - { - // Check serial for cancel or new potentiometer value - getSerialChars(); - int in = 0; - if (input[0] <= 57) - { - in = input[0] - '0'; // Convert char to int - } - else - { - in = input[0] - 55; - } - - if (in >= 1 && in <= 15) - { - // Increment potentiometer value by multiples of 10 up to 220 - int add = 15 * in; - potVal = 1 + add; - digitalPotWrite(potVal); - } - else if (in == 0) - { - potVal = 1; - digitalPotWrite(potVal); - } - int counter = 0; - long value = 0; - while (counter < 250) - { - value += getSingleADCValue(); - counter++; - } - value /= counter; - Serial.print("Brightness:"); - Serial.print(value); - Serial.print(":"); - Serial.println(potVal); - delay(300); + Keyboard.print(extGammaKeys[i]); + delay(200); + runADC(extGammaArr[i], extGammaArr[i], extGammaKeys[i], "Gamma: "); + delay(200); } } - else if (input[0] == 'F') - { - Serial.println("FW:" + firmware); - } - else if (input[0] == 'I') + else { - testRuns = input[1] - '0'; - delay(100); - Serial.print("Runs:"); - Serial.println(testRuns); - delay(100); - Serial.print("BoardType:"); - Serial.println(boardType); - delay(50); - Serial.print("BoardType:"); - Serial.println(boardType); - delay(100); - Serial.println("FW:" + firmware); - delay(100); - Serial.print("FPS Key:"); - Serial.println(fpsLimit); - delay(100); int arrSize = sizeof(RGBArr) / sizeof(int); - Serial.print("RGB Array:"); for (int i = 0; i < arrSize; i++) { - Serial.print(RGBArr[i]); - Serial.print(","); - } - - Serial.println(); - UniqueIDdump(Serial); - Serial.println("Handshake"); - } - else if (input[0] == 'J') - { - Serial.println("Starting Pro Potentiometer Check"); - int count = 0; - while (count < 256) - { - digitalPotWrite(count); - Serial.println(count); - //Serial.print(","); - delay(100); - adcBuff[count] = getSingleADCValue(); - //Serial.println(value); - //delay(2000); - count++; - } - Serial.print("PROADC:"); - for (int i = 0; i < 256; i++) - { - Serial.print(i); - Serial.print(":"); - Serial.print(adcBuff[i]); - Serial.print(","); - } - Serial.println(); - //checkLightLevel(); - } - else if (input[0] == 'K') - { - int count = 1; - Serial.println(count); - while (count < 256) - { - buttonState = digitalRead(buttonPin); - if (buttonState == HIGH) //Run when button pressed - { - digitalPotWrite(count); - digitalPotWrite(count); - //Serial.print(count); - //Serial.print(","); - delay(200); - adcBuff[count] = getSingleADCValue(); - //Serial.println(value); - //delay(2000); - count*=2; - Serial.println(count); - } - delay(50); - } - Serial.print("PROADC:"); - for (int i = 0; i < 256; i++) - { - Serial.print(i); - Serial.print(":"); - Serial.print(adcBuff[i]); - Serial.print(","); - } - Serial.println(); - //checkLightLevel(); - } - else if (input[0] == 'M') - { - testRuns = input[1] - '0'; - delay(100); - Serial.print("Runs:"); - Serial.println(testRuns); - } - else if (input[0] == 'L') - { - int hundreds = convertHexToDec(input[1]) * 100; - int tens = convertHexToDec(input[2]) * 10; - int ones = convertHexToDec(input[3]); - fpsLimit = hundreds + tens + ones; - delay(100); - Serial.print("FPS Key:"); - Serial.println(fpsLimit); - } - else if (input[0] == 'G') - { - delay(2000); - int brightnessTest = checkLightLevel(); - runGammaTest(); - } - else if (input[0] == 'V') - { - int vState = input[1] - '0'; - if (vState == 0) - { - vsync = false; - } - else if (vState == 1) - { - vsync = true; + Keyboard.print(Keys[i]); + delay(200); + runADC(RGBArr[i], RGBArr[i], Keys[i], "Gamma: "); + delay(200); } - Serial.print("VSync:"); - Serial.println(vsync); } - else if (input[0] == 'Q') + Serial.println("G Test Complete"); +} + +void runInputLagTest(int timeBetween) +{ + //Keyboard.print('1'); + //Keyboard.print('Q'); + //delay(50); + + unsigned long clickTime = micros(); + //Mouse.click(MOUSE_LEFT); + //Mouse.click(MOUSE_LEFT); + Keyboard.print('6'); + long start_time = micros(); + int timeTaken = fillADCBuffer(ArraySize - 1, 2); + Keyboard.print('1'); + + Serial.print("IL:"); + Serial.print(start_time - clickTime); + Serial.print(","); + Serial.print(timeTaken); + Serial.print(","); + Serial.print(ArraySize - 1); + Serial.print(","); + for (int i = 0; i < ArraySize - 1; i++) + { + Serial.print(adcBuff[i]); + Serial.print(","); + } + Serial.println(); + Keyboard.print('1'); + Keyboard.print('1'); +} + +void checkLatency() { + delay(100); + Keyboard.print('Q'); + delay(100); + runADC(1000, 1000, 'F', "TL:"); + unsigned long startTime = micros(); + while (curr_time < (startTime + 3000)) { - int extGammaState = input[1] - '0'; - if (extGammaState == 0) + curr_time = micros(); + getSerialChars(); + if (input[0] == 'X') { - extendedGamma = false; + break; } - else if (extGammaState == 1) + else if (input[0] == 'S') { - extendedGamma = true; + int t = input[1] - '0'; + t++; + + break; } - Serial.print("Extended Gamma:"); - Serial.println(extendedGamma); } - else if (input[0] == 'N') - { - int length = input[1] - '0'; - length++; - samplingTime = 50000 * length; - Serial.print("Sampling Time:"); - Serial.println(samplingTime); - } - else if (input[0] == 'T') - { - Serial.println("Ready to test"); - oledFourLines("PRESS", "BUTTON", "TO START", "THE TEST"); - Serial.setTimeout(200); - while (input[0] != 'X') - { - // Check if button has been pressed - buttonState = digitalRead(buttonPin); - if (buttonState == HIGH) //Run when button pressed - { - Serial.setTimeout(500); - Keyboard.print((char)fpsLimit); - Keyboard.print((char)fpsLimit); - Keyboard.print('f'); - delay(100); - oledFourLines("CHECKING", "FOR", "STROBING", ""); - int sample_count = 0; - while (sample_count < 1000) - { - adcBuff[sample_count] = getSingleADCValue(); //save new ADC value to buffer @ sample_count position - sample_count++; //Increment sample count - } - int minVal = 65520; - int maxVal = 0; - for (int i = 200; i < sample_count; i++) - { - if (adcBuff[i] < minVal) - { - minVal = adcBuff[i]; - } - else if (adcBuff[i] > maxVal) - { - maxVal = adcBuff[i]; - } - } - oledFourLines("Strobing", "value:", F(maxVal - minVal), ""); - if ((maxVal - minVal) > 1000) - { - oledFourLines("BACKLIGHT", "STROBING,", "CONTINUE?", "PRESS BTN"); - bool btn = digitalRead(buttonPin); - while (input[0] != 'X' && !btn) - { - getSerialChars(); - btn = digitalRead(buttonPin); - } - if (input[0] == 'X') - { - break; - } - } - sample_count = 0; +} - // Check monitor brightness level - oledFourLines("CHECKING", "LIGHT", "LEVEL", ""); - int brightnessTest = checkLightLevel(); - if (brightnessTest == 0) - { - // If brightness too low or high, don't run the test - Serial.println("Cancelling test"); - //digitalWrite(13, HIGH); - digitalPotWrite(0x00); - oledFourLines("FAILED TO", "CALIBRATE", "LIGHT", "LEVEL"); - break; - } - else - { - oledFourLines("CHECKING", "SYSTEM", "LATENCY", ""); - checkLatency(); - delay(100); - Serial.println("Test Started"); - // Set FPS limit (default 1000 FPS, key '1') - delay(50); - oledFourLines("RUNNING", "GAMMA", "TEST", ""); - runGammaTest(); - delay(100); - int runCount = 0; - while (input[0] != 'X') - { - //oledFourLines("RUNNING", "FULL", "TEST", ""); - getSerialChars(); - if (input[0] == 'X') - { - break; - } - else if (input[0] == 'S') - { - int t = input[1] - '0'; - t++; - samplingTime = 50000 * t; - } - else - { - int currentIndex = 0; - int nextIndex = 0; - if (input[0] <= 57) - { - currentIndex = input[0] - '0'; // Convert char to int - } - else - { - currentIndex = input[0] - 55; - } - if (input[1] <= 57) - { - nextIndex = input[1] - '0'; // Convert char to int - } - else - { - nextIndex = input[1] - 55; - } - if (currentIndex == 0 && nextIndex == 1) - { - runCount++; - } - int arrSize = sizeof(RGBArr) / sizeof(int); - if (currentIndex >= 0 && currentIndex < arrSize) - { - int current = RGBArr[currentIndex]; - int next = RGBArr[nextIndex]; - oledTestRunning(current, next, runCount); - Keyboard.print(Keys[currentIndex]); - delay(300); - runADC(current, next, Keys[nextIndex], "Results: "); - delay(50); - Serial.println("NEXT"); - } - } - delay(50); - } - } - oledFourLines("TEST", "COMPLETE", "CHECK", "DESKTOP"); - digitalPotWrite(0x01); - //} - } - else - { - for (int i = 0; i < INPUT_SIZE + 1; i++) - { - input[i] = ' '; - } - byte sized = Serial.readBytes(input, INPUT_SIZE); - input[sized] = 0; - if (input[0] == 'P') - { - while (input[0] != 'X' && input[0] != 'S') - { - getSerialChars(); - curr_time = micros(); //update current time - } - } - else if (input[0] == 'X') - { - break; - } - } - } +int convertHexToDec(char c) { + if (c <= 57) { + return c - '0'; // Convert char to int + } else { + return c - 55; } - else if (input[0] == 'P') - { - // Input lag testing - int clicks = 1; - int timeBetween = 300; - int totalTime = 100; - delay(100); - oledFourLines("SETTING","CLICK","COUNT",""); - Serial.println("IL Clicks"); - while (input[0] != 'X') - { - getSerialChars(); - if (input[0] != ' ') - { - int firstDigit = input[0] - '0'; - int secondDigit = input[1] - '0'; - if (firstDigit == 0) - { - clicks = (secondDigit * 10); - } - else - { - clicks = ((firstDigit * 100) + (secondDigit*10)); - } - break; - } - } - Serial.print("C: "); - Serial.println(clicks); - if (input[0] != 'X') { - oledFourLines("SETTING","TIME","BETWEEN",""); - Serial.println("IL Time"); - while (input[0] != 'X') - { - getSerialChars(); - if (input[0] != ' ') - { - int firstDigit = input[0] - '0'; - int secondDigit = input[1] - '0'; - if (firstDigit == 0) - { - timeBetween = secondDigit * 100; - } - else - { - firstDigit *= 1000; - secondDigit *= 100; - timeBetween = firstDigit + secondDigit; - } - if (timeBetween == 100) - { - totalTime = 100; - timeBetween = 0; - } - else if (timeBetween == 200) - { - totalTime = 200; - timeBetween = 0; - } - else - { - totalTime = timeBetween; - timeBetween = timeBetween - 200; - } - Serial.print("Time between saved: "); - Serial.println(timeBetween); - break; - } - } - } - if (input[0] != 'X') { - Serial.setTimeout(200); - digitalPotWrite(1); - while (input[0] != 'X') - { - oledFourLines("PRESS","BUTTON","TO","START"); - buttonState = digitalRead(buttonPin); - if (buttonState == HIGH) //Run when button pressed - { - oledFourLines("RUNNING","INPUT","LATENCY","TEST"); - Keyboard.print('1'); - delay(100); - int sw = micros(); - for (int k = 0; k < clicks; k++) - { - runInputLagTest(totalTime); - int sw2 = micros(); - if (sw2 < (sw + timeBetween)) - { - delay((sw + timeBetween) - sw2); - } - } - Serial.println("IL Finished"); - Keyboard.press(KEY_ESC); - Keyboard.releaseAll(); - oledFourLines("LATENCY","TEST","FINISHED",""); - input[0] = 'X'; - break; - } - getSerialChars(); - delay(10); - } - } +} + +void getSerialChars() { + for (int i = 0; i < INPUT_SIZE + 1; i++) { + input[i] = ' '; } - else if (input[0] == 'O') - { - // Brightness Calibration screen - Serial.setTimeout(200); - int mod = input[1] - '0'; - int potVal = 1 + mod; - digitalPotWrite(potVal); - Serial.println("LIVE VIEW"); - delay(200); - while (input[0] != 'X') - { - getSerialChars(); - if (input[0] == 'P') - { + byte size = Serial.readBytes(input, INPUT_SIZE); + input[size] = 0; +} - long startTime = micros(); - long currentTime = micros(); - long times[16000]; - int count = 0; - while (currentTime < (startTime + 3000000)) - { - currentTime = micros(); - times[count] = currentTime - startTime; - adcBuff[count] = getSingleADCValue(); - delayMicroseconds(250); - count++; - } - Serial.print("LiveData:"); - for (int i = 0; i < count; i++) - { - Serial.print(times[i]); - Serial.print(":"); - Serial.print(adcBuff[i]); - Serial.print(","); - } - Serial.println(); - Serial.println("End"); - } - int in = 0; - if (input[0] <= 57) - { - in = input[0] - '0'; // Convert char to int - } - else - { - in = input[0] - 55; - } +void setup() { + pinMode(buttonPin, INPUT_PULLUP); //Button input on pin 2 + if (!display.begin(SSD1306_SWITCHCAPVCC, SCREEN_ADDRESS)) { + Serial.println(F("SSD1306 allocation failed")); + for (;;); + } + drawSplashScreen(); + + pinMode (4, OUTPUT); //D2, SW1 + pinMode (5, OUTPUT); //D3, SW2 + pinMode (6, OUTPUT); //D4, SW3 + pinMode (8, OUTPUT); //D7, SW4 + pinMode (9, OUTPUT); //D9, SW5 + pinMode (11, OUTPUT); //D11, SW6 + pinMode (12, OUTPUT); //D12, SW7 + pinMode (13, OUTPUT); //D13, SW8 + + pinMode(CS, OUTPUT); // D0, CS + digitalWrite(CS, LOW); + digitalPotWrite(0x00); - if (in >= 1 && in <= 15) - { - // Increment potentiometer value by multiples of 10 up to 220 - int add = 15 * in; - potVal = 1 + add; - digitalPotWrite(potVal); - Serial.print("pot val:"); - Serial.println(potVal); - } - else if (in == 0) - { - potVal = 1; - digitalPotWrite(potVal); - Serial.print("pot val:"); - Serial.println(potVal); - } - } - } - else if (input[0] == 'W') + Serial.begin(115200); //Open Serial connection at 115200 baud + long timer = millis(); + while (!Serial) { - long s = micros(); - int counter = 10000; - for(int i = 0; i < counter; i++) + if (millis() > (timer + 180000)) { - adcBuff[i] = getSingleADCValue(); + clearDisplayBuffer(); } - long e = micros(); - Serial.print("Sample time: "); - float t = (e - s) / counter; - Serial.println(t); - - } - else if (input[0] == 'Y') - { - int counter = 0; - digitalPotWrite(0); - while (input[0] != 'X') + buttonState = digitalRead(buttonPin); + if (buttonState == HIGH) { - if (digitalRead(buttonPin)) - { - counter *= 2; - if (counter == 0) - { - counter++; - } else if (counter > 128) - { - counter = 0; - } - digitalPotWrite(counter); - Serial.print("Current value:"); - Serial.println(counter); - delay(300); - } - delay(10); + oledAwaitingSerial("CONNECTION"); } } - else if (input[0] == 'Z') - { - int potVal = 1; - uint16_t result = 0; - Serial.println("PotVal,Result"); - for (int i = 0; i < 255; i++) - { - int counter = 0; - digitalPotWrite(i); - Serial.print(i); - Serial.print(","); - while (counter < 100) - { - result = getSingleADCValue(); //save new ADC value to buffer @ sample_count position - counter++; - } - Serial.println(result); - oledFourLines("POT VAL:", String(potVal), "VAL:", String(result)); - } - } - delay(100); + Keyboard.begin(); //Open keyboard connection over USB + + SPI.begin(); + + Serial.println("Begin..."); + Serial.println("EXPERT"); + } diff --git a/Hardware/OSRTT_Expert/file4.ino b/Hardware/OSRTT_Expert/file4.ino new file mode 100644 index 0000000..9f0b709 --- /dev/null +++ b/Hardware/OSRTT_Expert/file4.ino @@ -0,0 +1,687 @@ +void loop() { + //Delay600ns(); + Serial.setTimeout(100); + getSerialChars(); + if (millis() == (loopTimer + 180000)) + { + clearDisplayBuffer(); + loopTimer = millis(); + } + buttonState = digitalRead(buttonPin); + if (buttonState == HIGH) + { + // oledFourLines("CONNECTED", "TO", "DESKTOP", "APP"); + //digitalPotWrite(208); + fillADCBuffer(10000, 100); + for (int i = 0; i < 10000; i++) + { + Serial.print(adcBuff[i]); + Serial.print(","); + } + Serial.println(); + + } + if (input[0] == 'A') + { + int arrSize = sizeof(RGBArr) / sizeof(int); + Serial.print("RGB Array : "); + for (int i = 0; i < arrSize; i++) + { + Serial.print(RGBArr[i]); + Serial.print(","); + } + Serial.println(); + } + else if (input[0] == 'B') + { + // Brightness Calibration screen + Serial.setTimeout(200); + int mod = input[1] - '0'; + int potVal = 1 + mod; + digitalPotWrite(potVal); + Serial.println("BRIGHTNESS CHECK"); + delay(500); + int sample_count = 0; + while (sample_count < 1000) + { + adcBuff[sample_count] = getSingleADCValue(); //save new ADC value to buffer @ sample_count position + sample_count++; //Increment sample count + } + Serial.print("Stability:"); + for (int i = 0; i < sample_count; i++) + { + Serial.print(adcBuff[i]); + Serial.print(","); + } + Serial.println(); + sample_count = 0; + + while (input[0] != 'X') + { + // Check serial for cancel or new potentiometer value + getSerialChars(); + int in = 0; + if (input[0] <= 57) + { + in = input[0] - '0'; // Convert char to int + } + else + { + in = input[0] - 55; + } + + if (in >= 1 && in <= 15) + { + // Increment potentiometer value by multiples of 10 up to 220 + int add = 15 * in; + potVal = 1 + add; + digitalPotWrite(potVal); + } + else if (in == 0) + { + potVal = 1; + digitalPotWrite(potVal); + } + int counter = 0; + long value = 0; + while (counter < 250) + { + value += getSingleADCValue(); + counter++; + } + value /= counter; + Serial.print("Brightness:"); + Serial.print(value); + Serial.print(":"); + Serial.println(potVal); + delay(300); + } + } + else if (input[0] == 'F') + { + Serial.println("FW:" + firmware); + } + else if (input[0] == 'I') + { + testRuns = input[1] - '0'; + delay(100); + Serial.print("Runs:"); + Serial.println(testRuns); + delay(100); + Serial.print("BoardType:"); + Serial.println(boardType); + delay(50); + Serial.print("BoardType:"); + Serial.println(boardType); + delay(100); + Serial.println("FW:" + firmware); + delay(100); + Serial.print("FPS Key:"); + Serial.println(fpsLimit); + delay(100); + int arrSize = sizeof(RGBArr) / sizeof(int); + Serial.print("RGB Array:"); + for (int i = 0; i < arrSize; i++) + { + Serial.print(RGBArr[i]); + Serial.print(","); + } + + Serial.println(); + UniqueIDdump(Serial); + Serial.println("Handshake"); + } + else if (input[0] == 'J') + { + Serial.println("Starting Pro Potentiometer Check"); + int count = 0; + while (count < 256) + { + digitalPotWrite(count); + Serial.println(count); + //Serial.print(","); + delay(100); + adcBuff[count] = getSingleADCValue(); + //Serial.println(value); + //delay(2000); + count++; + } + Serial.print("PROADC:"); + for (int i = 0; i < 256; i++) + { + Serial.print(i); + Serial.print(":"); + Serial.print(adcBuff[i]); + Serial.print(","); + } + Serial.println(); + //checkLightLevel(); + } + else if (input[0] == 'K') + { + int count = 1; + Serial.println(count); + while (count < 256) + { + buttonState = digitalRead(buttonPin); + if (buttonState == HIGH) //Run when button pressed + { + digitalPotWrite(count); + digitalPotWrite(count); + //Serial.print(count); + //Serial.print(","); + delay(200); + adcBuff[count] = getSingleADCValue(); + //Serial.println(value); + //delay(2000); + count*=2; + Serial.println(count); + } + delay(50); + } + Serial.print("PROADC:"); + for (int i = 0; i < 256; i++) + { + Serial.print(i); + Serial.print(":"); + Serial.print(adcBuff[i]); + Serial.print(","); + } + Serial.println(); + //checkLightLevel(); + } + else if (input[0] == 'M') + { + testRuns = input[1] - '0'; + delay(100); + Serial.print("Runs:"); + Serial.println(testRuns); + } + else if (input[0] == 'L') + { + int hundreds = convertHexToDec(input[1]) * 100; + int tens = convertHexToDec(input[2]) * 10; + int ones = convertHexToDec(input[3]); + fpsLimit = hundreds + tens + ones; + delay(100); + Serial.print("FPS Key:"); + Serial.println(fpsLimit); + } + else if (input[0] == 'G') + { + delay(2000); + int brightnessTest = checkLightLevel(); + runGammaTest(); + } + else if (input[0] == 'V') + { + int vState = input[1] - '0'; + if (vState == 0) + { + vsync = false; + } + else if (vState == 1) + { + vsync = true; + } + Serial.print("VSync:"); + Serial.println(vsync); + } + else if (input[0] == 'Q') + { + int extGammaState = input[1] - '0'; + if (extGammaState == 0) + { + extendedGamma = false; + } + else if (extGammaState == 1) + { + extendedGamma = true; + } + Serial.print("Extended Gamma:"); + Serial.println(extendedGamma); + } + else if (input[0] == 'N') + { + int length = input[1] - '0'; + if (length == 0) { GlobalSampleCount = 18326; } // 50ms + else if (length == 1) { GlobalSampleCount = 36651; } // 100ms + else if (length == 2) { GlobalSampleCount = 54976; } // 150ms + else if (length == 3) { GlobalSampleCount = 73302; } // 200ms + else if (length == 4) { // 250ms + GlobalSampleCount = 18326; + GlobalSampleDelay = 1; + } + else if (length == 5) { // 350ms + GlobalSampleCount = 73877; + GlobalSampleDelay = 2; + } + else if (length == 6) { // 500ms + GlobalSampleCount = 64615; + GlobalSampleDelay = 5; + } + else if (length == 7) { // 1s + GlobalSampleCount = 72790; + GlobalSampleDelay = 11; + } + // Serial.print("Sampling Time:"); + // Serial.println(samplingTime); + } + else if (input[0] == 'T') + { + Serial.println("Ready to test"); + oledFourLines("PRESS", "BUTTON", "TO START", "THE TEST"); + Serial.setTimeout(200); + while (input[0] != 'X') + { + // Check if button has been pressed + buttonState = digitalRead(buttonPin); + if (buttonState == HIGH) //Run when button pressed + { + Serial.setTimeout(500); + Keyboard.print((char)fpsLimit); + Keyboard.print((char)fpsLimit); + Keyboard.print('f'); + delay(100); + oledFourLines("CHECKING", "FOR", "STROBING", ""); + int sample_count = 0; + while (sample_count < 1000) + { + adcBuff[sample_count] = getSingleADCValue(); //save new ADC value to buffer @ sample_count position + sample_count++; //Increment sample count + } + int minVal = 65520; + int maxVal = 0; + for (int i = 200; i < sample_count; i++) + { + if (adcBuff[i] < minVal) + { + minVal = adcBuff[i]; + } + else if (adcBuff[i] > maxVal) + { + maxVal = adcBuff[i]; + } + } + oledFourLines("Strobing", "value:", F(maxVal - minVal), ""); + if ((maxVal - minVal) > 1000) + { + oledFourLines("BACKLIGHT", "STROBING,", "CONTINUE?", "PRESS BTN"); + bool btn = digitalRead(buttonPin); + while (input[0] != 'X' && !btn) + { + getSerialChars(); + btn = digitalRead(buttonPin); + } + if (input[0] == 'X') + { + break; + } + } + sample_count = 0; + + // Check monitor brightness level + oledFourLines("CHECKING", "LIGHT", "LEVEL", ""); + int brightnessTest = checkLightLevel(); + if (brightnessTest == 0) + { + // If brightness too low or high, don't run the test + Serial.println("Cancelling test"); + //digitalWrite(13, HIGH); + digitalPotWrite(0x00); + oledFourLines("FAILED TO", "CALIBRATE", "LIGHT", "LEVEL"); + break; + } + else + { + oledFourLines("CHECKING", "SYSTEM", "LATENCY", ""); + checkLatency(); + delay(100); + Serial.println("Test Started"); + // Set FPS limit (default 1000 FPS, key '1') + delay(50); + oledFourLines("RUNNING", "GAMMA", "TEST", ""); + runGammaTest(); + delay(100); + int runCount = 0; + while (input[0] != 'X') + { + //oledFourLines("RUNNING", "FULL", "TEST", ""); + getSerialChars(); + if (input[0] == 'X') + { + break; + } + else if (input[0] == 'S') + { + int t = input[1] - '0'; + t++; + + } + else + { + int currentIndex = 0; + int nextIndex = 0; + if (input[0] <= 57) + { + currentIndex = input[0] - '0'; // Convert char to int + } + else + { + currentIndex = input[0] - 55; + } + if (input[1] <= 57) + { + nextIndex = input[1] - '0'; // Convert char to int + } + else + { + nextIndex = input[1] - 55; + } + if (currentIndex == 0 && nextIndex == 1) + { + runCount++; + } + int arrSize = sizeof(RGBArr) / sizeof(int); + if (currentIndex >= 0 && currentIndex < arrSize) + { + int current = RGBArr[currentIndex]; + int next = RGBArr[nextIndex]; + oledTestRunning(current, next, runCount); + Keyboard.print(Keys[currentIndex]); + delay(300); + runADC(current, next, Keys[nextIndex], "Results: ", GlobalSampleCount, GlobalSampleDelay, GlobalStartDelay); + delay(50); + Serial.println("NEXT"); + } + } + delay(50); + } + } + oledFourLines("TEST", "COMPLETE", "CHECK", "DESKTOP"); + digitalPotWrite(0x01); + //} + } + else + { + for (int i = 0; i < INPUT_SIZE + 1; i++) + { + input[i] = ' '; + } + byte sized = Serial.readBytes(input, INPUT_SIZE); + input[sized] = 0; + if (input[0] == 'P') + { + while (input[0] != 'X' && input[0] != 'S') + { + getSerialChars(); + curr_time = micros(); //update current time + } + } + else if (input[0] == 'X') + { + break; + } + } + } + } + else if (input[0] == 'P') + { + // Input lag testing + int clicks = 1; + int timeBetween = 300; + int totalTime = 100; + delay(100); + oledFourLines("SETTING","CLICK","COUNT",""); + Serial.println("IL Clicks"); + while (input[0] != 'X') + { + getSerialChars(); + if (input[0] != ' ') + { + int firstDigit = input[0] - '0'; + int secondDigit = input[1] - '0'; + if (firstDigit == 0) + { + clicks = (secondDigit * 10); + } + else + { + clicks = ((firstDigit * 100) + (secondDigit*10)); + } + break; + } + } + Serial.print("C: "); + Serial.println(clicks); + if (input[0] != 'X') { + oledFourLines("SETTING","TIME","BETWEEN",""); + Serial.println("IL Time"); + while (input[0] != 'X') + { + getSerialChars(); + if (input[0] != ' ') + { + int firstDigit = input[0] - '0'; + int secondDigit = input[1] - '0'; + if (firstDigit == 0) + { + timeBetween = secondDigit * 100; + } + else + { + firstDigit *= 1000; + secondDigit *= 100; + timeBetween = firstDigit + secondDigit; + } + if (timeBetween == 100) + { + totalTime = 100; + timeBetween = 0; + } + else if (timeBetween == 200) + { + totalTime = 200; + timeBetween = 0; + } + else + { + totalTime = timeBetween; + timeBetween = timeBetween - 200; + } + Serial.print("Time between saved: "); + Serial.println(timeBetween); + break; + } + } + } + if (input[0] != 'X') { + Serial.setTimeout(200); + digitalPotWrite(1); + while (input[0] != 'X') + { + oledFourLines("PRESS","BUTTON","TO","START"); + buttonState = digitalRead(buttonPin); + if (buttonState == HIGH) //Run when button pressed + { + oledFourLines("RUNNING","INPUT","LATENCY","TEST"); + Keyboard.print('1'); + delay(100); + int sw = micros(); + for (int k = 0; k < clicks; k++) + { + runInputLagTest(totalTime); + int sw2 = micros(); + if (sw2 < (sw + timeBetween)) + { + delay((sw + timeBetween) - sw2); + } + } + Serial.println("IL Finished"); + Keyboard.press(KEY_ESC); + Keyboard.releaseAll(); + oledFourLines("LATENCY","TEST","FINISHED",""); + input[0] = 'X'; + break; + } + getSerialChars(); + delay(10); + } + } + } + else if (input[0] == 'O') + { + // Brightness Calibration screen + Serial.setTimeout(200); + int mod = input[1] - '0'; + int potVal = 1 + mod; + digitalPotWrite(potVal); + Serial.println("LIVE VIEW"); + delay(200); + while (input[0] != 'X') + { + getSerialChars(); + if (input[0] == 'P') + { + + long startTime = micros(); + long currentTime = micros(); + uint16_t times[16000]; + int count = 0; + times[count] = currentTime - startTime; + adcBuff[count] = getSingleADCValue(); + delayMicroseconds(250); + count++; + while (currentTime < (startTime + 3000000)) + { + currentTime = micros(); + times[count] = currentTime - times[count - 1]; + adcBuff[count] = getSingleADCValue(); + delayMicroseconds(250); + count++; + } + Serial.print("LiveData:"); + for (int i = 0; i < count; i++) + { + Serial.print(times[i]); + Serial.print(":"); + Serial.print(adcBuff[i]); + Serial.print(","); + } + Serial.println(); + Serial.println("End"); + } + int in = 0; + if (input[0] <= 57) + { + in = input[0] - '0'; // Convert char to int + } + else + { + in = input[0] - 55; + } + + if (in >= 1 && in <= 15) + { + // Increment potentiometer value by multiples of 10 up to 220 + int add = 15 * in; + potVal = 1 + add; + digitalPotWrite(potVal); + Serial.print("pot val:"); + Serial.println(potVal); + } + else if (in == 0) + { + potVal = 1; + digitalPotWrite(potVal); + Serial.print("pot val:"); + Serial.println(potVal); + } + } + } + else if (input[0] == 'W') + { + // long s = micros(); + // int counter = 10000; + // for(int i = 0; i < counter; i++) + // { + // adcBuff[i] = getSingleADCValue(); + // } + // long e = micros(); + // Serial.print("Sample time: "); + // float t = (e - s) / counter; + // Serial.println(t); + while (input[0] != 'X') + { + getSerialChars(); + if (digitalRead(buttonPin)) + { + Serial.println("EXSTART"); + for (int p = 0; p < 256; p++) + { + digitalPotWrite(p); + delay(10); + long t = fillADCBuffer(); + Serial.print("EXSWEEP:"); + Serial.print(p); + Serial.print(","); + Serial.print(p); + Serial.print(","); + Serial.print(t); + Serial.print(",10000,"); + for (int l = 0; l < 10000; l++) + { + Serial.print(adcBuff[l]); + Serial.print(","); + } + Serial.println(); + } + Serial.println("EXFIN"); + } + } + } + else if (input[0] == 'Y') + { + int counter = 0; + digitalPotWrite(0); + while (input[0] != 'X') + { + if (digitalRead(buttonPin)) + { + counter *= 2; + if (counter == 0) + { + counter++; + } else if (counter > 128) + { + counter = 0; + } + digitalPotWrite(counter); + Serial.print("Current value:"); + Serial.println(counter); + delay(300); + } + delay(10); + } + } + else if (input[0] == 'Z') + { + int potVal = 1; + uint16_t result = 0; + Serial.println("PotVal,Result"); + for (int i = 0; i < 255; i++) + { + int counter = 0; + digitalPotWrite(i); + Serial.print(i); + Serial.print(","); + while (counter < 100) + { + result = getSingleADCValue(); //save new ADC value to buffer @ sample_count position + counter++; + } + Serial.println(result); + oledFourLines("POT VAL:", String(potVal), "VAL:", String(result)); + } + } +} diff --git a/Hardware/OSRTT_Pro_Code/file3.ino b/Hardware/OSRTT_Pro_Code/file3.ino index 3674ae4..5c34052 100644 --- a/Hardware/OSRTT_Pro_Code/file3.ino +++ b/Hardware/OSRTT_Pro_Code/file3.ino @@ -600,22 +600,6 @@ void loop() { Serial.print("Rotation set as: "); Serial.println(rotation); } - else if (input[0] == 'W') - { - long s = micros(); - int counter = 10000; - for(int i = 0; i < counter; i++) - { - ADC0->SWTRIG.bit.START = 1; //Start ADC - while (!ADC0->INTFLAG.bit.RESRDY); //wait for ADC to have a new value - adcBuff[i] = ADC0->RESULT.reg; - } - long e = micros(); - Serial.print("Sample time: "); - float t = (e - s) / counter; - Serial.println(t); - - } else if (input[0] == 'Y') { int counter = 0; @@ -640,6 +624,49 @@ void loop() { delay(10); } } + else if (input[0] == 'W') + { + if (input[1] == '1') + { + for (int h = 0; h < 256; h++) + { + digitalPotWrite(h); + Serial.print(h); + Serial.print(",,"); + int counter = 0; + long tStart = micros(); + while (counter < 10000) + { + ADC0->SWTRIG.bit.START = 1; //Start ADC + while (!ADC0->INTFLAG.bit.RESRDY); //wait for ADC to have a new value + adcBuff[counter] = ADC0->RESULT.reg; //save new ADC value to buffer @ sample_count position + counter++; + } + long tEnd = micros(); + for (int i = 0; i < counter; i++) + { + Serial.print(adcBuff[i]); + Serial.print(","); + } + Serial.println(); + } + } + else if (input[1] == '2') + { + int potVal = 0; + while (potVal < 256) + { + if (digitalRead(buttonPin)) + { + digitalPotWrite(potVal); + Serial.print("POT VAL:"); + Serial.println(potVal); + potVal++; + delay(100); + } + } + } + } else if (input[0] == 'Z') { int potVal = 1; diff --git a/OSRTT Launcher/OSRTT Launcher/App.config b/OSRTT Launcher/OSRTT Launcher/App.config index 8182143..bb74387 100644 --- a/OSRTT Launcher/OSRTT Launcher/App.config +++ b/OSRTT Launcher/OSRTT Launcher/App.config @@ -151,6 +151,9 @@ 10 + + True + diff --git a/OSRTT Launcher/OSRTT Launcher/LiveView.cs b/OSRTT Launcher/OSRTT Launcher/LiveView.cs index 7486052..5f4664d 100644 --- a/OSRTT Launcher/OSRTT Launcher/LiveView.cs +++ b/OSRTT Launcher/OSRTT Launcher/LiveView.cs @@ -49,7 +49,15 @@ public class LiveData public void addData(LiveData d) { - xDataList.Add(d.time); + if (m.boardType == 2) // Expert only + { + if (xDataList.Count != 0) + { + xDataList.Add(xDataList.Last() + d.time); + } + else { xDataList.Add(d.time); } + } + else { xDataList.Add(d.time); } yDataList.Add(d.result); } public void copyListToArray() diff --git a/OSRTT Launcher/OSRTT Launcher/Main.Designer.cs b/OSRTT Launcher/OSRTT Launcher/Main.Designer.cs index e9c37fb..a445173 100644 --- a/OSRTT Launcher/OSRTT Launcher/Main.Designer.cs +++ b/OSRTT Launcher/OSRTT Launcher/Main.Designer.cs @@ -43,6 +43,7 @@ private void InitializeComponent() this.debugModeToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveUSBOutputToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.updateDeviceToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.testButtonMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.devStat = new System.Windows.Forms.Label(); this.controlsPanel = new System.Windows.Forms.Panel(); @@ -105,7 +106,6 @@ private void InitializeComponent() this.progressBar1 = new System.Windows.Forms.ProgressBar(); this.toolTipController = new System.Windows.Forms.ToolTip(this.components); this.overdriveModes1 = new OSRTT_Launcher.OverdriveModes(); - this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripMenuItem(); this.menuStrip1.SuspendLayout(); this.controlsPanel.SuspendLayout(); ((System.ComponentModel.ISupportInitialize)(this.testCount)).BeginInit(); @@ -270,6 +270,14 @@ private void InitializeComponent() this.updateDeviceToolStripMenuItem.Text = "Update Device Firmware"; this.updateDeviceToolStripMenuItem.Click += new System.EventHandler(this.updateDeviceToolStripMenuItem_Click); // + // toolStripMenuItem1 + // + this.toolStripMenuItem1.CheckOnClick = true; + this.toolStripMenuItem1.Name = "toolStripMenuItem1"; + this.toolStripMenuItem1.Size = new System.Drawing.Size(211, 22); + this.toolStripMenuItem1.Text = "Test Button"; + this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); + // // testButtonMenuItem // this.testButtonMenuItem.CheckOnClick = true; @@ -328,9 +336,9 @@ private void InitializeComponent() this.vsyncStateList.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.vsyncStateList.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.vsyncStateList.FormattingEnabled = true; - this.vsyncStateList.Location = new System.Drawing.Point(157, 256); + this.vsyncStateList.Location = new System.Drawing.Point(141, 256); this.vsyncStateList.Name = "vsyncStateList"; - this.vsyncStateList.Size = new System.Drawing.Size(111, 26); + this.vsyncStateList.Size = new System.Drawing.Size(127, 26); this.vsyncStateList.TabIndex = 28; this.vsyncStateList.SelectedIndexChanged += new System.EventHandler(this.vsyncStateList_SelectedIndexChanged); // @@ -349,9 +357,9 @@ private void InitializeComponent() this.captureTimeBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; this.captureTimeBox.Font = new System.Drawing.Font("Arial", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0))); this.captureTimeBox.FormattingEnabled = true; - this.captureTimeBox.Location = new System.Drawing.Point(157, 212); + this.captureTimeBox.Location = new System.Drawing.Point(141, 212); this.captureTimeBox.Name = "captureTimeBox"; - this.captureTimeBox.Size = new System.Drawing.Size(111, 26); + this.captureTimeBox.Size = new System.Drawing.Size(127, 26); this.captureTimeBox.TabIndex = 21; this.captureTimeBox.SelectedIndexChanged += new System.EventHandler(this.captureTimeBox_SelectedIndexChanged); // @@ -1013,14 +1021,6 @@ private void InitializeComponent() this.overdriveModes1.Size = new System.Drawing.Size(511, 299); this.overdriveModes1.TabIndex = 34; // - // toolStripMenuItem1 - // - this.toolStripMenuItem1.CheckOnClick = true; - this.toolStripMenuItem1.Name = "toolStripMenuItem1"; - this.toolStripMenuItem1.Size = new System.Drawing.Size(211, 22); - this.toolStripMenuItem1.Text = "Test Button"; - this.toolStripMenuItem1.Click += new System.EventHandler(this.toolStripMenuItem1_Click); - // // Main // this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.None; diff --git a/OSRTT Launcher/OSRTT Launcher/Main.cs b/OSRTT Launcher/OSRTT Launcher/Main.cs index 36670f7..cd92716 100644 --- a/OSRTT Launcher/OSRTT Launcher/Main.cs +++ b/OSRTT Launcher/OSRTT Launcher/Main.cs @@ -28,15 +28,10 @@ public partial class Main : Form private double boardVersion = 2.6; private double V1DLFW = 2.8; private double ProDLFW = 1.7; + private double ExpertDLFW = 1.0; public int boardType = -1; private string softwareVersion = "4.7"; - // TODO // - // - // - // Current known issues // - // - public static System.IO.Ports.SerialPort port; delegate void SetTextCallback(string text); private bool boardUpdate = false; @@ -668,14 +663,68 @@ private void listFramerates() } private void listCaptureTimes() - { - captureTimeBox.Items.Clear(); - captureTimeBox.Items.Add("50ms"); - captureTimeBox.Items.Add("100ms"); - captureTimeBox.Items.Add("150ms"); - captureTimeBox.Items.Add("200ms"); - captureTimeBox.Items.Add("250ms"); - captureTimeBox.SelectedIndex = Properties.Settings.Default.captureTime; + { + if (captureTimeBox.InvokeRequired) + { + this.Invoke((MethodInvoker)delegate () + { + captureTimeBox.Items.Clear(); + if (boardType != 2) + { + captureTimeBox.Items.Add("50ms"); + captureTimeBox.Items.Add("100ms"); + captureTimeBox.Items.Add("150ms"); + captureTimeBox.Items.Add("200ms"); + captureTimeBox.Items.Add("250ms"); + } + else + { + captureTimeBox.Items.Add("50ms @ 2.7us"); + captureTimeBox.Items.Add("100ms @ 2.7us"); + captureTimeBox.Items.Add("150ms @ 2.7us"); + captureTimeBox.Items.Add("200ms @ 2.7us"); + captureTimeBox.Items.Add("250ms @ 3.7us"); + captureTimeBox.Items.Add("350ms @ 4.7us"); + captureTimeBox.Items.Add("500ms @ 7.7us"); + captureTimeBox.Items.Add("1s @ 13.7us"); + } + int savedState = Properties.Settings.Default.captureTime; + if (savedState >= captureTimeBox.Items.Count) + { + savedState = captureTimeBox.Items.Count - 1; + } + captureTimeBox.SelectedIndex = savedState; + }); + } + else + { + captureTimeBox.Items.Clear(); + if (boardType != 2) + { + captureTimeBox.Items.Add("50ms"); + captureTimeBox.Items.Add("100ms"); + captureTimeBox.Items.Add("150ms"); + captureTimeBox.Items.Add("200ms"); + captureTimeBox.Items.Add("250ms"); + } + else + { + captureTimeBox.Items.Add("50ms @ 2.7us"); + captureTimeBox.Items.Add("100ms @ 2.7us"); + captureTimeBox.Items.Add("150ms @ 2.7us"); + captureTimeBox.Items.Add("200ms @ 2.7us"); + captureTimeBox.Items.Add("250ms @ 3.7us"); + captureTimeBox.Items.Add("350ms @ 4.7us"); + captureTimeBox.Items.Add("500ms @ 7.7us"); + captureTimeBox.Items.Add("1s @ 13.7us"); + } + int savedState = Properties.Settings.Default.captureTime; + if (savedState >= captureTimeBox.Items.Count) + { + savedState = captureTimeBox.Items.Count - 1; + } + captureTimeBox.SelectedIndex = savedState; + } } private void listVsyncState() @@ -789,7 +838,8 @@ private void findAndConnectToBoard() } if (s.Contains("adafruit:samd:adafruit_feather_m4")) { - //boardType = 2; // probably not needed + boardType = 2; // probably not needed + listCaptureTimes(); } } if (p != "") @@ -811,7 +861,7 @@ private void findAndConnectToBoard() } else if (boardUpdate) { - if ((boardVersion < V1DLFW && boardType == 0) || forceUpdate || (boardVersion < ProDLFW && boardType == 1)) + if ((boardVersion < V1DLFW && boardType == 0) || forceUpdate || (boardVersion < ProDLFW && boardType == 1) || (boardVersion < ExpertDLFW && boardType == 2)) { string p = ""; p = port.PortName; @@ -834,19 +884,26 @@ private void findAndConnectToBoard() process.StartInfo.FileName = "cmd.exe"; string installCommand = ""; string updateCommand = ""; - if (boardType == 1) + if (boardType == 1 || boardType == 2) { string binFileAvailable = ""; foreach (var f in Directory.GetFiles(localPath + @"\\arduinoCLI")) { if (f.Contains("ino.bin") && f.Contains("Pro")) { binFileAvailable = f; } + else if (f.Contains("ino.bin") && f.Contains("Expert")) { binFileAvailable = f; } } if (binFileAvailable != "") { - Console.WriteLine(binFileAvailable); + installCommand = ""; - updateCommand = "/C .\\arduinoCLI\\arduino-cli.exe upload --port " + p + " --fqbn adafruit:samd:adafruit_itsybitsy_m4 -i \""+ binFileAvailable + "\""; - Console.WriteLine(updateCommand); + if (boardType == 1) + { + updateCommand = "/C .\\arduinoCLI\\arduino-cli.exe upload --port " + p + " --fqbn adafruit:samd:adafruit_itsybitsy_m4 -i \""+ binFileAvailable + "\""; + } + else if (boardType == 2) + { + updateCommand = "/C .\\arduinoCLI\\arduino-cli.exe upload --port " + p + " --fqbn adafruit:samd:adafruit_feather_m4 -i \"" + binFileAvailable + "\""; + } } else { @@ -1948,6 +2005,20 @@ public void Read() } File.WriteAllText(USBOutputPath, USBOutputString.ToString()); Console.WriteLine("Test finished"); + } + else if (message.Contains("EXSTART")) + { + currentRun = 0; + } + else if (message.Contains("EXSWEEP")) + { + string newMessage = message.Remove(0, 8); + File.AppendAllText(path + "\\expertTest.csv", newMessage); + + } + else if (message.Contains("EXFIN")) + { + } else { @@ -2405,7 +2476,7 @@ private void runTest() Stopwatch sw = new Stopwatch(); sw.Reset(); sw.Start(); - while (sw.ElapsedMilliseconds < 5000) + while (sw.ElapsedMilliseconds < 20000) { // wait for CORRECT result to come back if (currentStart == RGBArr[i] && currentEnd == RGBArr[k] && triggerNextResult) { @@ -2413,7 +2484,7 @@ private void runTest() } Thread.Sleep(10); } - if (sw.ElapsedMilliseconds > 5000) + if (sw.ElapsedMilliseconds > 20000) { DialogResult d = showMessageBox("Error: The test was unable to run the last transition, try again?", "Test Timed Out", MessageBoxButtons.RetryCancel, MessageBoxIcon.Error); if (d == DialogResult.Retry) @@ -3360,8 +3431,8 @@ private void setProgressBar(bool on) private void testButtonToolStripMenuItemToolStripMenuItem_Click(object sender, EventArgs e) { //testRawInput(); - port.Write("J"); - //port.Write("W"); + //port.Write("J"); + port.Write("W"); //Thread.Sleep(500); //SendKeys.SendWait("{NUM0}"); //runDirectXWindow(); diff --git a/OSRTT Launcher/OSRTT Launcher/Main.resx b/OSRTT Launcher/OSRTT Launcher/Main.resx index 40ce0da..5b92741 100644 --- a/OSRTT Launcher/OSRTT Launcher/Main.resx +++ b/OSRTT Launcher/OSRTT Launcher/Main.resx @@ -126,9 +126,6 @@ 149, 22 - - 255, 22 - 42 diff --git a/OSRTT Launcher/OSRTT Launcher/ProcessData.cs b/OSRTT Launcher/OSRTT Launcher/ProcessData.cs index 6e50e50..91faf85 100644 --- a/OSRTT Launcher/OSRTT Launcher/ProcessData.cs +++ b/OSRTT Launcher/OSRTT Launcher/ProcessData.cs @@ -277,7 +277,7 @@ public List processGammaTable(List gamma, List flickerLocations = new List(); + int lookBehind = 3; + int lookAhead = 100; + for (int i = lookBehind; i < samples.Length; i++) // this doesn't currently account for a flicker at the START. + { + // check if current sample has dropped dramatically + if (samples[i] < (samples[i-lookBehind] * 0.5)) + { + List potentialLocations = new List(); + potentialLocations.AddRange(new List { i - 2, i - 1, i }); + for (int k = i + 1; k < i + lookAhead; k++) + { + if (samples[k] < samples[i] || samples[k] < (samples[i] * 1.1) || samples[k] < (samples[i - lookBehind] * 0.5)) + { + potentialLocations.Add(k); + } + else if (samples[k] > (samples[i-lookBehind] * 0.9)) + { + // samples DO go back up, stop searching, add drops to list, skip ahead + flickerLocations.AddRange(potentialLocations); + // add another 5 samples to be removed to ensure endpoint accuracy + int lastLocation = potentialLocations.Last(); + flickerLocations.AddRange(new List { lastLocation + 1, lastLocation + 2, lastLocation + 3, lastLocation + 4, lastLocation + 5 }); + i = k + 5; + break; + } + } + } + } + Console.WriteLine(flickerLocations.Count); + Console.WriteLine(); + + if (flickerLocations.Count != 0 && Properties.Settings.Default.flickerCulling) + { + for (int p = 0; p < flickerLocations.Count; p++) + { + // Find current continuous group to replace + int startLocation = flickerLocations[p]; + int endLocation = flickerLocations[p]; + for (int m = p + 1; m < flickerLocations.Count; m++) + { + if ((flickerLocations[m] - 1) == endLocation) + { + endLocation = flickerLocations[m]; + } + else + { + p = m; + break; + } + } + + // Replace the group + // Optional upgrade - include more results then only take the middle ones + double[] rawX = new double[2]; + double[] rawY = new double[2]; + rawX[0] = 0; + rawX[1] = 1; + rawY[0] = samples[startLocation - 1]; + rawY[1] = samples[endLocation + 1]; + var line = ScottPlot.Statistics.Interpolation.Cubic.InterpolateXY(rawX, rawY, endLocation - startLocation); + for (int q = 0; q < line.ys.Length - 1; q++) + { + samples[startLocation + q] = (int)line.ys[q + 1]; + } + } + int max = 0; + int min = 65536; + for (int i = 20; i < 300; i++) + { + if (samples[i] < min) { min = samples[i]; } + else if (samples[i] > max) { max = samples[i]; } + } + + return new CulledSamples { sampleArray = samples, NoiseLevel = max - min }; + } + else { return new CulledSamples { sampleArray = samples, NoiseLevel = 0 }; } + } + public processedResult ProcessResponseTimeData(List> data, resultSelection res, int startDelay, List processedGamma, runSettings runSetting) { //This is a long one. This is the code that builds the gamma curve, finds the start/end points and calculates response times and overshoot % (gamma corrected) @@ -382,7 +472,6 @@ public processedResult ProcessResponseTimeData(List> data, r List fullGammaTable = new List(); List smoothedDataTable = new List(); - try //Wrapped whole thing in try just in case { // Save start, end, time and sample count then clear the values from the array @@ -394,9 +483,24 @@ public processedResult ProcessResponseTimeData(List> data, r double SampleTime = ((double)TimeTaken / (double)SampleCount); // Get the time taken between samples + int[] originalSamples = new int[samples.Length]; + Array.Copy(samples, originalSamples, samples.Length); // make a copy just in case... + // Clean up flicker noise before filtering regular noise + CulledSamples culledSamples = CullBacklightFlicker(samples); + Array.Copy(culledSamples.sampleArray, samples, culledSamples.sampleArray.Length); + + //Debug + StringBuilder csv = new StringBuilder(); + csv.AppendLine(StartingRGB.ToString() + "," + EndRGB.ToString() + "," + String.Join(",", samples)); + Console.WriteLine(csv.ToString()); // Clean up noisy data using moving average function int period = 10; int noise = data[res.arrayIndex][res.resultIndex].noiseLevel; + if (culledSamples.NoiseLevel != 0) + { + noise = culledSamples.NoiseLevel; + Console.WriteLine("Using culled noise value: " + culledSamples.NoiseLevel); + } if (noise < 250) { period = 20; @@ -1100,6 +1204,7 @@ public processedResult ProcessResponseTimeData(List> data, r double initialTransCount = initialTransEnd - initialTransStart; double initialTransTime = (initialTransCount * SampleTime) / 1000; + //if (initialTransTime) double perceivedTransCount = perceivedTransEnd - perceivedTransStart; double perceivedTransTime = (perceivedTransCount * SampleTime) / 1000; @@ -1501,8 +1606,16 @@ public List> SmoothAllData(List> rawData foreach (ProcessData.rawResultData raw in res) { int[] samples = raw.Samples.ToArray(); + // Clean up flicker noise before filtering regular noise + CulledSamples culledSamples = CullBacklightFlicker(samples); + Array.Copy(culledSamples.sampleArray, samples, culledSamples.sampleArray.Length); int period = 10; int noise = raw.noiseLevel; + if (culledSamples.NoiseLevel != 0) + { + noise = culledSamples.NoiseLevel; + Console.WriteLine("Using culled noise value: " + culledSamples.NoiseLevel); + } if (noise < 250) { period = 20; diff --git a/OSRTT Launcher/OSRTT Launcher/Properties/Settings.Designer.cs b/OSRTT Launcher/OSRTT Launcher/Properties/Settings.Designer.cs index 6d519a5..41bb3cc 100644 --- a/OSRTT Launcher/OSRTT Launcher/Properties/Settings.Designer.cs +++ b/OSRTT Launcher/OSRTT Launcher/Properties/Settings.Designer.cs @@ -502,5 +502,17 @@ public int movingAverageSize { this["movingAverageSize"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("True")] + public bool flickerCulling { + get { + return ((bool)(this["flickerCulling"])); + } + set { + this["flickerCulling"] = value; + } + } } } diff --git a/OSRTT Launcher/OSRTT Launcher/Properties/Settings.settings b/OSRTT Launcher/OSRTT Launcher/Properties/Settings.settings index c5be20f..24553b5 100644 --- a/OSRTT Launcher/OSRTT Launcher/Properties/Settings.settings +++ b/OSRTT Launcher/OSRTT Launcher/Properties/Settings.settings @@ -122,5 +122,8 @@ 10 + + True + \ No newline at end of file diff --git a/OSRTT Launcher/OSRTT Launcher/ResultsSettings.Designer.cs b/OSRTT Launcher/OSRTT Launcher/ResultsSettings.Designer.cs index 3d7e6ad..63881a4 100644 --- a/OSRTT Launcher/OSRTT Launcher/ResultsSettings.Designer.cs +++ b/OSRTT Launcher/OSRTT Launcher/ResultsSettings.Designer.cs @@ -128,6 +128,9 @@ private void InitializeComponent() this.openColourPickerBtn = new OSRTT_Launcher.RoundButton(); this.roundButton1 = new OSRTT_Launcher.RoundButton(); this.roundButton2 = new OSRTT_Launcher.RoundButton(); + this.panel13 = new System.Windows.Forms.Panel(); + this.label31 = new System.Windows.Forms.Label(); + this.flickerSelect = new System.Windows.Forms.ComboBox(); this.panel2.SuspendLayout(); this.tolerancePanel.SuspendLayout(); this.testSettingsPanel.SuspendLayout(); @@ -165,6 +168,7 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.rtHighNum)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.rtMidNum)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.rtLowNum)).BeginInit(); + this.panel13.SuspendLayout(); this.SuspendLayout(); // // panel2 @@ -595,7 +599,7 @@ private void InitializeComponent() this.tabControl1.Location = new System.Drawing.Point(9, 11); this.tabControl1.Name = "tabControl1"; this.tabControl1.SelectedIndex = 0; - this.tabControl1.Size = new System.Drawing.Size(1027, 792); + this.tabControl1.Size = new System.Drawing.Size(1027, 818); this.tabControl1.TabIndex = 34; // // testSettingsTab @@ -627,6 +631,7 @@ private void InitializeComponent() // resultSettingsTab // this.resultSettingsTab.BackColor = System.Drawing.SystemColors.ControlDark; + this.resultSettingsTab.Controls.Add(this.panel13); this.resultSettingsTab.Controls.Add(this.panel9); this.resultSettingsTab.Controls.Add(this.panel8); this.resultSettingsTab.Controls.Add(this.panel6); @@ -643,7 +648,7 @@ private void InitializeComponent() this.resultSettingsTab.Location = new System.Drawing.Point(4, 42); this.resultSettingsTab.Name = "resultSettingsTab"; this.resultSettingsTab.Padding = new System.Windows.Forms.Padding(3); - this.resultSettingsTab.Size = new System.Drawing.Size(1019, 746); + this.resultSettingsTab.Size = new System.Drawing.Size(1019, 772); this.resultSettingsTab.TabIndex = 1; this.resultSettingsTab.Text = "Results Settings"; // @@ -1253,12 +1258,44 @@ private void InitializeComponent() this.roundButton2.TabIndex = 34; this.roundButton2.UseVisualStyleBackColor = false; // + // panel13 + // + this.panel13.BackColor = System.Drawing.SystemColors.ButtonFace; + this.panel13.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.panel13.Controls.Add(this.label31); + this.panel13.Controls.Add(this.flickerSelect); + this.panel13.Location = new System.Drawing.Point(387, 708); + this.panel13.Name = "panel13"; + this.panel13.Size = new System.Drawing.Size(615, 50); + this.panel13.TabIndex = 53; + // + // label31 + // + this.label31.AutoSize = true; + this.label31.Font = new System.Drawing.Font("Arial", 18F); + this.label31.Location = new System.Drawing.Point(10, 11); + this.label31.Name = "label31"; + this.label31.Size = new System.Drawing.Size(166, 27); + this.label31.TabIndex = 23; + this.label31.Text = "Flicker Culling"; + // + // flickerSelect + // + this.flickerSelect.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.flickerSelect.Font = new System.Drawing.Font("Microsoft Sans Serif", 14F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(0))); + this.flickerSelect.FormattingEnabled = true; + this.flickerSelect.Location = new System.Drawing.Point(246, 8); + this.flickerSelect.Name = "flickerSelect"; + this.flickerSelect.Size = new System.Drawing.Size(354, 32); + this.flickerSelect.TabIndex = 21; + this.flickerSelect.SelectedIndexChanged += new System.EventHandler(this.flickerSelect_SelectedIndexChanged); + // // ResultsSettings // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.BackColor = System.Drawing.SystemColors.ControlDark; - this.ClientSize = new System.Drawing.Size(1043, 811); + this.ClientSize = new System.Drawing.Size(1043, 841); this.Controls.Add(this.saveLabel); this.Controls.Add(this.tabControl1); this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; @@ -1330,6 +1367,8 @@ private void InitializeComponent() ((System.ComponentModel.ISupportInitialize)(this.rtHighNum)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.rtMidNum)).EndInit(); ((System.ComponentModel.ISupportInitialize)(this.rtLowNum)).EndInit(); + this.panel13.ResumeLayout(false); + this.panel13.PerformLayout(); this.ResumeLayout(false); this.PerformLayout(); @@ -1434,5 +1473,8 @@ private void InitializeComponent() private System.Windows.Forms.Panel panel9; private System.Windows.Forms.NumericUpDown movingAverageCount; private System.Windows.Forms.Label label30; + private System.Windows.Forms.Panel panel13; + private System.Windows.Forms.Label label31; + private System.Windows.Forms.ComboBox flickerSelect; } } \ No newline at end of file diff --git a/OSRTT Launcher/OSRTT Launcher/ResultsSettings.cs b/OSRTT Launcher/OSRTT Launcher/ResultsSettings.cs index 307e0b0..9b4d4e9 100644 --- a/OSRTT Launcher/OSRTT Launcher/ResultsSettings.cs +++ b/OSRTT Launcher/OSRTT Launcher/ResultsSettings.cs @@ -36,6 +36,7 @@ public ResultsSettings() initKeys(); initTextColour(); initDenoiseSelect(); + initFlickerSelect(); initDateSelect(); initAutoSavePNGSelect(); initMASize(); @@ -341,6 +342,20 @@ private void initDenoiseSelect() denoiseSelect.SelectedIndex = 1; } } + private void initFlickerSelect() + { + denoiseSelect.Items.Clear(); + denoiseSelect.Items.Add("Disabled"); + denoiseSelect.Items.Add("Enabled"); + if (!Properties.Settings.Default.flickerCulling) + { + denoiseSelect.SelectedIndex = 0; + } + else + { + denoiseSelect.SelectedIndex = 1; + } + } private void initDateSelect() { showDataBox.Items.Clear(); @@ -1097,8 +1112,28 @@ private void movingAverageCount_ValueChanged(object sender, EventArgs e) Properties.Settings.Default.Save(); } } - + private void flickerSelect_SelectedIndexChanged(object sender, EventArgs e) + { + var ctrl = sender as ComboBox; + if (ctrl.Focused) + { + if (saveThread == null || !saveThread.IsAlive) + { + saveThread = new Thread(new ThreadStart(this.SavingLabel)); + saveThread.Start(); + } + if (ctrl.SelectedIndex == 0) + { + Properties.Settings.Default.flickerCulling = false; + } + else + { + Properties.Settings.Default.flickerCulling = true; + } + Properties.Settings.Default.Save(); + } + } } public class RoundButton : Button diff --git a/OSRTT Launcher/OSRTT Launcher/ResultsView.cs b/OSRTT Launcher/OSRTT Launcher/ResultsView.cs index e9b8c07..e399ab4 100644 --- a/OSRTT Launcher/OSRTT Launcher/ResultsView.cs +++ b/OSRTT Launcher/OSRTT Launcher/ResultsView.cs @@ -496,7 +496,7 @@ private void drawGraph(int arrayIndex = 0, int resultIndex = 0) int sampleCount = rawData[arrayIndex][resultIndex].SampleCount; double averageTime = rawData[arrayIndex][resultIndex].SampleTime; double[] resultData; - if (Properties.Settings.Default.smoothGraph) + if (Properties.Settings.Default.smoothGraph && smoothedData.Count != 0) { resultData = smoothedData[arrayIndex][resultIndex].Samples.Select(x => (double)x).ToArray(); }