Fix for hack that worked around iOS app
Diff: Haptics.cpp
- Revision:
- 2:4f76784f8968
- Parent:
- 0:8c0ecbdd3449
- Child:
- 3:b64f3abb3c0b
--- a/Haptics.cpp Mon Feb 08 18:52:46 2016 +0000 +++ b/Haptics.cpp Thu Feb 25 00:19:46 2016 +0000 @@ -12,12 +12,14 @@ * (ERM, LRA, Piezo) * ******************************************************************************/ -#include "Haptics.h" + #include "Actuator_Waveforms.h" // private variables //static uint8_t j,k; +extern float lraEffectMultiplier; // defined in main.cpp + // public variables uint16_t Haptics_dumbModeTick = DUMBTICK; // Sets the LRA Auto-resonance off frequency (use DUMBTICK above to set frequency) uint16_t Haptics_resonantModeTick; @@ -27,6 +29,12 @@ extern DigitalOut led1; + +// Used for off-mode haptics and LED signature +Timeout firstLEDOff; +Timeout secondBuzz; +Timeout secondLEDOff; + Ticker hapticsTicker; volatile uint16_t lraPlaybackMode = 0; volatile int lraCurrent = 0; @@ -35,7 +43,10 @@ volatile uint16_t placeInWaveform = 0; volatile uint16_t waveformDelayCounter = 0; const Waveform* volatile waveform; -const Waveform* volatile heartbeatWaveform = &lra_tick; +//const Waveform* volatile heartbeatWaveform = &lra_tick; +const Waveform* volatile heartbeatWaveform = &lra_rampdown; + + // TODO: Support haptics modalities here: off, waveform, delayed waveform, ramp to target @@ -52,9 +63,10 @@ LRA_EN = 0; } else { LRA_EN = 1; - //LRA.pulsewidth_us(90); - LRA.pulsewidth_us(((((uint16_t)waveform->data[placeInWaveform])*3) >> 3)); // mult by 3 shift right by 4 to get in range of 0..47 - + float scaledWaveform = ((float)waveform->data[placeInWaveform]) * 0.375 * lraEffectMultiplier; // 0.375 is 96/256 + LRA.pulsewidth_us((uint16_t)scaledWaveform); + //LRA.pulsewidth_us(((((uint16_t)waveform->data[placeInWaveform])*3) >> 3)); // mult by 3 shift right by 3 to get in range of 0..96 + //LRA.pulsewidth_us(90); // used for fixed intensity output (for testing) } // run down the timer on this amplitude @@ -189,7 +201,41 @@ //printf("Haptics: mode=%d, delay=%d, until=%d, place=%d\n\r", lraPlaybackMode, waveformDelayCounter, lraDelay, placeInWaveform); } } + + +void LEDOffCallback() { + led1=0; +} + +void BuzzCallback() { + Haptics_OutputWaveform(&lra_alert); + led1 = 1; +} + +// generate off mode haptic response +// This is 2 buzzes separated by 300 ms, and 2 led blinks with the same timing. +void LeavingOffModeHapticResponse(int ledFinalState) { + // Turn on LED and generate first buzz + BuzzCallback(); + + // Setup callback to turn off LED after 50ms + firstLEDOff.attach(&LEDOffCallback,0.05); + + // Setup callback to generate second buzz after 300ms, and turn on LED second time + secondBuzz.attach(&BuzzCallback,0.3); + + // Setup callback to turn off LED after 350mS + if (ledFinalState == 0) { + secondLEDOff.attach(&LEDOffCallback,0.35); + } +} + +void EnteringOffModeHapticResponse() { + Haptics_OutputWaveform(&lra_rampdown); + led1 = 0; +} + // Ignored while waveform is playing or queued. Overridden by waveforms. void Haptics_SetRampTarget(float amplitude) {