Various fixes
authorThomas Pietrzak <thomas.pietrzak@gmail.com>
Sun, 9 Sep 2012 14:16:52 +0000 (14:16 +0000)
committerThomas Pietrzak <thomas.pietrzak@gmail.com>
Sun, 9 Sep 2012 14:16:52 +0000 (14:16 +0000)
git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@97 47cf9a05-e0a8-4ed5-9e9b-101a649bc004

Arduino/dynamickeyboard/dynamickeyboard.ino
DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo
DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardController.h
DynamicKeyboardLibrary/DynamicKeyboardLibrary/DynamicKeyboardLibrary.vcxproj
DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.cpp
DynamicKeyboardLibrary/DynamicKeyboardLibrary/QPushKeysKeyboardController.h
DynamicKeyboardLibrary/DynamicKeyboardLibrary/QSideKeyEvent.h
Expe-selection/dyna-expe2/design/dyna-selection-2.xml

index 5b7a88b8b6dd5334e61441629472be620c14d24b..60a931ee69af21a4dae5ff3fbcc54ea7fc9a7b34 100644 (file)
@@ -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);
 }\r
index 46612a8d2b466c558544e3b9b58bc190bbd9e206..0f103d6bd2a28bac101d788120ba015d27ef4c89 100644 (file)
Binary files a/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo and b/DynamicKeyboardLibrary/DynamicKeyboardLibrary.suo differ
index bb6de186040fdb3e9172371a993062c848fd400d..2577487b7e55da4d8820d6deb2b07ab78bac6ccb 100644 (file)
@@ -4,9 +4,15 @@
 #ifdef __MACOSX__\r
 #include <Serial.hpp>\r
 #define EXPORTED\r
-#else\r
-#include <ArduinoSerial\Serial.hpp>\r
-#define EXPORTED __declspec(dllexport)\r
+#define STDCALL\r
+#elif _WIN32\r
+       #ifdef _WINDLL\r
+               #define EXPORTED __declspec(dllexport)\r
+       #else\r
+               #define EXPORTED __declspec(dllimport)\r
+       #endif\r
+       #define STDCALL \r
+       #include <ArduinoSerial\Serial.hpp>\r
 #endif\r
 \r
 #include <iostream>\r
index a1c04c00789b981d04641f6c77dd0eeab6c7da8b..3c7972819361923e8973f879c8e4de3d63152088 100644 (file)
@@ -55,7 +55,7 @@
   </PropertyGroup>\r
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">\r
     <ClCompile>\r
-      <PreprocessorDefinitions>UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_CORE_LIB;DYNAMICKEYBOARDLIBRARY_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <PreprocessorDefinitions>DEBUG;UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_CORE_LIB;DYNAMICKEYBOARDLIBRARY_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
       <AdditionalIncludeDirectories>.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
       <Optimization>Disabled</Optimization>\r
       <DebugInformationFormat>ProgramDatabase</DebugInformationFormat>\r
@@ -72,7 +72,7 @@
   </ItemDefinitionGroup>\r
   <ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">\r
     <ClCompile>\r
-      <PreprocessorDefinitions>UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;DYNAMICKEYBOARDLIBRARY_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
+      <PreprocessorDefinitions>DLLEXPORT;UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;DYNAMICKEYBOARDLIBRARY_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>\r
       <AdditionalIncludeDirectories>.\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>\r
       <DebugInformationFormat>\r
       </DebugInformationFormat>\r
index aa24af5981ed5ab88df6a57f2d28a5727478ff22..658770c90f68fddb8aefc62a953f0c150c0708e2 100644 (file)
@@ -3,9 +3,14 @@
 #include <QCoreApplication>\r
 #include "QSideKeyEvent.h"\r
 \r
+#if DEBUG\r
+#include <QDebug>\r
+#endif\r
+\r
 QPushKeysKeyboardController::QPushKeysKeyboardController(char *port, int baudrate, QObject *receiver)\r
 : DynamicKeyboardController(port, baudrate), _receiver(receiver)\r
 {\r
+       start();\r
 }\r
 \r
 \r
@@ -16,6 +21,10 @@ QPushKeysKeyboardController::~QPushKeysKeyboardController(void)
 void QPushKeysKeyboardController::run()\r
 {\r
        char buffer[6];\r
+       qDebug() << "Watching for side key events, send them to " << hex << _receiver; \r
+#if DEBUG\r
+                       qDebug() << "Watching for side key events, send them to " << hex << _receiver; \r
+#endif\r
 \r
        while (true)\r
        {\r
@@ -31,7 +40,12 @@ void QPushKeysKeyboardController::run()
                        if (buffer[5] > 0)\r
                                sides |= QSideKeyEvent::Left;\r
 \r
+#if DEBUG\r
+                       qDebug() << "post key " << buffer[1] << " sides " << hex << sides; \r
+#endif\r
+\r
                        QCoreApplication::postEvent(_receiver, new QSideKeyEvent(buffer[1], sides));\r
                }\r
+               sleep(1000);\r
        }\r
 }\r
index 01e5d5db0047cd8701fbb5f1fa291dd3810535c8..8902995b6c1de4fb49dcfd691dbb9880c785292e 100644 (file)
@@ -1,4 +1,5 @@
-#pragma once\r
+#ifndef __QPUSHKEYSKEYBOARDCONTROLLER_\r
+#define __QPUSHKEYSKEYBOARDCONTROLLER_\r
 \r
 #include <QThread>\r
 #include <QObject>\r
@@ -17,3 +18,4 @@ class EXPORTED QPushKeysKeyboardController: public DynamicKeyboardController, QT
                QObject *_receiver;\r
 };\r
 \r
+#endif\r
index d02fb18ff3eea92b6a6c55a2fbebb56dc81b3ed1..19f37651772a25f95681e3d27050fb0ec7b270b5 100644 (file)
@@ -1,12 +1,19 @@
-#pragma once\r
+#ifndef __QKEYSIDEEVENT__\r
+#define __QKEYSIDEEVENT__\r
 \r
 #include <QEvent>\r
 #include <QFlags>\r
 \r
 #ifdef __MACOSX__\r
-#define EXPORTED\r
-#else\r
-#define EXPORTED __declspec(dllexport)\r
+       #define EXPORTED\r
+       #define STDCALL\r
+#elif _WIN32\r
+       #ifdef _WINDLL\r
+               #define EXPORTED __declspec(dllexport)\r
+       #else\r
+               #define EXPORTED __declspec(dllimport)\r
+       #endif\r
+       #define STDCALL \r
 #endif\r
 \r
 class EXPORTED QSideKeyEvent: public QEvent\r
@@ -24,12 +31,13 @@ class EXPORTED QSideKeyEvent: public QEvent
                ~QSideKeyEvent();\r
 \r
                int getKey() { return  _key; }\r
-               Sides getSides() {return _sides; }\r
+               Sides getSides() { return _sides; }\r
 \r
-               static const QEvent::Type QSideKeyEventType;\r
+               static const QEvent::Type STDCALL QSideKeyEventType;\r
 \r
        private:\r
                int _key;\r
                Sides _sides; \r
 };\r
 \r
+#endif\r
index d7f88b1010e1a46d78789f478dc77bcb9643fecd..2216ba9bea778db01290b0e35aa16de7d1a4c2eb 100644 (file)
@@ -1,4 +1,4 @@
-<?xml version="1.0" encoding="ISO-8859-1"?>
+<?xml version="1.0" encoding="UTF-8"?>
 <experiment author="" description="" id="" name="selection-2">
     <factor id="target" kind="key" name="target" tag="Within Subject" type="character">
         <value id="dt"/>