From c4147980c94250b07c978951b1b91857a5b58e26 Mon Sep 17 00:00:00 2001 From: bsongis Date: Thu, 16 Feb 2012 13:12:35 +0000 Subject: [PATCH] Beeper mode is now splitted from beeper length. Haptic mode added. Haptic only sounds now ok on v4. --- src/audio.cpp | 150 +++++++++++++++++++----------------------- src/audio.h | 14 ++-- src/beeper.cpp | 7 +- src/beeper.h | 2 +- src/general_menus.cpp | 25 +++++-- src/model_menus.cpp | 2 +- src/myeeprom.h | 9 ++- src/o9xstrings.cpp | 21 +++--- src/o9xstrings.h | 16 +++-- src/open9x.cpp | 8 +-- src/translations/en.h | 20 ++++-- src/translations/fr.h | 20 ++++-- 12 files changed, 159 insertions(+), 135 deletions(-) diff --git a/src/audio.cpp b/src/audio.cpp index 597ea4131..71e6de1da 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -59,8 +59,10 @@ void audioQueue::heartbeat() { if (toneTimeLeft > 0) { #if defined(PCBV4) - OCR0A = (5000 / toneFreq); // sticking with old values approx 20(abs. min) to 90, 60 being the default tone(?). - SPEAKER_ON; + if (toneFreq) { + OCR0A = (5000 / toneFreq); // sticking with old values approx 20(abs. min) to 90, 60 being the default tone(?). + SPEAKER_ON; + } #endif toneTimeLeft--; //time gets counted down toneFreq += toneFreqIncr; @@ -102,77 +104,94 @@ void audioQueue::heartbeat() inline uint8_t audioQueue::getToneLength(uint8_t tLen) { uint8_t result = tLen; // default - if (g_eeGeneral.beeperVal == 2) { - result /= 3; + if (g_eeGeneral.beeperLength < 0) { + result /= (1-g_eeGeneral.beeperLength); } - else if (g_eeGeneral.beeperVal == 3) { - result /= 2; - } - else if (g_eeGeneral.beeperVal == 5) { - //long - result *= 2; - } - else if (g_eeGeneral.beeperVal == 6) { - //xlong - result *= 3; + if (g_eeGeneral.beeperLength > 0) { + result *= (1+g_eeGeneral.beeperLength); } return result; } +bool s_beeper; +bool s_haptic; + void audioQueue::playNow(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr) { - if (g_eeGeneral.beeperVal) { - toneFreq = (tFreq ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator - toneTimeLeft = getToneLength(tLen); - tonePause = tPause; + toneFreq = ((s_beeper && tFreq) ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator + toneTimeLeft = getToneLength(tLen); + tonePause = tPause; #if defined(HAPTIC) - toneHaptic = tHaptic; + toneHaptic = s_haptic ? tHaptic : 0; #endif - toneFreqIncr = tFreqIncr; - t_queueWidx = t_queueRidx; + toneFreqIncr = tFreqIncr; + t_queueWidx = t_queueRidx; - if (tRepeat) { - playASAP(tFreq, tLen, tPause, tRepeat-1, tHaptic, tFreqIncr); - } + if (tRepeat) { + playASAP(tFreq, tLen, tPause, tRepeat-1, tHaptic, tFreqIncr); } } void audioQueue::playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr) { - if (g_eeGeneral.beeperVal) { - uint8_t next_queueWidx = (t_queueWidx + 1) % AUDIO_QUEUE_LENGTH; - if (next_queueWidx != t_queueRidx) { - queueToneFreq[t_queueWidx] = (tFreq ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator - queueToneLength[t_queueWidx] = getToneLength(tLen); - queueTonePause[t_queueWidx] = tPause; + uint8_t next_queueWidx = (t_queueWidx + 1) % AUDIO_QUEUE_LENGTH; + if (next_queueWidx != t_queueRidx) { + queueToneFreq[t_queueWidx] = ((s_beeper && tFreq) ? tFreq + g_eeGeneral.speakerPitch + BEEP_OFFSET : 0); // add pitch compensator + queueToneLength[t_queueWidx] = getToneLength(tLen); + queueTonePause[t_queueWidx] = tPause; #if defined(HAPTIC) - queueToneHaptic[t_queueWidx] = tHaptic; + queueToneHaptic[t_queueWidx] = s_haptic ? tHaptic : 0; #endif - queueToneRepeat[t_queueWidx] = tRepeat; - queueToneFreqIncr[t_queueWidx] = tFreqIncr; - t_queueWidx = next_queueWidx; - } + queueToneRepeat[t_queueWidx] = tRepeat; + queueToneFreqIncr[t_queueWidx] = tFreqIncr; + t_queueWidx = next_queueWidx; } } -// TODO check -#define BEEP_NOKEYS 1 void audioQueue::event(uint8_t e, uint8_t f) { - uint8_t beepVal = g_eeGeneral.beeperVal; + s_beeper = (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && e>AU_MENUS) || (g_eeGeneral.beeperMode>=-1 && e<=AU_ERROR)); + s_haptic = (g_eeGeneral.hapticMode>0 || (g_eeGeneral.hapticMode==0 && e>AU_MENUS) || (g_eeGeneral.hapticMode>=-1 && e<=AU_ERROR)); if (e < AU_FRSKY_FIRST || empty()) { switch (e) { - // startup tune - case AU_TADA: + // inactivity timer alert + case AU_INACTIVITY: + playNow(70, 10, 2, 2); + break; + // low battery in tx + case AU_TX_BATTERY_LOW: if (empty()) { - playASAP(50, 10, 5); - playASAP(90, 10, 5); - playASAP(110, 5, 4, 2); + playASAP(60, 20, 3, 2, 0, 1); + playASAP(80, 20, 3, 2, 1, -1); } break; + // error + case AU_ERROR: + playNow(BEEP_DEFAULT_FREQ, 40, 1, 0, 1); + break; + // keypad up (seems to be used when going left/right through system menu options. 0-100 scales etc) + case AU_KEYPAD_UP: + playNow(BEEP_KEY_UP_FREQ, 10, 1); + break; + // keypad down (seems to be used when going left/right through system menu options. 0-100 scales etc) + case AU_KEYPAD_DOWN: + playNow(BEEP_KEY_DOWN_FREQ, 10, 1); + break; + // menu display (also used by a few generic beeps) + case AU_MENUS: + playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 0); + break; + // trim move + case AU_TRIM_MOVE: + playNow(f, 6, 1); + break; + // trim center + case AU_TRIM_MIDDLE: + playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1); + break; // warning one case AU_WARNING1: playNow(BEEP_DEFAULT_FREQ, 10, 1, 0, 1); @@ -185,35 +204,11 @@ void audioQueue::event(uint8_t e, uint8_t f) case AU_WARNING3: playNow(BEEP_DEFAULT_FREQ, 30, 1, 0, 1); break; - // error - case AU_ERROR: - playNow(BEEP_DEFAULT_FREQ, 40, 1, 0, 1); - break; - // keypad up (seems to be used when going left/right through system menu options. 0-100 scales etc) - case AU_KEYPAD_UP: - if (beepVal != BEEP_NOKEYS) { - playNow(BEEP_KEY_UP_FREQ, 10, 1); - } - break; - // keypad down (seems to be used when going left/right through system menu options. 0-100 scales etc) - case AU_KEYPAD_DOWN: - if (beepVal != BEEP_NOKEYS) { - playNow(BEEP_KEY_DOWN_FREQ, 10, 1); - } - break; - // trim move - case AU_TRIM_MOVE: - playNow(f, 6, 1); - break; - // trim center - case AU_TRIM_MIDDLE: - playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1); - break; - // menu display (also used by a few generic beeps) - case AU_MENUS: - if (beepVal != BEEP_NOKEYS) { - playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 0); - } + // startup tune + case AU_TADA: + playASAP(50, 10, 5); + playASAP(90, 10, 5); + playASAP(110, 5, 4, 2); break; // pot/stick center case AU_POT_STICK_MIDDLE: @@ -247,17 +242,6 @@ void audioQueue::event(uint8_t e, uint8_t f) case AU_TIMER_LT3: playNow(BEEP_DEFAULT_FREQ, 20, 25, 1, 1); break; - // inactivity timer alert - case AU_INACTIVITY: - playNow(70, 10, 2, 2); - break; - // low battery in tx - case AU_TX_BATTERY_LOW: - if (empty()) { - playASAP(60, 20, 3, 2, 0, 1); - playASAP(80, 20, 3, 2, 1, -1); - } - break; case AU_FRSKY_WARN1: playASAP(BEEP_DEFAULT_FREQ+20,15,5,2,1); break; diff --git a/src/audio.h b/src/audio.h index 384dba8d9..ff4bfabb0 100644 --- a/src/audio.h +++ b/src/audio.h @@ -54,16 +54,18 @@ /* make sure the defines below always go in numeric order */ enum AUDIO_SOUNDS { - AU_TADA, - AU_WARNING1, - AU_WARNING2, - AU_WARNING3, + AU_INACTIVITY, + AU_TX_BATTERY_LOW, AU_ERROR, AU_KEYPAD_UP, AU_KEYPAD_DOWN, + AU_MENUS, AU_TRIM_MOVE, AU_TRIM_MIDDLE, - AU_MENUS, + AU_WARNING1, + AU_WARNING2, + AU_WARNING3, + AU_TADA, AU_POT_STICK_MIDDLE, AU_MIX_WARNING_1, AU_MIX_WARNING_2, @@ -72,8 +74,6 @@ enum AUDIO_SOUNDS { AU_TIMER_20, AU_TIMER_10, AU_TIMER_LT3, - AU_INACTIVITY, - AU_TX_BATTERY_LOW, AU_FRSKY_FIRST, AU_FRSKY_WARN1 = AU_FRSKY_FIRST, AU_FRSKY_WARN2, diff --git a/src/beeper.cpp b/src/beeper.cpp index 846e3f002..48814d941 100644 --- a/src/beeper.cpp +++ b/src/beeper.cpp @@ -44,8 +44,7 @@ uint8_t hapticTick = 0; // The various "beep" tone lengths static const pm_uint8_t beepTab[] PROGMEM = { - // 0 1 2 3 4 - 0, 1, 8, 30, 100, //silent + // key, trim, warn2, warn1, error 1, 1, 8, 30, 100, //xShort 1, 1, 8, 30, 100, //short 1, 1, 8, 30, 100, //normal @@ -55,7 +54,7 @@ static const pm_uint8_t beepTab[] PROGMEM = { void beep(uint8_t val) { - if (g_eeGeneral.beeperVal>0) { - _beep(pgm_read_byte(beepTab+5*g_eeGeneral.beeperVal-5+val)); + if (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && val!=0) || (g_eeGeneral.beeperMode==-1 && val==4)) { + _beep(pgm_read_byte(beepTab+(5*2)+(5*g_eeGeneral.beeperLength)+val)); } } diff --git a/src/beeper.h b/src/beeper.h index 0897cc338..d27e55909 100644 --- a/src/beeper.h +++ b/src/beeper.h @@ -57,7 +57,7 @@ extern void beep(uint8_t val); #define AUDIO_TIMER_10() beep(2) #define AUDIO_TIMER_LT3() beep(2) #define AUDIO_MINUTE_BEEP() beep(2) -#define AUDIO_INACTIVITY() beep(3) +#define AUDIO_INACTIVITY() AUDIO_ERROR() #define AUDIO_MIX_WARNING_1() beep(1) #define AUDIO_MIX_WARNING_3() beep(1) diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 3a117cf82..75430c186 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -71,7 +71,7 @@ const MenuFuncP_PROGMEM menuTabDiag[] PROGMEM = { }; enum menuProcSetupItems { - ITEM_SETUP_BASE=17, + ITEM_SETUP_BASE=18, #ifdef SPLASH ITEM_SETUP_SPLASH, #endif @@ -79,7 +79,8 @@ enum menuProcSetupItems { ITEM_SETUP_SPEAKER, #endif #ifdef HAPTIC - ITEM_SETUP_HAPTIC, + ITEM_SETUP_HAPTIC_MODE, + ITEM_SETUP_HAPTIC_STRENGTH, #endif ITEM_SETUP_MAX }; @@ -101,9 +102,16 @@ void menuProcSetup(uint8_t event) uint8_t subN = 1; if(s_pgOfs7*FH) return; + }subN++; + + if(s_pgOfs7*FH) return; }subN++; @@ -119,6 +127,13 @@ void menuProcSetup(uint8_t event) #endif #ifdef HAPTIC + if(s_pgOfs7*FH) return; + }subN++; + if(s_pgOfsparam); #else - if (g_eeGeneral.beeperVal>0) { - _beep(10); - } + beep(3); #endif } #if defined(SOMO) diff --git a/src/translations/en.h b/src/translations/en.h index 1180ef09a..257b091d3 100644 --- a/src/translations/en.h +++ b/src/translations/en.h @@ -8,8 +8,11 @@ #define LEN_NCHANNELS 4 #define TR_NCHANNELS "4CH 6CH 8CH 10CH12CH14CH16CH" -#define LEN_VBEEPER 6 -#define TR_VBEEPER "Quiet ""NoKey ""xShort""Short ""Norm ""Long ""xLong " +#define LEN_VBEEPMODE 6 +#define TR_VBEEPMODE "Quiet ""Alarms""NoKey ""Normal" + +#define LEN_VBEEPLEN 6 +#define TR_VBEEPLEN "xShort""Short ""Normal""Long ""xLong " #define LEN_ADCFILTER 4 #define TR_ADCFILTER "SING""OSMP""FILT" @@ -194,7 +197,16 @@ #define TR_BLADES "Blades" #define TR_BARS "Bars" #define TR_CLEARMIXMENU "CLEAR MIXES [MENU]" -#define TR_BEEPER "Beeper" +#ifdef AUDIO +#define TR_BEEPERMODE "Speaker Mode" +#define TR_BEEPERLEN "Speaker Length" +#define TR_SPKRPITCH "Speaker Pitch" +#else +#define TR_BEEPERMODE "Beeper Mode" +#define TR_BEEPERLEN "Beeper Length" +#endif +#define TR_HAPTICMODE "Haptic Mode" +#define TR_HAPTICSTRENGTH "Haptic Strength" #define TR_CONTRAST "Contrast" #define TR_BATTERYWARNING "Battery warning" #define TR_INACTIVITYALARM "Inactivity alarm" @@ -286,5 +298,3 @@ #define TR_MENUDEBUG "DEBUG" #define TR_RXNUM "RxNum" #define TR_SYNCMENU "Sync [MENU]" -#define TR_HAPTICSTRENGTH "Haptic Strength" -#define TR_SPKRPITCH "Speaker Pitch" diff --git a/src/translations/fr.h b/src/translations/fr.h index e907f3b40..4551e79b3 100644 --- a/src/translations/fr.h +++ b/src/translations/fr.h @@ -8,8 +8,11 @@ #define LEN_NCHANNELS 4 #define TR_NCHANNELS "4CH 6CH 8CH 10CH12CH14CH16CH" -#define LEN_VBEEPER 6 -#define TR_VBEEPER "Quiet ""NoKey ""xShort""Court ""Norm ""Long ""xLong " +#define LEN_VBEEPMODE 6 +#define TR_VBEEPMODE "Quiet ""Alarms""NoKey ""Normal" + +#define LEN_VBEEPLEN 6 +#define TR_VBEEPLEN "xShort""Short ""Normal""Long ""xLong " #define LEN_ADCFILTER 4 #define TR_ADCFILTER "SING""OSMP""FILT" @@ -194,7 +197,16 @@ #define TR_BLADES "Blades" #define TR_BARS "Bars" #define TR_CLEARMIXMENU "EFFACER MIXAGES[MENU]" -#define TR_BEEPER "Bipeur" +#ifdef AUDIO +#define TR_BEEPERMODE "Speaker Mode" +#define TR_BEEPERLEN "Speaker Length" +#define TR_SPKRPITCH "Speaker Pitch" +#else +#define TR_BEEPERMODE "Beeper Mode" +#define TR_BEEPERLEN "Beeper Length" +#endif +#define TR_HAPTICMODE "Mode Vibreur" +#define TR_HAPTICSTRENGTH "Haptic Strength" #define TR_CONTRAST "Contraste" #define TR_BATTERYWARNING "Alarme Batterie" #define TR_INACTIVITYALARM "Alarme inactivite" @@ -286,5 +298,3 @@ #define TR_MENUDEBUG "DEBUG" #define TR_RXNUM "RxNum" #define TR_SYNCMENU "Sync [MENU]" -#define TR_HAPTICSTRENGTH "Haptic Strength" -#define TR_SPKRPITCH "Speaker Pitch"