byte command = 0;
+//threshold values for side keys
+//with hysteresis
+int thresholda = 1;
+int thresholdb = 10;
+
void sendInformation()
{
Serial.write(keysState[1]);
*/
Serial.begin(115200);
- keysState[0] = 0;
- keysState[1] = 0;
+ keysState[0] = 255;
+ keysState[1] = 255;
analogWrite(pwmPin, minDutyCycle);
}
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;
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;
Serial.write("F");
Serial.write(2);
for (int i = 0 ; i < 4 ; i++)
- Serial.print(keySides2[i]);
+ Serial.write(255 - keySides2[i]);
newevent = false;
}
}
{
checkEvents();
readCommands();
+ delay(100);
}\r
#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
</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
</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
#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
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
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
-#pragma once\r
+#ifndef __QPUSHKEYSKEYBOARDCONTROLLER_\r
+#define __QPUSHKEYSKEYBOARDCONTROLLER_\r
\r
#include <QThread>\r
#include <QObject>\r
QObject *_receiver;\r
};\r
\r
+#endif\r
-#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
~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
-<?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"/>