From e84ece8055cb781e5d9d13f10e78aba30d7000e3 Mon Sep 17 00:00:00 2001 From: bsongis Date: Fri, 10 Aug 2012 20:34:33 +0000 Subject: [PATCH] Issue 67 fixed (comma missing!) Issue 63 fixed (InstantTrim, Trims2Ofs to double check before release) Issue 68 fixed (better names for vario sources) [gruvin] 2 digits for voltage calibration --- src/ersky9x/audio.cpp | 2 +- src/general_menus.cpp | 8 ++ src/main_views.cpp | 2 +- src/model_menus.cpp | 12 ++- src/open9x.cpp | 186 +++++++++++++++++++++--------------------- src/open9x.h | 13 +++ src/rotarysw.cpp | 2 +- src/translations/cz.h | 4 +- src/translations/de.h | 4 +- src/translations/en.h | 4 +- src/translations/fr.h | 4 +- src/translations/it.h | 4 +- src/translations/se.h | 4 +- 13 files changed, 141 insertions(+), 108 deletions(-) diff --git a/src/ersky9x/audio.cpp b/src/ersky9x/audio.cpp index d5d00c221..f75a03415 100644 --- a/src/ersky9x/audio.cpp +++ b/src/ersky9x/audio.cpp @@ -39,7 +39,7 @@ const char * audioFilenames[] = { "thralert", "swalert", "eebad", - "eeformat" + "eeformat", "error", "keyup", "keydown", diff --git a/src/general_menus.cpp b/src/general_menus.cpp index 76fb66923..b98c32def 100644 --- a/src/general_menus.cpp +++ b/src/general_menus.cpp @@ -806,7 +806,15 @@ void menuProcDiagAna(uint8_t event) // Voltage calibration lcd_putsLeft(6*FH-2, STR_BATT_CALIB); +#if defined (PCBV4) + // Gruvin wants 2 decimal places and instant update of volts calib field when button pressed + static uint16_t adcBatt; + adcBatt = ((adcBatt * 7) + anaIn(7)) / 8; // running average, sourced directly (to avoid unending debate :P) + uint32_t batCalV = ((uint32_t)adcBatt*1390 + (10*(int32_t)adcBatt*g_eeGeneral.vBatCalib)/8) / BandGap; + lcd_outdezNAtt(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, batCalV, PREC2|(m_posVert==1 ? INVERS : 0)); +#else putsVolts(LEN_CALIB_FIELDS*FW+4*FW, 6*FH-2, g_vbat100mV, (m_posVert==1 ? INVERS : 0)); +#endif if (m_posVert==1) CHECK_INCDEC_GENVAR(event, g_eeGeneral.vBatCalib, -127, 127); #if defined(PCBARM) && defined(REVB) diff --git a/src/main_views.cpp b/src/main_views.cpp index 5832be35d..2182fa2cd 100644 --- a/src/main_views.cpp +++ b/src/main_views.cpp @@ -200,7 +200,7 @@ void menuMainView(uint8_t event) uint8_t phase = s_perout_flight_phase; lcd_putsnAtt(6*FW, 2*FH, g_model.phaseData[phase].name, sizeof(g_model.phaseData[phase].name), ZCHAR); - uint8_t att = (g_vbat100mV < g_eeGeneral.vBatWarn ? BLINK|INVERS : 0) | DBLSIZE; + uint8_t att = (g_vbat100mV <= g_eeGeneral.vBatWarn ? BLINK|INVERS : 0) | DBLSIZE; putsModelName(2*FW-2, 0*FH, g_model.name, g_eeGeneral.currModel, DBLSIZE); putsVBat(6*FW-1, 2*FH, att|NO_UNIT); lcd_putc(6*FW, 3*FH, 'V'); diff --git a/src/model_menus.cpp b/src/model_menus.cpp index b06ef4655..03447ec3e 100644 --- a/src/model_menus.cpp +++ b/src/model_menus.cpp @@ -2107,9 +2107,19 @@ void menuProcLimits(uint8_t _event) } } else if (attr && event==EVT_KEY_LONG(KEY_MENU)) { - int16_t zero = g_chans512[k]; pauseMixerCalculations(); + int32_t zero = (int32_t)g_chans512[k]; + s_perout_mode = e_perout_mode_nosticks+e_perout_mode_notrainer; + perOut(0); + int32_t chan = chans[k]; + int8_t lim = ld->max+100; + if (chan < 0) { + chan = -chan; + lim = ld->min-100; + } + zero = (zero*100000 - 10*chan*lim) / (102400 - chan); ld->offset = (ld->revert) ? -zero : zero; + s_perout_mode = e_perout_mode_normal; resumeMixerCalculations(); s_editMode = 0; STORE_MODELVARS; diff --git a/src/open9x.cpp b/src/open9x.cpp index 56fd93fb7..072f39f87 100644 --- a/src/open9x.cpp +++ b/src/open9x.cpp @@ -1399,16 +1399,18 @@ void getADC_single() void getADC_bandgap() { #if defined (PCBV4) - // For times over-sample with no divide, x2 to end at a half averaged, x8. DON'T ASK mmmkay? :P This is how I want it. - ADCSRA|=0x40; while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; - BandGap=ADCW; - ADCSRA|=0x40; while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; - BandGap+=ADCW; - ADCSRA|=0x40; while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; - BandGap+=ADCW; - ADCSRA|=0x40; while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; - BandGap+=ADCW; - BandGap *= 2; + static uint8_t s_bgCheck = 0; + static uint16_t s_bgSum = 0; + ADCSRA|=0x40; // request sample + s_bgCheck += 32; + while ((ADCSRA & 0x10)==0); ADCSRA|=0x10; // wait for sample + if (s_bgCheck == 0) { // 8x over-sample (256/32=8) + BandGap = s_bgSum+ADCW; + s_bgSum = 0; + } + else { + s_bgSum += ADCW; + } ADCSRB |= (1<mode) { @@ -1919,72 +1914,72 @@ void perOut(uint8_t tick10ms) anaCenter &= g_model.beepANACenter; if(((bpanaCenter ^ anaCenter) & anaCenter)) AUDIO_POT_STICK_MIDDLE(); bpanaCenter = anaCenter; + } #ifdef HELI - if(g_model.swashR.value) + if(g_model.swashR.value) + { + uint32_t v = ((int32_t)anas[ELE_STICK]*anas[ELE_STICK] + (int32_t)anas[AIL_STICK]*anas[AIL_STICK]); + uint32_t q = (int32_t)RESX*g_model.swashR.value/100; + q *= q; + if(v>q) { - uint32_t v = ((int32_t)anas[ELE_STICK]*anas[ELE_STICK] + (int32_t)anas[AIL_STICK]*anas[AIL_STICK]); - uint32_t q = (int32_t)RESX*g_model.swashR.value/100; - q *= q; - if(v>q) - { - uint16_t d = isqrt32(v); - anas[ELE_STICK] = (int32_t)anas[ELE_STICK]*g_model.swashR.value*RESX/((int32_t)d*100); - anas[AIL_STICK] = (int32_t)anas[AIL_STICK]*g_model.swashR.value*RESX/((int32_t)d*100); - } + uint16_t d = isqrt32(v); + anas[ELE_STICK] = (int32_t)anas[ELE_STICK]*g_model.swashR.value*RESX/((int32_t)d*100); + anas[AIL_STICK] = (int32_t)anas[AIL_STICK]*g_model.swashR.value*RESX/((int32_t)d*100); } + } #define REZ_SWASH_X(x) ((x) - (x)/8 - (x)/128 - (x)/512) // 1024*sin(60) ~= 886 #define REZ_SWASH_Y(x) ((x)) // 1024 => 1024 - if(g_model.swashR.type) + if(g_model.swashR.type) + { + int16_t vp = anas[ELE_STICK]+trims[ELE_STICK]; + int16_t vr = anas[AIL_STICK]+trims[AIL_STICK]; + int16_t vc = 0; + if (g_model.swashR.collectiveSource) + vc = getValue(g_model.swashR.collectiveSource-1); + + if(g_model.swashR.invertELE) vp = -vp; + if(g_model.swashR.invertAIL) vr = -vr; + if(g_model.swashR.invertCOL) vc = -vc; + + switch (g_model.swashR.type) { - int16_t vp = anas[ELE_STICK]+trims[ELE_STICK]; - int16_t vr = anas[AIL_STICK]+trims[AIL_STICK]; - int16_t vc = 0; - if (g_model.swashR.collectiveSource) - vc = getValue(g_model.swashR.collectiveSource-1); - - if(g_model.swashR.invertELE) vp = -vp; - if(g_model.swashR.invertAIL) vr = -vr; - if(g_model.swashR.invertCOL) vc = -vc; - - switch (g_model.swashR.type) - { - case (SWASH_TYPE_120): - vp = REZ_SWASH_Y(vp); - vr = REZ_SWASH_X(vr); - cyc_anas[0] = vc - vp; - cyc_anas[1] = vc + vp/2 + vr; - cyc_anas[2] = vc + vp/2 - vr; - break; - case (SWASH_TYPE_120X): - vp = REZ_SWASH_X(vp); - vr = REZ_SWASH_Y(vr); - cyc_anas[0] = vc - vr; - cyc_anas[1] = vc + vr/2 + vp; - cyc_anas[2] = vc + vr/2 - vp; - break; - case (SWASH_TYPE_140): - vp = REZ_SWASH_Y(vp); - vr = REZ_SWASH_Y(vr); - cyc_anas[0] = vc - vp; - cyc_anas[1] = vc + vp + vr; - cyc_anas[2] = vc + vp - vr; - break; - case (SWASH_TYPE_90): - vp = REZ_SWASH_Y(vp); - vr = REZ_SWASH_Y(vr); - cyc_anas[0] = vc - vp; - cyc_anas[1] = vc + vr; - cyc_anas[2] = vc - vr; - break; - default: - break; - } + case SWASH_TYPE_120: + vp = REZ_SWASH_Y(vp); + vr = REZ_SWASH_X(vr); + cyc_anas[0] = vc - vp; + cyc_anas[1] = vc + vp/2 + vr; + cyc_anas[2] = vc + vp/2 - vr; + break; + case SWASH_TYPE_120X: + vp = REZ_SWASH_X(vp); + vr = REZ_SWASH_Y(vr); + cyc_anas[0] = vc - vr; + cyc_anas[1] = vc + vr/2 + vp; + cyc_anas[2] = vc + vr/2 - vp; + break; + case SWASH_TYPE_140: + vp = REZ_SWASH_Y(vp); + vr = REZ_SWASH_Y(vr); + cyc_anas[0] = vc - vp; + cyc_anas[1] = vc + vp + vr; + cyc_anas[2] = vc + vp - vr; + break; + case SWASH_TYPE_90: + vp = REZ_SWASH_Y(vp); + vr = REZ_SWASH_Y(vr); + cyc_anas[0] = vc - vp; + cyc_anas[1] = vc + vr; + cyc_anas[2] = vc - vr; + break; + default: + break; } -#endif } +#endif memclear(chans, sizeof(chans)); // All outputs to 0 @@ -2016,8 +2011,15 @@ void perOut(uint8_t tick10ms) uint8_t k = md->srcRaw-1; int16_t v = 0; if (s_perout_mode != e_perout_mode_normal) { - if (!sw || k >= NUM_STICKS || (k == THR_STICK && g_model.thrTrim)) + if (!sw || k >= NUM_STICKS || (k == THR_STICK && g_model.thrTrim)) { + printf("CONTINUE\n"); continue; + } + else { + printf("LIGNE AJOUTEE\n"); + if (!(s_perout_mode & e_perout_mode_nosticks)) + v = anas[k]; + } } else { if (k < NUM_STICKS) @@ -2093,8 +2095,21 @@ void perOut(uint8_t tick10ms) //========== OFFSET =============== if (apply_offset && md->sOffset) v += calc100toRESX(md->sOffset); + //========== TRIMS =============== + if (!(s_perout_mode & e_perout_mode_notrims)) { + int8_t mix_trim = md->carryTrim; + if (mix_trim < TRIM_ON) + mix_trim = -mix_trim-1; + else if (mix_trim == TRIM_ON && k < NUM_STICKS) + mix_trim = k; + else + mix_trim = -1; + if (mix_trim >= 0) + v += trims[mix_trim]; + } + //========== SPEED =============== - if (s_perout_mode==e_perout_mode_normal && (md->speedUp || md->speedDown)) // there are delay values + if (s_perout_mode == e_perout_mode_normal && (md->speedUp || md->speedDown)) // there are delay values { #define DEL_MULT 256 @@ -2125,19 +2140,6 @@ void perOut(uint8_t tick10ms) if (md->curve) v = applyCurve(v, md->curve); - //========== TRIMS =============== - if (s_perout_mode < e_perout_mode_zeros) { - int8_t mix_trim = md->carryTrim; - if (mix_trim < TRIM_ON) - mix_trim = -mix_trim-1; - else if (mix_trim == TRIM_ON && k < NUM_STICKS) - mix_trim = k; - else - mix_trim = -1; - if (mix_trim >= 0) - v += trims[mix_trim]; - } - //========== MULTIPLEX =============== int32_t dv = (int32_t)v*md->weight; @@ -2640,7 +2642,7 @@ void perMain() else if (s_batCheck == 0) { g_vbat100mV = s_batSum / 8; s_batSum = 0; - if (g_vbat100mV50) { + if (g_vbat100mV <= g_eeGeneral.vBatWarn && g_vbat100mV>50) { AUDIO_TX_BATTERY_LOW(); } } @@ -2926,7 +2928,7 @@ void instantTrim() if (i!=THR_STICK) { // don't instant trim the throttle stick uint8_t trim_phase = getTrimFlightPhase(s_perout_flight_phase, i); - s_perout_mode = e_instant_trim; + s_perout_mode = e_perout_mode_notrainer; evalSticks(); s_perout_mode = e_perout_mode_normal; int16_t trim = (anas[i] + trims[i]) / 2; @@ -2948,13 +2950,13 @@ void moveTrimsToOffsets() // copy state of 3 primary to subtrim { int16_t zeros[NUM_CHNOUT]; - s_perout_mode = e_perout_mode_zeros; + s_perout_mode = e_perout_mode_noinput; perOut(0); // do output loop - zero input sticks and trims for (uint8_t i=0; i