Haptic123 will be different.

This commit is contained in:
gbirkus@gmail.com
2012-04-06 14:52:06 +00:00
parent af3f17a8ae
commit f08e201045
+327 -323
View File
@@ -1,323 +1,327 @@
/* /*
* Authors (alphabetical order) * Authors (alphabetical order)
* - Bertrand Songis <bsongis@gmail.com> * - Bertrand Songis <bsongis@gmail.com>
* - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com> * - Bryan J. Rentoul (Gruvin) <gruvin@gmail.com>
* - Cameron Weeks <th9xer@gmail.com> * - Cameron Weeks <th9xer@gmail.com>
* - Erez Raviv * - Erez Raviv
* - Jean-Pierre Parisy * - Jean-Pierre Parisy
* - Karl Szmutny <shadow@privy.de> * - Karl Szmutny <shadow@privy.de>
* - Michael Blandford * - Michael Blandford
* - Michal Hlavinka * - Michal Hlavinka
* - Pat Mackenzie * - Pat Mackenzie
* - Philip Moss * - Philip Moss
* - Rob Thomson * - Rob Thomson
* - Romolo Manfredini <romolo.manfredini@gmail.com> * - Romolo Manfredini <romolo.manfredini@gmail.com>
* - Thomas Husterer * - Thomas Husterer
* *
* open9x is based on code named * open9x is based on code named
* gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/,
* er9x by Erez Raviv: http://code.google.com/p/er9x/, * er9x by Erez Raviv: http://code.google.com/p/er9x/,
* and the original (and ongoing) project by * and the original (and ongoing) project by
* Thomas Husterer, th9x: http://code.google.com/p/th9x/ * Thomas Husterer, th9x: http://code.google.com/p/th9x/
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as * it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation. * published by the Free Software Foundation.
* *
* This program is distributed in the hope that it will be useful, * This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details. * GNU General Public License for more details.
* *
*/ */
#include "open9x.h" #include "open9x.h"
audioQueue::audioQueue() audioQueue::audioQueue()
{ {
toneTimeLeft = 0; toneTimeLeft = 0;
tonePause = 0; tonePause = 0;
t_queueRidx = 0; t_queueRidx = 0;
t_queueWidx = 0; t_queueWidx = 0;
#ifdef HAPTIC #ifdef HAPTIC
hapticTick = 0; hapticTick = 0;
#endif #endif
} }
#if 0 #if 0
bool audioQueue::freeslots(uint8_t slots) bool audioQueue::freeslots(uint8_t slots)
{ {
return AUDIO_QUEUE_LENGTH - ((t_queueWidx + AUDIO_QUEUE_LENGTH - t_queueRidx) % AUDIO_QUEUE_LENGTH) >= slots; return AUDIO_QUEUE_LENGTH - ((t_queueWidx + AUDIO_QUEUE_LENGTH - t_queueRidx) % AUDIO_QUEUE_LENGTH) >= slots;
} }
#endif #endif
// heartbeat is responsibile for issueing the audio tones and general square waves // heartbeat is responsibile for issueing the audio tones and general square waves
// it is essentially the life of the class. // it is essentially the life of the class.
// it is called every 10ms // it is called every 10ms
void audioQueue::heartbeat() void audioQueue::heartbeat()
{ {
if (toneTimeLeft > 0) { if (toneTimeLeft > 0) {
#if defined(PCBV4) #if defined(PCBV4)
if (toneFreq) { if (toneFreq) {
OCR0A = (5000 / toneFreq); // sticking with old values approx 20(abs. min) to 90, 60 being the default tone(?). OCR0A = (5000 / toneFreq); // sticking with old values approx 20(abs. min) to 90, 60 being the default tone(?).
SPEAKER_ON; SPEAKER_ON;
} }
#endif #endif
toneTimeLeft--; //time gets counted down toneTimeLeft--; //time gets counted down
toneFreq += toneFreqIncr; toneFreq += toneFreqIncr;
#if defined(HAPTIC) #if defined(HAPTIC)
if (toneHaptic){ if (toneHaptic){
if (hapticTick-- > 0) { if (hapticTick-- > 0) {
HAPTIC_ON; // haptic output 'high' HAPTIC_ON; // haptic output 'high'
} }
else { else {
HAPTIC_OFF; // haptic output 'low' HAPTIC_OFF; // haptic output 'low'
hapticTick = g_eeGeneral.hapticStrength; hapticTick = g_eeGeneral.hapticStrength;
} }
} }
#endif #endif
} }
else { else {
SPEAKER_OFF; SPEAKER_OFF;
HAPTIC_OFF; HAPTIC_OFF;
if (tonePause > 0) { if (tonePause > 0) {
tonePause--; tonePause--;
} }
else if (t_queueRidx != t_queueWidx) { else if (t_queueRidx != t_queueWidx) {
toneFreq = queueToneFreq[t_queueRidx]; toneFreq = queueToneFreq[t_queueRidx];
toneTimeLeft = queueToneLength[t_queueRidx]; toneTimeLeft = queueToneLength[t_queueRidx];
toneFreqIncr = queueToneFreqIncr[t_queueRidx]; toneFreqIncr = queueToneFreqIncr[t_queueRidx];
tonePause = queueTonePause[t_queueRidx]; tonePause = queueTonePause[t_queueRidx];
#if defined(HAPTIC) #if defined(HAPTIC)
toneHaptic = queueToneHaptic[t_queueRidx]; toneHaptic = queueToneHaptic[t_queueRidx];
#endif #endif
if (!queueToneRepeat[t_queueRidx]--) { if (!queueToneRepeat[t_queueRidx]--) {
t_queueRidx = (t_queueRidx + 1) % AUDIO_QUEUE_LENGTH; t_queueRidx = (t_queueRidx + 1) % AUDIO_QUEUE_LENGTH;
} }
} }
} }
} }
inline uint8_t audioQueue::getToneLength(uint8_t tLen) inline uint8_t audioQueue::getToneLength(uint8_t tLen)
{ {
uint8_t result = tLen; // default uint8_t result = tLen; // default
if (g_eeGeneral.beeperLength < 0) { if (g_eeGeneral.beeperLength < 0) {
result /= (1-g_eeGeneral.beeperLength); result /= (1-g_eeGeneral.beeperLength);
} }
if (g_eeGeneral.beeperLength > 0) { if (g_eeGeneral.beeperLength > 0) {
result *= (1+g_eeGeneral.beeperLength); result *= (1+g_eeGeneral.beeperLength);
} }
return result; return result;
} }
bool s_beeper; bool s_beeper;
#if defined(HAPTIC) #if defined(HAPTIC)
bool s_haptic; bool s_haptic;
#endif #endif
void audioQueue::playNow(uint8_t tFreq, uint8_t tLen, uint8_t tPause, void audioQueue::playNow(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr) uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr)
{ {
toneFreq = ((s_beeper && tFreq) ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator toneFreq = ((s_beeper && tFreq) ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator
toneTimeLeft = getToneLength(tLen); toneTimeLeft = getToneLength(tLen);
tonePause = tPause; tonePause = tPause;
#if defined(HAPTIC) #if defined(HAPTIC)
toneHaptic = s_haptic ? tHaptic : 0; toneHaptic = s_haptic ? tHaptic : 0;
#endif #endif
toneFreqIncr = tFreqIncr; toneFreqIncr = tFreqIncr;
t_queueWidx = t_queueRidx; t_queueWidx = t_queueRidx;
if (tRepeat) { if (tRepeat) {
playASAP(tFreq, tLen, tPause, tRepeat-1, tHaptic, tFreqIncr); playASAP(tFreq, tLen, tPause, tRepeat-1, tHaptic, tFreqIncr);
} }
} }
void audioQueue::playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause, void audioQueue::playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause,
uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr) uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr)
{ {
uint8_t next_queueWidx = (t_queueWidx + 1) % AUDIO_QUEUE_LENGTH; uint8_t next_queueWidx = (t_queueWidx + 1) % AUDIO_QUEUE_LENGTH;
if (next_queueWidx != t_queueRidx) { if (next_queueWidx != t_queueRidx) {
queueToneFreq[t_queueWidx] = ((s_beeper && tFreq) ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator queueToneFreq[t_queueWidx] = ((s_beeper && tFreq) ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator
queueToneLength[t_queueWidx] = getToneLength(tLen); queueToneLength[t_queueWidx] = getToneLength(tLen);
queueTonePause[t_queueWidx] = tPause; queueTonePause[t_queueWidx] = tPause;
#if defined(HAPTIC) #if defined(HAPTIC)
queueToneHaptic[t_queueWidx] = s_haptic ? tHaptic : 0; queueToneHaptic[t_queueWidx] = s_haptic ? tHaptic : 0;
#endif #endif
queueToneRepeat[t_queueWidx] = tRepeat; queueToneRepeat[t_queueWidx] = tRepeat;
queueToneFreqIncr[t_queueWidx] = tFreqIncr; queueToneFreqIncr[t_queueWidx] = tFreqIncr;
t_queueWidx = next_queueWidx; t_queueWidx = next_queueWidx;
} }
} }
void audioQueue::event(uint8_t e, uint8_t f) void audioQueue::event(uint8_t e, uint8_t f)
{ {
s_beeper = (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && e>=AU_WARNING1) || (g_eeGeneral.beeperMode>=-1 && e<=AU_ERROR)); s_beeper = (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && e>=AU_WARNING1) || (g_eeGeneral.beeperMode>=-1 && e<=AU_ERROR));
#if defined(HAPTIC) #if defined(HAPTIC)
s_haptic = (g_eeGeneral.hapticMode>0 || (g_eeGeneral.hapticMode==0 && e>=AU_WARNING1) || (g_eeGeneral.hapticMode>=-1 && e<=AU_ERROR)); s_haptic = (g_eeGeneral.hapticMode>0 || (g_eeGeneral.hapticMode==0 && e>=AU_WARNING1) || (g_eeGeneral.hapticMode>=-1 && e<=AU_ERROR));
#endif #endif
if (g_eeGeneral.flashBeep && (e <= AU_ERROR || e >= AU_WARNING1)) g_LightOffCounter = FLASH_DURATION; // we got an event do we need to flash the display ? if (g_eeGeneral.flashBeep && (e <= AU_ERROR || e >= AU_WARNING1)) g_LightOffCounter = FLASH_DURATION; // we got an event do we need to flash the display ?
if (e < AU_FRSKY_FIRST || empty()) { if (e < AU_FRSKY_FIRST || empty()) {
switch (e) { switch (e) {
// inactivity timer alert // inactivity timer alert
case AU_INACTIVITY: case AU_INACTIVITY:
playNow(70, 10, 2, 2); playNow(70, 10, 2, 2);
break; break;
// low battery in tx // low battery in tx
case AU_TX_BATTERY_LOW: case AU_TX_BATTERY_LOW:
if (empty()) { if (empty()) {
playASAP(60, 20, 3, 2, 0, 1); playASAP(60, 20, 3, 2, 0, 1);
playASAP(80, 20, 3, 2, 1, -1); playASAP(80, 20, 3, 2, 1, -1);
} }
break; break;
// error // error
case AU_ERROR: case AU_ERROR:
playNow(BEEP_DEFAULT_FREQ, 40, 1, 0, 1); playNow(BEEP_DEFAULT_FREQ, 40, 1, 0, 1);
break; break;
// keypad up (seems to be used when going left/right through system menu options. 0-100 scales etc) // keypad up (seems to be used when going left/right through system menu options. 0-100 scales etc)
case AU_KEYPAD_UP: case AU_KEYPAD_UP:
playNow(BEEP_KEY_UP_FREQ, 10, 1, 0, 1); playNow(BEEP_KEY_UP_FREQ, 10, 1, 0, 1);
break; break;
// keypad down (seems to be used when going left/right through system menu options. 0-100 scales etc) // keypad down (seems to be used when going left/right through system menu options. 0-100 scales etc)
case AU_KEYPAD_DOWN: case AU_KEYPAD_DOWN:
playNow(BEEP_KEY_DOWN_FREQ, 10, 1, 0, 1); playNow(BEEP_KEY_DOWN_FREQ, 10, 1, 0, 1);
break; break;
// menu display (also used by a few generic beeps) // menu display (also used by a few generic beeps)
case AU_MENUS: case AU_MENUS:
playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1); playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1);
break; break;
// trim move // trim move
case AU_TRIM_MOVE: case AU_TRIM_MOVE:
playNow(f, 6, 1); playNow(f, 6, 1);
break; break;
// trim center // trim center
case AU_TRIM_MIDDLE: case AU_TRIM_MIDDLE:
playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1); playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1);
break; break;
// warning one // warning one
case AU_WARNING1: case AU_WARNING1:
playNow(BEEP_DEFAULT_FREQ, 10, 1, 0, 1); playNow(BEEP_DEFAULT_FREQ, 10, 1, 0, 1);
break; break;
// warning two // warning two
case AU_WARNING2: case AU_WARNING2:
playNow(BEEP_DEFAULT_FREQ, 20, 1, 0, 1); playNow(BEEP_DEFAULT_FREQ, 20, 1, 0, 1);
break; break;
// warning three // warning three
case AU_WARNING3: case AU_WARNING3:
playNow(BEEP_DEFAULT_FREQ, 30, 1, 0, 1); playNow(BEEP_DEFAULT_FREQ, 30, 1, 0, 1);
break; break;
// startup tune // startup tune
case AU_TADA: case AU_TADA:
playASAP(50, 10, 5); playASAP(50, 10, 5);
playASAP(90, 10, 5); playASAP(90, 10, 5);
playASAP(110, 5, 4, 2); playASAP(110, 5, 4, 2);
break; break;
// pot/stick center // pot/stick center
case AU_POT_STICK_MIDDLE: case AU_POT_STICK_MIDDLE:
playNow(BEEP_DEFAULT_FREQ + 50, 10, 1, 0, 0); playNow(BEEP_DEFAULT_FREQ + 50, 10, 1, 0, 0);
break; break;
// mix warning 1 // mix warning 1
case AU_MIX_WARNING_1: case AU_MIX_WARNING_1:
playNow(BEEP_DEFAULT_FREQ + 50, 6, 0, 0, 1); playNow(BEEP_DEFAULT_FREQ + 50, 6, 0, 0, 1);
break; break;
// mix warning 2 // mix warning 2
case AU_MIX_WARNING_2: case AU_MIX_WARNING_2:
playNow(BEEP_DEFAULT_FREQ + 52, 6, 0, 0, 1); playNow(BEEP_DEFAULT_FREQ + 52, 6, 0, 0, 1);
break; break;
// mix warning 3 // mix warning 3
case AU_MIX_WARNING_3: case AU_MIX_WARNING_3:
playNow(BEEP_DEFAULT_FREQ + 54, 6, 0, 0, 1); playNow(BEEP_DEFAULT_FREQ + 54, 6, 0, 0, 1);
break; break;
// time 30 seconds left // time 30 seconds left
case AU_TIMER_30: case AU_TIMER_30:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 3, 1); playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 3, 1);
break; break;
// time 20 seconds left // time 20 seconds left
case AU_TIMER_20: case AU_TIMER_20:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 2, 1); playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 2, 1);
break; break;
// time 10 seconds left // time 10 seconds left
case AU_TIMER_10: case AU_TIMER_10:
playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 1, 1); playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 1, 1);
break; break;
// time <3 seconds left // time <3 seconds left
case AU_TIMER_LT3: case AU_TIMER_LT3:
playNow(BEEP_DEFAULT_FREQ, 20, 25, 1, 1); playNow(BEEP_DEFAULT_FREQ, 20, 25, 1, 1);
break; break;
case AU_FRSKY_WARN1: case AU_FRSKY_WARN1:
playASAP(BEEP_DEFAULT_FREQ+20,15,5,2,1); playASAP(BEEP_DEFAULT_FREQ+20,15,5,2,1);
break; break;
case AU_FRSKY_WARN2: case AU_FRSKY_WARN2:
playASAP(BEEP_DEFAULT_FREQ+30,15,5,2,1); playASAP(BEEP_DEFAULT_FREQ+30,15,5,2,1);
break; break;
case AU_FRSKY_CHEEP: case AU_FRSKY_CHEEP:
playASAP(BEEP_DEFAULT_FREQ+30,10,2,2,1,2); playASAP(BEEP_DEFAULT_FREQ+30,10,2,2,1,2);
break; break;
case AU_FRSKY_RING: case AU_FRSKY_RING:
playASAP(BEEP_DEFAULT_FREQ+25,5,2,10,1); playASAP(BEEP_DEFAULT_FREQ+25,5,2,10,1);
playASAP(BEEP_DEFAULT_FREQ+25,5,10,1,1); playASAP(BEEP_DEFAULT_FREQ+25,5,10,1,1);
playASAP(BEEP_DEFAULT_FREQ+25,5,2,10,1); playASAP(BEEP_DEFAULT_FREQ+25,5,2,10,1);
break; break;
case AU_FRSKY_SCIFI: case AU_FRSKY_SCIFI:
playASAP(80,10,3,2,0,-1); playASAP(80,10,3,2,0,-1);
playASAP(60,10,3,2,0,1); playASAP(60,10,3,2,0,1);
playASAP(70,10,1,0,2); playASAP(70,10,1,0,2);
break; break;
case AU_FRSKY_ROBOT: case AU_FRSKY_ROBOT:
playASAP(70,5,1,1,1); playASAP(70,5,1,1,1);
playASAP(50,15,2,1,1); playASAP(50,15,2,1,1);
playASAP(80,15,2,1,1); playASAP(80,15,2,1,1);
break; break;
case AU_FRSKY_CHIRP: case AU_FRSKY_CHIRP:
playASAP(BEEP_DEFAULT_FREQ+40,5,1,2,1); playASAP(BEEP_DEFAULT_FREQ+40,5,1,2,1);
playASAP(BEEP_DEFAULT_FREQ+54,5,1,3,1); playASAP(BEEP_DEFAULT_FREQ+54,5,1,3,1);
break; break;
case AU_FRSKY_TADA: case AU_FRSKY_TADA:
playASAP(50,5,5); playASAP(50,5,5);
playASAP(90,5,5); playASAP(90,5,5);
playASAP(110,3,4,2); playASAP(110,3,4,2);
break; break;
case AU_FRSKY_CRICKET: case AU_FRSKY_CRICKET:
playASAP(80,5,10,3,1); playASAP(80,5,10,3,1);
playASAP(80,5,20,1,1); playASAP(80,5,20,1,1);
playASAP(80,5,10,3,1); playASAP(80,5,10,3,1);
break; break;
case AU_FRSKY_SIREN: case AU_FRSKY_SIREN:
playASAP(10,20,5,2,1,1); playASAP(10,20,5,2,1,1);
break; break;
case AU_FRSKY_ALARMC: case AU_FRSKY_ALARMC:
playASAP(50,4,10,2,1); playASAP(50,4,10,2,1);
playASAP(70,8,20,1,1); playASAP(70,8,20,1,1);
playASAP(50,8,10,2,1); playASAP(50,8,10,2,1);
playASAP(70,4,20,1,1); playASAP(70,4,20,1,1);
break; break;
case AU_FRSKY_RATATA: case AU_FRSKY_RATATA:
playASAP(BEEP_DEFAULT_FREQ+50,5,10,10,1); playASAP(BEEP_DEFAULT_FREQ+50,5,10,10,1);
break; break;
case AU_FRSKY_TICK: case AU_FRSKY_TICK:
playASAP(BEEP_DEFAULT_FREQ+50,5,50,2,1); playASAP(BEEP_DEFAULT_FREQ+50,5,50,2,1);
break; break;
#ifdef HAPTIC #ifdef HAPTIC
case AU_FRSKY_HAPTIC1: case AU_FRSKY_HAPTIC1:
playASAP(0,20,10,1,1); playASAP(0,30,10,0,1);
break; playASAP(0,10,50,0,1);
case AU_FRSKY_HAPTIC2: break;
playASAP(0,20,10,2,1); case AU_FRSKY_HAPTIC2:
break; playASAP(0,30,10,0,1);
case AU_FRSKY_HAPTIC3: playASAP(0,10,10,0,1);
playASAP(0,20,10,3,1); playASAP(0,10,30,0,1);
break; break;
#endif case AU_FRSKY_HAPTIC3:
default: playASAP(0,30,10,0,1);
break; playASAP(0,10,10,2,1);
} break;
} #endif
} default:
break;
void audioDefevent(uint8_t e) }
{ }
audio.event(e, BEEP_DEFAULT_FREQ); }
}
void audioDefevent(uint8_t e)
{
audio.event(e, BEEP_DEFAULT_FREQ);
}