diff --git a/src/gruvin9x.cpp b/src/gruvin9x.cpp index b40450d7b..a70388ee4 100644 --- a/src/gruvin9x.cpp +++ b/src/gruvin9x.cpp @@ -757,51 +757,46 @@ uint16_t anaIn(uint8_t chan) #define ADC_VREF_TYPE 0x40 // AVCC with external capacitor at AREF pin void getADC_filt() { - static uint16_t t_ana[3][8]; - for (uint8_t adc_input=0;adc_input<8;adc_input++) - { + static uint16_t t_ana[2][8]; + for (uint8_t adc_input=0; adc_input<8; adc_input++) { ADMUX=adc_input|ADC_VREF_TYPE; // Start the AD conversion ADCSRA|=0x40; + + // Do this while waiting + s_anaFilt[adc_input] = (s_anaFilt[adc_input]/2 + t_ana[1][adc_input]) & 0xFFFE; //gain of 2 on last conversion - clear last bit + t_ana[1][adc_input] = (t_ana[1][adc_input] + t_ana[0][adc_input]) >> 1; + // Wait for the AD conversion to complete while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; - s_anaFilt[adc_input] = (s_anaFilt[adc_input]/2 + t_ana[1][adc_input]) & 0xFFFE; //gain of 2 on last conversion - clear last bit - //t_ana[2][adc_input] = (t_ana[2][adc_input] + t_ana[1][adc_input]) >> 1; - t_ana[1][adc_input] = (t_ana[1][adc_input] + t_ana[0][adc_input]) >> 1; t_ana[0][adc_input] = (t_ana[0][adc_input] + ADCW ) >> 1; } } -/* - s_anaFilt[chan] = (s_anaFilt[chan] + sss_ana[chan]) >> 1; - sss_ana[chan] = (sss_ana[chan] + ss_ana[chan]) >> 1; - ss_ana[chan] = (ss_ana[chan] + s_ana[chan]) >> 1; - s_ana[chan] = (ADC + s_ana[chan]) >> 1; - */ void getADC_osmp() { - uint16_t temp_ana[8] = {0}; - for (uint8_t adc_input=0;adc_input<8;adc_input++) - { - ADMUX=adc_input|ADC_VREF_TYPE; // TODO now it is done only one time before the loop, is it good? + 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[adc_input] += ADCW; + temp_ana += ADCW; } - s_anaFilt[adc_input] = temp_ana[adc_input] / 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; @@ -812,13 +807,20 @@ void getADC_single() } } +getADCp getADC[3] = { + getADC_single, + getADC_osmp, + getADC_filt +}; + void getADC_bandgap() { #if defined(PCBSTD) ADMUX=0x1E|ADC_VREF_TYPE; // Switch MUX to internal 1.22V reference - _delay_us(10); // short delay to stablise reference voltage - ADCSRA|=0x40; while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; // grab a sample - ADCSRA|=0x40; while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; // grab a sample + _delay_us(5); // short delay to stablise reference voltage + ADCSRA|=0x40; + while ((ADCSRA & 0x10)==0); + ADCSRA|=0x10; // grab a sample BandGap=ADCW; #elif defined (PCBV4) // For PCB V4, use our own 1.2V, external reference (connected to ADC3) @@ -846,11 +848,6 @@ void getADC_bandgap() #endif } -getADCp getADC[3] = { - getADC_single, - getADC_osmp, - getADC_filt -}; #else uint16_t BandGap = 225; #endif @@ -1104,9 +1101,9 @@ inline void evalTrims() int32_t vv = 2*RESX; int16_t trim = getTrimValue(getTrimFlightPhase(i), i); if (IS_THROTTLE(i) && g_model.thrTrim) { - vv = (g_eeGeneral.throttleReversed) ? - ((int32_t)trim+TRIM_MIN)*(RESX+v)/(2*RESX) : - ((int32_t)trim-TRIM_MIN)*(RESX-v)/(2*RESX); + if (g_eeGeneral.throttleReversed) + trim = -trim; + vv = ((int32_t)trim-TRIM_MIN)*(RESX-v)/(2*RESX); } else if (trimsCheckTimer > 0) { trim = 0; @@ -1147,6 +1144,10 @@ uint8_t evalSticks() if(v <= -RESX) v = -RESX; if(v >= RESX) v = RESX; + + if (g_eeGeneral.throttleReversed && i==THR_STICK) + v = -v; + calibratedStick[i] = v; //for show in expo if(!(v/16)) anaCenter |= 1<<(CONVERT_MODE((i+1))-1); @@ -1367,13 +1368,15 @@ void perOut(int16_t *chanOut) if(diff) sDelay[i] = (diff<0 ? md->delayUp : md->delayDown) * 100; } - if(sDelay[i]){ // perform delay - if(tick10ms) sDelay[i]--; - v = act[i]/DEL_MULT; + if (sDelay[i]) { // perform delay + if(tick10ms) sDelay[i]--; + if (sDelay[i] != 0) { + v = act[i]/DEL_MULT; // Stay in old position until delay over diff = 0; + } } - if(diff && (md->speedUp || md->speedDown)){ + if (diff && (md->speedUp || md->speedDown)) { //rate = steps/sec => 32*1024/100*md->speedUp/Down //act[i] += diff>0 ? (32768)/((int16_t)100*md->speedUp) : -(32768)/((int16_t)100*md->speedDown); //-100..100 => 32768 -> 100*83886/256 = 32768, For MAX we divide by 2 sincde it's asymmetrical @@ -1387,6 +1390,9 @@ void perOut(int16_t *chanOut) if(((diff>0) && (v<(act[i]/DEL_MULT))) || ((diff<0) && (v>(act[i]/DEL_MULT)))) act[i]=(int32_t)v*DEL_MULT; //deal with overflow v = act[i]/DEL_MULT; } + else if (diff) { + act[i]=(int32_t)v*DEL_MULT; + } } //========== CURVES =============== diff --git a/src/model_menus.cpp b/src/model_menus.cpp index b13589854..c2b37b061 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -373,10 +373,10 @@ void EditName(uint8_t x, uint8_t y, char *name, uint8_t size, uint8_t event, boo } } -#define PARAM_OFS (9*FW) +#define PARAM_OFS (9*FW+2) void menuProcModel(uint8_t event) { - MENU("SETUP", menuTabModel, e_Model, 10, {0,sizeof(g_model.name)-1,3,3,0,0,0,1,6,3}); + MENU("SETUP", menuTabModel, e_Model, (g_model.protocol ? 10 : 11), {0,sizeof(g_model.name)-1,3,3,0,0,0,1,6,2,1}); uint8_t sub = m_posVert; uint8_t y = 1*FH; @@ -468,7 +468,7 @@ void menuProcModel(uint8_t event) if(s_pgOfs7*FH) return; + }subN++; + + if(s_pgOfs7*FH) return; + } + else { + + } } } diff --git a/src/myeeprom.h b/src/myeeprom.h index 93cfb4fed..26f654a20 100644 --- a/src/myeeprom.h +++ b/src/myeeprom.h @@ -253,7 +253,8 @@ typedef struct t_ModelData { FuncSwData funcSw[NUM_FSW]; SwashRingData swashR; PhaseData phaseData[MAX_PHASES]; - FrSkyData frsky; + FrSkyData frsky; + int8_t ppmFrameLength; // 0=22.5ms (10ms-30ms) 0.5msec increments } __attribute__((packed)) ModelData; extern EEGeneral g_eeGeneral; diff --git a/src/pers.cpp b/src/pers.cpp index a5c684040..c8896c6d1 100644 --- a/src/pers.cpp +++ b/src/pers.cpp @@ -204,6 +204,7 @@ uint8_t Translate() } for (uint8_t i=0; i9) rest=p*(1720u*2 + q) + 4000u*2; //for more than 9 channels, frame must be longer for (uint8_t i=0; i vSTK @@ -107,39 +123,39 @@ void applyTemplate(uint8_t idx) for(uint8_t i=1; i<=4; i++) //generate inverse array for(uint8_t j=1; j<=4; j++) if(CC(i)==j) icc[j-1]=i; - switch (idx){ - //Simple 4-Ch - case (0): + // Simple 4-Ch + case (0): + clearMixes(); md=setDest(ICC(STK_RUD)); md->srcRaw=CM(STK_RUD); md->weight=100; md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_ELE); md->weight=100; md=setDest(ICC(STK_THR)); md->srcRaw=CM(STK_THR); md->weight=100; md=setDest(ICC(STK_AIL)); md->srcRaw=CM(STK_AIL); md->weight=100; break; - //T-Cut - case (1): + // T-Cut + case (1): md=setDest(ICC(STK_THR)); md->srcRaw=MIX_MAX; md->weight=-100; md->swtch=DSW_THR; md->mltpx=MLTPX_REP; break; - //V-Tail - case (2): + // V-Tail + case (2): md=setDest(ICC(STK_RUD)); md->srcRaw=CM(STK_RUD); md->weight= 100; md=setDest(ICC(STK_RUD)); md->srcRaw=CM(STK_ELE); md->weight=-100; md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_RUD); md->weight= 100; md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_ELE); md->weight= 100; break; - //Elevon\\Delta - case (3): + // Elevon\\Delta + case (3): md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_ELE); md->weight= 100; md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_AIL); md->weight= 100; md=setDest(ICC(STK_AIL)); md->srcRaw=CM(STK_ELE); md->weight= 100; md=setDest(ICC(STK_AIL)); md->srcRaw=CM(STK_AIL); md->weight=-100; break; - //eCCPM - case (4): + // eCCPM + case (4): md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_ELE); md->weight= 72; md=setDest(ICC(STK_ELE)); md->srcRaw=CM(STK_THR); md->weight= 55; md=setDest(ICC(STK_AIL)); md->srcRaw=CM(STK_ELE); md->weight=-36; @@ -150,8 +166,8 @@ void applyTemplate(uint8_t idx) md=setDest(6); md->srcRaw=CM(STK_THR); md->weight= 55; break; - //Heli Setup - case (5): + // Heli Setup + case (5): clearMixes(); //This time we want a clean slate clearCurves(); @@ -186,15 +202,15 @@ void applyTemplate(uint8_t idx) md=setDest(11); md->srcRaw=CM(STK_THR); md->weight=100; md->swtch=DSW_THR; md->curve=CV(5); md->carryTrim=TRIM_OFF; md->mltpx=MLTPX_REP; //Set up Curves - setCurve(CURVE5(1),heli_ar1); - setCurve(CURVE5(2),heli_ar2); - setCurve(CURVE5(3),heli_ar3); - setCurve(CURVE5(4),heli_ar4); - setCurve(CURVE5(5),heli_ar5); + setCurve(CURVE5(1), heli_ar1); + setCurve(CURVE5(2), heli_ar2); + setCurve(CURVE5(3), heli_ar3); + setCurve(CURVE5(4), heli_ar4); + setCurve(CURVE5(5), heli_ar5); break; - //Servo Test - case (6): + // Servo Test + case (6): md=setDest(15); md->srcRaw=CH(16); md->weight= 100; md->speedUp = 8; md->speedDown = 8; md=setDest(16); md->srcRaw=MIX_FULL; md->weight= 110; md->swtch=DSW_SW1; md=setDest(16); md->srcRaw=MIX_MAX; md->weight=-110; md->swtch=DSW_SW2; md->mltpx=MLTPX_REP; @@ -210,6 +226,6 @@ void applyTemplate(uint8_t idx) break; } - STORE_MODELVARS; + STORE_MODELVARS; }