commit 713f323c543f3190e96e05b421ab2ec087b4bbdf
Author: d3fault <d3fault@d3fault.net>
Date:   Wed May 24 13:22:31 2017 -0700

    QuickDirtyAutoBackupHalper3 Commit @24 May 2017 13:22:27 -0700

diff --git a/.lastModifiedTimestamps b/.lastModifiedTimestamps
index 46598c1..949bc08 100644
--- a/.lastModifiedTimestamps
+++ b/.lastModifiedTimestamps
@@ -5893,23 +5893,23 @@ Projects/libAvGraphicsItem3/src/main.cpp:1327003410
Projects/wasdf/:1495333245
Projects/wasdf/assets/:1463107603
Projects/wasdf/assets/ArduinoSketches/:1463107625
Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/:1495494535
Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino:1495494535Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/:1495657293
Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino:1495657293
Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/Makefile:1495394559
Projects/wasdf/design/:1495255816
Projects/wasdf/design/pin.detection.and.finger.mapping.are.same.step.as.calibration.txt:1495315077
Projects/wasdf/design/renaming.from.MusicFingers.txt:1495250184
Projects/wasdf/src/:1495592877Projects/wasdf/src/:1495657296
Projects/wasdf/src/cli/:1495395081
Projects/wasdf/src/cli/main.cpp:1495395081
Projects/wasdf/src/cli/wasdfcli.cpp:1495394570
Projects/wasdf/src/cli/wasdfcli.h:1495394574
Projects/wasdf/src/lib/:1495592857Projects/wasdf/src/lib/:1495656263
Projects/wasdf/src/lib/fingeriteratororderedbymostusedfingers.cpp:1495480054
Projects/wasdf/src/lib/fingeriteratororderedbymostusedfingers.h:1495480049
Projects/wasdf/src/lib/wasdf.cpp:1495592670
Projects/wasdf/src/lib/wasdf.h:1495592478
Projects/wasdf/src/lib/wasdfarduino.cpp:1495494079Projects/wasdf/src/lib/wasdf.cpp:1495655402
Projects/wasdf/src/lib/wasdf.h:1495654643
Projects/wasdf/src/lib/wasdfarduino.cpp:1495656263
Projects/wasdf/src/lib/wasdfarduino.h:1495419683
Projects/wasdf/src/lib/wasdfcalibrationatrestdetector.cpp:1495592857
Projects/wasdf/src/lib/wasdfcalibrationatrestdetector.h:1495591219
diff --git a/Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino b/Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino
index 56880a7..88dad64 100644
--- a/Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino
+++ b/Projects/wasdf/assets/ArduinoSketches/ArduinoWriteChangesOnAnalogPinsToSerial/ArduinoWriteChangesOnAnalogPinsToSerial.ino
@@ -166,13 +166,16 @@ void processInputCommandString()
    {
        CurrentMode = Mode::Calibrating;
    }
    else if(inputCommandString.startsWith("startWithPinToFingerMap:"))if(inputCommandString.startsWith("startReportingThesePinsExcludingTheirAtRestRanges:"))
    {
        //TODOreq:
        //where the fuck is my String.split!?!? aww come pls don't make me use indexOf :(
        //*cough* json *cough*

    }
    else
    {
        //TODOreq: blink pin 13 rapidly to indicate an error. longer term should request the command is re-sentre-sent. note: even if the checksum succeeds we still might get an invalid command (checksums aren't perfect), we we'd STILL want to request the command is re-sent. if however 50 invalid commands are received IN A ROW, then we would want to go into blink-13-error-mode as that indicates a bug
    }
}
void loop()
diff --git a/Projects/wasdf/src/lib/wasdf.cpp b/Projects/wasdf/src/lib/wasdf.cpp
index f88b336..2352027 100644
--- a/Projects/wasdf/src/lib/wasdf.cpp
+++ b/Projects/wasdf/src/lib/wasdf.cpp
@@ -132,6 +132,17 @@ QString fingerEnumToHumanReadableString(Finger finger)
    }
    return "#error finger#"; //should (will) never get here
}
void WasdfCalibrationConfiguration::calculateAtRestRange(const WasdfCalibrationFingerConfiguration &fingerConfiguration, int *out_AtRestMin, int *out_AtRestMax)
{
#define WASDF_AT_REST_RANGE_PERCENT 10
    //calculate range based on AtRestValue using a hardcdoed percentage _OF_ the calibrated MinValue<-->MaxValue range (not of 0-1023)
    //constrain it to within MinValue<-->MaxValue (inclusive) too
    qreal halfAtRestRangePercent = static_cast<qreal>(WASDF_AT_REST_RANGE_PERCENT) / 2.0; //half for the upper range, half for the lower range
    qreal calibratedTotalRange = qAbs(fingerConfiguration.MaxValue - fingerConfiguration.MinValue);
    int halfAtRestRange = qRound(calibratedTotalRange * (halfAtRestRangePercent / 100.0));
    *out_AtRestMin = qMax(fingerConfiguration.AtRestPosition - halfAtRestRange, fingerConfiguration.MinValue); //get the higher of the 2 values: calculated at rest min vs. calibrated min value
    *out_AtRestMax = qMin(fingerConfiguration.AtRestPosition + halfAtRestRange, fingerConfiguration.MaxValue); //get the lower of the 2 values: calculated at rest max vs. calibrated max value
}
bool WasdfCalibrationConfiguration::hasFingerWithAnalogPinId(int analogPinId) const
{
    QHashIterator<Finger, WasdfCalibrationFingerConfiguration> it(*this);
diff --git a/Projects/wasdf/src/lib/wasdf.h b/Projects/wasdf/src/lib/wasdf.h
index 66e293a..924f26c 100644
--- a/Projects/wasdf/src/lib/wasdf.h
+++ b/Projects/wasdf/src/lib/wasdf.h
@@ -62,6 +62,7 @@ struct WasdfCalibrationFingerConfiguration
class WasdfCalibrationConfiguration : public QHash<Finger, WasdfCalibrationFingerConfiguration>
{
public:
    static void calculateAtRestRange(const WasdfCalibrationFingerConfiguration &fingerConfiguration, int *out_AtRestMin, int *out_AtRestMax);
    bool hasFingerWithAnalogPinId(int analogPinId) const;
    Finger getFingerByAnalogPinId(int analogPinId) const;
};
diff --git a/Projects/wasdf/src/lib/wasdfarduino.cpp b/Projects/wasdf/src/lib/wasdfarduino.cpp
index bce79c9..177d431 100644
--- a/Projects/wasdf/src/lib/wasdfarduino.cpp
+++ b/Projects/wasdf/src/lib/wasdfarduino.cpp
@@ -66,6 +66,39 @@ void WasdfArduino::start(const WasdfCalibrationConfiguration &calibrationConfig)

    openSerialPortIfNotOpen();

#if 1
    QHashIterator<Finger, WasdfCalibrationFingerConfiguration> it(calibrationConfig);
    QString startCommand("startReportingThesePinsExcludingTheirAtRestRanges:");
    bool first = true;
    while(it.hasNext())
    {
        it.next();
        if(!first)
            startCommand.append(";"); //TODOreq: semi-colon delim in shared header
        first = false;
        //startCommand.append(static_cast<int>(it.key())); //the arduino doesn't give a fuck (at this point in my design. might change in the future) which analog pins correspond to which fingers, we (the PC) simply tell it which 10 pins to report (and which ranges of values to ignore for each of those 10 pins)
        //startCommand.append(",");
        startCommand.append(it.value().AnalogPinIdOnArduino);
        startCommand.append(","); //TODOreq: comma delim in shared header

        int atRestMin, atRestMax;
        WasdfCalibrationConfiguration::calculateAtRestRange(it.value(), &atRestMin, &atRestMax);

        startCommand.append(atRestMin);
        startCommand.append(",");
        startCommand.append(atRestMax);
    }

    //example start command:
    //startWithPinAtRestRanges:18,0,1023;19,1,1022;28,50,950;...
    //18 = analog pin id
    //0 = min at rest value
    //1023 = max at rest value
    //repeat for each finger, separated by semicolon
    //note: the analog pins can be sent in any order. the semicolons separate each finger and are in order of finger id (0-9)

#else //There's really only ONE reason to send the finger map to the arduino: to store it in it's eeprom. that should be implemented at a later date, on a rainy day. What we SHOULD send to the arduino during the 'start' command, however, is the "at rest range". Sure I could send the finger map over and have the arduino do the map/constrain calls, but the PC has assloads more processing power (and spare lines of code) than the arduino so it should be the one to do it. Sending over the "at rest range" is a good idea though because it will keep the Serial line much quieter (and dead silent if there's finger no movement on any of the 10 fingers). TODOreq: "at rest range", if calculated using a hardcoded percentage (~10%), might cover the entire range of their normal min/max usage! so NO movements would ever be detected. that 10% needs to be "10% of their calibrated range", not "10% of the total range (0-1023)". ----The _FOLLOWING_ ifdef'd out code sends over the finger map (but is missing the "at rest range" stuff), but the _ABOVE_ code sends over the "at rest range" stuff only---- (the amount of values sent over is the same so they appear almost identical (and indeed were copy/paste), but the values sent are completely different)

    QHashIterator<Finger, WasdfCalibrationFingerConfiguration> it(calibrationConfig);
    QString startCommand("startWithPinToFingerMap:");
    bool first = true;
@@ -91,6 +124,7 @@ void WasdfArduino::start(const WasdfCalibrationConfiguration &calibrationConfig)
    //1023 = max value
    //repeat for each finger, separated by semicolon
    //note: the analog pins can be sent in any order. the semicolons separate each finger and are in order of finger id (0-9)
#endif

    //TODOreq: on arduino side we do splitByColon then splitBySemiColon then splitByComma

@@ -129,6 +163,10 @@ void WasdfArduino::handleSerialPortReadyReadCalibrationMode()
            qDebug() << "sensor value on rhs of colon was out of bounds:" << line;
            continue;
        }

        //should I map the raw sensor values to the calibrated range here? should wasdf do it when it receives the signal emitted below? I think it kind of makes sense to do it right here, because Wasdf called m_Arduino.start(m_Calibration) ... so it makes sense that m_Arduino (this class) reports mapped/calibrated values
        //TODOreq: map the sensor value to 0-1023. wait no map it to their min/max range, wait no it's a 2 step process, map it to their min/max range and then map that to 0-1023? ehh need to think a little harder on this xD. there's also "constrain" to consider. also the above error checking needs to be modified accordingly

        emit analogPinReadingChangedDuringCalibration(analogPinId, sensorValue);
    }
}