diff --git a/src/Makefile b/src/Makefile index e37516b85..145206d2e 100644 --- a/src/Makefile +++ b/src/Makefile @@ -83,10 +83,6 @@ DISPLAY_USER_DATA = NO # Values = YES, NO FRSKY_HUB = YES -# Enable Extended vario functions (V4 board only) -# Values = YES, NO -VARIO_EXTENDED = NO - # WS HowHigh # Values = YES, NO WS_HOW_HIGH = YES @@ -296,7 +292,7 @@ ifeq ($(PCB), ARM) # ersky9x/ff.c ersky9x/diskio_sam3s.c ersky9x/Media.c ersky9x/ccsbcs.c ersky9x/sdcard.c ersky9x/MEDSdcard.c EEPROMSRC = eeprom_arm.cpp PULSESSRC = pulses_arm.cpp - CPPSRC += audio.cpp haptic.cpp + CPPSRC += audio.cpp CPPSRC += ersky9x/sound.cpp endif @@ -308,7 +304,7 @@ ifeq ($(PCB), V4) BOARDSRC += board_gruvin9x.cpp EEPROMSRC = eeprom_avr.cpp PULSESSRC = pulses_avr.cpp - CPPSRC += audio.cpp haptic.cpp + CPPSRC += audio.cpp CPPSRC += gruvin9x/gtime.cpp CPPSRC += gruvin9x/rtc.cpp CPPSRC += gruvin9x/ff.cpp @@ -358,7 +354,6 @@ ifeq ($(PCB), STD) ifeq ($(HAPTIC), YES) CPPDEFS += -DHAPTIC - CPPSRC += haptic.cpp endif endif diff --git a/src/audio.cpp b/src/audio.cpp index ba0be6d11..8bbb27a5a 100644 --- a/src/audio.cpp +++ b/src/audio.cpp @@ -40,8 +40,20 @@ audioQueue::audioQueue() t_queueRidx = 0; t_queueWidx = 0; + +#ifdef HAPTIC + hapticTick = 0; + hapticSpinUpTime = 0; +#endif } +#if 0 +bool audioQueue::freeslots(uint8_t slots) +{ + return AUDIO_QUEUE_LENGTH - ((t_queueWidx + AUDIO_QUEUE_LENGTH - t_queueRidx) % AUDIO_QUEUE_LENGTH) >= slots; +} +#endif + // heartbeat is responsibile for issueing the audio tones and general square waves // it is essentially the life of the class. // it is called every 10ms @@ -58,8 +70,27 @@ void audioQueue::heartbeat() toneFreqIncr * 61 / 2)) { toneTimeLeft = 0; //time gets counted down } + + +#if defined(HAPTIC) + + if (toneHaptic) { + hapticOn((g_eeGeneral.hapticStrength * 2) * 10); + hapticSpinUpTime = HAPTIC_SPINUP; //min time haptic runs for. Might be worth a config option in system prefs to allow user to set to suit motor? + } + +#endif } else { + +#if defined(HAPTIC) + if(hapticSpinUpTime > 0){ + hapticSpinUpTime--; + } else { + hapticOff(); + } +#endif + if (tonePause) { if (queueTone(0, tonePause * 10, 0)) { tonePause = 0; //time gets counted down @@ -71,6 +102,8 @@ void audioQueue::heartbeat() toneTimeLeft = queueToneLength[t_queueRidx]; toneFreqIncr = queueToneFreqIncr[t_queueRidx]; tonePause = queueTonePause[t_queueRidx]; + toneHaptic = queueToneHaptic[t_queueRidx]; + hapticTick = 0; if (!queueToneRepeat[t_queueRidx]--) { t_queueRidx = (t_queueRidx + 1) % AUDIO_QUEUE_LENGTH; } @@ -87,11 +120,24 @@ void audioQueue::heartbeat() #endif toneTimeLeft--; //time gets counted down toneFreq += toneFreqIncr; + +#if defined(HAPTIC) + if (toneHaptic){ + if (hapticTick-- > 0) { + HAPTIC_ON; // haptic output 'high' + } + else { + HAPTIC_OFF; // haptic output 'low' + hapticTick = g_eeGeneral.hapticStrength; + } + } +#endif } else { - + SPEAKER_OFF; + HAPTIC_OFF; + if (tonePause > 0) { - SPEAKER_OFF; tonePause--; } else if (t_queueRidx != t_queueWidx) { @@ -99,14 +145,12 @@ void audioQueue::heartbeat() toneTimeLeft = queueToneLength[t_queueRidx]; toneFreqIncr = queueToneFreqIncr[t_queueRidx]; tonePause = queueTonePause[t_queueRidx]; - if((toneFreq==0) || (toneTimeLeft==0)){ - SPEAKER_OFF; - } +#if defined(HAPTIC) + toneHaptic = queueToneHaptic[t_queueRidx]; +#endif if (!queueToneRepeat[t_queueRidx]--) { t_queueRidx = (t_queueRidx + 1) % AUDIO_QUEUE_LENGTH; } - } else { - SPEAKER_OFF; } } #endif @@ -125,54 +169,50 @@ inline uint8_t audioQueue::getToneLength(uint8_t tLen) } bool s_beeper; - +#if defined(HAPTIC) +bool s_haptic; +#endif void audioQueue::playNow(uint8_t tFreq, uint8_t tLen, uint8_t tPause, - uint8_t tRepeat, 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 toneTimeLeft = getToneLength(tLen); tonePause = tPause; +#if defined(HAPTIC) + toneHaptic = s_haptic ? tHaptic : 0; +#endif toneFreqIncr = tFreqIncr; t_queueWidx = t_queueRidx; if (tRepeat) { - playASAP(tFreq, tLen, tPause, tRepeat-1, tFreqIncr); + playASAP(tFreq, tLen, tPause, tRepeat-1, tHaptic, tFreqIncr); } } void audioQueue::playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause, - uint8_t tRepeat, int8_t tFreqIncr) + uint8_t tRepeat, uint8_t tHaptic, int8_t tFreqIncr) { 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; - queueToneRepeat[t_queueWidx] = tRepeat -1; +#if defined(HAPTIC) + queueToneHaptic[t_queueWidx] = s_haptic ? tHaptic : 0; +#endif + queueToneRepeat[t_queueWidx] = tRepeat; queueToneFreqIncr[t_queueWidx] = tFreqIncr; t_queueWidx = next_queueWidx; } } -#if defined(VARIO_EXTENDED) -void audioQueue::playVario(uint8_t tFreq, uint8_t tLen) -{ - uint8_t next_queueWidx = (t_queueWidx + 1) % AUDIO_QUEUE_LENGTH; - if (next_queueWidx != t_queueRidx) { - queueToneFreq[t_queueWidx] = tFreq; - queueToneLength[t_queueWidx] = tLen; - queueTonePause[t_queueWidx] = 0; - queueToneRepeat[t_queueWidx] = 0; - queueToneFreqIncr[t_queueWidx] = 0; - t_queueWidx = next_queueWidx; - } -} -#endif - 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)); +#if defined(HAPTIC) + s_haptic = (g_eeGeneral.hapticMode>0 || (g_eeGeneral.hapticMode==0 && e>=AU_WARNING1) || (g_eeGeneral.hapticMode>=-1 && e<=AU_ERROR)); +#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 (e < AU_FRSKY_FIRST || empty()) { switch (e) { @@ -183,25 +223,25 @@ void audioQueue::event(uint8_t e, uint8_t f) // low battery in tx case AU_TX_BATTERY_LOW: if (empty()) { - playASAP(60, 20, 3, 2, 1); - playASAP(80, 20, 3, 2, -1); + 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); + 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, 0); + playNow(BEEP_KEY_UP_FREQ, 10, 1, 0, 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, 0); + playNow(BEEP_KEY_DOWN_FREQ, 10, 1, 0, 1); break; // menu display (also used by a few generic beeps) case AU_MENUS: - playNow(BEEP_DEFAULT_FREQ, 10, 2, 0); + playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1); break; // trim move case AU_TRIM_MOVE: @@ -209,19 +249,19 @@ void audioQueue::event(uint8_t e, uint8_t f) break; // trim center case AU_TRIM_MIDDLE: - playNow(BEEP_DEFAULT_FREQ, 10, 2, 0); + playNow(BEEP_DEFAULT_FREQ, 10, 2, 0, 1); break; // warning one case AU_WARNING1: - playNow(BEEP_DEFAULT_FREQ, 10, 1, 0); + playNow(BEEP_DEFAULT_FREQ, 10, 1, 0, 1); break; // warning two case AU_WARNING2: - playNow(BEEP_DEFAULT_FREQ, 20, 1, 0); + playNow(BEEP_DEFAULT_FREQ, 20, 1, 0, 1); break; // warning three case AU_WARNING3: - playNow(BEEP_DEFAULT_FREQ, 30, 1, 0); + playNow(BEEP_DEFAULT_FREQ, 30, 1, 0, 1); break; // startup tune case AU_TADA: @@ -231,63 +271,63 @@ void audioQueue::event(uint8_t e, uint8_t f) break; // pot/stick center case AU_POT_STICK_MIDDLE: - playNow(BEEP_DEFAULT_FREQ + 50, 10, 1, 0); + playNow(BEEP_DEFAULT_FREQ + 50, 10, 1, 0, 0); break; // mix warning 1 case AU_MIX_WARNING_1: - playNow(BEEP_DEFAULT_FREQ + 50, 6, 0, 0); + playNow(BEEP_DEFAULT_FREQ + 50, 6, 0, 0, 1); break; // mix warning 2 case AU_MIX_WARNING_2: - playNow(BEEP_DEFAULT_FREQ + 52, 6, 0, 0); + playNow(BEEP_DEFAULT_FREQ + 52, 6, 0, 0, 1); break; // mix warning 3 case AU_MIX_WARNING_3: - playNow(BEEP_DEFAULT_FREQ + 54, 6, 0, 0); + playNow(BEEP_DEFAULT_FREQ + 54, 6, 0, 0, 1); break; // time 30 seconds left case AU_TIMER_30: - playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 3); + playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 3, 1); break; // time 20 seconds left case AU_TIMER_20: - playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 2); + playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 2, 1); break; // time 10 seconds left case AU_TIMER_10: - playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 0); + playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 1, 1); break; // time <3 seconds left case AU_TIMER_LT3: - playNow(BEEP_DEFAULT_FREQ + 50, 15, 3, 0); + playNow(BEEP_DEFAULT_FREQ, 20, 25, 1, 1); break; case AU_FRSKY_WARN1: - playASAP(BEEP_DEFAULT_FREQ+20,15,5,2); + playASAP(BEEP_DEFAULT_FREQ+20,15,5,2,1); break; case AU_FRSKY_WARN2: - playASAP(BEEP_DEFAULT_FREQ+30,15,5,2); + playASAP(BEEP_DEFAULT_FREQ+30,15,5,2,1); break; case AU_FRSKY_CHEEP: - playASAP(BEEP_DEFAULT_FREQ+30,10,2,2,2); + playASAP(BEEP_DEFAULT_FREQ+30,10,2,2,1,2); break; case AU_FRSKY_RING: - playASAP(BEEP_DEFAULT_FREQ+25,5,2,10); - playASAP(BEEP_DEFAULT_FREQ+25,5,10,1); - playASAP(BEEP_DEFAULT_FREQ+25,5,2,10); + playASAP(BEEP_DEFAULT_FREQ+25,5,2,10,1); + playASAP(BEEP_DEFAULT_FREQ+25,5,10,1,1); + playASAP(BEEP_DEFAULT_FREQ+25,5,2,10,1); break; case AU_FRSKY_SCIFI: - playASAP(80,10,3,2,-1); - playASAP(60,10,3,2,1); - playASAP(70,10,1,0); + playASAP(80,10,3,2,0,-1); + playASAP(60,10,3,2,0,1); + playASAP(70,10,1,0,2); break; case AU_FRSKY_ROBOT: - playASAP(70,5,1,1); - playASAP(50,15,2,1); - playASAP(80,15,2,1); + playASAP(70,5,1,1,1); + playASAP(50,15,2,1,1); + playASAP(80,15,2,1,1); break; case AU_FRSKY_CHIRP: - playASAP(BEEP_DEFAULT_FREQ+40,5,1,2); - playASAP(BEEP_DEFAULT_FREQ+54,5,1,3); + playASAP(BEEP_DEFAULT_FREQ+40,5,1,2,1); + playASAP(BEEP_DEFAULT_FREQ+54,5,1,3,1); break; case AU_FRSKY_TADA: playASAP(50,5,5); @@ -295,25 +335,40 @@ void audioQueue::event(uint8_t e, uint8_t f) playASAP(110,3,4,2); break; case AU_FRSKY_CRICKET: - playASAP(80,5,10,3); - playASAP(80,5,20,1); - playASAP(80,5,10,3); + playASAP(80,5,10,3,1); + playASAP(80,5,20,1,1); + playASAP(80,5,10,3,1); break; case AU_FRSKY_SIREN: - playASAP(10,20,5,2,1); + playASAP(10,20,5,2,1,1); break; case AU_FRSKY_ALARMC: - playASAP(50,4,10,2); - playASAP(70,8,20,1); - playASAP(50,8,10,2); - playASAP(70,4,20,1); + playASAP(50,4,10,2,1); + playASAP(70,8,20,1,1); + playASAP(50,8,10,2,1); + playASAP(70,4,20,1,1); break; case AU_FRSKY_RATATA: - playASAP(BEEP_DEFAULT_FREQ+50,5,10,10); + playASAP(BEEP_DEFAULT_FREQ+50,5,10,10,1); break; case AU_FRSKY_TICK: - playASAP(BEEP_DEFAULT_FREQ+50,5,50,2); + playASAP(BEEP_DEFAULT_FREQ+50,5,50,2,1); break; +#ifdef HAPTIC + case AU_FRSKY_HAPTIC1: + playASAP(0,30,10,0,1); + playASAP(0,10,50,0,1); + break; + case AU_FRSKY_HAPTIC2: + playASAP(0,30,10,0,1); + playASAP(0,10,10,0,1); + playASAP(0,10,30,0,1); + break; + case AU_FRSKY_HAPTIC3: + playASAP(0,30,10,0,1); + playASAP(0,10,10,2,1); + break; +#endif default: break; } @@ -322,8 +377,5 @@ void audioQueue::event(uint8_t e, uint8_t f) void audioDefevent(uint8_t e) { -#ifdef HAPTIC - hapticAudioEvent(e); //do this before audio to help sync timings -#endif audio.event(e, BEEP_DEFAULT_FREQ); } diff --git a/src/audio.h b/src/audio.h index e6743074e..1408e8dd4 100644 --- a/src/audio.h +++ b/src/audio.h @@ -86,6 +86,11 @@ enum AUDIO_SOUNDS { AU_FRSKY_ALARMC, AU_FRSKY_RATATA, AU_FRSKY_TICK, +#ifdef HAPTIC + AU_FRSKY_HAPTIC1, + AU_FRSKY_HAPTIC2, + AU_FRSKY_HAPTIC3, +#endif AU_FRSKY_LAST, }; @@ -97,13 +102,9 @@ class audioQueue // only difference between these two functions is that one does the // interupt queue (Now) and the other queues for playing ASAP. - void playNow(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0, int8_t tFreqIncr=0); + void playNow(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0, uint8_t tHaptic=0, int8_t tFreqIncr=0); - void playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0, int8_t tFreqIncr=0); - -#if defined(VARIO_EXTENDED) - void playVario(uint8_t tFreq, uint8_t tLen); -#endif + void playASAP(uint8_t tFreq, uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0, uint8_t tHaptic=0, int8_t tFreqIncr=0); inline bool busy() { return (toneTimeLeft > 0); } @@ -176,6 +177,13 @@ class audioQueue uint8_t queueTonePause[AUDIO_QUEUE_LENGTH]; uint8_t queueToneRepeat[AUDIO_QUEUE_LENGTH]; +#ifdef HAPTIC + uint8_t toneHaptic; + uint8_t hapticTick; + uint8_t queueToneHaptic[AUDIO_QUEUE_LENGTH]; + uint8_t hapticSpinUpTime; +#endif + #if defined(PCBSTD) uint8_t toneCounter; #endif @@ -186,6 +194,8 @@ extern audioQueue audio; void audioDefevent(uint8_t e); +#define HAPTIC_SPINUP (10); + #define AUDIO_KEYPAD_UP() audioDefevent(AU_KEYPAD_UP) #define AUDIO_KEYPAD_DOWN() audioDefevent(AU_KEYPAD_DOWN) #define AUDIO_MENUS() audioDefevent(AU_MENUS) diff --git a/src/beeper.cpp b/src/beeper.cpp index 6c995c224..a817de706 100644 --- a/src/beeper.cpp +++ b/src/beeper.cpp @@ -39,6 +39,9 @@ uint8_t beepAgainOrig = 0; uint8_t beepOn = false; bool warble = false; bool warbleC; +#if defined(HAPTIC) +uint8_t hapticTick = 0; +#endif // The various "beep" tone lengths static const pm_uint8_t beepTab[] PROGMEM = { @@ -57,7 +60,4 @@ void beep(uint8_t val) if (g_eeGeneral.beeperMode>0 || (g_eeGeneral.beeperMode==0 && val!=0) || (g_eeGeneral.beeperMode==-1 && val>=3)) { _beep(pgm_read_byte(beepTab+5*(2+g_eeGeneral.beeperLength)+val)); } -#ifdef HAPTIC - hapticBeepEvent(val); -#endif } diff --git a/src/beeper.h b/src/beeper.h index bc059da62..8d7e7a33c 100644 --- a/src/beeper.h +++ b/src/beeper.h @@ -40,6 +40,9 @@ extern uint8_t beepAgainOrig; extern uint8_t beepOn; extern bool warble; extern bool warbleC; +#if defined(HAPTIC) +extern uint8_t hapticTick; +#endif #if defined(PCBARM) #include "ersky9x/sound.h" @@ -107,9 +110,19 @@ FORCEINLINE void AUDIO_HEARTBEAT() BUZZER_OFF; else BUZZER_ON; +#if defined(HAPTIC) + if (hapticTick-- > 0) { + HAPTIC_ON; // haptic output 'high' + } + else { + HAPTIC_OFF; // haptic output 'low' + hapticTick = g_eeGeneral.hapticStrength; + } +#endif } else { BUZZER_OFF; + HAPTIC_OFF; } } #endif diff --git a/src/board_gruvin9x.cpp b/src/board_gruvin9x.cpp index b439da66a..930d39b66 100644 --- a/src/board_gruvin9x.cpp +++ b/src/board_gruvin9x.cpp @@ -128,8 +128,8 @@ uint8_t vpot_mod_state = 0; ISR(USART2_RX_vect) { - //receive data from extension board - //bit 9 = 1 mean encoder number, following byte with bit 9 = 0 is increment value + //receive data from extension board + //bit 9 = 1 mean encoder number, following byte with bit 9 = 0 is increment value /* Get status and 9th bit, then data */ /* from buffer */ //uint8_t status = UCSR2A; @@ -144,7 +144,8 @@ ISR(USART2_RX_vect) if((res & 0x100) == 0x100){ vpotToChange = res & 0xff; vpot_mod_state = 1; - }else{ + } + else { if(vpot_mod_state & (vpotToChange>0) & (vpotToChange<=NUM_EXTRA_ROTARY_ENCODERS)) { int8_t vpot_inc = res & 0xff; diff --git a/src/frsky.cpp b/src/frsky.cpp index d7df4f651..1b3f29283 100644 --- a/src/frsky.cpp +++ b/src/frsky.cpp @@ -241,48 +241,7 @@ void parseTelemHubByte(uint8_t byte) if (frskyHubData.temperature2 > frskyHubData.maxTemperature2) frskyHubData.maxTemperature2 = frskyHubData.temperature2; break; -#if defined(VARIO_EXTENDED) - case offsetof(FrskyHubData, baroAltitude_bp): - case offsetof(FrskyHubData, baroAltitude_ap): - if((!g_model.frsky.use_baroAltitude_ap & (offsetof(FrskyHubData, baroAltitude_bp) == (uint8_t)structPos)) | - (g_model.frsky.use_baroAltitude_ap & (offsetof(FrskyHubData, baroAltitude_ap) == (uint8_t)structPos))){ - //here is baro altitude suggested 0.01m accuracy, i.e. baroAltitude_ap in range [0:99] - if(g_model.frsky.use_baroAltitude_ap){ - uint16_t alt_sign = frskyHubData.baroAltitude_bp/abs(frskyHubData.baroAltitude_bp); - frskyHubData.baroAltitude_full = frskyHubData.baroAltitude_bp*100 + frskyHubData.baroAltitude_ap*alt_sign; - }else{ - frskyHubData.baroAltitude_full = frskyHubData.baroAltitude_bp; - } - if(++frskyHubData.queuePointer>=5) - frskyHubData.queuePointer = 0; - frskyHubData.baroAltitudeQueue_Acc[frskyHubData.queuePointer] = - frskyHubData.baroAltitude_full - frskyHubData.baroAltitude_full_prev; - - frskyHubData.baroAltitude_full_prev = frskyHubData.baroAltitude_full; - - frskyHubData.varioSpeed = 0; - for(uint8_t vi=0; vi<5; vi++){ - frskyHubData.varioSpeed += frskyHubData.baroAltitudeQueue_Acc[vi]; - } - - // First received barometer altitude => Altitude offset - if (!frskyHubData.baroAltitudeOffset) - frskyHubData.baroAltitudeOffset = -frskyHubData.baroAltitude_bp; - - frskyHubData.baroAltitude_bp += frskyHubData.baroAltitudeOffset; - - if(g_model.frsky.use_baroAltitude_only){ - frskyHubData.Altitude_show = frskyHubData.gpsAltitude_bp; - if (frskyHubData.baroAltitude_bp > frskyHubData.maxAltitude) - frskyHubData.maxAltitude = frskyHubData.baroAltitude_bp; - if (frskyHubData.baroAltitude_bp < frskyHubData.minAltitude) - frskyHubData.minAltitude = frskyHubData.baroAltitude_bp; - } - - } - break; -#else case offsetof(FrskyHubData, baroAltitude_bp): // First received barometer altitude => Altitude offset if (!frskyHubData.baroAltitudeOffset) @@ -309,35 +268,7 @@ void parseTelemHubByte(uint8_t byte) frskyHubData.lastBaroAltitude_bp = frskyHubData.baroAltitude_bp; } break; -#endif -#if defined(VARIO_EXTENDED) - case offsetof(FrskyHubData, gpsAltitude_ap): - if(g_model.frsky.use_baroAltitude_ap){ - frskyHubData.gpsAltitude_full = frskyHubData.gpsAltitude_bp*100; - } else { - frskyHubData.gpsAltitude_full = frskyHubData.gpsAltitude_bp; - } - if (!frskyHubData.gpsAltitudeOffset) - frskyHubData.gpsAltitudeOffset = -frskyHubData.gpsAltitude_bp; - frskyHubData.gpsAltitude_bp += frskyHubData.gpsAltitudeOffset; - - if(!g_model.frsky.use_baroAltitude_only){ - frskyHubData.Altitude_show = frskyHubData.gpsAltitude_bp; - if (frskyHubData.gpsAltitude_bp > frskyHubData.maxAltitude) - frskyHubData.maxAltitude = frskyHubData.gpsAltitude_bp; - if (frskyHubData.gpsAltitude_bp < frskyHubData.minAltitude) - frskyHubData.minAltitude = frskyHubData.gpsAltitude_bp; - } - if (!frskyHubData.pilotLatitude && !frskyHubData.pilotLongitude) { - // First received GPS position => Pilot GPS position - getGpsPilotPosition(); - } - else if (frskyHubData.gpsDistNeeded || g_menuStack[0] == menuProcFrsky) { - getGpsDistance(); - } - break; -#else case offsetof(FrskyHubData, gpsAltitude_ap): if (!frskyHubData.gpsAltitudeOffset) frskyHubData.gpsAltitudeOffset = -frskyHubData.gpsAltitude_bp; @@ -355,7 +286,7 @@ void parseTelemHubByte(uint8_t byte) getGpsDistance(); } break; -#endif + case offsetof(FrskyHubData, gpsSpeed_bp): // Speed => Max speed if (frskyHubData.gpsSpeed_bp < frskyHubData.maxGpsSpeed) @@ -694,37 +625,8 @@ void check_frsky() if (isFunctionActive(FUNC_VARIO)) { #if defined(AUDIO) - -#if defined(VARIO_EXTENDED) - -#define VARIO_SPEED_LIMIT 10 //m/s - int16_t verticalSpeed = 0; - //vertical speed in 0.01m/s now - if(g_model.frsky.use_baroAltitude_ap)//means if additional data enabled then _ap unit is 0.01 - verticalSpeed = limit((int16_t)(-VARIO_SPEED_LIMIT*100), (int16_t)frskyHubData.varioSpeed, (int16_t)(+VARIO_SPEED_LIMIT*100)); - else - verticalSpeed = limit((int16_t)-VARIO_SPEED_LIMIT, (int16_t)(frskyHubData.varioSpeed), (int16_t)+VARIO_SPEED_LIMIT)*100; - - uint8_t SoundAltBeepNextFreq = (0); - uint8_t SoundAltBeepNextTime = (0); - if(verticalSpeed < g_model.varioSpeedUpMin*VARIO_LIM_MUL && verticalSpeed > g_model.varioSpeedDownMin*(-VARIO_LIM_MUL)) //check thresholds here in cm/s - { - SoundAltBeepNextFreq = (0); - SoundAltBeepNextTime = (0); - }else{ - SoundAltBeepNextFreq = (((((int32_t)verticalSpeed * 84) + 125000)/10)/10)/20;//;150000)/10)/10)/20; - SoundAltBeepNextTime = ((1600 - verticalSpeed) / 100); - if(verticalSpeed > 0){ - if ((int16_t)(g_tmr10ms - s_varioTmr) > (int16_t)(SoundAltBeepNextTime*2)) { - s_varioTmr = g_tmr10ms; - audio.playVario(SoundAltBeepNextFreq, SoundAltBeepNextTime); - } - } else {//negative vertical speed gives sound without pauses - audio.playVario(SoundAltBeepNextFreq, 1); - } - } -#else //VARIO_EXTENDED uint8_t warble = 0; +#endif int8_t verticalSpeed = limit((int16_t)-100, (int16_t)(frskyHubData.varioSpeed/10), (int16_t)+100); uint16_t interval; @@ -745,11 +647,8 @@ void check_frsky() else AUDIO_VARIO_UP(); } -#endif //VARIO_EXTENDED - -#endif //AUDIO -#endif //FRSKY_HUB || WS_HOW_HIGH } +#endif } bool FRSKY_alarmRaised(uint8_t idx) @@ -896,9 +795,7 @@ void resetTelemetry() frskyHubData.cellsCount = 6; frskyHubData.gpsAltitude_bp = 50; - frskyHubData.gpsAltitude_full = 5000; frskyHubData.baroAltitude_bp = 50; - frskyHubData.baroAltitude_full = 5000; frskyHubData.minAltitude = 10; frskyHubData.maxAltitude = 500; @@ -1177,15 +1074,7 @@ void menuProcFrsky(uint8_t event) putsTime(x, 1+FH+2*FH*i, value, att, att); } else { -#if defined(VARIO_EXTENDED) - if(g_model.frsky.use_baroAltitude_ap & (field == TELEM_VSPD)){ - putsTelemetryChannel(j ? 128 : 63, i==3 ? 1+7*FH : 1+2*FH+2*FH*i, field-1, value, att|PREC2); - } - else -#endif - { - putsTelemetryChannel(j ? 128 : 63, i==3 ? 1+7*FH : 1+2*FH+2*FH*i, field-1, value, att); - } + putsTelemetryChannel(j ? 128 : 63, i==3 ? 1+7*FH : 1+2*FH+2*FH*i, field-1, value, att); lcd_putsiAtt(j*65, 1+FH+2*FH*i, STR_VTELEMCHNS, field, 0); } } @@ -1227,14 +1116,14 @@ void menuProcFrsky(uint8_t event) } uint8_t width = (uint8_t)limit((int16_t)0, (int16_t)(((int32_t)100 * (value - barMin)) / (barMax - barMin)), (int16_t)100); - // reversed barshade for T1/T2 - uint8_t barShade; - if (source == TELEM_T1 || source == TELEM_T2) - barShade = ((threshold < value) ? DOTTED : SOLID); - else - barShade = ((threshold > value) ? DOTTED : SOLID); - lcd_filled_rect(26, bars_height+6+1+i*(bars_height+6), width, bars_height, barShade); - + // reversed barshade for T1/T2 + uint8_t barShade; + if (source == TELEM_T1 || source == TELEM_T2) + barShade = ((threshold < value) ? DOTTED : SOLID); + else + barShade = ((threshold > value) ? DOTTED : SOLID); + lcd_filled_rect(26, bars_height+6+1+i*(bars_height+6), width, bars_height, barShade); + for (uint8_t j=50; j<125; j+=25) if (j>26+thresholdX || j>26+width) lcd_vline(j, bars_height+6+1+i*(bars_height+6), bars_height); if (thresholdX) { diff --git a/src/frsky.h b/src/frsky.h index 82899ab03..9da0a0e8d 100644 --- a/src/frsky.h +++ b/src/frsky.h @@ -109,18 +109,10 @@ PACK(struct FrskyHubData { uint8_t cellsCount:4; // 4bits out of 16bits spare reused uint8_t minCellVolts; // 8bits out of 16bits spare reused uint16_t current; // 0x28 Current -#if defined(VARIO_EXTENDED) - int8_t spare2[10]; -#else int8_t varioQueue[10]; // circular-buffer -#endif uint8_t queuePointer; // circular-buffer pointer - int8_t spare3; -#if defined(VARIO_EXTENDED) - int16_t spare4; -#else + int8_t spare2; int16_t lastBaroAltitude_bp; -#endif int16_t varioSpeed; /* next fields must keep this order! */ int16_t minAltitude; @@ -131,25 +123,15 @@ PACK(struct FrskyHubData { uint16_t maxGpsSpeed; uint16_t maxGpsDistance; /* end */ -#if defined(VARIO_EXTENDED) - int16_t Altitude_show; - int16_t spare5; -#else int16_t varioAcc1; int16_t varioAcc2; -#endif uint16_t volts_bp; // 0x3A uint16_t volts_ap; // 0x3B // end of FrSky Hub data uint16_t gpsDistance; int16_t gpsAltitudeOffset; uint8_t minCellMinVolts; -#if defined(VARIO_EXTENDED) - int32_t baroAltitude_full; - int32_t gpsAltitude_full; - int32_t baroAltitude_full_prev; - int16_t baroAltitudeQueue_Acc[5]; -#endif + }); #elif defined(WS_HOW_HIGH) diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 669c03ea1..c3196304a 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -98,7 +98,6 @@ enum menuProcSetupItems { #ifdef HAPTIC ITEM_SETUP_HAPTIC_MODE, ITEM_SETUP_HAPTIC_STRENGTH, - ITEM_SETUP_HAPTIC_LENGTH, #endif #ifdef SPLASH ITEM_SETUP_SPLASH, @@ -119,7 +118,7 @@ void menuProcSetup(uint8_t event) #define AUDIO_ZEROS #endif #ifdef HAPTIC -#define HAPTIC_ZEROS 0, 0, 0, +#define HAPTIC_ZEROS 0, 0, #else #define HAPTIC_ZEROS #endif @@ -198,14 +197,6 @@ void menuProcSetup(uint8_t event) } if((y+=FH)>7*FH) return; }subN++; - - if(s_pgOfs7*FH) return; - }subN++; - #endif #if defined(PCBARM) diff --git a/src/haptic.cpp b/src/haptic.cpp deleted file mode 100644 index 229de62c8..000000000 --- a/src/haptic.cpp +++ /dev/null @@ -1,150 +0,0 @@ -/* - * Authors (alphabetical order) - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - Cameron Weeks - * - Erez Raviv - * - Jean-Pierre Parisy - * - Karl Szmutny - * - Michael Blandford - * - Michal Hlavinka - * - Pat Mackenzie - * - Philip Moss - * - Rob Thomson - * - Romolo Manfredini - * - Thomas Husterer - * - * open9x is based on code named - * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, - * er9x by Erez Raviv: http://code.google.com/p/er9x/, - * and the original (and ongoing) project by - * Thomas Husterer, th9x: http://code.google.com/p/th9x/ - * - * 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 - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#include "open9x.h" - -hapticQueue::hapticQueue() -{ - buzzTimeLeft = 0; - buzzPause = 0; - - t_queueRidx = 0; - t_queueWidx = 0; - - hapticTick = 0; -} - -void hapticQueue::heartbeat() -{ -#if defined(SIMU) - return; -#endif - -#if defined(PCBARM) - if (buzzTimeLeft > 0) { - buzzTimeLeft--; //time gets counted down - hapticOn((g_eeGeneral.hapticStrength * 2) * 10); - } - else { - hapticOff(); - - if (buzzPause > 0) { - buzzPause--; - } - else if (t_queueRidx != t_queueWidx) { - buzzTimeLeft = queueHapticLength[t_queueRidx]; - buzzPause = queueHapticPause[t_queueRidx]; - if (!queueHapticRepeat[t_queueRidx]--) { - t_queueRidx = (t_queueRidx + 1) % HAPTIC_QUEUE_LENGTH; - } - } - } -#else - if (buzzTimeLeft > 0) { - buzzTimeLeft--; // time gets counted down - - if (hapticTick-- > 0) { - HAPTIC_ON; // haptic output 'high' - } - else { - HAPTIC_OFF; // haptic output 'high' - hapticTick = g_eeGeneral.hapticStrength; - } - } - else { - HAPTIC_OFF; // haptic output 'high' - if (buzzPause > 0) { - buzzPause--; - } - else if (t_queueRidx != t_queueWidx) { - buzzTimeLeft = queueHapticLength[t_queueRidx]; - buzzPause = queueHapticPause[t_queueRidx]; - if (!queueHapticRepeat[t_queueRidx]--) { - t_queueRidx = (t_queueRidx + 1) % HAPTIC_QUEUE_LENGTH; - } - } - } -#endif -} - -inline uint8_t hapticQueue::getHapticLength(uint8_t tLen) -{ - return ((g_eeGeneral.hapticLength * 2) + tLen) * 2; -} - -void hapticQueue::playNow(uint8_t tLen, uint8_t tPause, uint8_t tRepeat) -{ - buzzTimeLeft = getHapticLength(tLen); - buzzPause = tPause; - t_queueWidx = t_queueRidx; - - if (tRepeat) { - playASAP(tLen, tPause, tRepeat-1); - } -} - -void hapticQueue::playASAP(uint8_t tLen, uint8_t tPause, uint8_t tRepeat) -{ - uint8_t next_queueWidx = (t_queueWidx + 1) % HAPTIC_QUEUE_LENGTH; - if (next_queueWidx != t_queueRidx) { - queueHapticLength[t_queueWidx] = getHapticLength(tLen); - queueHapticPause[t_queueWidx] = tPause; - queueHapticRepeat[t_queueWidx] = tRepeat-1; - t_queueWidx = next_queueWidx; - } -} - -void hapticQueue::event(uint8_t e) -{ - switch (e) { - case 0: // very little buzz for keys / trims - playNow(5, 0, 0); - break; - case 1: // one buzz - playASAP(10,2,1); - break; - case 2: // two buzz - playASAP(10,2,2); - break; - case 3: // three buzz - playASAP(10,2,3); - break; - default: - break; - } -} - -void hapticDefevent(uint8_t e) -{ - haptic.event(e); -} diff --git a/src/haptic.h b/src/haptic.h deleted file mode 100644 index 1148d1953..000000000 --- a/src/haptic.h +++ /dev/null @@ -1,126 +0,0 @@ -/* - * Authors (alphabetical order) - * - Bertrand Songis - * - Bryan J. Rentoul (Gruvin) - * - Cameron Weeks - * - Erez Raviv - * - Jean-Pierre Parisy - * - Karl Szmutny - * - Michael Blandford - * - Michal Hlavinka - * - Pat Mackenzie - * - Philip Moss - * - Rob Thomson - * - Romolo Manfredini - * - Thomas Husterer - * - * open9x is based on code named - * gruvin9x by Bryan J. Rentoul: http://code.google.com/p/gruvin9x/, - * er9x by Erez Raviv: http://code.google.com/p/er9x/, - * and the original (and ongoing) project by - * Thomas Husterer, th9x: http://code.google.com/p/th9x/ - * - * 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 - * published by the Free Software Foundation. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - */ - -#ifndef haptic_h -#define haptic_h - -#define HAPTIC_QUEUE_LENGTH 3 - -class hapticQueue -{ - public: - - hapticQueue(); - - // only difference between these two functions is that one does the - // interupt queue (Now) and the other queues for playing ASAP. - void playNow(uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0); - - void playASAP(uint8_t tLen, uint8_t tPause, uint8_t tRepeat=0); - - inline bool busy() { return (buzzTimeLeft > 0); } - - void event(uint8_t e); - - // heartbeat is responsibile for issueing the haptic buzzs and general square waves - // it is essentially the life of the class. - void heartbeat(); - - // bool freeslots(uint8_t slots); - - inline bool empty() { - return (t_queueRidx == t_queueWidx); - } - - protected: - inline uint8_t getHapticLength(uint8_t tLen); - - private: - uint8_t t_queueRidx; - uint8_t t_queueWidx; - - uint8_t buzzTimeLeft; - uint8_t buzzPause; - - uint8_t hapticTick; - - // queue arrays - uint8_t queueHapticLength[HAPTIC_QUEUE_LENGTH]; - uint8_t queueHapticPause[HAPTIC_QUEUE_LENGTH]; - uint8_t queueHapticRepeat[HAPTIC_QUEUE_LENGTH]; -}; - -//wrapper function - dirty but results in a space saving!!! -extern hapticQueue haptic; - -void hapticDefevent(uint8_t e); - -#define IS_HAPTIC_BUSY() haptic.busy() - -#define HAPTIC_HEARTBEAT() haptic.heartbeat() - -#ifdef AUDIO -inline void hapticAudioEvent(uint8_t e) -{ - if (g_eeGeneral.hapticMode>=-1 && e<=AU_ERROR) - hapticDefevent(1); - else if (e == AU_TIMER_30) - hapticDefevent(3); - else if (e == AU_TIMER_20) - hapticDefevent(2); - else if (e == AU_TIMER_10) - hapticDefevent(1); - else if (g_eeGeneral.hapticMode==0 && e>=AU_WARNING1) - hapticDefevent(1); - else if (g_eeGeneral.hapticMode>0) - hapticDefevent(0); -} -#else -inline void hapticBeepEvent(uint8_t e) -{ - if (g_eeGeneral.hapticMode>=-1 && e>=3) - hapticDefevent(1); - else if (e == AU_TIMER_30) - hapticDefevent(3); - else if (e == AU_TIMER_20) - hapticDefevent(2); - else if (e == AU_TIMER_10) - hapticDefevent(1); - else if (g_eeGeneral.hapticMode==0 && e>0) - hapticDefevent(1); - else if (g_eeGeneral.hapticMode>0) - hapticDefevent(0); -} -#endif - -#endif // haptic_h diff --git a/src/model_menus.cpp b/src/model_menus.cpp index 94caf3653..8595e51d0 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -1967,12 +1967,6 @@ void menuProcFunctionSwitches(uint8_t event) break; #endif } -#if defined(HAPTIC) - else if (sd->func == FUNC_HAPTIC) { - val_max = 3; - lcd_outdezAtt(21*FW, y, val_displayed, attr); - } -#endif #if defined(SOMO) else if (sd->func == FUNC_PLAY_SOMO) { lcd_outdezAtt(21*FW, y, val_displayed, attr); @@ -2009,12 +2003,8 @@ void menuProcFunctionSwitches(uint8_t event) #define TELEM_COL2 (9*FW+2) void menuProcTelemetry(uint8_t event) { -#if defined(FRSKY_HUB) || defined(WS_HOW_HIGH)// v v v v 4 new menu items for baro alt/vario -#if defined(VARIO_EXTENDED) - MENU(STR_MENUTELEMETRY, menuTabModel, e_Telemetry, 32, {0, (uint8_t)-1, 1, 0, 2, 2, (uint8_t)-1, 1, 0, 2, 2, (uint8_t)-1, 1, 1, (uint8_t)-1, 0, 0, (uint8_t)-1, 0, 0, 0, 0, (uint8_t)-1, 1, 1, 1, 1, (uint8_t)-1, 2, 2, 2, 2}); -#else +#if defined(FRSKY_HUB) || defined(WS_HOW_HIGH) MENU(STR_MENUTELEMETRY, menuTabModel, e_Telemetry, 27, {0, (uint8_t)-1, 1, 0, 2, 2, (uint8_t)-1, 1, 0, 2, 2, (uint8_t)-1, 1, 1, (uint8_t)-1, 0, 0, (uint8_t)-1, 1, 1, 1, 1, (uint8_t)-1, 2, 2, 2, 2}); -#endif #else MENU(STR_MENUTELEMETRY, menuTabModel, e_Telemetry, 24, {0, (uint8_t)-1, 1, 0, 2, 2, (uint8_t)-1, 1, 0, 2, 2, (uint8_t)-1, 1, 1, (uint8_t)-1, 1, 1, 1, 1, (uint8_t)-1, 2, 2, 2, 2}); #endif @@ -2162,49 +2152,6 @@ void menuProcTelemetry(uint8_t event) CHECK_INCDEC_MODELVAR(event, g_model.frsky.blades, 0, 2); } subN++; -#if defined(VARIO_EXTENDED) - if(s_pgOfsfunc == FUNC_HAPTIC) { - hapticDefevent(sd->param); - } -#endif - active_functions |= mask; } else { @@ -2053,7 +2038,6 @@ void perMain() #if defined(PCBARM) AUDIO_HEARTBEAT(); // the queue processing - HAPTIC_HEARTBEAT(); #endif } @@ -2124,10 +2108,6 @@ ISR(TIMER0_COMP_vect, ISR_NOBLOCK) //10ms timer AUDIO_HEARTBEAT(); -#ifdef HAPTIC - HAPTIC_HEARTBEAT(); -#endif - #ifdef DEBUG // Record start time from TCNT1 to record excution time cli(); diff --git a/src/open9x.h b/src/open9x.h index f3f4c8b09..95648f238 100644 --- a/src/open9x.h +++ b/src/open9x.h @@ -818,10 +818,6 @@ extern uint16_t jeti_keys; #include "beeper.h" #endif -#if defined(HAPTIC) -#include "haptic.h" -#endif - #if defined(SDCARD) #include "logs.h" #endif diff --git a/src/pulses_avr.cpp b/src/pulses_avr.cpp index 231a90b47..25efe9d9c 100644 --- a/src/pulses_avr.cpp +++ b/src/pulses_avr.cpp @@ -210,7 +210,7 @@ FORCEINLINE void setupPulsesPPM() uint16_t rest = 22500u*2-q; //Minimum Framelen=22.5 ms rest += (int16_t(g_model.ppmFrameLength))*1000; for (uint8_t i=0; i