From: Thomas Pietrzak Date: Sun, 9 Sep 2012 14:16:52 +0000 (+0000) Subject: Various fixes X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=eeda1e54cb1a33e4d47b836431d0898198606a81;p=DynamicKeyboardLib.git Various fixes git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@97 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/Arduino/dynamickeyboard/dynamickeyboard.ino b/Arduino/dynamickeyboard/dynamickeyboard.ino index 5b7a88b..60a931e 100644 --- a/Arduino/dynamickeyboard/dynamickeyboard.ino +++ b/Arduino/dynamickeyboard/dynamickeyboard.ino @@ -18,6 +18,11 @@ int keyPins2[4]; byte command = 0; +//threshold values for side keys +//with hysteresis +int thresholda = 1; +int thresholdb = 10; + void sendInformation() { Serial.write(keysState[1]); @@ -74,8 +79,8 @@ void setup() */ Serial.begin(115200); - keysState[0] = 0; - keysState[1] = 0; + keysState[0] = 255; + keysState[1] = 255; analogWrite(pwmPin, minDutyCycle); } @@ -93,13 +98,26 @@ 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("F"); + Serial.write(1); + for (int i = 0 ; i < 4 ; i++) + Serial.print(analogRead(keyPins2[i]),HEX); + Serial.println(""); + return;*/ //check key1 for (int i = 0 ; i < 4 ; i++) { byte b = analogRead(keyPins1[i]); - //check if the state has changed - if ((keySides1[i] == 0 && b > 0) || (keySides1[i] > 0 && b == 0)) + //press / release + if (keySides1[i] > thresholda && b < thresholda || + keySides1[i] < thresholdb && b > thresholdb) { keySides1[i] = b; newevent = true; @@ -110,16 +128,18 @@ void checkEvents() Serial.write("F"); Serial.write(1); for (int i = 0 ; i < 4 ; i++) - Serial.print(keySides1[i]); + Serial.write(255 - keySides1[i]); newevent = false; } + newevent = false; //check key2 for (int i = 0 ; i < 4 ; i++) { byte b = analogRead(keyPins2[i]); - //check if the state has changed - if ((keySides2[i] == 0 && b > 0) || (keySides2[i] > 0 && b == 0)) + //press / release + if (keySides2[i] > thresholda && b < thresholda || + keySides2[i] < thresholdb && b > thresholdb) { keySides2[i] = b; newevent = true; @@ -130,7 +150,7 @@ void checkEvents() Serial.write("F"); Serial.write(2); for (int i = 0 ; i < 4 ; i++) - Serial.print(keySides2[i]); + Serial.write(255 - keySides2[i]); newevent = false; } } @@ -235,4 +255,5 @@ void loop() { checkEvents(); readCommands(); + delay(100); } diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo b/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo index 46612a8..0f103d6 100644 Binary files a/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo and b/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo differ diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h index bb6de18..2577487 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h @@ -4,9 +4,15 @@ #ifdef __MACOSX__ #include #define EXPORTED -#else -#include -#define EXPORTED __declspec(dllexport) +#define STDCALL +#elif _WIN32 + #ifdef _WINDLL + #define EXPORTED __declspec(dllexport) + #else + #define EXPORTED __declspec(dllimport) + #endif + #define STDCALL + #include #endif #include diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj index a1c04c0..3c79728 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj @@ -55,7 +55,7 @@ - UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_CORE_LIB;DYNAMICKEYBOARDLIBRARY_LIB;%(PreprocessorDefinitions) + DEBUG;UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_CORE_LIB;DYNAMICKEYBOARDLIBRARY_LIB;%(PreprocessorDefinitions) .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;%(AdditionalIncludeDirectories) Disabled ProgramDatabase @@ -72,7 +72,7 @@ - UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;DYNAMICKEYBOARDLIBRARY_LIB;%(PreprocessorDefinitions) + DLLEXPORT;UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;DYNAMICKEYBOARDLIBRARY_LIB;%(PreprocessorDefinitions) .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;%(AdditionalIncludeDirectories) diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp index aa24af5..658770c 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp @@ -3,9 +3,14 @@ #include #include "QSideKeyEvent.h" +#if DEBUG +#include +#endif + QPushKeysKeyboardController::QPushKeysKeyboardController(char *port, int baudrate, QObject *receiver) : DynamicKeyboardController(port, baudrate), _receiver(receiver) { + start(); } @@ -16,6 +21,10 @@ QPushKeysKeyboardController::~QPushKeysKeyboardController(void) void QPushKeysKeyboardController::run() { 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; +#endif while (true) { @@ -31,7 +40,12 @@ void QPushKeysKeyboardController::run() if (buffer[5] > 0) sides |= QSideKeyEvent::Left; +#if DEBUG + qDebug() << "post key " << buffer[1] << " sides " << hex << sides; +#endif + QCoreApplication::postEvent(_receiver, new QSideKeyEvent(buffer[1], sides)); } + sleep(1000); } } diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h index 01e5d5d..8902995 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h @@ -1,4 +1,5 @@ -#pragma once +#ifndef __QPUSHKEYSKEYBOARDCONTROLLER_ +#define __QPUSHKEYSKEYBOARDCONTROLLER_ #include #include @@ -17,3 +18,4 @@ class EXPORTED QPushKeysKeyboardController: public DynamicKeyboardController, QT QObject *_receiver; }; +#endif diff --git a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QSideKeyEvent.h b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QSideKeyEvent.h index d02fb18..19f3765 100644 --- a/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QSideKeyEvent.h +++ b/DynamicKeyboardLibrary/DynamicKeyboardLibrary/QSideKeyEvent.h @@ -1,12 +1,19 @@ -#pragma once +#ifndef __QKEYSIDEEVENT__ +#define __QKEYSIDEEVENT__ #include #include #ifdef __MACOSX__ -#define EXPORTED -#else -#define EXPORTED __declspec(dllexport) + #define EXPORTED + #define STDCALL +#elif _WIN32 + #ifdef _WINDLL + #define EXPORTED __declspec(dllexport) + #else + #define EXPORTED __declspec(dllimport) + #endif + #define STDCALL #endif class EXPORTED QSideKeyEvent: public QEvent @@ -24,12 +31,13 @@ class EXPORTED QSideKeyEvent: public QEvent ~QSideKeyEvent(); int getKey() { return _key; } - Sides getSides() {return _sides; } + Sides getSides() { return _sides; } - static const QEvent::Type QSideKeyEventType; + static const QEvent::Type STDCALL QSideKeyEventType; private: int _key; Sides _sides; }; +#endif diff --git a/Expe-selection/dyna-expe2/design/dyna-selection-2.xml b/Expe-selection/dyna-expe2/design/dyna-selection-2.xml index d7f88b1..2216ba9 100644 --- a/Expe-selection/dyna-expe2/design/dyna-selection-2.xml +++ b/Expe-selection/dyna-expe2/design/dyna-selection-2.xml @@ -1,4 +1,4 @@ - +