diff --git a/src/open9x.cpp b/src/open9x.cpp index 9ed358190..1212232ec 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -52,9 +52,9 @@ EEGeneral g_eeGeneral; ModelData g_model; #if !defined(PCBARM) -uint8_t g_tmr1Latency_max; +uint8_t g_tmr1Latency_max; uint8_t g_tmr1Latency_min; -#endif +#endif uint16_t g_timeMain; #ifdef DEBUG uint16_t g_time_per10; @@ -321,12 +321,12 @@ int16_t Expo::expo(int16_t x) #endif -void applyExpos(int16_t *anas) +void applyExpos(int16_t *anas) { static int16_t anas2[NUM_STICKS]; // values before expo, to ensure same expo base when multiple expo lines are used memcpy(anas2, anas, sizeof(anas2)); - uint8_t phase = s_perout_flight_phase + 1; + uint8_t phase = s_perout_flight_phase + 1; int8_t cur_chn = -1; for (uint8_t i=0; i=0 && k<8) { // && (event & _MSK_KEY_REPT)) //LH_DWN LH_UP LV_DWN LV_UP RV_DWN RV_UP RH_DWN RH_UP uint8_t idx = CONVERT_MODE(1+k/2) - 1; - uint8_t phase = getTrimFlightPhase(s_perout_flight_phase, idx); + uint8_t phase = getTrimFlightPhase(s_perout_flight_phase, idx); int16_t before = getRawTrimValue(phase, idx); int8_t v = (s==0) ? min(32, abs(before)/4+1) : 1 << (s-1); // 1=>1 2=>2 3=>4 4=>8 bool thro = (idx==THR_STICK && g_model.thrTrim); @@ -1161,26 +1161,26 @@ void getADC_filt() void getADC_osmp() { - uint16_t temp_ana; - - for (uint8_t adc_input=0; adc_input<8; adc_input++) { - temp_ana = 0; - ADMUX = adc_input|ADC_VREF_TYPE; + uint16_t temp_ana; + + for (uint8_t adc_input=0; adc_input<8; adc_input++) { + temp_ana = 0; + ADMUX = adc_input|ADC_VREF_TYPE; for (uint8_t i=0; i<4;i++) { // Going from 10bits to 11 bits. Addition = n. Loop 4^n times // Start the AD conversion ADCSRA|=0x40; // Wait for the AD conversion to complete while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; - temp_ana += ADCW; + temp_ana += ADCW; } - s_anaFilt[adc_input] = temp_ana / 2; // divide by 2^n to normalize result. + s_anaFilt[adc_input] = temp_ana / 2; // divide by 2^n to normalize result. } } void getADC_single() { - for (uint8_t adc_input=0; adc_input<8; adc_input++) { + for (uint8_t adc_input=0; adc_input<8; adc_input++) { ADMUX=adc_input|ADC_VREF_TYPE; // Start the AD conversion ADCSRA|=0x40; @@ -1192,7 +1192,7 @@ void getADC_single() } #endif -#if not defined(PCBARM) +#if not defined(PCBARM) void getADC_bandgap() { #if defined (PCBV4) @@ -1316,7 +1316,7 @@ int32_t act [MAX_MIXERS] = {0}; uint8_t swOn [MAX_MIXERS] = {0}; uint8_t mixWarning; -FORCEINLINE void evalTrims() +FORCEINLINE void evalTrims() { uint8_t phase = s_perout_flight_phase; for (uint8_t i=0; i 0) { trim = 0; @@ -1347,7 +1347,7 @@ enum PerOutMode { uint8_t s_perout_mode = e_perout_mode_normal; -BeepANACenter evalSticks() +BeepANACenter evalSticks() { BeepANACenter anaCenter = 0; @@ -1385,10 +1385,10 @@ BeepANACenter evalSticks() if(v < -RESX) v = -RESX; if(v > RESX) v = RESX; - - if (g_eeGeneral.throttleReversed && ch==THR_STICK) - v = -v; - + + if (g_eeGeneral.throttleReversed && ch==THR_STICK) + v = -v; + if (i < NUM_STICKS+NUM_POTS) calibratedStick[ch] = v; //for show in expo @@ -1421,17 +1421,17 @@ BeepANACenter evalSticks() } /* EXPOs */ - applyExpos(anas); + applyExpos(anas); /* TRIMs */ - evalTrims(); + evalTrims(); return anaCenter; } #ifdef DEBUG /* - * This is a test function for debugging purpose, you may insert there your code and compile with the option DEBUG=YES + * This is a test function for debugging purpose, you may insert there your code and compile with the option DEBUG=YES */ void testFunc() { @@ -1549,9 +1549,9 @@ void evalFunctions() } uint8_t s_perout_flight_phase; -void perOut() +void perOut() { - BeepANACenter anaCenter = evalSticks(); + BeepANACenter anaCenter = evalSticks(); if (s_perout_mode == e_perout_mode_normal) { //===========BEEP CENTER================ @@ -1798,9 +1798,9 @@ void perOut() mixWarning = lv_mixWarning; } -#ifdef DISPLAY_USER_DATA -char userDataDisplayBuf[TELEM_SCREEN_BUFFER_SIZE]; -#endif +#ifdef DISPLAY_USER_DATA +char userDataDisplayBuf[TELEM_SCREEN_BUFFER_SIZE]; +#endif #if (defined(PCBARM) && !defined(REVA) && !defined(SIMU)) || (defined(PCBV4) && !defined(REV0) && !defined(SIMU)) #define TIME_TO_WRITE (s_eeDirtyMsk && (get_tmr10ms() - s_eeDirtyTime10ms) >= WRITE_DELAY_10MS) @@ -1808,7 +1808,7 @@ char userDataDisplayBuf[TELEM_SCREEN_BUFFER_SIZE]; #define TIME_TO_WRITE s_eeDirtyMsk #endif -int32_t sum_chans512[NUM_CHNOUT] = {0}; +int32_t sum_chans512[NUM_CHNOUT] = {0}; void perMain() { static uint16_t lastTMR; @@ -1817,51 +1817,51 @@ void perMain() lastTMR = tmr10ms; #define MAX_ACT 0xffff - static uint16_t fp_act[MAX_PHASES] = {0}; - static uint16_t delta = 0; - static uint8_t s_fade_flight_phases = 0; + static uint16_t fp_act[MAX_PHASES] = {0}; + static uint16_t delta = 0; + static uint8_t s_fade_flight_phases = 0; static uint8_t s_last_phase = 255; uint8_t phase = getFlightPhase(); int32_t weight = 0; - if (s_last_phase != phase) { - if (s_last_phase == 255) { - fp_act[phase] = MAX_ACT; + if (s_last_phase != phase) { + if (s_last_phase == 255) { + fp_act[phase] = MAX_ACT; } - else { - uint8_t fadeTime = max(g_model.phaseData[s_last_phase].fadeOut, g_model.phaseData[phase].fadeIn); + else { + uint8_t fadeTime = max(g_model.phaseData[s_last_phase].fadeOut, g_model.phaseData[phase].fadeIn); if (fadeTime) { - s_fade_flight_phases |= (1< delta) - fp_act[p] += delta; - else { - fp_act[p] = MAX_ACT; - s_fade_flight_phases -= (1< delta) - fp_act[p] -= delta; - else { - fp_act[p] = 0; - s_fade_flight_phases -= (1< delta) + fp_act[p] += delta; + else { + fp_act[p] = MAX_ACT; + s_fade_flight_phases -= (1< delta) + fp_act[p] -= delta; + else { + fp_act[p] = 0; + s_fade_flight_phases -= (1< 20) - { - for (int xx=0; xx<20; xx++) // scroll one char left - userDataDisplayBuf[xx] = userDataDisplayBuf[xx+1]; - displayBufferIndex = 20; - } - userDataDisplayBuf[displayBufferIndex] = userDataRxBuffer[byt]; - - // Write the raw byte out to log file, if open - if (testLogOpen && (g_oLogFile.fs != 0)) - f_putc(userDataRxBuffer[byt], &g_oLogFile); - - } -#endif - + char userDataRxBuffer[21]; // Temp buffer used to collect fr-sky user data + + // retrieve bytes from user data buffer and insert into display string, + // scrolling at the 21 character mark (edge of screen) + uint8_t numbytes = frskyGetUserData(userDataRxBuffer, 21); // Get as many bytes as we can + + static uint8_t displayBufferIndex; + for (uint8_t byt=0; byt < numbytes; byt++) + { + displayBufferIndex++; + if (displayBufferIndex > 20) + { + for (int xx=0; xx<20; xx++) // scroll one char left + userDataDisplayBuf[xx] = userDataDisplayBuf[xx+1]; + displayBufferIndex = 20; + } + userDataDisplayBuf[displayBufferIndex] = userDataRxBuffer[byt]; + + // Write the raw byte out to log file, if open + if (testLogOpen && (g_oLogFile.fs != 0)) + f_putc(userDataRxBuffer[byt], &g_oLogFile); + + } +#endif + lcd_clear(); uint8_t evt = getEvent(); evt = checkTrim(evt); @@ -2153,23 +2153,23 @@ void perMain() else { PIOC->PIO_PER = PIO_PC22 ; // Enable bit C22 as input } -#elif defined(PCBV4) +#elif defined(PCBV4) + // PPM signal on phono-jack. In or out? ... + if(checkSlaveMode()) { + PORTG |= (1<4000 && val < 16000) // G: Prioritize reset pulse. (Needed when less than 8 incoming pulses) + if (val>4000 && val < 16000) // G: Prioritize reset pulse. (Needed when less than 8 incoming pulses) ppmInState = 1; // triggered else { @@ -2352,7 +2352,7 @@ ISR(TIMER3_CAPT_vect) // G: High frequency noise can cause stack overflo with IS lastCapt = capture; - cli(); // disable other interrupts for stack pops before this function's RETI + cli(); // disable other interrupts for stack pops before this function's RETI #if defined (PCBV4) TIMSK3 |= (1< 0) { - UDR0 = frskyTxBuffer[--frskyTxBufferCount]; - } - else { - UCSR0B &= ~(1 << UDRIE0); // disable UDRE0 interrupt - } -} -#endif - -#if defined (DSM2_SERIAL) && !defined(PCBARM) -FORCEINLINE void DSM2_USART0_vect() -{ - UDR0 = *((uint16_t*)pulses2MHzRPtr); - pulses2MHzRPtr += sizeof(uint16_t); - if (pulses2MHzRPtr == pulses2MHzWPtr) { - UCSR0B &= ~(1 << UDRIE0); // disable UDRE0 interrupt - } -} -#endif - -#if !defined(SIMU) && !defined(PCBARM) -#if defined (FRSKY) or defined(DSM2_SERIAL) -ISR(USART0_UDRE_vect) -{ -#if defined (FRSKY) and defined (DSM2_SERIAL) - if (g_model.protocol == PROTO_DSM2) { - DSM2_USART0_vect(); - } - else { - FRSKY_USART0_vect(); - } -#elif defined (FRSKY) - FRSKY_USART0_vect(); -#else - DSM2_USART0_vect(); -#endif -} -#endif +#if defined (FRSKY) && !defined(PCBARM) +FORCEINLINE void FRSKY_USART0_vect() +{ + if (frskyTxBufferCount > 0) { + UDR0 = frskyTxBuffer[--frskyTxBufferCount]; + } + else { + UCSR0B &= ~(1 << UDRIE0); // disable UDRE0 interrupt + } +} +#endif + +#if defined (DSM2_SERIAL) && !defined(PCBARM) +FORCEINLINE void DSM2_USART0_vect() +{ + UDR0 = *((uint16_t*)pulses2MHzRPtr); + + pulses2MHzRPtr += sizeof(uint16_t); + if (pulses2MHzRPtr == pulses2MHzWPtr) { + UCSR0B &= ~(1 << UDRIE0); // disable UDRE0 interrupt + } +} +#endif + +#if !defined(SIMU) && !defined(PCBARM) +#if defined (FRSKY) or defined(DSM2_SERIAL) +ISR(USART0_UDRE_vect) +{ +#if defined (FRSKY) and defined (DSM2_SERIAL) + if (g_model.protocol == PROTO_DSM2) { + DSM2_USART0_vect(); + } + else { + FRSKY_USART0_vect(); + } +#elif defined (FRSKY) + FRSKY_USART0_vect(); +#else + DSM2_USART0_vect(); +#endif +} +#endif #endif void instantTrim() @@ -2448,9 +2448,9 @@ void instantTrim() for (uint8_t i=0; i>> p\206esko\201it" #define TR_THROTTLENOTIDLE "P\200ka plynu je pohnut\200." -#define TR_ALARMSDISABLED "Alarmy Zak\200z\200ny" +#define TR_ALARMSDISABLED "Alarmy jsou zak\200z\200ny" #define TR_PRESSANYKEY "\003Stiskni Kl\200vesu" #define TR_BADEEPROMDATA "\003Chyba dat EEprom" #define TR_EEPROMFORMATTING " Formatov\200n\204 EEPROM" @@ -392,8 +392,8 @@ #define TR_RESTORE_MODEL "Restore Model" #define TR_SDCARD_ERROR "SDCARD Error" #define TR_NO_SDCARD "No SDCARD" -#define TR_WARNING "WARNING" +#define TR_WARNING "KONTROLA" #define TR_EEPROMWARN "EEPROM" -#define TR_THROTTLEWARN "THROTTLE" -#define TR_ALARMSWARN "ALARMS" -#define TR_SWITCHWARN "SWITCH" +#define TR_THROTTLEWARN "PLYNU" +#define TR_ALARMSWARN "ALARMU" +#define TR_SWITCHWARN "POZICE"