From d64f14674d6fed1e7c32c417937347854ee98c39 Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Mon, 18 Feb 2013 12:27:40 +0000 Subject: [PATCH] Add press & release options, disable wristband/touchscreen if not connected. git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@106 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- TouchscreenButton/TouchscreenButton.cpp | 52 +++++++++++- TouchscreenButton/TouchscreenButton.h | 5 +- TouchscreenButton/TouchscreenButton.vcxproj | 6 +- .../USBHIDImmersionTouchscreen.cpp | 6 +- .../USBHIDImmersionTouchscreen.h | 2 +- TouchscreenButton/Wristband.cpp | 50 +++++++++++- TouchscreenButton/Wristband.h | 2 +- TouchscreenButton/touchscreenbutton.ui | 80 ++++++++++++++++++- 8 files changed, 183 insertions(+), 20 deletions(-) diff --git a/TouchscreenButton/TouchscreenButton.cpp b/TouchscreenButton/TouchscreenButton.cpp index 5471467..165dc0d 100644 --- a/TouchscreenButton/TouchscreenButton.cpp +++ b/TouchscreenButton/TouchscreenButton.cpp @@ -1,24 +1,49 @@ #include "TouchscreenButton.h" #include +#include + TouchscreenButton::TouchscreenButton(QWidget *parent, Qt::WFlags flags) : QMainWindow(parent, flags) { setupUi(this); - + try { _touchscreen = new USBHIDImmersionTouchscreen(); - _wristband = new TactonPlayer("COM11"); } catch(...) { - qDebug() << "Cannot find the touchscreen or the wristband"; + qDebug() << "Cannot find the touchscreen"; + _touchscreenoption->setChecked(false); + _touchscreenoption->setDisabled(true); + _touchscreen = NULL; + } + + try + { + _wristband = new Wristband(); + } + catch(...) + { + qDebug() << "Cannot find the wristband"; + _wristbandoption->setChecked(false); + _wristbandoption->setDisabled(true); + _wristband = NULL; } + _play->setAttribute( Qt::WA_AcceptTouchEvents); + connect(_play, SIGNAL(pressed()), this, SLOT(play())); + connect(_play, SIGNAL(released()), this, SLOT(play())); connect(_stop, SIGNAL(pressed()), this, SLOT(stop())); + + connect(_pressoption, SIGNAL(stateChanged (int)), this, SLOT(pressFeedback(int))); + connect(_releaseoption, SIGNAL(stateChanged (int)), this, SLOT(releaseFeedback(int))); + +// connect(_wristbandoption, SIGNAL(stateChanged(int)), this, SLOT(setWristbandState(int))); +// connect(_touchscreenoption, SIGNAL(stateChanged(int)), this, SLOT(setTouchscreenState(int))); } TouchscreenButton::~TouchscreenButton() @@ -30,10 +55,29 @@ TouchscreenButton::~TouchscreenButton() void TouchscreenButton::play() { - _touchscreen->playEffect((unsigned char)(_effect->value()), (unsigned char)(_repeats->value())); + if (_touchscreenoption->checkState() == Qt::Checked) + _touchscreen->playEffect((unsigned char)(_effect->value()), (unsigned char)(_repeats->value())); + if (_wristbandoption->checkState() == Qt::Checked) + _wristband->playEffect((unsigned char)(_effect->value()), (unsigned char)(_repeats->value())); } void TouchscreenButton::stop() { _touchscreen->playEffect(0, 1); } + +void TouchscreenButton::pressFeedback(int state) +{ + if (state == Qt::Checked) + connect(_play, SIGNAL(pressed()), this, SLOT(play())); + else + disconnect(_play, SIGNAL(pressed()), this, SLOT(play())); +} + +void TouchscreenButton::releaseFeedback(int state) +{ + if (state == Qt::Checked) + connect(_play, SIGNAL(released()), this, SLOT(play())); + else + disconnect(_play, SIGNAL(released()), this, SLOT(play())); +} diff --git a/TouchscreenButton/TouchscreenButton.h b/TouchscreenButton/TouchscreenButton.h index 79fec7d..99f8fc6 100644 --- a/TouchscreenButton/TouchscreenButton.h +++ b/TouchscreenButton/TouchscreenButton.h @@ -6,6 +6,7 @@ #include #include "USBHIDImmersionTouchscreen.h" +#include "Wristband.h" class TouchscreenButton : public QMainWindow, public Ui::TouchscreenButtonClass { @@ -18,10 +19,12 @@ class TouchscreenButton : public QMainWindow, public Ui::TouchscreenButtonClass public slots: void play(); void stop(); + void pressFeedback(int); + void releaseFeedback(int); private: USBHIDImmersionTouchscreen *_touchscreen; - TactonPlayer *_wristband; + Wristband *_wristband; }; #endif // TOUCHSCREENBUTTON_H diff --git a/TouchscreenButton/TouchscreenButton.vcxproj b/TouchscreenButton/TouchscreenButton.vcxproj index 55d5fc0..20d2a82 100644 --- a/TouchscreenButton/TouchscreenButton.vcxproj +++ b/TouchscreenButton/TouchscreenButton.vcxproj @@ -56,7 +56,7 @@ $(OutDir)\$(ProjectName).exe $(QTDIR)\lib;%(AdditionalLibraryDirectories) true - hidapid.lib;qtmaind.lib;QtCored4.lib;QtGuid4.lib;%(AdditionalDependencies) + tactonplayerd.lib;hidapid.lib;qtmaind.lib;QtCored4.lib;QtGuid4.lib;%(AdditionalDependencies) @@ -73,7 +73,7 @@ $(OutDir)\$(ProjectName).exe $(QTDIR)\lib;%(AdditionalLibraryDirectories) false - hidapi.lib;qtmain.lib;QtCore4.lib;QtGui4.lib;%(AdditionalDependencies) + tactonplayer.lib;hidapi.lib;qtmain.lib;QtCore4.lib;QtGui4.lib;%(AdditionalDependencies) @@ -92,6 +92,7 @@ + @@ -120,6 +121,7 @@ + %(AdditionalInputs) diff --git a/TouchscreenButton/USBHIDImmersionTouchscreen.cpp b/TouchscreenButton/USBHIDImmersionTouchscreen.cpp index 75d2aa4..56a8f05 100644 --- a/TouchscreenButton/USBHIDImmersionTouchscreen.cpp +++ b/TouchscreenButton/USBHIDImmersionTouchscreen.cpp @@ -30,16 +30,14 @@ USBHIDImmersionTouchscreen::~USBHIDImmersionTouchscreen(void) } } -bool USBHIDImmersionTouchscreen::playEffect(unsigned char effect, unsigned char nbrepeat) const +void USBHIDImmersionTouchscreen::playEffect(unsigned char effect, unsigned char nbrepeat) const { unsigned char buffer[35]; buffer[0] = PLAYEFFECTREPREAT_BYTE; buffer[1] = effect; buffer[2] = nbrepeat; if (_devicehandle) - return hid_write(_devicehandle, buffer, 35); - else - return -1; + hid_write(_devicehandle, buffer, 35); } char * USBHIDImmersionTouchscreen::getStatus() const diff --git a/TouchscreenButton/USBHIDImmersionTouchscreen.h b/TouchscreenButton/USBHIDImmersionTouchscreen.h index f40bb6a..da5caf1 100644 --- a/TouchscreenButton/USBHIDImmersionTouchscreen.h +++ b/TouchscreenButton/USBHIDImmersionTouchscreen.h @@ -13,7 +13,7 @@ class USBHIDImmersionTouchscreen See documentation for list of effects (0-46), 255 for no effect nbrepeats: 255 for infinite until other effect or no effect */ - bool playEffect(unsigned char effect, unsigned char nbrepeat) const; + void playEffect(unsigned char effect, unsigned char nbrepeat) const; char *getStatus() const; //bool setNonVolatileEffects() const; diff --git a/TouchscreenButton/Wristband.cpp b/TouchscreenButton/Wristband.cpp index 8e7af34..9dfebb6 100644 --- a/TouchscreenButton/Wristband.cpp +++ b/TouchscreenButton/Wristband.cpp @@ -1,12 +1,13 @@ #include "Wristband.h" #include +#include Wristband::Wristband() { try { - _tactonplayer = new TactonPlayer("COM11"); + _tactonplayer = new TactonPlayer("COM8"); } catch(...) { @@ -14,6 +15,43 @@ Wristband::Wristband() _tactonplayer = NULL; } + unsigned char desc[12]; + //patterns + desc[0] = desc[6] = 0xff; + //duration + desc[1] = desc[7] = 0; + desc[2] = 10; + desc[8] = 90; + //frequency + desc[3] = desc[9] = 0; + desc[4] = desc[10] = 250; + //amplitude + desc[5] = 255; + desc[11] = 0; + + //rel magnitude 10, durations 10; 90 + _effects[0] = Tacton(2, desc); + //rel magnitude 8, durations 10; 45 + desc[5] = 204; + desc[8] = 45; + _effects[1] = Tacton(2, desc); + //rel magnitude 8, durations 10; 90 + desc[5] = 204; + desc[8] = 90; + _effects[2] = Tacton(2, desc); + //rel magnitude 8, durations 10; 180 + desc[5] = 204; + desc[8] = 180; + _effects[3] = Tacton(2, desc); + //rel magnitude 6, durations 10; 90 + desc[5] = 153; + desc[8] = 90; + _effects[4] = Tacton(2, desc); + //rel magnitude 5, durations 10; 90 + desc[5] = 127; + _effects[5] = Tacton(2, desc); + + //TODO: setup the other effects } @@ -23,15 +61,21 @@ Wristband::~Wristband() delete _tactonplayer; } -bool Wristband::playEffect(unsigned char effect, unsigned char nbrepeat) const +void Wristband::playEffect(unsigned char effect, unsigned char nbrepeat) const { + if (!_tactonplayer) + return; + for (int i = 0 ; i < nbrepeat ; i++) { _tactonplayer->play(_effects[effect]); - ///TODO: add a pause + ///TODO: add a pause to prevent from overloading the arduino buffer + //messages are queues anyway, so it should not matters if nbrepeat is small + //QThread::msleep(_effects[effect].getDuration()); } } char *Wristband::getStatus() const { + return NULL; } diff --git a/TouchscreenButton/Wristband.h b/TouchscreenButton/Wristband.h index aa6f0ce..e8a40f3 100644 --- a/TouchscreenButton/Wristband.h +++ b/TouchscreenButton/Wristband.h @@ -14,7 +14,7 @@ class Wristband : Mimics Immersion touchscreen effects (0-46), 255 for no effect nbrepeats: 255 for infinite until other effect or no effect */ - bool playEffect(unsigned char effect, unsigned char nbrepeat) const; + void playEffect(unsigned char effect, unsigned char nbrepeat) const; char *getStatus() const; private: diff --git a/TouchscreenButton/touchscreenbutton.ui b/TouchscreenButton/touchscreenbutton.ui index 7dfcac8..b4e6b4c 100644 --- a/TouchscreenButton/touchscreenbutton.ui +++ b/TouchscreenButton/touchscreenbutton.ui @@ -7,11 +7,11 @@ 0 0 345 - 191 + 321 - TouchscreenButton + Button @@ -48,13 +48,85 @@ + + + + Press + + + true + + + + + + + Wristband + + + true + + + + + + + Touchscreen + + + true + + + + + + + Release + + + true + + + + + + + + 75 + true + + + + Feedback + + + Qt::AlignCenter + + + + + + + + 75 + true + + + + Events + + + Qt::AlignCenter + + + - 20 + 50 @@ -66,7 +138,7 @@ - 20 + 50 -- 2.30.2