commit 4d479946bd1eeeceb0be8c1438ca4b813a955c88
Author: d3fault <d3fault@d3fault.net>
Date:   Sat May 20 19:27:38 2017 -0700

    wasdf: I think finished the PC side of the right index finger calibration, now onto modifying the arduino sketch

diff --git a/.lastModifiedTimestamps b/.lastModifiedTimestamps
index f14dcf2..3fce5d8 100644
--- a/.lastModifiedTimestamps
+++ b/.lastModifiedTimestamps
@@ -4117,17 +4117,17 @@ Projects/MusicFingers/assets/0_ArduinoWriteChangesOnAnalogPinstoSerial_WithCalib
Projects/MusicFingers/design/:1438697274
Projects/MusicFingers/design/maybe.version.2.andor.the.commercial.version.svg:1438727885
Projects/MusicFingers/src/:1428303545
Projects/MusicFingers/src/cli/:1495254723Projects/MusicFingers/src/cli/:1495333248
Projects/MusicFingers/src/cli/MusicFingersCli.pro:1426284942
Projects/MusicFingers/src/cli/main.cpp:1424887225
Projects/MusicFingers/src/cli/musicfingerscli.cpp:1453592588
Projects/MusicFingers/src/cli/musicfingerscli.h:1426283088
Projects/MusicFingers/src/lib/:1495251362Projects/MusicFingers/src/lib/:1495330611
Projects/MusicFingers/src/lib/finger.cpp:1428893432
Projects/MusicFingers/src/lib/finger.h:1495251362
Projects/MusicFingers/src/lib/musicfingers.cpp:1495242720
Projects/MusicFingers/src/lib/musicfingers.h:1429353502
Projects/MusicFingers/src/lib/musicfingersserialportintegration.cpp:1428309895Projects/MusicFingers/src/lib/musicfingersserialportintegration.cpp:1495330611
Projects/MusicFingers/src/lib/musicfingersserialportintegration.h:1429353470
Projects/MusicFingers/src/lib/musicfingerssynthesizer.cpp:1426312003
Projects/MusicFingers/src/lib/musicfingerssynthesizer.h:1426304790
@@ -5880,21 +5880,21 @@ Projects/libAvGraphicsItem3/src/frontend/videoplayerwidget.cpp:1327006070
Projects/libAvGraphicsItem3/src/frontend/videoplayerwidget.h:1327005797
Projects/libAvGraphicsItem3/src/libAvGraphicsItem3.pro:1327004311
Projects/libAvGraphicsItem3/src/main.cpp:1327003410
Projects/wasdf/:1495320113Projects/wasdf/:1495333245
Projects/wasdf/assets/:1495250258
Projects/wasdf/assets/ArduinoWriteChangesOnAnalogPinstoSerial/:1495250286
Projects/wasdf/assets/ArduinoWriteChangesOnAnalogPinstoSerial/ArduinoWriteChangesOnAnalogPinstoSerial.cpp:1495243391
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/:1495327369Projects/wasdf/src/:1495333599
Projects/wasdf/src/cli/:1495318115
Projects/wasdf/src/cli/main.cpp:1495318115
Projects/wasdf/src/lib/:1495327362Projects/wasdf/src/lib/:1495333560
Projects/wasdf/src/lib/wasdf.cpp:1495323646
Projects/wasdf/src/lib/wasdf.h:1495323646
Projects/wasdf/src/lib/wasdfarduino.cpp:1495327362
Projects/wasdf/src/lib/wasdfarduino.h:1495324301Projects/wasdf/src/lib/wasdfarduino.cpp:1495333560
Projects/wasdf/src/lib/wasdfarduino.h:1495333423
Projects/wasdf/src/lib/wasdfcalibrator.cpp:1495322369
Projects/wasdf/src/lib/wasdfcalibrator.h:1495322369
Projects/wasdf/src/wasdf-cli.pro:1495319518
diff --git a/Projects/MusicFingers/src/lib/musicfingersserialportintegration.cpp b/Projects/MusicFingers/src/lib/musicfingersserialportintegration.cpp
index 4312dd6..16c6738 100644
--- a/Projects/MusicFingers/src/lib/musicfingersserialportintegration.cpp
+++ b/Projects/MusicFingers/src/lib/musicfingersserialportintegration.cpp
@@ -41,7 +41,7 @@ MusicFingersSerialPortIntegration::~MusicFingersSerialPortIntegration()
{ }
void MusicFingersSerialPortIntegration::privateConstructor()
{
    setBaudRate(QSerialPort::Baud9600);//TODOoptional: QSerialPortInfo supplies a list of "standard baud rates" that the serial port supports
    connect(this, SIGNAL(readyRead()), this, SLOT(handleSerialPortReadyRead()));
}
void MusicFingersSerialPortIntegration::processLineOfFingerMovementProtocol(const QString &lineOfFingerMovementProtocol)
diff --git a/Projects/wasdf/src/lib/wasdfarduino.cpp b/Projects/wasdf/src/lib/wasdfarduino.cpp
index 5b8f3fd..7b27f49 100644
--- a/Projects/wasdf/src/lib/wasdfarduino.cpp
+++ b/Projects/wasdf/src/lib/wasdfarduino.cpp
@@ -1,6 +1,7 @@
#include "wasdfarduino.h"

