diff --git a/radio/src/mixer.cpp b/radio/src/mixer.cpp index f336703cb..3db2b1fe6 100755 --- a/radio/src/mixer.cpp +++ b/radio/src/mixer.cpp @@ -645,10 +645,22 @@ void evalFlightModeMixes(uint8_t mode, uint8_t tick10ms) bool mixCondition = (md->flightModes != 0 || md->swtch); delayval_t mixEnabled = (!(md->flightModes & (1 << mixerCurrentFlightMode)) && getSwitch(md->swtch)) ? DELAY_POS_MARGIN+1 : 0; +#define MIXER_LINE_DISABLE() (mixCondition = true, mixEnabled = 0) + if (mixEnabled && md->srcRaw >= MIXSRC_FIRST_TRAINER && md->srcRaw <= MIXSRC_LAST_TRAINER && !ppmInValid) { - mixEnabled = 0; + MIXER_LINE_DISABLE(); } +#if defined(PCBTARANIS) && defined(LUA_MODEL_SCRIPTS) + // disable mixer if Lua script is used as source and script was killed + if (mixEnabled && md->srcRaw >= MIXSRC_FIRST_LUA && md->srcRaw <= MIXSRC_LAST_LUA) { + div_t qr = div(md->srcRaw-MIXSRC_FIRST_LUA, MAX_SCRIPT_OUTPUTS); + if (scriptInternalData[qr.quot].state != SCRIPT_OK) { + MIXER_LINE_DISABLE(); + } + } +#endif + //========== VALUE =============== getvalue_t v = 0; if (mode > e_perout_mode_inactive_flight_mode) { diff --git a/radio/src/tests/eeprom.cpp b/radio/src/tests/eeprom.cpp new file mode 100644 index 000000000..9b8b3e9b3 --- /dev/null +++ b/radio/src/tests/eeprom.cpp @@ -0,0 +1,164 @@ +/* + * Authors (alphabetical order) + * - Andre Bernet + * - Andreas Weitl + * - Bertrand Songis + * - Bryan J. Rentoul (Gruvin) + * - Cameron Weeks + * - Erez Raviv + * - Gabriel Birkus + * - Jean-Pierre Parisy + * - Karl Szmutny + * - Michael Blandford + * - Michal Hlavinka + * - Pat Mackenzie + * - Philip Moss + * - Rob Thomson + * - Romolo Manfredini + * - Thomas Husterer + * + * opentx 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 "gtests.h" + +#if !defined(PCBSKY9X) +TEST(EEPROM, 100_random_writes) +{ + eepromFile = NULL; // in memory + RlcFile f; + uint8_t buf[1000]; + uint8_t buf2[1000]; + + EeFsFormat(); + + for(int i=0; i<100; i++) { + int size = rand()%800; + for(int j=0; j -#include -#include - -#define SWAP_DEFINED -#include "opentx.h" - -#define TELEMETRY_RESET() \ - memclear(&frskyData, sizeof(frskyData)); \ - frskyData.rssi[0].value = 100 - -extern bool checkScreenshot(QString test); +#include "gtests.h" #if defined(FRSKY) && !defined(FRSKY_SPORT) extern void frskyDProcessPacket(uint8_t *packet); @@ -181,6 +170,7 @@ TEST(FrSkySPORT, frskySetCellVoltage) { uint8_t packet[FRSKY_SPORT_PACKET_SIZE]; + MODEL_RESET(); TELEMETRY_RESET(); // test that simulates 3 cell battery @@ -290,6 +280,7 @@ TEST(FrSkySPORT, frskySetCellVoltageTwoSensors) { uint8_t packet[FRSKY_SPORT_PACKET_SIZE]; + MODEL_RESET(); TELEMETRY_RESET(); //sensor 1: 3 cell battery diff --git a/radio/src/tests/gtests.cpp b/radio/src/tests/gtests.cpp index c36ea5e6b..01557fcec 100644 --- a/radio/src/tests/gtests.cpp +++ b/radio/src/tests/gtests.cpp @@ -35,10 +35,17 @@ */ #include -#include +#include "gtests.h" -#define SWAP_DEFINED -#include "opentx.h" +int32_t lastAct = 0; +uint16_t anaInValues[NUM_STICKS+NUM_POTS] = { 0 }; +uint16_t anaIn(uint8_t chan) +{ + if (chan < NUM_STICKS+NUM_POTS) + return anaInValues[chan]; + else + return 0; +} static char _zchar2stringResult[200]; const char * zchar2string(const char * zstring, int size) @@ -50,133 +57,6 @@ const char * zchar2string(const char * zstring, int size) return _zchar2stringResult; } -#if !defined(PCBSKY9X) -TEST(EEPROM, 100_random_writes) -{ - eepromFile = NULL; // in memory - RlcFile f; - uint8_t buf[1000]; - uint8_t buf2[1000]; - - EeFsFormat(); - - for(int i=0; i<100; i++) { - int size = rand()%800; - for(int j=0; j +#include +#include + +#define SWAP_DEFINED +#include "opentx.h" + +#define CHANNEL_MAX (1024*256) + +extern int32_t lastAct; +extern uint16_t anaInValues[NUM_STICKS+NUM_POTS]; + +void doMixerCalculations(); + +inline void MODEL_RESET() +{ + memset(&g_model, 0, sizeof(g_model)); + memset(&anaInValues, 0, sizeof(anaInValues)); + extern uint8_t s_mixer_first_run_done; + s_mixer_first_run_done = false; + lastFlightMode = 255; +} + +inline void MIXER_RESET() +{ + memset(channelOutputs, 0, sizeof(channelOutputs)); + memset(chans, 0, sizeof(chans)); + memset(ex_chans, 0, sizeof(ex_chans)); + memset(act, 0, sizeof(act)); + memset(swOn, 0, sizeof(swOn)); +#if !defined(CPUARM) + s_last_switch_used = 0; + s_last_switch_value = 0; +#endif + mixerCurrentFlightMode = lastFlightMode = 0; + lastAct = 0; + logicalSwitchesReset(); +} + +inline void TELEMETRY_RESET() +{ + memclear(&frskyData, sizeof(frskyData)); + frskyData.rssi[0].value = 100; +} + +void MIXER_RESET(); + +bool checkScreenshot(QString test); + +#endif diff --git a/radio/src/tests/mixer.cpp b/radio/src/tests/mixer.cpp index 57dcf4684..7655e3ac9 100644 --- a/radio/src/tests/mixer.cpp +++ b/radio/src/tests/mixer.cpp @@ -34,47 +34,31 @@ * */ -#include -#include +#include "gtests.h" -#define SWAP_DEFINED -#include "opentx.h" +#define CHECK_NO_MOVEMENT(channel, value, duration) \ + for (int i=1; i<=(duration); i++) { \ + evalFlightModeMixes(e_perout_mode_normal, 1); \ + EXPECT_EQ(chans[(channel)], (value)); \ + } -#define CHANNEL_MAX (1024*256) +#define CHECK_SLOW_MOVEMENT(channel, sign, duration) \ + do { \ + for (int i=1; i<=(duration); i++) { \ + evalFlightModeMixes(e_perout_mode_normal, 1); \ + lastAct = lastAct + (sign) * (1<<19)/500; /* 100 on ARM */ \ + EXPECT_EQ(chans[(channel)], 256 * (lastAct >> 8)); \ + } \ + } while (0) -void doMixerCalculations(); - -#define MODEL_RESET() \ - memset(&g_model, 0, sizeof(g_model)); \ - memset(&anaInValues, 0, sizeof(anaInValues)); \ - extern uint8_t s_mixer_first_run_done; \ - s_mixer_first_run_done = false; \ - lastFlightMode = 255; - -int32_t lastAct = 0; -void MIXER_RESET() -{ - memset(channelOutputs, 0, sizeof(channelOutputs)); - memset(ex_chans, 0, sizeof(ex_chans)); - memset(act, 0, sizeof(act)); - memset(swOn, 0, sizeof(swOn)); -#if !defined(CPUARM) - s_last_switch_used = 0; - s_last_switch_value = 0; -#endif - mixerCurrentFlightMode = lastFlightMode = 0; - lastAct = 0; - logicalSwitchesReset(); -} - -uint16_t anaInValues[NUM_STICKS+NUM_POTS] = { 0 }; -uint16_t anaIn(uint8_t chan) -{ - if (chan < NUM_STICKS+NUM_POTS) - return anaInValues[chan]; - else - return 0; -} +#define CHECK_DELAY(channel, duration) \ + do { \ + int32_t value = chans[(channel)]; \ + for (int i=1; i<=(duration); i++) { \ + evalFlightModeMixes(e_perout_mode_normal, 1); \ + EXPECT_EQ(chans[(channel)], value); \ + } \ + } while (0) TEST(Trims, throttleTrim) { @@ -643,30 +627,6 @@ TEST(Mixer, RecursiveAddChannelAfterInactivePhase) EXPECT_EQ(chans[1], CHANNEL_MAX); } -#define CHECK_NO_MOVEMENT(channel, value, duration) \ - for (int i=1; i<=(duration); i++) { \ - evalFlightModeMixes(e_perout_mode_normal, 1); \ - EXPECT_EQ(chans[(channel)], (value)); \ - } - -#define CHECK_SLOW_MOVEMENT(channel, sign, duration) \ - do { \ - for (int i=1; i<=(duration); i++) { \ - evalFlightModeMixes(e_perout_mode_normal, 1); \ - lastAct = lastAct + (sign) * (1<<19)/500; /* 100 on ARM */ \ - EXPECT_EQ(chans[(channel)], 256 * (lastAct >> 8)); \ - } \ - } while (0) - -#define CHECK_DELAY(channel, duration) \ - do { \ - int32_t value = chans[(channel)]; \ - for (int i=1; i<=(duration); i++) { \ - evalFlightModeMixes(e_perout_mode_normal, 1); \ - EXPECT_EQ(chans[(channel)], value); \ - } \ - } while (0) - #if !defined(CPUARM) TEST(Mixer, SlowOnSwitch) { @@ -1009,7 +969,9 @@ TEST(Heli, Mode2Test) EXPECT_EQ(chans[1], CHANNEL_MAX/2); EXPECT_EQ(chans[2], CHANNEL_MAX/2); } -#elif defined(HELI) +#endif + +#if defined(HELI) && !defined(PCBTARANIS) TEST(Heli, SimpleTest) { MODEL_RESET(); @@ -1021,3 +983,18 @@ TEST(Heli, SimpleTest) EXPECT_EQ(chans[1], CHANNEL_MAX/2); } #endif + +TEST(Trainer, UnpluggedTest) +{ + MODEL_RESET(); + MIXER_RESET(); + g_model.mixData[0].destCh = 0; + g_model.mixData[0].mltpx = MLTPX_ADD; + g_model.mixData[0].srcRaw = MIXSRC_FIRST_TRAINER; + g_model.mixData[0].weight = 100; + g_model.mixData[0].delayUp = DELAY_STEP*5; + g_model.mixData[0].delayDown = DELAY_STEP*5; + ppmInValid = 0; + g_ppmIns[0] = 1024; + CHECK_DELAY(0, 5000); +}