From: Thomas Pietrzak Date: Mon, 30 Jul 2012 15:46:20 +0000 (+0000) Subject: Circle illusion demo X-Git-Url: https://git.thomaspietrzak.com/?a=commitdiff_plain;h=b7822f7c82295c3e2f08594fdb4c8cf411d45b94;p=tactonlibrary.git Circle illusion demo git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@81 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- diff --git a/Arduino/wristbandTactons/wristbandTactons.ino b/Arduino/wristbandTactons/wristbandTactons.ino index 96bbff9..883d53a 100644 --- a/Arduino/wristbandTactons/wristbandTactons.ino +++ b/Arduino/wristbandTactons/wristbandTactons.ino @@ -153,6 +153,7 @@ void loop() //stop any vibration case 'A': manager.stop(); + command = 0; break; //unknown command: do nothing default: diff --git a/TactonDebug/MagicCircle/MagicCircle.vcxproj b/TactonDebug/MagicCircle/MagicCircle.vcxproj new file mode 100644 index 0000000..29f1bb3 --- /dev/null +++ b/TactonDebug/MagicCircle/MagicCircle.vcxproj @@ -0,0 +1,144 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + + {E39CA6E9-BA0B-4C12-8090-D5CE66CADF94} + Qt4VSv1.0 + + + + Application + + + Application + + + + + + + + + + + + + <_ProjectFileVersion>10.0.30319.1 + AllRules.ruleset + + + AllRules.ruleset + + + $(SolutionDir)$(Platform)\$(Configuration)\ + $(SolutionDir)$(Platform)\$(Configuration)\ + + + + _USE_MATH_DEFINES;UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_CORE_LIB;QT_GUI_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;%(AdditionalIncludeDirectories) + Disabled + ProgramDatabase + MultiThreadedDebugDLL + false + + + Windows + $(OutDir)\$(ProjectName).exe + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + true + TactonPlayerd.lib;qtmaind.lib;QtCored4.lib;QtGuid4.lib;%(AdditionalDependencies) + + + + + _USE_MATH_DEFINES;UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_DLL;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;%(PreprocessorDefinitions) + .\GeneratedFiles;.;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;%(AdditionalIncludeDirectories) + + + MultiThreadedDLL + false + + + Windows + $(OutDir)\$(ProjectName).exe + $(QTDIR)\lib;%(AdditionalLibraryDirectories) + false + TactonPlayer.lib;qtmain.lib;QtCore4.lib;QtGui4.lib;%(AdditionalDependencies) + + + + + true + + + + + + + + + true + + + + + + + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing magiccircle.h... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_USE_MATH_DEFINES -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_CORE_LIB -DQT_GUI_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" + $(QTDIR)\bin\moc.exe;%(FullPath) + Moc%27ing magiccircle.h... + .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -D_USE_MATH_DEFINES -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_DLL -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I.\GeneratedFiles" "-I." "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" + + + + + Document + $(QTDIR)\bin\uic.exe;%(AdditionalInputs) + Uic%27ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h;%(Outputs) + "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)" + $(QTDIR)\bin\uic.exe;%(AdditionalInputs) + Uic%27ing %(Identity)... + .\GeneratedFiles\ui_%(Filename).h;%(Outputs) + "$(QTDIR)\bin\uic.exe" -o ".\GeneratedFiles\ui_%(Filename).h" "%(FullPath)" + + + + + + + + Document + %(FullPath);%(AdditionalInputs) + Rcc%27ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp;%(Outputs) + "$(QTDIR)\bin\rcc.exe" -name "%(Filename)" -no-compress "%(FullPath)" -o .\GeneratedFiles\qrc_%(Filename).cpp + %(FullPath);%(AdditionalInputs) + Rcc%27ing %(Identity)... + .\GeneratedFiles\qrc_%(Filename).cpp;%(Outputs) + "$(QTDIR)\bin\rcc.exe" -name "%(Filename)" -no-compress "%(FullPath)" -o .\GeneratedFiles\qrc_%(Filename).cpp + + + + + + + + + + + \ No newline at end of file diff --git a/TactonDebug/MagicCircle/magiccircle.cpp b/TactonDebug/MagicCircle/magiccircle.cpp new file mode 100644 index 0000000..306cd3d --- /dev/null +++ b/TactonDebug/MagicCircle/magiccircle.cpp @@ -0,0 +1,109 @@ +#include "magiccircle.h" + +#include + +MagicCircle::MagicCircle(QWidget *parent, Qt::WFlags flags) + : QMainWindow(parent, flags), _timer(this), _angle(0), _clockwise(true) +{ + try + { + _tactonPlayer = new TactonPlayer("COM4"); + } + catch(...) + { + _tactonPlayer = NULL; + } + + setupUi(this); + + layout()->setSizeConstraint(QLayout::SetFixedSize); + + //set initial parameters + setDirection(_direction->currentText()); + setResolution(_resolution->value()); + setSpeed(_speed->value()); + + connect(_play, SIGNAL(clicked(bool)), this, SLOT(play(bool))); + connect(_stop, SIGNAL(clicked(bool)), this, SLOT(stop(bool))); + + connect(_direction, SIGNAL(editTextChanged(const QString &)), this, SLOT(setDirection(const QString &))); + connect(_speed, SIGNAL(valueChanged(int)), this, SLOT(setSpeed(int))); + connect(_resolution, SIGNAL(valueChanged(int)), this, SLOT(setResolution(int))); + + connect(this, SIGNAL(setAngle(float)), SLOT(tactileFeedback(float))); + connect(this, SIGNAL(setAngle(float)), SLOT(visualFeedback(float))); + + connect(&_timer, SIGNAL(timeout()), this, SLOT(update())); +} + +MagicCircle::~MagicCircle() +{ + stop(true); +} + +void MagicCircle::play(bool) +{ + _timer.start(); +} + +void MagicCircle::stop(bool) +{ + _timer.stop(); + _tactonPlayer->stopBuzz(); +} + +void MagicCircle::update() +{ + if (_clockwise) + _angle -= _stepsize; + else + _angle += _stepsize; + + while (_angle < 0) + _angle += 360; + + while (_angle >= 360) + _angle -= 360; + + emit setAngle(_angle); +} + +void MagicCircle::setDirection(const QString &direction) +{ + _clockwise = (direction == "Clockwise"); +} + +void MagicCircle::setSpeed(int speed) +{ + _timer.setInterval(_stepsize / speed * 1000); +} + +void MagicCircle::setResolution(int res) +{ + _stepsize = 360.0 / res; + setSpeed(_speed->value()); +} + +void MagicCircle::tactileFeedback(float angle) +{ + unsigned char amplitudes[4]; + memset(amplitudes, 0, 4); + + //vertical + if (angle < 180) + amplitudes[1] = 255 * sin(angle * M_PI / 180); + else + amplitudes[3] = - 255 * sin(angle * M_PI / 180); + + //horizontal + if (angle < 90 ||angle > 270) + amplitudes[0] = 255 * cos(angle * M_PI / 180); + else + amplitudes[2] = - 255 * cos(angle * M_PI / 180); + + _tactonPlayer->buzz(_frequency->value(), 4, amplitudes); +} + +void MagicCircle::visualFeedback(float) +{ +} diff --git a/TactonDebug/MagicCircle/magiccircle.h b/TactonDebug/MagicCircle/magiccircle.h new file mode 100644 index 0000000..a8be0b5 --- /dev/null +++ b/TactonDebug/MagicCircle/magiccircle.h @@ -0,0 +1,42 @@ +#ifndef MAGICCIRCLE_H +#define MAGICCIRCLE_H + +#include +#include "ui_magiccircle.h" + +#include + +#include + +class MagicCircle : public QMainWindow, Ui::MagicCircleClass +{ + Q_OBJECT + + public: + MagicCircle(QWidget *parent = 0, Qt::WFlags flags = 0); + ~MagicCircle(); + + public slots: + void play(bool); + void stop(bool); + void update(); + + void setDirection(const QString &); + void setSpeed(int); + void setResolution(int); + + void tactileFeedback(float); + void visualFeedback(float); + + signals: + void setAngle(float a); + + private: + float _angle, _stepsize; + bool _clockwise; + + TactonPlayer *_tactonPlayer; + QTimer _timer; +}; + +#endif // MAGICCIRCLE_H diff --git a/TactonDebug/MagicCircle/magiccircle.qrc b/TactonDebug/MagicCircle/magiccircle.qrc new file mode 100644 index 0000000..57f6489 --- /dev/null +++ b/TactonDebug/MagicCircle/magiccircle.qrc @@ -0,0 +1,4 @@ + + + + diff --git a/TactonDebug/MagicCircle/magiccircle.ui b/TactonDebug/MagicCircle/magiccircle.ui new file mode 100644 index 0000000..cc56a5d --- /dev/null +++ b/TactonDebug/MagicCircle/magiccircle.ui @@ -0,0 +1,154 @@ + + + MagicCircleClass + + + + 0 + 0 + 268 + 448 + + + + MagicCircle + + + + + + + + 250 + 250 + + + + + 250 + 250 + + + + + + + + + + Speed (degrees/s) + + + + + + + 1 + + + 720 + + + 30 + + + + + + + Resolution (steps/360°) + + + + + + + + Clockwise + + + + + Counterclockwise + + + + + + + + Direction + + + + + + + 4 + + + 360 + + + 16 + + + + + + + Frequency + + + + + + + 1 + + + 400 + + + 250 + + + + + + + + + + + Stop + + + + + + + Play + + + + + + + + + + + _frequency + _direction + _speed + _resolution + _play + _stop + _canvas + + + + + + diff --git a/TactonDebug/MagicCircle/main.cpp b/TactonDebug/MagicCircle/main.cpp new file mode 100644 index 0000000..288aa7c --- /dev/null +++ b/TactonDebug/MagicCircle/main.cpp @@ -0,0 +1,10 @@ +#include "magiccircle.h" +#include + +int main(int argc, char *argv[]) +{ + QApplication a(argc, argv); + MagicCircle w; + w.show(); + return a.exec(); +} diff --git a/TactonDebug/TactonDebug.sln b/TactonDebug/TactonDebug.sln index 0ab897a..972e2a2 100644 --- a/TactonDebug/TactonDebug.sln +++ b/TactonDebug/TactonDebug.sln @@ -3,6 +3,8 @@ Microsoft Visual Studio Solution File, Format Version 11.00 # Visual Studio 2010 Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "TactonDebug", "TactonDebug\TactonDebug.vcxproj", "{245FF8C0-7CC0-4A37-9F07-6B3C8E29D089}" EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "MagicCircle", "MagicCircle\MagicCircle.vcxproj", "{E39CA6E9-BA0B-4C12-8090-D5CE66CADF94}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -13,6 +15,10 @@ Global {245FF8C0-7CC0-4A37-9F07-6B3C8E29D089}.Debug|Win32.Build.0 = Debug|Win32 {245FF8C0-7CC0-4A37-9F07-6B3C8E29D089}.Release|Win32.ActiveCfg = Release|Win32 {245FF8C0-7CC0-4A37-9F07-6B3C8E29D089}.Release|Win32.Build.0 = Release|Win32 + {E39CA6E9-BA0B-4C12-8090-D5CE66CADF94}.Debug|Win32.ActiveCfg = Debug|Win32 + {E39CA6E9-BA0B-4C12-8090-D5CE66CADF94}.Debug|Win32.Build.0 = Debug|Win32 + {E39CA6E9-BA0B-4C12-8090-D5CE66CADF94}.Release|Win32.ActiveCfg = Release|Win32 + {E39CA6E9-BA0B-4C12-8090-D5CE66CADF94}.Release|Win32.Build.0 = Release|Win32 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/TactonDebug/TactonDebug.suo b/TactonDebug/TactonDebug.suo index d47ffd0..1f131fa 100644 Binary files a/TactonDebug/TactonDebug.suo and b/TactonDebug/TactonDebug.suo differ diff --git a/TactonDebug/TactonDebug/TactonDebug.vcxproj b/TactonDebug/TactonDebug/TactonDebug.vcxproj index 857dc95..2ae6513 100644 --- a/TactonDebug/TactonDebug/TactonDebug.vcxproj +++ b/TactonDebug/TactonDebug/TactonDebug.vcxproj @@ -44,7 +44,7 @@ - UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_CORE_LIB;QT_GUI_LIB;%(PreprocessorDefinitions) + UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_CORE_LIB;QT_GUI_LIB;QT_DLL;%(PreprocessorDefinitions) .\GeneratedFiles;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\qtmain;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;.\;..;%(AdditionalIncludeDirectories) Disabled ProgramDatabase @@ -61,7 +61,7 @@ - UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;%(PreprocessorDefinitions) + UNICODE;WIN32;QT_LARGEFILE_SUPPORT;QT_NO_DEBUG;NDEBUG;QT_CORE_LIB;QT_GUI_LIB;QT_DLL;%(PreprocessorDefinitions) .\GeneratedFiles;$(QTDIR)\include;.\GeneratedFiles\$(ConfigurationName);$(QTDIR)\include\qtmain;$(QTDIR)\include\QtCore;$(QTDIR)\include\QtGui;.\;..;%(AdditionalIncludeDirectories) @@ -97,11 +97,11 @@ $(QTDIR)\bin\moc.exe;%(FullPath) Moc%27ing %(Identity)... .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp - "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I.\.." "-I." "-I." "-I." "tactondebug.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_CORE_LIB -DQT_GUI_LIB -DQT_DLL "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I.\.." $(QTDIR)\bin\moc.exe;%(FullPath) Moc%27ing %(Identity)... .\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp - "$(QTDIR)\bin\moc.exe" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB "-I." "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I.\.." "-I." "-I." "-I." "tactondebug.h" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" + "$(QTDIR)\bin\moc.exe" "%(FullPath)" -o ".\GeneratedFiles\$(ConfigurationName)\moc_%(Filename).cpp" -DUNICODE -DWIN32 -DQT_LARGEFILE_SUPPORT -DQT_NO_DEBUG -DNDEBUG -DQT_CORE_LIB -DQT_GUI_LIB -DQT_DLL "-I.\GeneratedFiles" "-I$(QTDIR)\include" "-I.\GeneratedFiles\$(ConfigurationName)\." "-I$(QTDIR)\include\qtmain" "-I$(QTDIR)\include\QtCore" "-I$(QTDIR)\include\QtGui" "-I." "-I.\.." @@ -138,7 +138,7 @@ - + \ No newline at end of file diff --git a/TactonDebug/TactonDebug/main.cpp b/TactonDebug/TactonDebug/main.cpp index 3ebd253..5fcd7b9 100644 --- a/TactonDebug/TactonDebug/main.cpp +++ b/TactonDebug/TactonDebug/main.cpp @@ -6,5 +6,6 @@ int main(int argc, char *argv[]) QApplication a(argc, argv); TactonDebug w; w.show(); + w.raise(); return a.exec(); } diff --git a/TactonDebug/TactonDebug/tactondebug.cpp b/TactonDebug/TactonDebug/tactondebug.cpp index 70442ad..ebad3a9 100644 --- a/TactonDebug/TactonDebug/tactondebug.cpp +++ b/TactonDebug/TactonDebug/tactondebug.cpp @@ -9,7 +9,7 @@ TactonDebug::TactonDebug(QWidget *parent, Qt::WFlags flags) { try { - _tactonPlayer = new TactonPlayer("COM5"); + _tactonPlayer = new TactonPlayer("COM4"); } catch(...) { @@ -17,6 +17,9 @@ TactonDebug::TactonDebug(QWidget *parent, Qt::WFlags flags) } setupUi(this); + + layout()->setSizeConstraint(QLayout::SetFixedSize); + QObject::connect(frequencebox, SIGNAL(textChanged(const QString &)), this, SLOT(setFrequency(const QString &))); QObject::connect(frequenceslider, SIGNAL(valueChanged(int)), this, SLOT(setFrequency(int))); QObject::connect(amplitudebox, SIGNAL(textChanged(const QString &)), this, SLOT(setAmplitude(const QString &))); diff --git a/TactonLibrary.suo b/TactonLibrary.suo index 6134b9f..fc693ea 100644 Binary files a/TactonLibrary.suo and b/TactonLibrary.suo differ diff --git a/TactonPlayer/Tacton.hpp b/TactonPlayer/Tacton.hpp index 60f3ee0..d71859a 100644 --- a/TactonPlayer/Tacton.hpp +++ b/TactonPlayer/Tacton.hpp @@ -11,6 +11,12 @@ #define POS2_LEFT 0x04 #define POS2_DOWN 0x08 +#ifdef __MACOSX__ +#define EXPORTED +#else +#define EXPORTED __declspec(dllexport) +#endif + class Tacton { public: @@ -20,46 +26,46 @@ class Tacton //2 for the duration //2 for the frequency //1 for the amplitude - __declspec(dllexport) Tacton(unsigned int nbframes, unsigned char *desc); + EXPORTED Tacton(unsigned int nbframes, unsigned char *desc); //creates a tacton using the CSV format //1 field for the number of frames, then 4 fields per frame //1 for the pattern //1 for the duration //1 for the frequency //1 for the amplitude - __declspec(dllexport) Tacton(char *desc); - __declspec(dllexport) Tacton(unsigned int nbframes, unsigned char *patterns, unsigned int *durations, unsigned int *frequencies, unsigned char *amplitudes); + EXPORTED Tacton(char *desc); + EXPORTED Tacton(unsigned int nbframes, unsigned char *patterns, unsigned int *durations, unsigned int *frequencies, unsigned char *amplitudes); //create a simple vibration - __declspec(dllexport) Tacton(char *pattern, unsigned int duration, unsigned int frequency, unsigned char amplitude); - __declspec(dllexport) Tacton(const char *pattern, unsigned int duration, unsigned int frequency, unsigned char amplitude); - __declspec(dllexport) Tacton(unsigned char pattern, unsigned int duration, unsigned int frequency, unsigned char amplitude); - __declspec(dllexport) Tacton(const Tacton &t); - __declspec(dllexport) ~Tacton(); + EXPORTED Tacton(char *pattern, unsigned int duration, unsigned int frequency, unsigned char amplitude); + EXPORTED Tacton(const char *pattern, unsigned int duration, unsigned int frequency, unsigned char amplitude); + EXPORTED Tacton(unsigned char pattern, unsigned int duration, unsigned int frequency, unsigned char amplitude); + EXPORTED Tacton(const Tacton &t); + EXPORTED ~Tacton(); //changes the pattern using raw format - __declspec(dllexport) void setPattern(char pattern); - __declspec(dllexport) void setPattern(unsigned int frame, char pattern); + EXPORTED void setPattern(char pattern); + EXPORTED void setPattern(unsigned int frame, char pattern); //changes the pattern using string format - __declspec(dllexport) void setPattern(char *pattern); - __declspec(dllexport) void setPattern(const char *pattern); - __declspec(dllexport) void setPattern(unsigned int frame, char *pattern); - __declspec(dllexport) void setPattern(unsigned int frame, const char *pattern); + EXPORTED void setPattern(char *pattern); + EXPORTED void setPattern(const char *pattern); + EXPORTED void setPattern(unsigned int frame, char *pattern); + EXPORTED void setPattern(unsigned int frame, const char *pattern); //changes the duration - __declspec(dllexport) void setDuration(unsigned int duration); - __declspec(dllexport) void setDuration(unsigned int frame, unsigned int duration); + EXPORTED void setDuration(unsigned int duration); + EXPORTED void setDuration(unsigned int frame, unsigned int duration); //changes the frequency - __declspec(dllexport) void setFrequency(unsigned int frequency); - __declspec(dllexport) void setFrequency(unsigned int frame, unsigned int frequency); + EXPORTED void setFrequency(unsigned int frequency); + EXPORTED void setFrequency(unsigned int frame, unsigned int frequency); //changes the amplitude - __declspec(dllexport) void setAmplitude(unsigned int amplitude); - __declspec(dllexport) void setAmplitude(unsigned int frame, unsigned int amplitude); + EXPORTED void setAmplitude(unsigned int amplitude); + EXPORTED void setAmplitude(unsigned int frame, unsigned int amplitude); //returns the number of frames - __declspec(dllexport) const unsigned int getNbFrames() const; + EXPORTED const unsigned int getNbFrames() const; //returns the raw code (useful to send to the serial port) - __declspec(dllexport) void *rawCode() const; + EXPORTED void *rawCode() const; private: unsigned int _nbframes; diff --git a/TactonPlayer/TactonPlayer.cpp b/TactonPlayer/TactonPlayer.cpp index d2f3be0..23f716e 100644 --- a/TactonPlayer/TactonPlayer.cpp +++ b/TactonPlayer/TactonPlayer.cpp @@ -43,6 +43,7 @@ void TactonPlayer::regist(const Tacton &t) buffer[0] = 'N'; buffer[1] = (nbframes & 0xff00) >> 8; buffer[2] = nbframes & 0xff; + memcpy(buffer + 3, t.rawCode(), 6 * nbframes); _comport->WriteData(buffer, 3 + 6 * nbframes); delete []buffer; @@ -118,6 +119,29 @@ void TactonPlayer::schedule(unsigned char index, unsigned long timestamp) _comport->WriteData(buffer, 6); } +void TactonPlayer::buzz(unsigned int frequency, unsigned int nbtactors, unsigned char *amplitudes) +{ + if (!_comport) + return; + + unsigned char *buffer = new unsigned char[4 + nbtactors]; + buffer[0] = 'B'; + buffer[1] = nbtactors; + buffer[2] = (unsigned char)((frequency & 0x0000ff00) >> 8); + buffer[3] = (unsigned char)(frequency & 0x000000ff); + memcpy(buffer + 4, amplitudes, nbtactors); + _comport->WriteData(buffer, 4 + nbtactors); + delete[] buffer; +} + +void TactonPlayer::stopBuzz() +{ + if (!_comport) + return; + + _comport->WriteData("A", 1); +} + void TactonPlayer::debugRead(char *res, int nb) const { if (_comport) diff --git a/TactonPlayer/TactonPlayer.hpp b/TactonPlayer/TactonPlayer.hpp index 3671db2..8e520c3 100644 --- a/TactonPlayer/TactonPlayer.hpp +++ b/TactonPlayer/TactonPlayer.hpp @@ -1,32 +1,44 @@ #include "Tacton.hpp" +#ifdef __MACOSX__ +#include +#define EXPORTED +#else #include +#define EXPORTED __declspec(dllexport) +#endif class TactonPlayer { public: - __declspec(dllexport) TactonPlayer(const char *port = "COM5"); - __declspec(dllexport) ~TactonPlayer(); + EXPORTED TactonPlayer(const char *port = "COM5"); + EXPORTED ~TactonPlayer(); //set the timestamp to 0, and watch for scheduled tactons - void __declspec(dllexport) start(); + EXPORTED void start(); //stop watching scheduled tactons, and erase registered tactons - void __declspec(dllexport) stop(); + EXPORTED void stop(); //register a tacton - __declspec(dllexport) void regist(const Tacton &t); + EXPORTED void regist(const Tacton &t); //register a list of tactons in a file, returns the number of tactons loaded - __declspec(dllexport) unsigned int registFile(char *filename); + EXPORTED unsigned int registFile(char *filename); //play a registered tacton - __declspec(dllexport) void play(unsigned char index); + EXPORTED void play(unsigned char index); //play a specified tacton - __declspec(dllexport) void play(const Tacton &t); + EXPORTED void play(const Tacton &t); //schedule the play of a registered tacton - __declspec(dllexport) void schedule(unsigned char index, unsigned long timestamp); + EXPORTED void schedule(unsigned char index, unsigned long timestamp); + + //sets a given frequency for all vibrators, and an amplitude for each vibrator + //vibrates until explicitely stop + EXPORTED void buzz(unsigned int frequency, unsigned int nbtactors, unsigned char *amplitudes); + //stop any vibration + EXPORTED void stopBuzz(); //read on the serial port - __declspec(dllexport) void debugRead(char *res, int nb) const; + EXPORTED void debugRead(char *res, int nb) const; private: Serial *_comport; diff --git a/TactonPlayer/TactonPlayer.vcxproj b/TactonPlayer/TactonPlayer.vcxproj index 86019d3..6a08bb8 100644 --- a/TactonPlayer/TactonPlayer.vcxproj +++ b/TactonPlayer/TactonPlayer.vcxproj @@ -39,6 +39,7 @@ true + $(ProjectName)d false