#include <QtSerialPort/QSerialPort>
#include <QStringList>

#include "wasdf.h"

@@ -17,21 +18,66 @@
//I want to use json but I don't see any built-in libs and I'm sure as shit not about to write a parser. there are very likely lightweight self-contained pure c/c++ libraries I could just #include, but I'm pretty sure this arduino micro has.... a micro amount of space available. mb just 8kb compiled? *checks*. oh nice 28kb, that should be enough for anyone (ziiiiiing)
//meh after researching a decent sounding MIT-licensed ArduionJson library... and thinking about it more in the process... I don't think my protocol will be so complex to warrant json. I'll keep json in mind in case things start to get complex, but meh just a plaintext+colon+newlines protocol (like in MusicFingers, though obviously more robust since calibration mode must exist) sounds sufficient. I'll think about it more while I eat dinner (clam chowda)
//another way I could do things is to have 1 sketch for calibration and 1 sketch for normal operation, that would both give me more room to code the sketches and it would get dead (calibration) code paths out of normal operation
//TODOreq: the arduino could persist calibration/configuration to it's EEPROM, which would allow users to take their arduino around to various computers and use them without needing to recalibrate. The protocol would need to be more robust (we first query the arduino to see if it has a stored conf), but it wouldn't be too difficult to implement
WasdfArduino::WasdfArduino(QObject *parent)
    : QObject(parent)
    , m_SerialPort(new QSerialPort(this))
    , m_SerialPortTextStream(m_SerialPort)
{
    connect(m_SerialPort, &QSerialPort::readyRead, this, &WasdfArduino::handleSerialPortReadyRead);m_SerialPort->setBaudRate(QSerialPort::Baud9600); //TODOoptional: QSerialPortInfo supplies a list of "standard baud rates" that the serial port supports
}
void WasdfArduino::openSerialPortIfNotOpen()
{
    if(m_SerialPort->isOpen())
    {
        if(!m_SerialPort->open(QIODevice::ReadWrite /*QIODevice::Text <-- apparently not supported, but I guess it's text by default?*/))
        {
            emit e("failed to open serial port \"" + m_SerialPort->portName() + "\" for reading/writing"); //TODOreq: connect all output/error signals (not just this class)
            //TODOreq: error out, return false or emit finished(false) etc
        }
    }
}
void WasdfArduino::startInCalibrationMode()
{
    //TODOreq://in calibration mode, arduino sends _ALL_ (not just 10) analog pin readings over serial

    disconnect(m_SerialPort, SIGNAL(readyRead())); //TODOreq: for some reason this fails with qt5-style pmf syntax. maybe a newer version of Qt doesn't (otherwise file a bugreport)
    connect(m_SerialPort, &QSerialPort::readyRead, this, &WasdfArduino::handleSerialPortReadyReadCalibrationMode);

    openSerialPortIfNotOpen();

    m_SerialPortTextStream << "calibrate" << endl; //TODOmb: these strings should be in a shared header, shared between the arduino sketch and this sauce
    m_SerialPortTextStream.flush(); //TODOmb: encapsulate writes so I can't forget to flush (and psbly an endl)
}
void WasdfArduino::start(const WasdfCalibrationConfiguration &calibrationConfig)
{
    //TODOreq: this is where the 10 fingers get mapped to the 10 pins

    disconnect(m_SerialPort, &QSerialPort::readyRead, this, &WasdfArduino::handleSerialPortReadyReadCalibrationMode);
    connect(m_SerialPort, &QSerialPort::readyRead, this, &WasdfArduino::handleSerialPortReadyReadNormalFingerMovementMode);

    openSerialPortIfNotOpen();

    m_SerialPortTextStream << "start[BLAH:MAP:0:5:A7:ETC:TODOreq]" << endl;
    m_SerialPortTextStream.flush();
}
void WasdfArduino::handleSerialPortReadyReadCalibrationMode()
{
    while(m_SerialPort->canReadLine())
    {
        QString line = m_SerialPortTextStream.readLine();
        //line is simply: "[pinId]:[sensorValue]"
        QStringList lineSplitAtColon = line.split(":");
        Q_ASSERT(lineSplitAtColon.size() == 2); //TODOmb: instead of these asserts, we should just silently ignore errors? still this is useful for debugging
        bool stringToIntConvertedOk;
        int analogPinId = lineSplitAtColon.first().toInt(&stringToIntConvertedOk);
        Q_ASSERT(stringToIntConvertedOk);
        int sensorValue = lineSplitAtColon.at(1).toInt(&stringToIntConvertedOk);
        Q_ASSERT(stringToIntConvertedOk);
        emit analogPinReadingChangedDuringCalibration(analogPinId, sensorValue);
    }
}
void WasdfArduino::handleSerialPortReadyRead()WasdfArduino::handleSerialPortReadyReadNormalFingerMovementMode()
{
    //TODOreq:
}
diff --git a/Projects/wasdf/src/lib/wasdfarduino.h b/Projects/wasdf/src/lib/wasdfarduino.h
index a46465a..647a4f4 100644
--- a/Projects/wasdf/src/lib/wasdfarduino.h
+++ b/Projects/wasdf/src/lib/wasdfarduino.h
@@ -1,6 +1,10 @@
#ifndef WASDFARDUINO_H
#define WASDFARDUINO_H

#include <QObject>

#include <QTextStream>

#include "wasdf.h"

class QSerialPort;
@@ -11,15 +15,28 @@ class WasdfArduino : public QObject
public:
    explicit WasdfArduino(QObject *parent = 0);
private:
#if 0 //different readyRead handlers is better/cleaner :)
    enum class WasdfArduinoMode
    {
          Calibrating = 0x001
        , Report10fingerMovements = 0x010
        , ControlMouseAndKeyboard = 0x100 //TODOreq: I forget how to properly set up 'flags' that can be combined, this might be wrong (also calibrating can never be used with any other modes, but eh)
    };
#endif
    void openSerialPortIfNotOpen();

    QSerialPort *m_SerialPort;
    QTextStream m_SerialPortTextStream;
signals:
    void e(const QString &msg);
    void analogPinReadingChangedDuringCalibration(int analogPinId, int newPosition);
    void fingerMoved(Finger finger, int newPosition);
public slots:
    void startInCalibrationMode();
    void start(const WasdfCalibrationConfiguration &calibrationConfig);
private slots:
    void handleSerialPortReadyRead();handleSerialPortReadyReadCalibrationMode();
    void handleSerialPortReadyReadNormalFingerMovementMode();
};

#endif // WASDFARDUINO_H