From: Thomas Pietrzak Date: Wed, 23 Jan 2013 10:55:46 +0000 (+0000) Subject: Added Tactile fluids, fixed tactile buttons X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=HEAD;p=DynamicKeyboardLib.git Added Tactile fluids, fixed tactile buttons git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@100 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/Arduino/dynamickeyboard/dynamickeyboard.ino b/Arduino/dynamickeyboard/dynamickeyboard.ino index 60a931e..66e1407 100644 --- a/Arduino/dynamickeyboard/dynamickeyboard.ino +++ b/Arduino/dynamickeyboard/dynamickeyboard.ino @@ -20,8 +20,8 @@ byte command = 0; //threshold values for side keys //with hysteresis -int thresholda = 1; -int thresholdb = 10; +int thresholda = 0x20; +int thresholdb = 0x10; void sendInformation() { @@ -79,8 +79,8 @@ void setup() */ Serial.begin(115200); - keysState[0] = 255; - keysState[1] = 255; + keysState[0] = 0; + keysState[1] = 0; analogWrite(pwmPin, minDutyCycle); } @@ -98,17 +98,15 @@ void setup() void checkEvents() { boolean newevent = false; - /* + /* Serial.write("F"); Serial.write(1); for (int i = 0 ; i < 4 ; i++) - Serial.print(analogRead(keyPins1[i]),HEX); - Serial.print(" "); + Serial.write(analogRead(keyPins1[i])); Serial.write("F"); Serial.write(1); for (int i = 0 ; i < 4 ; i++) - Serial.print(analogRead(keyPins2[i]),HEX); - Serial.println(""); + Serial.write(analogRead(keyPins2[i])); return;*/ //check key1 @@ -116,19 +114,22 @@ void checkEvents() { byte b = analogRead(keyPins1[i]); //press / release - if (keySides1[i] > thresholda && b < thresholda || - keySides1[i] < thresholdb && b > thresholdb) + if ((keySides1[i] < thresholda && b > thresholda)) { keySides1[i] = b; newevent = true; } + else if ((keySides1[i] > thresholdb && b < thresholdb)) + { + keySides1[i] = b; + } } if (newevent) { Serial.write("F"); Serial.write(1); for (int i = 0 ; i < 4 ; i++) - Serial.write(255 - keySides1[i]); + Serial.write(keySides1[i]); newevent = false; } @@ -138,19 +139,22 @@ void checkEvents() { byte b = analogRead(keyPins2[i]); //press / release - if (keySides2[i] > thresholda && b < thresholda || - keySides2[i] < thresholdb && b > thresholdb) + if ((keySides2[i] < thresholda && b > thresholda)) { keySides2[i] = b; newevent = true; } + else if ((keySides2[i] > thresholdb && b < thresholdb)) + { + keySides2[i] = b; + } } if (newevent) { Serial.write("F"); Serial.write(2); for (int i = 0 ; i < 4 ; i++) - Serial.write(255 - keySides2[i]); + Serial.write(keySides2[i]); newevent = false; } } diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo b/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo index 0f103d6..413054b 100644 Binary files a/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo and b/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo differ diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp index e7d6afd..d2f57e8 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.cpp @@ -97,7 +97,7 @@ void DynamicKeyboardController::setBoostDuration(UINT16 val) const bool DynamicKeyboardController::getState(UINT16 &solenoids, UINT8 &minDutyCycle, UINT8 &maxDutyCycle, UINT16 &boostDuration) const { char comm = 'I'; - if (!_comPort || !_comPort->WriteData(&comm,1)) + if (!_comPort || !_comPort->WriteData(&comm, 1)) return false; #ifdef WIN32 Sleep(1000); diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj index 3c79728..86492be 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj @@ -12,12 +12,25 @@ - - + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing QPushKeysKeyboardController.h... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DDEBUG -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DDYNAMICKEYBOARDLIBRARY_LIB -D_WINDLL "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing QPushKeysKeyboardController.h... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DDLLEXPORT -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DDYNAMICKEYBOARDLIBRARY_LIB -D_WINDLL "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" + - + + true + + + true + diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj.filters b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj.filters index 51c5a9d..6a99078 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj.filters +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj.filters @@ -23,17 +23,21 @@ moc;h;cpp False + + {b926e84f-3889-4973-bac7-53502e36e5e9} + cpp;moc + False + + + {5b1fdf1f-d57f-4851-9b1e-ca12f863c532} + cpp;moc + False + - - Header Files - Header Files - - Header Files - @@ -42,8 +46,16 @@ Source Files - - Source Files + + Generated Files\Debug + + + Generated Files\Release + + + Header Files + + \ No newline at end of file diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp index 658770c..58fcf4e 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp @@ -1,14 +1,13 @@ #include "QPushKeysKeyboardController.h" #include -#include "QSideKeyEvent.h" #if DEBUG #include #endif -QPushKeysKeyboardController::QPushKeysKeyboardController(char *port, int baudrate, QObject *receiver) -: DynamicKeyboardController(port, baudrate), _receiver(receiver) +QPushKeysKeyboardController::QPushKeysKeyboardController(char *port, int baudrate)//, QObject *receiver) +: DynamicKeyboardController(port, baudrate)//, _receiver(receiver) { start(); } @@ -20,32 +19,37 @@ QPushKeysKeyboardController::~QPushKeysKeyboardController(void) void QPushKeysKeyboardController::run() { +// if (!_receiver ||!_comPort) + if (!_comPort) + return; + char buffer[6]; - qDebug() << "Watching for side key events, send them to " << hex << _receiver; #if DEBUG - qDebug() << "Watching for side key events, send them to " << hex << _receiver; + qDebug() << "Watching for side key events";//, send them to " << hex << _receiver; #endif while (true) { - if (_comPort->ReadData(buffer, 6) == 6 && _receiver) + if (_comPort->ReadData(buffer, 6) == 6) { - QSideKeyEvent::Sides sides = 0; - if (buffer[2] > 0) - sides |= QSideKeyEvent::Front; - if (buffer[3] > 0) - sides |= QSideKeyEvent::Right; - if (buffer[4] > 0) - sides |= QSideKeyEvent::Back; - if (buffer[5] > 0) - sides |= QSideKeyEvent::Left; + Sides sides = 0; + + if (buffer[2] == 0xff) + sides |= QPushKeysKeyboardController::Front; + if (buffer[3] == 0xff) + sides |= QPushKeysKeyboardController::Right; + if (buffer[4] == 0xff) + sides |= QPushKeysKeyboardController::Back; + if (buffer[5] == 0xff) + sides |= QPushKeysKeyboardController::Left; #if DEBUG qDebug() << "post key " << buffer[1] << " sides " << hex << sides; #endif - QCoreApplication::postEvent(_receiver, new QSideKeyEvent(buffer[1], sides)); + //QCoreApplication::postEvent(_receiver, new QSideKeyEvent(buffer[1], sides)); + emit keyEvent(buffer[1], int(sides)); } - sleep(1000); + msleep(1); } } diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h index 8902995..06fa72a 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h @@ -1,21 +1,42 @@ #ifndef __QPUSHKEYSKEYBOARDCONTROLLER_ #define __QPUSHKEYSKEYBOARDCONTROLLER_ -#include #include +#include +#include +#include +//#include "QSideKeyEvent.h" #include "DynamicKeyboardController.h" -class EXPORTED QPushKeysKeyboardController: public DynamicKeyboardController, QThread +class EXPORTED QPushKeysKeyboardController: public QThread, public DynamicKeyboardController { + Q_OBJECT + public: - QPushKeysKeyboardController(char *port, int baudrate, QObject *receiver=NULL); + QPushKeysKeyboardController(char *port, int baudrate);//, QObject *receiver=NULL); ~QPushKeysKeyboardController(); + enum Side { + Front = 0x01, + Right = 0x02, + Back = 0x04, + Left = 0x08 }; + + Q_DECLARE_FLAGS(Sides, Side) + Q_FLAGS(Sides) + + signals: + void keyEvent(int, int); + protected: void run(); - QObject *_receiver; + //QObject *_receiver; }; +Q_DECLARE_OPERATORS_FOR_FLAGS(QPushKeysKeyboardController::Sides) + +Q_DECLARE_METATYPE(QPushKeysKeyboardController::Sides); + #endif diff --git a/Expe-selection/dyna-expe2/Controler.cpp b/Expe-selection/dyna-expe2/Controler.cpp index 626e625..81f9263 100644 --- a/Expe-selection/dyna-expe2/Controler.cpp +++ b/Expe-selection/dyna-expe2/Controler.cpp @@ -10,6 +10,15 @@ //int secondScreenWidth = 1920; //int secondScreenHeight = 1200; +Controler::Controler(MainWindow *_experimenterWindow) +: Expe(), successSound(":ressources/success.wav"), errorSound("ressources/error.wav"), + experimenterWindow(_experimenterWindow), keyboardListener("COM9", 115200) +{ + //qDebug() << __PRETTY_FUNCTION__ ; + setNbBlock(5); //TODO + setNbTrials(28); //TODO +} + void Controler::setFullScreen() { widgetParent->showFullScreen(); @@ -20,15 +29,8 @@ void Controler::setFullScreen() HCISheet* sheet = dynamic_cast(this->trialSheet); sheet->resize(this->widgetParent->width(), this->widgetParent->height()); -} -Controler::Controler(MainWindow *_experimenterWindow) -: Expe(), successSound(":ressources/success.wav"), errorSound("ressources/error.wav"), - experimenterWindow(_experimenterWindow), keyboardControler(NULL) -{ - //qDebug() << __PRETTY_FUNCTION__ ; - setNbBlock(5); //TODO - setNbTrials(28); //TODO + sheet->raise(); } //----------------------------- @@ -50,15 +52,17 @@ void Controler::initCSVWriter(const QStringList &l) h = h.mid(0,1); title += h+"["+l.at(i) +"]"; } + title += "dy[" + this->keyboardType + "]"; + //title += "tec["+ this->tech +"]"; - //title += "set" + this->set +"]"; + //title += " set" + this->set +"]"; title +=".csv"; csvWriter.openFile(title); csvWriter.setColumnNames(columNames); } //---------------------- -void Controler::start(const QString& nameFile, QString user, const QString& , const QString& ) +void Controler::start(const QString& nameFile, QString user, const QString& option1, const QString& ) { // qDebug()<<__PRETTY_FUNCTION__; QFile f(nameFile); @@ -67,6 +71,8 @@ void Controler::start(const QString& nameFile, QString user, const QString& , co Expe::start(nameFile, user); + this->keyboardType = option1; + QRect geometry = QApplication::desktop()->screenGeometry(); this->widgetParent->move(0, 0); //this->widgetParent->resize(1280,1024); @@ -91,10 +97,23 @@ void Controler::start(const QString& nameFile, QString user, const QString& , co connect(sheet, SIGNAL(hotkeyPressed(char)), this, SLOT(hotkeyPressed(char))); connect(sheet, SIGNAL(hotkeyReleased(char)), this, SLOT(hotkeyReleased(char))); //key sides - connect(sheet, SIGNAL(raisedKeyReleased(char, int)), this, SLOT(raisedKeyReleased(char, int))); - connect(sheet, SIGNAL(ctrlPressed()), this, SLOT(raiseKeys())); + //connect(sheet, SIGNAL(raisedKeyReleased(char, int)), this, SLOT(raisedKeyReleased(char, int))); +// connect(sheet, SIGNAL(ctrlPressed()), this, SLOT(raiseKeys())); +// connect(sheet, SIGNAL(ctrlReleased()), this, SLOT(lowerKeys())); this->setFullScreen(); - keyboardControler = new QPushKeysKeyboardController("COM9", 115200, sheet); +/* + try + { + keyboardControler = new QPushKeysKeyboardController("COM9", 115200); + + connect(dynamic_cast(keyboardControler), SIGNAL(keyEvent(int, int)), this, SLOT(sideKeyEvent(int, int))); + } + catch (...) + { + qDebug() << "No dynamic keyboard found"; + keyboardControler = NULL; + }*/ + connect(&keyboardListener, SIGNAL(keyEvent(int, int)), this, SLOT(sideKeyEvent(int, int))); } //---------------------- @@ -147,6 +166,10 @@ void Controler::prepareTrialData(const QMap& prop) HCISheet * sheet = dynamic_cast(this->trialSheet); sheet->setTargetKey(key, type); + csvWriter.write("blockbis", QString::number(this->numBlock())); + + csvWriter.write("dk_keyboard", QString::number(this->keyboardType != "NORMAL")); + // QString str_item = prop["item"]; //define the stimulus //display the stimulus. @@ -205,6 +228,7 @@ QStringList Controler::completeCSVHeaderData() { csvWriter.setSeparator("\t"); QStringList res; + res << "blockbis"; res << "key"; res << "type"; res <<"raised"; @@ -214,6 +238,7 @@ QStringList Controler::completeCSVHeaderData() res << "correct"; res << "false"; res << "time"; + res << "dk_keyboard"; return res; } @@ -275,12 +300,19 @@ QString Controler::getCharFromConfiguration(int keyId, int configuration) return key; }*/ - +/* void Controler::raiseKeys() { - keyboardControler->raiseKeys(0xffff); + if (keyboardControler) + keyboardControler->raiseKeys(0xffff); } +void Controler::lowerKeys() +{ + if (keyboardControler) + keyboardControler->lowerKeys(0xffff); +} +*/ //--------------------------- void Controler::hotkeyPressed(char /*c*/) { @@ -288,19 +320,28 @@ void Controler::hotkeyPressed(char /*c*/) } //--------------------------- -void Controler::raisedKeyReleased(char key, int sides){ - QString res = QString(key); +//void Controler::raisedKeyReleased(char key, int sides){ +void Controler::sideKeyEvent(int key, int sides) +{ +// QPushKeysKeyboardController::Sides s = + QString res = ""; + if (key == 1) + res += "d"; + else if (key == 2) + res += "o"; if(sides & QSideKeyEvent::Left) res += "l"; else if(sides & QSideKeyEvent::Right) res += "r"; else if(sides & QSideKeyEvent::Front) res += "f"; else if(sides & QSideKeyEvent::Back) res += "b"; + + activateHotkey(res); } //--------------------------- void Controler::hotkeyReleased(char keyf) { activateHotkey(QString(keyf)+"t"); - keyboardControler->lowerKeys(0xffff); + //ododdolowerKeys(); } diff --git a/Expe-selection/dyna-expe2/Controler.h b/Expe-selection/dyna-expe2/Controler.h index d608b31..c917bcc 100644 --- a/Expe-selection/dyna-expe2/Controler.h +++ b/Expe-selection/dyna-expe2/Controler.h @@ -3,11 +3,12 @@ #include #include +#include #include "expe/Expe.h" #include "HCISheet.h" #include "MainWindow.h" -#include +#include "QKeyboardListener.h" class Controler : public Expe { @@ -21,8 +22,6 @@ public: //void setExperimenterWindow(MainWindow* _experimenterWindow); - - signals: void blockPrepared(); @@ -33,9 +32,11 @@ public slots: //key will probably D or O. //side can be l(left), r(right) f(front) b(back) t(top) //force is the force - void raisedKeyReleased(char key, int sides);//thomas, you can call this method + // void raisedKeyReleased(char key, int sides);//thomas, you can call this method + void sideKeyEvent(int, int); void activateHotkey(QString advHotkey); - void raiseKeys(); + /*void raiseKeys(); + void lowerKeys();*/ protected: @@ -65,8 +66,10 @@ protected: QString keyTarget; //int configuration; bool succes; + QString keyboardType; - DynamicKeyboardController *keyboardControler; + QKeyboardListener keyboardListener; + //DynamicKeyboardController *keyboardControler; }; #endif // CONTROLER_H diff --git a/Expe-selection/dyna-expe2/HCISheet.cpp b/Expe-selection/dyna-expe2/HCISheet.cpp index 58daf85..fcacb22 100644 --- a/Expe-selection/dyna-expe2/HCISheet.cpp +++ b/Expe-selection/dyna-expe2/HCISheet.cpp @@ -555,6 +555,7 @@ void HCISheet::keyReleaseEvent(QKeyEvent *ke){ { this->ctrl_pressed = false; qDebug() << "ctrl released"; + emit ctrlReleased(); //TODO //RaiseKey 1 2 } @@ -581,69 +582,69 @@ void HCISheet::keyReleaseEvent(QKeyEvent *ke){ bool HCISheet::event(QEvent *event) { - if (event->type() == QSideKeyEvent::QSideKeyEventType) + /* if (event->type() == QSideKeyEvent::QSideKeyEventType) { QSideKeyEvent *evt = static_cast(event); qDebug() << "Key " << evt->getKey() << "sides " << hex << evt->getSides(); emit raisedKeyReleased(evt->getKey(), evt->getSides()); return true; - } + }*/ return QWidget::event(event); } -void HCISheet::ctrlF(){ qDebug()<<"ctrl F"; ctrl_pressed = false; emit hotkeyReleased('f'); } -void HCISheet::ctrlA(){ qDebug()<<"ctrl A"; ctrl_pressed = false; emit hotkeyReleased('a'); } -void HCISheet::ctrlS(){ qDebug()<<"ctrl S"; ctrl_pressed = false; emit hotkeyReleased('s'); } -void HCISheet::ctrlD(){ qDebug()<<"ctrl D"; ctrl_pressed = false; emit hotkeyReleased('D'); } -void HCISheet::ctrlG(){ qDebug()<<"ctrl G"; ctrl_pressed = false; emit hotkeyReleased('g'); } -void HCISheet::ctrlE(){ qDebug()<<"ctrl E"; ctrl_pressed = false; emit hotkeyReleased('e'); } -void HCISheet::ctrl4(){ qDebug()<<"ctrl F"; ctrl_pressed = false; emit hotkeyReleased('4'); } -void HCISheet::ctrlX(){ qDebug()<<"ctrl X"; ctrl_pressed = false; emit hotkeyReleased('x'); } -void HCISheet::ctrlC(){ qDebug()<<"ctrl C"; ctrl_pressed = false; emit hotkeyReleased('c'); } -void HCISheet::ctrlH(){ qDebug()<<"ctrl H"; ctrl_pressed = false; emit hotkeyReleased('h'); } - -void HCISheet::ctrlQ(){ qDebug()<<"ctrl Q"; ctrl_pressed = false; emit hotkeyReleased('q'); } -void HCISheet::ctrlW(){ qDebug()<<"ctrl W"; ctrl_pressed = false; emit hotkeyReleased('w'); } -void HCISheet::ctrlR(){ qDebug()<<"ctrl R"; ctrl_pressed = false; emit hotkeyReleased('r'); } -void HCISheet::ctrlT(){ qDebug()<<"ctrl T"; ctrl_pressed = false; emit hotkeyReleased('t'); } -void HCISheet::ctrlY(){ qDebug()<<"ctrl Y"; ctrl_pressed = false; emit hotkeyReleased('y'); } -void HCISheet::ctrlU(){ qDebug()<<"ctrl U"; ctrl_pressed = false; emit hotkeyReleased('u'); } -void HCISheet::ctrlI(){ qDebug()<<"ctrl I"; ctrl_pressed = false; emit hotkeyReleased('i'); } -void HCISheet::ctrlO(){ qDebug()<<"ctrl O"; ctrl_pressed = false; emit hotkeyReleased('O'); } -void HCISheet::ctrlP(){ qDebug()<<"ctrl P"; ctrl_pressed = false; emit hotkeyReleased('p'); } -void HCISheet::ctrlBracketLeft(){ qDebug()<<"ctrl ["; ctrl_pressed = false; emit hotkeyReleased('['); } -void HCISheet::ctrlBracketRight(){ qDebug()<<"ctrl ]"; ctrl_pressed = false; emit hotkeyReleased(']'); } -void HCISheet::ctrlJ(){ qDebug()<<"ctrl J"; ctrl_pressed = false; emit hotkeyReleased('j'); } -void HCISheet::ctrlK(){ qDebug()<<"ctrl K"; ctrl_pressed = false; emit hotkeyReleased('k'); } -void HCISheet::ctrlL(){ qDebug()<<"ctrl L"; ctrl_pressed = false; emit hotkeyReleased('l'); } -void HCISheet::ctrlPointVirgule(){ qDebug()<<"ctrl ;"; ctrl_pressed = false; emit hotkeyReleased(';'); } -void HCISheet::ctrlApostrophe(){ qDebug()<<"ctrl '"; ctrl_pressed = false; emit hotkeyReleased('\''); } -void HCISheet::ctrlZ(){ qDebug()<<"ctrl Z"; ctrl_pressed = false; emit hotkeyReleased('z'); } -void HCISheet::ctrlV(){ qDebug()<<"ctrl V"; ctrl_pressed = false; emit hotkeyReleased('v'); } -void HCISheet::ctrlB(){ qDebug()<<"ctrl B"; ctrl_pressed = false; emit hotkeyReleased('b'); } -void HCISheet::ctrlN(){ qDebug()<<"ctrl N"; ctrl_pressed = false; emit hotkeyReleased('n'); } -void HCISheet::ctrlM(){ qDebug()<<"ctrl M"; ctrl_pressed = false; emit hotkeyReleased('m'); } -void HCISheet::ctrlVirgule(){ qDebug()<<"ctrl ,"; ctrl_pressed = false; emit hotkeyReleased(','); } -void HCISheet::ctrlPoint(){ qDebug()<<"ctrl ."; ctrl_pressed = false; emit hotkeyReleased('.'); } -void HCISheet::ctrlSlash(){ qDebug()<<"ctrl /"; ctrl_pressed = false; emit hotkeyReleased('/'); } - -void HCISheet::ctrlChapeau(){ qDebug()<<"ctrl ^"; ctrl_pressed = false; emit hotkeyReleased('^'); } -void HCISheet::ctrlDollar(){ qDebug()<<"ctrl $"; ctrl_pressed = false; emit hotkeyReleased('$'); } -void HCISheet::ctrlStar(){ qDebug()<<"ctrl *"; ctrl_pressed = false; emit hotkeyReleased('*'); } -void HCISheet::ctrlAdvU(){ qDebug()<<("ctrl ù"); ctrl_pressed = false; emit hotkeyReleased('\xf9'); } -void HCISheet::ctrlChevron(){ qDebug()<<"ctrl <"; ctrl_pressed = false; emit hotkeyReleased('<'); } -void HCISheet::ctrlDoubleDot(){ qDebug()<<"ctrl :"; ctrl_pressed = false; emit hotkeyReleased(':'); } -void HCISheet::ctrlExclamation(){ qDebug()<<"ctrl !"; ctrl_pressed = false; emit hotkeyReleased('!'); } - -void HCISheet::ctrlEtCommercial(){ qDebug()<<"ctrl &"; ctrl_pressed = false; emit hotkeyReleased('&'); } -void HCISheet::ctrlEAigu(){ qDebug()<<"ctrl é"; ctrl_pressed = false; emit hotkeyReleased('\xe9'); } -void HCISheet::ctrlEGrave(){ qDebug()<<"ctrl è"; ctrl_pressed = false; emit hotkeyReleased('\xe8'); } -void HCISheet::ctrlGuillement(){ qDebug()<<"ctrl \""; ctrl_pressed = false; emit hotkeyReleased('\"'); } -void HCISheet::ctrlParentheseO(){ qDebug()<<"ctrl ("; ctrl_pressed = false; emit hotkeyReleased('('); } -void HCISheet::ctrlParentheseF(){ qDebug()<<"ctrl )"; ctrl_pressed = false; emit hotkeyReleased(')'); } -void HCISheet::ctrl_(){ qDebug()<<"ctrl _"; ctrl_pressed = false; emit hotkeyReleased('_'); } -void HCISheet::ctrlCedille(){ qDebug()<<"ctrl ç"; ctrl_pressed = false; emit hotkeyReleased('\xe7'); } -void HCISheet::ctrlAGrave(){ qDebug()<<"ctrl à"; ctrl_pressed = false; emit hotkeyReleased('\xe0'); } -void HCISheet::ctrlEqual(){ qDebug()<<"ctrl ="; ctrl_pressed = false; emit hotkeyReleased('='); } -void HCISheet::ctrlMinus(){ qDebug()<<"ctrl -"; ctrl_pressed = false; emit hotkeyReleased('-'); } +void HCISheet::ctrlF(){ qDebug()<<"ctrl F"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('f'); } +void HCISheet::ctrlA(){ qDebug()<<"ctrl A"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('a'); } +void HCISheet::ctrlS(){ qDebug()<<"ctrl S"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('s'); } +void HCISheet::ctrlD(){ qDebug()<<"ctrl D"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('D'); } +void HCISheet::ctrlG(){ qDebug()<<"ctrl G"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('g'); } +void HCISheet::ctrlE(){ qDebug()<<"ctrl E"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('e'); } +void HCISheet::ctrl4(){ qDebug()<<"ctrl F"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('4'); } +void HCISheet::ctrlX(){ qDebug()<<"ctrl X"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('x'); } +void HCISheet::ctrlC(){ qDebug()<<"ctrl C"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('c'); } +void HCISheet::ctrlH(){ qDebug()<<"ctrl H"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('h'); } + +void HCISheet::ctrlQ(){ qDebug()<<"ctrl Q"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('q'); } +void HCISheet::ctrlW(){ qDebug()<<"ctrl W"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('w'); } +void HCISheet::ctrlR(){ qDebug()<<"ctrl R"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('r'); } +void HCISheet::ctrlT(){ qDebug()<<"ctrl T"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('t'); } +void HCISheet::ctrlY(){ qDebug()<<"ctrl Y"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('y'); } +void HCISheet::ctrlU(){ qDebug()<<"ctrl U"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('u'); } +void HCISheet::ctrlI(){ qDebug()<<"ctrl I"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('i'); } +void HCISheet::ctrlO(){ qDebug()<<"ctrl O"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('O'); } +void HCISheet::ctrlP(){ qDebug()<<"ctrl P"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('p'); } +void HCISheet::ctrlBracketLeft(){ qDebug()<<"ctrl ["; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('['); } +void HCISheet::ctrlBracketRight(){ qDebug()<<"ctrl ]"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased(']'); } +void HCISheet::ctrlJ(){ qDebug()<<"ctrl J"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('j'); } +void HCISheet::ctrlK(){ qDebug()<<"ctrl K"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('k'); } +void HCISheet::ctrlL(){ qDebug()<<"ctrl L"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('l'); } +void HCISheet::ctrlPointVirgule(){ qDebug()<<"ctrl ;"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased(';'); } +void HCISheet::ctrlApostrophe(){ qDebug()<<"ctrl '"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('\''); } +void HCISheet::ctrlZ(){ qDebug()<<"ctrl Z"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('z'); } +void HCISheet::ctrlV(){ qDebug()<<"ctrl V"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('v'); } +void HCISheet::ctrlB(){ qDebug()<<"ctrl B"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('b'); } +void HCISheet::ctrlN(){ qDebug()<<"ctrl N"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('n'); } +void HCISheet::ctrlM(){ qDebug()<<"ctrl M"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('m'); } +void HCISheet::ctrlVirgule(){ qDebug()<<"ctrl ,"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased(','); } +void HCISheet::ctrlPoint(){ qDebug()<<"ctrl ."; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('.'); } +void HCISheet::ctrlSlash(){ qDebug()<<"ctrl /"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('/'); } + +void HCISheet::ctrlChapeau(){ qDebug()<<"ctrl ^"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('^'); } +void HCISheet::ctrlDollar(){ qDebug()<<"ctrl $"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('$'); } +void HCISheet::ctrlStar(){ qDebug()<<"ctrl *"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('*'); } +void HCISheet::ctrlAdvU(){ qDebug()<<("ctrl ù"); ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('\xf9'); } +void HCISheet::ctrlChevron(){ qDebug()<<"ctrl <"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('<'); } +void HCISheet::ctrlDoubleDot(){ qDebug()<<"ctrl :"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased(':'); } +void HCISheet::ctrlExclamation(){ qDebug()<<"ctrl !"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('!'); } + +void HCISheet::ctrlEtCommercial(){ qDebug()<<"ctrl &"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('&'); } +void HCISheet::ctrlEAigu(){ qDebug()<<"ctrl é"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('\xe9'); } +void HCISheet::ctrlEGrave(){ qDebug()<<"ctrl è"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('\xe8'); } +void HCISheet::ctrlGuillement(){ qDebug()<<"ctrl \""; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('\"'); } +void HCISheet::ctrlParentheseO(){ qDebug()<<"ctrl ("; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('('); } +void HCISheet::ctrlParentheseF(){ qDebug()<<"ctrl )"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased(')'); } +void HCISheet::ctrl_(){ qDebug()<<"ctrl _"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('_'); } +void HCISheet::ctrlCedille(){ qDebug()<<"ctrl ç"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('\xe7'); } +void HCISheet::ctrlAGrave(){ qDebug()<<"ctrl à"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('\xe0'); } +void HCISheet::ctrlEqual(){ qDebug()<<"ctrl ="; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('='); } +void HCISheet::ctrlMinus(){ qDebug()<<"ctrl -"; ctrl_pressed = false; emit ctrlReleased(); emit hotkeyReleased('-'); } diff --git a/Expe-selection/dyna-expe2/HCISheet.h b/Expe-selection/dyna-expe2/HCISheet.h index 7bff87a..a34c4a3 100644 --- a/Expe-selection/dyna-expe2/HCISheet.h +++ b/Expe-selection/dyna-expe2/HCISheet.h @@ -26,6 +26,7 @@ public: signals: void ctrlPressed(); + void ctrlReleased(); void hotkeyPressed(char c); void hotkeyReleased(char c); void raisedKeyReleased(char key, int sides); diff --git a/Expe-selection/dyna-expe2/QKeyboarLlistener.cpp b/Expe-selection/dyna-expe2/QKeyboarLlistener.cpp new file mode 100644 index 0000000..9532258 --- /dev/null +++ b/Expe-selection/dyna-expe2/QKeyboarLlistener.cpp @@ -0,0 +1,81 @@ +#include "QKeyboardListener.h" + +#include + +QKeyboardListener::QKeyboardListener(char *port, int baudrate, QObject *parent) +:QThread(parent) +{ + + try + { +#ifdef WIN32 + _comPort = new SerialWindows(port, baudrate); +#elif defined __MACOSX__ + _comPort = new SerialMac(port, baudrate); +#endif + } + catch (...) + { + qDebug() << "No Dynamic Keyboard found"; + _comPort = NULL; + } + + start(); +} + +void QKeyboardListener::run() +{ +// if (!_receiver ||!_comPort) + if (!_comPort) + return; + + char buffer[6]; +#if DEBUG + qDebug() << "Watching for side key events";//, send them to " << hex << _receiver; +#endif + + while (true) + { + if (_comPort->ReadData(buffer, 6) == 6) + { + //Sides sides = 0; + + int max = buffer[2]; + int side = QKeyboardListener::Front; + if (buffer[3] > max) + { + side = QKeyboardListener::Right; + max = buffer [3]; + } + if (buffer[4] > max) + { + side = QKeyboardListener::Back; + max = buffer [4]; + } + if (buffer[5] > max) + { + side = QKeyboardListener::Left; + max = buffer [5]; + } + emit keyEvent(buffer[1], side); + + /* + if (buffer[2] > 0x10) + sides |= QKeyboardListener::Front; + if (buffer[3] > 0x10) + sides |= QKeyboardListener::Right; + if (buffer[4] > 0x10) + sides |= QKeyboardListener::Back; + if (buffer[5] > 0x10) + sides |= QKeyboardListener::Left; + +#if DEBUG + qDebug() << "post key " << buffer[1] << " sides " << hex << sides; +#endif + + //QCoreApplication::postEvent(_receiver, new QSideKeyEvent(buffer[1], sides)); + emit keyEvent(buffer[1], int(sides));*/ + } + msleep(1); + } +} diff --git a/Expe-selection/dyna-expe2/QKeyboardListener.h b/Expe-selection/dyna-expe2/QKeyboardListener.h new file mode 100644 index 0000000..eb8e6ea --- /dev/null +++ b/Expe-selection/dyna-expe2/QKeyboardListener.h @@ -0,0 +1,42 @@ +#ifndef QKEYBOARDLISTENER_H +#define QKEYBOARDLISTENER_H + +#include + +#ifdef __MACOSX__ +#include +#elif defined WIN32 +#include +#endif + +class QKeyboardListener : public QThread +{ + Q_OBJECT + public: + QKeyboardListener(char *port, int baudrate, QObject *parent = NULL); + void run(); + + + enum Side { + Front = 0x01, + Right = 0x02, + Back = 0x04, + Left = 0x08 }; + + Q_DECLARE_FLAGS(Sides, Side) + Q_FLAGS(Sides) + + signals: + void keyEvent(int, int); + + public slots: + + private: + Serial *_comPort; +}; + +Q_DECLARE_OPERATORS_FOR_FLAGS(QKeyboardListener::Sides) + +//Q_DECLARE_METATYPE(QKeyboardListener::Sides); + +#endif // QKEYBOARDLISTENER_H diff --git a/Expe-selection/dyna-expe2/dyna-expe2.pro b/Expe-selection/dyna-expe2/dyna-expe2.pro index 512fffe..5826abf 100644 --- a/Expe-selection/dyna-expe2/dyna-expe2.pro +++ b/Expe-selection/dyna-expe2/dyna-expe2.pro @@ -1,59 +1,59 @@ -TARGET = dyna-expe2 -DESTDIR = ../tmp/exec/ -TEMPLATE = app -QT += xml -OBJECTS_DIR = ./obj -MOC_DIR = ./moc -UI_DIR = ./ui - -INCLUDEPATH += expe - -RESOURCES += resources.qrc - -HEADERS += Controler.h \ - HCISheet.h -SOURCES += main.cpp Controler.cpp \ - HCISheet.cpp - -HEADERS += MainWindow.h -SOURCES += MainWindow.cpp - -# experience librairie -HEADERS += expe/ExpeData.h \ - expe/Global.h \ - expe/ExpeLoader.h \ - expe/Expe.h \ - expe/ExpeConfig.h -SOURCES += expe/ExpeData.cpp \ - expe/Global.cpp \ - expe/ExpeLoader.cpp \ - expe/Expe.cpp \ - expe/Expe_p.cpp \ - expe/ExpeConfig.cpp -HEADERS += expe/xml/DataImport.h \ - expe/xml/DataFactory.h -SOURCES += expe/xml/DataImport.cpp \ - expe/xml/DataFactory.cpp -HEADERS += expe/expeWidget/InterBlock.h \ - expe/expeWidget/InterTrial.h \ - expe/expeWidget/ExpeWidget.h \ - expe/expeWidget/TrialSheet.h -SOURCES += expe/expeWidget/InterBlock.cpp \ - expe/expeWidget/InterTrial.cpp \ - expe/expeWidget/ExpeWidget.cpp \ - expe/expeWidget/TrialSheet.cpp -HEADERS += expe/csv/CSVWriter.h -SOURCES += expe/csv/CSVWriter.cpp - - -FORMS += expe/ExpeConfig.ui - -CONFIG(release): LIBS += -lDynamicKeyboardLibrary -#-L$$PWD/../../../../../../../../Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib/ - -CONFIG(debug): LIBS += -lDynamicKeyboardLibraryd - -#-L$$PWD/../../../../../../../../Program Files (x86)/Microsoft Visual Studio 10.0/VC/lib/ - -#INCLUDEPATH += $$PWD/../../../../../../../../Program Files (x86)/Microsoft Visual Studio 10.0/VC/include -#DEPENDPATH += $$PWD/../../../../../../../../Program Files (x86)/Microsoft Visual Studio 10.0/VC/include +TARGET = dyna-expe2 +DESTDIR = ../tmp/exec/ +TEMPLATE = app +QT += xml +OBJECTS_DIR = ./obj +MOC_DIR = ./moc +UI_DIR = ./ui + +INCLUDEPATH += expe + +RESOURCES += resources.qrc + +HEADERS += Controler.h \ + HCISheet.h \ + QKeyboardListener.h +SOURCES += main.cpp Controler.cpp \ + HCISheet.cpp \ + QKeyboarLlistener.cpp + +HEADERS += MainWindow.h +SOURCES += MainWindow.cpp + +# experience librairie +HEADERS += expe/ExpeData.h \ + expe/Global.h \ + expe/ExpeLoader.h \ + expe/Expe.h \ + expe/ExpeConfig.h +SOURCES += expe/ExpeData.cpp \ + expe/Global.cpp \ + expe/ExpeLoader.cpp \ + expe/Expe.cpp \ + expe/Expe_p.cpp \ + expe/ExpeConfig.cpp +HEADERS += expe/xml/DataImport.h \ + expe/xml/DataFactory.h +SOURCES += expe/xml/DataImport.cpp \ + expe/xml/DataFactory.cpp +HEADERS += expe/expeWidget/InterBlock.h \ + expe/expeWidget/InterTrial.h \ + expe/expeWidget/ExpeWidget.h \ + expe/expeWidget/TrialSheet.h +SOURCES += expe/expeWidget/InterBlock.cpp \ + expe/expeWidget/InterTrial.cpp \ + expe/expeWidget/ExpeWidget.cpp \ + expe/expeWidget/TrialSheet.cpp +HEADERS += expe/csv/CSVWriter.h +SOURCES += expe/csv/CSVWriter.cpp + + +FORMS += expe/ExpeConfig.ui + +CONFIG(release, debug|release): LIBS += -lArduinoSerial + +CONFIG(debug, debug|release): LIBS += -lArduinoSeriald + +#CONFIG(release): LIBS += -lDynamicKeyboardLibrary + +#CONFIG(debug): LIBS += -lDynamicKeyboardLibraryd diff --git a/Expe-selection/dyna-expe2/expe/ExpeConfig.ui b/Expe-selection/dyna-expe2/expe/ExpeConfig.ui index 6cd30e2..62ee5c9 100644 --- a/Expe-selection/dyna-expe2/expe/ExpeConfig.ui +++ b/Expe-selection/dyna-expe2/expe/ExpeConfig.ui @@ -163,7 +163,7 @@ - linear + NORMAL diff --git a/Expe-selection/dyna-expe2/main.cpp b/Expe-selection/dyna-expe2/main.cpp index 1d030c8..e5ddd89 100644 --- a/Expe-selection/dyna-expe2/main.cpp +++ b/Expe-selection/dyna-expe2/main.cpp @@ -13,6 +13,9 @@ #include + +//#include + /* void unitTest() { @@ -38,6 +41,8 @@ int main(int argc, char **argv) QApplication a(argc, argv); Global::appPath(&a); + //qRegisterMetaType(); + // MainWindow * mainWindow = new MainWindow(); //mainWindow->show();