From 3492b5d0a61f27ee048f0f2b0516180594225baa Mon Sep 17 00:00:00 2001 From: "bsongis@gmail.com" Date: Mon, 27 May 2013 17:36:01 +0000 Subject: [PATCH] Issue 41 fixed RSSI alarms thresholds now 45 and 42 instead of 50 --- src/gtests.cpp | 165 +++++++++++++++++++++++++++++++++---- src/gui/view_telemetry.cpp | 2 +- src/opentx.cpp | 38 +++++---- src/telemetry/frsky.h | 2 + 4 files changed, 171 insertions(+), 36 deletions(-) diff --git a/src/gtests.cpp b/src/gtests.cpp index 375dd9c37..c27ff7be0 100644 --- a/src/gtests.cpp +++ b/src/gtests.cpp @@ -38,6 +38,8 @@ #include #include "opentx.h" +#define CHANNEL_MAX (1024*256) + void doMixerCalculations(); #define MODEL_RESET() memset(&g_model, 0, sizeof(g_model)) @@ -329,7 +331,7 @@ TEST(Mixer, R2029Comment) simuSetSwitch(0, 1); perOut(e_perout_mode_normal, 0); EXPECT_EQ(chans[0], 0); - EXPECT_EQ(chans[1], 1024*256); + EXPECT_EQ(chans[1], CHANNEL_MAX); simuSetSwitch(0, 0); perOut(e_perout_mode_normal, 0); EXPECT_EQ(chans[0], 0); @@ -337,7 +339,7 @@ TEST(Mixer, R2029Comment) simuSetSwitch(0, 1); perOut(e_perout_mode_normal, 0); EXPECT_EQ(chans[0], 0); - EXPECT_EQ(chans[1], 1024*256); + EXPECT_EQ(chans[1], CHANNEL_MAX); } TEST(Mixer, Cascaded3Channels) @@ -355,9 +357,9 @@ TEST(Mixer, Cascaded3Channels) g_model.mixData[2].weight = 100; simuSetSwitch(0, 1); perOut(e_perout_mode_normal, 0); - EXPECT_EQ(chans[0], 1024*256); - EXPECT_EQ(chans[1], 1024*256); - EXPECT_EQ(chans[2], 1024*256); + EXPECT_EQ(chans[0], CHANNEL_MAX); + EXPECT_EQ(chans[1], CHANNEL_MAX); + EXPECT_EQ(chans[2], CHANNEL_MAX); } TEST(Mixer, CascadedOrderedChannels) @@ -372,8 +374,8 @@ TEST(Mixer, CascadedOrderedChannels) g_model.mixData[1].weight = 100; simuSetSwitch(0, 1); perOut(e_perout_mode_normal, 0); - EXPECT_EQ(chans[0], 1024*256); - EXPECT_EQ(chans[1], 1024*256); + EXPECT_EQ(chans[0], CHANNEL_MAX); + EXPECT_EQ(chans[1], CHANNEL_MAX); } TEST(Mixer, Cascaded5Channels) @@ -398,18 +400,18 @@ TEST(Mixer, Cascaded5Channels) for (uint8_t i=0; i<10; i++) { simuSetSwitch(0, 1); doMixerCalculations(); - EXPECT_EQ(chans[0], 1024*256); - EXPECT_EQ(chans[1], 1024*256); - EXPECT_EQ(chans[2], 1024*256); - EXPECT_EQ(chans[3], 1024*256); - EXPECT_EQ(chans[4], 1024*256); + EXPECT_EQ(chans[0], CHANNEL_MAX); + EXPECT_EQ(chans[1], CHANNEL_MAX); + EXPECT_EQ(chans[2], CHANNEL_MAX); + EXPECT_EQ(chans[3], CHANNEL_MAX); + EXPECT_EQ(chans[4], CHANNEL_MAX); simuSetSwitch(0, 0); doMixerCalculations(); - EXPECT_EQ(chans[0], -1024*256); - EXPECT_EQ(chans[1], -1024*256); - EXPECT_EQ(chans[2], -1024*256); - EXPECT_EQ(chans[3], -1024*256); - EXPECT_EQ(chans[4], -1024*256); + EXPECT_EQ(chans[0], -CHANNEL_MAX); + EXPECT_EQ(chans[1], -CHANNEL_MAX); + EXPECT_EQ(chans[2], -CHANNEL_MAX); + EXPECT_EQ(chans[3], -CHANNEL_MAX); + EXPECT_EQ(chans[4], -CHANNEL_MAX); } } @@ -459,10 +461,137 @@ TEST(Mixer, RecursiveAddChannel) g_model.mixData[2].srcRaw = MIXSRC_Rud; g_model.mixData[2].weight = 100; perOut(e_perout_mode_normal, 0); - EXPECT_EQ(chans[0], 1024*256/2); + EXPECT_EQ(chans[0], CHANNEL_MAX/2); EXPECT_EQ(chans[1], 0); } +TEST(Mixer, SlowOnSwitch) +{ + MODEL_RESET(); + MIXER_RESET(); + g_model.mixData[0].destCh = 0; + g_model.mixData[0].mltpx = MLTPX_ADD; + g_model.mixData[0].srcRaw = MIXSRC_MAX; + g_model.mixData[0].weight = 100; + g_model.mixData[0].swtch = SWSRC_THR; + g_model.mixData[0].speedUp = 10; + g_model.mixData[0].speedDown = 10; + + perOut(e_perout_mode_normal, 0); + EXPECT_EQ(chans[0], 0); + + simuSetSwitch(0, 1); + int32_t lastAct = 0; + for (int i=1; i<=250; i++) { + perOut(e_perout_mode_normal, 1); + lastAct = lastAct + (1<<19)/500; /* 100 on ARM */ + EXPECT_EQ(chans[0], 256 * (lastAct >> 8)); + } + + simuSetSwitch(0, 0); + for (int i=1; i<=250; i++) { + perOut(e_perout_mode_normal, 1); + lastAct = lastAct - (1<<19)/500; /* 100 on ARM */ + EXPECT_EQ(chans[0], 256 * (lastAct >> 8)); + } +} + +TEST(Mixer, SlowOnPhase) +{ + MODEL_RESET(); + MIXER_RESET(); + g_model.phaseData[1].swtch = SWSRC_THR; + g_model.mixData[0].destCh = 0; + g_model.mixData[0].mltpx = MLTPX_ADD; + g_model.mixData[0].srcRaw = MIXSRC_MAX; + g_model.mixData[0].weight = 100; + g_model.mixData[0].phases = 0x2 + 0x4 + 0x8 + 0x10 /*only enabled in phase 0*/; + g_model.mixData[0].speedUp = 10; + g_model.mixData[0].speedDown = 10; + + s_perout_flight_phase = 0; + perOut(e_perout_mode_normal, 0); + EXPECT_EQ(chans[0], 0); + + int32_t lastAct = 0; + for (int i=1; i<=250; i++) { + perOut(e_perout_mode_normal, 1); + lastAct = lastAct+(1<<19)/500; /* 100 on ARM */ + EXPECT_EQ(chans[0], 256 * (lastAct >> 8)); + } + + s_perout_flight_phase = 1; + for (int i=1; i<=250; i++) { + perOut(e_perout_mode_normal, 1); + lastAct = lastAct - (1<<19)/500; /* 100 on ARM */ + EXPECT_EQ(chans[0], 256 * (lastAct >> 8)); + } +} + +TEST(Mixer, SlowOnSwitchAndPhase) +{ + MODEL_RESET(); + MIXER_RESET(); + g_model.phaseData[1].swtch = SWSRC_THR; + g_model.mixData[0].destCh = 0; + g_model.mixData[0].mltpx = MLTPX_ADD; + g_model.mixData[0].srcRaw = MIXSRC_MAX; + g_model.mixData[0].weight = 100; + g_model.mixData[0].swtch = SWSRC_THR; + g_model.mixData[0].phases = 0x2 + 0x4 + 0x8 + 0x10 /*only enabled in phase 0*/; + g_model.mixData[0].speedUp = 10; + g_model.mixData[0].speedDown = 10; + + perOut(e_perout_mode_normal, 0); + EXPECT_EQ(chans[0], 0); + + simuSetSwitch(0, 1); + s_perout_flight_phase = 0; + int32_t lastAct = 0; + for (int i=1; i<=250; i++) { + perOut(e_perout_mode_normal, 1); + lastAct = lastAct+(1<<19)/500; /* 100 on ARM */ + EXPECT_EQ(chans[0], 256 * (lastAct >> 8)); + } + + simuSetSwitch(0, 0); + s_perout_flight_phase = 1; + for (int i=1; i<=250; i++) { + perOut(e_perout_mode_normal, 1); + lastAct = lastAct - (1<<19)/500; /* 100 on ARM */ + EXPECT_EQ(chans[0], 256 * (lastAct >> 8)); + } +} + +TEST(Mixer, SlowOnSwitchSource) +{ + MODEL_RESET(); + MIXER_RESET(); + g_model.mixData[0].destCh = 0; + g_model.mixData[0].mltpx = MLTPX_ADD; + g_model.mixData[0].srcRaw = MIXSRC_THR; + g_model.mixData[0].weight = 100; + g_model.mixData[0].speedUp = 10; + g_model.mixData[0].speedDown = 10; + + simuSetSwitch(0, 0); + int32_t lastAct = 0; + for (int i=1; i<=250; i++) { + perOut(e_perout_mode_normal, 1); + lastAct = lastAct - (1<<19)/500; /* 100 on ARM */ + EXPECT_EQ(chans[0], 256 * (lastAct >> 8)); + } + + EXPECT_EQ(chans[0], -CHANNEL_MAX); + + simuSetSwitch(0, 1); + for (int i=1; i<=500; i++) { + perOut(e_perout_mode_normal, 1); + lastAct = lastAct + (1<<19)/500; /* 100 on ARM */ + EXPECT_EQ(chans[0], 256 * (lastAct >> 8)); + } +} + TEST(Curves, LinearIntpol) { MODEL_RESET(); diff --git a/src/gui/view_telemetry.cpp b/src/gui/view_telemetry.cpp index 3cb3b6596..a7e33aa07 100644 --- a/src/gui/view_telemetry.cpp +++ b/src/gui/view_telemetry.cpp @@ -144,7 +144,7 @@ void displayGpsCoord(uint8_t y, char direction, int16_t bp, int16_t ap) NOINLINE uint8_t getRssiAlarmValue(uint8_t alarm) { - return (50 + g_model.frsky.rssiAlarms[alarm].value); + return (45 - 3*alarm + g_model.frsky.rssiAlarms[alarm].value); } void displayVoltageScreenLine(uint8_t y, uint8_t index) diff --git a/src/opentx.cpp b/src/opentx.cpp index a5db0bda0..add65b69d 100644 --- a/src/opentx.cpp +++ b/src/opentx.cpp @@ -2881,15 +2881,14 @@ void perOut(uint8_t mode, uint8_t tick10ms) if (!(dirtyChannels & ((bitfield_channels_t)1 << md->destCh))) continue; - if (md->phases & (1 << s_perout_flight_phase)) continue; - - //========== SWITCH =============== - bool sw = getSwitch(md->swtch, 1); + //========== PHASE && SWITCH ===== + bool mixCondition = (md->phases != 0 || md->swtch); + bool mixEnabled = !(md->phases & (1 << s_perout_flight_phase)) && getSwitch(md->swtch, 1); //========== VALUE =============== getvalue_t v = 0; if (mode != e_perout_mode_normal) { - if (!sw || k >= NUM_STICKS || (k == THR_STICK && g_model.thrTrim)) { + if (!mixEnabled || k >= NUM_STICKS || (k == THR_STICK && g_model.thrTrim)) { continue; } else { @@ -2897,13 +2896,14 @@ void perOut(uint8_t mode, uint8_t tick10ms) } } else { - if (k < NUM_STICKS) + if (k < NUM_STICKS) { v = md->noExpo ? rawAnas[k] : anas[k]; //Switch is on. MAX=FULL=512 or value. + } #if defined(PCBTARANIS) else { v = getValue(k); if ((k == MIXSRC_SF-1) || (k >= MIXSRC_SH-1 && k <= MIXSRC_LAST_CSW-1)) { - if (v < 0 && !md->swtch) sw = false; + if (v < 0 && !mixCondition) mixEnabled = false; } if (k>=MIXSRC_CH1-1 && k<=MIXSRC_LAST_CH-1 && md->destCh != k-MIXSRC_CH1+1) { if (dirtyChannels & ((bitfield_channels_t)1 << (k-MIXSRC_CH1+1)) & (passDirtyChannels|~(((bitfield_channels_t) 1 << md->destCh)-1))) @@ -2916,7 +2916,7 @@ void perOut(uint8_t mode, uint8_t tick10ms) else { v = getValue(k); if (k >= MIXSRC_THR-1 && k <= MIXSRC_LAST_CSW-1) { - if (v < 0 && !md->swtch) sw = false; + if (v < 0 && !mixCondition) mixEnabled = false; } else if (k>=MIXSRC_CH1-1 && k<=MIXSRC_LAST_CH-1 && md->destCh != k-MIXSRC_CH1+1) { if (dirtyChannels & ((bitfield_channels_t)1 << (k-MIXSRC_CH1+1)) & (passDirtyChannels|~(((bitfield_channels_t) 1 << md->destCh)-1))) @@ -2932,7 +2932,7 @@ void perOut(uint8_t mode, uint8_t tick10ms) //========== DELAYS =============== uint8_t swTog; - if (sw) { // switch on? (if no switch selected => on) + if (mixEnabled) { // switch on? (if no switch selected => on) swTog = !swOn[i]; if (mode == e_perout_mode_normal) { swOn[i] = true; @@ -2942,7 +2942,7 @@ void perOut(uint8_t mode, uint8_t tick10ms) } if (sDelay[i] > 0) { // perform delay sDelay[i] = max(0, (int16_t)sDelay[i] - tick10ms); - if (!md->swtch) { + if (!mixCondition) { v = -1024; } else { @@ -2966,10 +2966,10 @@ void perOut(uint8_t mode, uint8_t tick10ms) } if (delay > 0) { // perform delay delay = max(0, (int16_t)delay - tick10ms); - if (!md->swtch) v = +1024; + if (!mixCondition) v = +1024; has_delay = true; } - else if (!md->swtch) { + else if (!mixCondition) { v = -1024; } sDelay[i] = delay; @@ -2977,12 +2977,12 @@ void perOut(uint8_t mode, uint8_t tick10ms) if (!has_delay) { if (md->speedDown) { if (md->mltpx == MLTPX_REP) continue; - if (md->swtch) { + if (mixCondition) { v = 0; apply_offset_and_curve = false; } } - else if (md->swtch) { + else if (mixCondition) { continue; } } @@ -3012,7 +3012,7 @@ void perOut(uint8_t mode, uint8_t tick10ms) // saves 12 bytes code if done here and not together with weight; unknown reason int16_t weight = GET_GVAR(MD_WEIGHT(md), GV_RANGELARGE_NEG, GV_RANGELARGE, s_perout_flight_phase); - weight=calc100to256_16Bits(weight); + weight = calc100to256_16Bits(weight); //========== SPEED =============== // now its on input side, but without weight compensation. More like other remote controls @@ -3037,14 +3037,14 @@ void perOut(uint8_t mode, uint8_t tick10ms) if (md->speedUp>0) { // if a speed upwards is defined recalculate the new value according configured speed; the higher the speed the smaller the add value is int32_t newValue = tact+rate/((int16_t)(100/SLOW_STEP)*md->speedUp); - if (newValuespeedDown>0) { // see explanation in speedUp int32_t newValue = tact-rate/((int16_t)(100/SLOW_STEP)*md->speedDown); - if (newValue>currentValue) currentValue=newValue; // Endposition; prevent toggling around the destination + if (newValue>currentValue) currentValue = newValue; // Endposition; prevent toggling around the destination } } //endif diff>0 act[i] = tact = currentValue; @@ -4284,6 +4284,10 @@ void menusTask(void * pdata) lcd_clear(); displayPopup(STR_SHUTDOWN); +#if defined(FRSKY) + FRSKY_End(); +#endif + #if defined(SDCARD) closeLogs(); #endif diff --git a/src/telemetry/frsky.h b/src/telemetry/frsky.h index 0212f3d40..c80ef1cd5 100644 --- a/src/telemetry/frsky.h +++ b/src/telemetry/frsky.h @@ -203,6 +203,8 @@ extern uint8_t frskyTxBuffer[FRSKY_TX_PACKET_SIZE]; extern uint8_t frskyTxBufferCount; void FRSKY_Init(void); +#define FRSKY_End() + void telemetryWakeup(void); void telemetryInterrupt10ms(void);