From accd4c6ee7732bd39d23476ec74965858cca5c4e Mon Sep 17 00:00:00 2001 From: Thomas Pietrzak Date: Wed, 1 Aug 2012 11:39:33 +0000 Subject: [PATCH] Separate setAmplitudes and setFrequency. No more flicker in the vibrations git-svn-id: svn+ssh://thomaspietrzak.com/var/svn/rep@82 47cf9a05-e0a8-4ed5-9e9b-101a649bc004 --- .../TactonPlayer/TactonPlayerPreciseNew.cpp | 6 ++++ Arduino/wristbandTactons/wristbandTactons.ino | 26 ++++++++++++------ TactonDebug/MagicCircle/magiccircle.cpp | 9 +++++- TactonDebug/MagicCircle/magiccircle.h | 1 + TactonDebug/MagicCircle/magiccircle.ui | 8 +++--- TactonDebug/TactonDebug.suo | Bin 35328 -> 35328 bytes TactonPlayer/TactonPlayer.cpp | 26 ++++++++++++------ TactonPlayer/TactonPlayer.hpp | 7 +++-- 8 files changed, 59 insertions(+), 24 deletions(-) diff --git a/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp b/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp index b06183f..4292279 100644 --- a/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp +++ b/Arduino/TactonPlayer/TactonPlayerPreciseNew.cpp @@ -62,6 +62,12 @@ void TactonPlayerPreciseNew::buzz(unsigned int frequency, byte nbtactors, byte * { if (nbtactors != _nbtactors) return; + + //clear + TCCR1A = 0; + //set duty cycle to 0 + OCR1A = 0; + OCR1B = 0; sei(); init(); diff --git a/Arduino/wristbandTactons/wristbandTactons.ino b/Arduino/wristbandTactons/wristbandTactons.ino index 883d53a..a22abe3 100644 --- a/Arduino/wristbandTactons/wristbandTactons.ino +++ b/Arduino/wristbandTactons/wristbandTactons.ino @@ -29,6 +29,7 @@ void loop() { byte index; unsigned long timestamp; + unsigned int freq; if (Serial.available() > 0) { @@ -125,33 +126,42 @@ void loop() command = 0; } break; - //sets a frequency for all the vibrators and an amplitude for each one - // BnFFa1a2...an + //sets an amplitude for each vibrator + // Ana1a2...an // n = nb tactors (1 byte) - // FF = frequency (2 bytes) // A1, A2, ..., an : amplitudes (1 byte per tactor) - case 'B': + case 'A': if (nbf == 0 && Serial.available() >= 1) nbf = (unsigned int) Serial.read(); if (nbf > 0) { //DO NOT OVERFLOW max(nbf): 60 - while (posbuf < nbf + 2 && Serial.available() > 0) + while (posbuf < nbf && Serial.available() > 0) { buffer[posbuf] = Serial.read(); posbuf++; } - if (posbuf >= nbf + 2) + if (posbuf >= nbf) { - manager.buzz(nbf, buffer); + manager.setAmplitudes(nbf, buffer); posbuf = 0; command = 0; nbf = 0; } } break; + //sets the frequency + case 'F': + if (Serial.available() >= 2) + { + freq = (((unsigned long)Serial.read()) << 8) | \ + (((unsigned long)Serial.read())); + manager.setFrequency(freq); + command = 0; + } + break; //stop any vibration - case 'A': + case 'B': manager.stop(); command = 0; break; diff --git a/TactonDebug/MagicCircle/magiccircle.cpp b/TactonDebug/MagicCircle/magiccircle.cpp index 306cd3d..8d19d8d 100644 --- a/TactonDebug/MagicCircle/magiccircle.cpp +++ b/TactonDebug/MagicCircle/magiccircle.cpp @@ -22,6 +22,7 @@ MagicCircle::MagicCircle(QWidget *parent, Qt::WFlags flags) setDirection(_direction->currentText()); setResolution(_resolution->value()); setSpeed(_speed->value()); + setFrequency(_frequency->value()); connect(_play, SIGNAL(clicked(bool)), this, SLOT(play(bool))); connect(_stop, SIGNAL(clicked(bool)), this, SLOT(stop(bool))); @@ -29,6 +30,7 @@ MagicCircle::MagicCircle(QWidget *parent, Qt::WFlags flags) 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(_frequency, SIGNAL(valueChanged(int)), this, SLOT(setFrequency(int))); connect(this, SIGNAL(setAngle(float)), SLOT(tactileFeedback(float))); connect(this, SIGNAL(setAngle(float)), SLOT(visualFeedback(float))); @@ -84,6 +86,11 @@ void MagicCircle::setResolution(int res) setSpeed(_speed->value()); } +void MagicCircle::setFrequency(int frequency) +{ + _tactonPlayer->setFrequency(frequency); +} + void MagicCircle::tactileFeedback(float angle) { unsigned char amplitudes[4]; @@ -101,7 +108,7 @@ void MagicCircle::tactileFeedback(float angle) else amplitudes[2] = - 255 * cos(angle * M_PI / 180); - _tactonPlayer->buzz(_frequency->value(), 4, amplitudes); + _tactonPlayer->setAmplitudes(4, amplitudes); } void MagicCircle::visualFeedback(float) diff --git a/TactonDebug/MagicCircle/magiccircle.h b/TactonDebug/MagicCircle/magiccircle.h index a8be0b5..3002144 100644 --- a/TactonDebug/MagicCircle/magiccircle.h +++ b/TactonDebug/MagicCircle/magiccircle.h @@ -24,6 +24,7 @@ class MagicCircle : public QMainWindow, Ui::MagicCircleClass void setDirection(const QString &); void setSpeed(int); void setResolution(int); + void setFrequency(int); void tactileFeedback(float); void visualFeedback(float); diff --git a/TactonDebug/MagicCircle/magiccircle.ui b/TactonDebug/MagicCircle/magiccircle.ui index cc56a5d..b6829a5 100644 --- a/TactonDebug/MagicCircle/magiccircle.ui +++ b/TactonDebug/MagicCircle/magiccircle.ui @@ -46,10 +46,10 @@ 1 - 720 + 3000 - 30 + 180 @@ -90,7 +90,7 @@ 360 - 16 + 360 @@ -110,7 +110,7 @@ 400 - 250 + 300 diff --git a/TactonDebug/TactonDebug.suo b/TactonDebug/TactonDebug.suo index 1f131fa54fbafb1a1acf1e3a5440e4abd5524ce0..a996f4d29d6fedd621735021324e5ea2c645031e 100644 GIT binary patch delta 1109 zcmY+@ZA?>F7zglsZf{GkExuGDXtWUH3o1f!6%dHrQq2T1X#;GGkiZCLn>uBsn?N?K zL>CwL!S;`Ci^ha@;+%@IGo9O!nmiYp9$ms1m!% zbH!9N_-9PpI(`3BxxJIyuL%oRBBioViwglPu$78~XtLF1*0A0{E2t5tY~4=tKDEs1 z2n8AQ=bHsn6AR}29Oq_w#cb%z2xOYY?M%ApRo;EJ{4pb};-E>befLJ8i^bfsG`&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omISEFs$>n9?Redwvdd-XC{|niVsxQ|7o0d9nnGO{b_t3a+ld zTyv6`syM8>4W;IKt)^aGT&LBP6|2=IuGoM-o??zOaK=i`Y&ILq9viA@b_bnix5pK% z9dd%Mxia12aqM&j>^6s!_j%_BFkvpL8o%p}L)O*VjzD+6+v^Lu0&a)LzA@6ZxxL-K z!JxEz$AP=veaKm5xAJxkTfvsvg8`?#x8H3aba(f<_@KQn=y!X&d^;o?w{^-)R zF0U)#;9cF3Q`=3huKr&8cAv8YEEX*sTYIka;D6_f(-&}g++FrZT>-DlWAEeL+g$;4 zrd)iyVJ`u{B@;e1e=GU{62)~9_I<`^!tZ~BF_xGZeAhzks&=2^FkX!+)tO-m9-ux5R2;o!! diff --git a/TactonPlayer/TactonPlayer.cpp b/TactonPlayer/TactonPlayer.cpp index 23f716e..975fceb 100644 --- a/TactonPlayer/TactonPlayer.cpp +++ b/TactonPlayer/TactonPlayer.cpp @@ -119,18 +119,28 @@ 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) +void TactonPlayer::setFrequency(unsigned int frequency) { if (!_comport) return; - unsigned char *buffer = new unsigned char[4 + nbtactors]; - buffer[0] = 'B'; + unsigned char buffer[3]; + buffer[0] = 'F'; + buffer[1] = (unsigned char)((frequency & 0x0000ff00) >> 8); + buffer[2] = (unsigned char)(frequency & 0x000000ff); + _comport->WriteData(buffer, 3); +} + +void TactonPlayer::setAmplitudes(unsigned int nbtactors, unsigned char *amplitudes) +{ + if (!_comport) + return; + + unsigned char *buffer = new unsigned char[2 + nbtactors]; + buffer[0] = 'A'; 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); + memcpy(buffer + 2, amplitudes, nbtactors); + _comport->WriteData(buffer, 2 + nbtactors); delete[] buffer; } @@ -139,7 +149,7 @@ void TactonPlayer::stopBuzz() if (!_comport) return; - _comport->WriteData("A", 1); + _comport->WriteData("B", 1); } void TactonPlayer::debugRead(char *res, int nb) const diff --git a/TactonPlayer/TactonPlayer.hpp b/TactonPlayer/TactonPlayer.hpp index 8e520c3..a7dd0ce 100644 --- a/TactonPlayer/TactonPlayer.hpp +++ b/TactonPlayer/TactonPlayer.hpp @@ -31,9 +31,10 @@ class TactonPlayer //schedule the play of a registered tacton 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); + //sets an amplitude for each vibrator + EXPORTED void setAmplitudes(unsigned int nbtactors, unsigned char *amplitudes); + //sets a frequency for all vibrator + EXPORTED void setFrequency(unsigned int frequency); //stop any vibration EXPORTED void stopBuzz(); -- 2.30.2