Esempio n. 1
0
void applyTemplate(uint8_t idx)
{
    MixData *md;

    //CC(STK)   -> vSTK
    //ICC(vSTK) -> STK
#define ICC(x) icc[(x)-1]
    uint8_t icc[4] = {0};
    for (uint8_t i=0; i<4; i++) { //generate inverse array
      for(uint8_t j=0; j<4; j++)
        if(CC(i+1)==j+MIXSRC_Rud) icc[j]=i;
    }

    switch (idx) {
      case TMPL_CLEAR_MIXES:
      case TMPL_SIMPLE_4CH:
      case TMPL_HELI_SETUP:
        clearMixes();
        break;
    }

    switch (idx) {
      // Simple 4-Ch
      case TMPL_SIMPLE_4CH:
        defaultInputs();
        setDest(ICC(STK_RUD), TMPL_INPUT(STK_RUD));
        setDest(ICC(STK_ELE), TMPL_INPUT(STK_ELE));
        setDest(ICC(STK_THR), TMPL_INPUT(STK_THR));
        setDest(ICC(STK_AIL), TMPL_INPUT(STK_AIL));
        break;

      // Sticky-T-Cut
      case TMPL_STI_THR_CUT:
        md=setDest(ICC(STK_THR), MIXSRC_MAX); mixSetWeight(md, -100);  md->swtch=SWSRC_SWC;  md->mltpx=MLTPX_REP;
        md=setDest(13, MIXSRC_CH14); // md->weight= 100; done by setDest anyway
        md=setDest(13, MIXSRC_MAX); mixSetWeight(md, -100);  md->swtch=SWSRC_SWB;  md->mltpx=MLTPX_REP;
        md=setDest(13, MIXSRC_MAX); /* md->weight= 100;*/  md->swtch=SWSRC_THR;  md->mltpx=MLTPX_REP;
        setLogicalSwitch(11, LS_FUNC_VNEG, STK_THR, -99);
        setLogicalSwitch(12, LS_FUNC_VPOS, MIXSRC_CH14, 0);
        break;

      // V-Tail
      case TMPL_V_TAIL:
        defaultInputs();
        setDest(ICC(STK_RUD), TMPL_INPUT(STK_RUD), true);
        md=setDest(ICC(STK_RUD), TMPL_INPUT(STK_ELE)); mixSetWeight(md, -100);
        setDest(ICC(STK_ELE), TMPL_INPUT(STK_RUD), true);
        setDest(ICC(STK_ELE), TMPL_INPUT(STK_ELE));
        break;

      // Elevon\\Delta
      case TMPL_ELEVON_DELTA:
        defaultInputs();
        setDest(ICC(STK_ELE), MIXSRC_Ele, true);
        setDest(ICC(STK_ELE), MIXSRC_Ail);
        setDest(ICC(STK_AIL), MIXSRC_Ele, true);
        md=setDest(ICC(STK_AIL), MIXSRC_Ail); mixSetWeight(md, -100);
        break;

      // eCCPM
      case TMPL_ECCPM:
        md=setDest(ICC(STK_ELE), MIXSRC_Ele, true); md->weight= 72;
        md=setDest(ICC(STK_ELE), MIXSRC_Thr);  md->weight= 55;
        md=setDest(ICC(STK_AIL), MIXSRC_Ele, true);  mixSetWeight(md, -36);
        md=setDest(ICC(STK_AIL), MIXSRC_Ail);  md->weight= 62;
        md=setDest(ICC(STK_AIL), MIXSRC_Thr);  md->weight= 55;
        md=setDest(5, MIXSRC_Ele, true);       mixSetWeight(md, -36);
        md=setDest(5, MIXSRC_Ail);             mixSetWeight(md, -62);
        md=setDest(5, MIXSRC_Thr);             md->weight= 55;
        break;

      // Heli Setup
      case TMPL_HELI_SETUP:
        clearCurves();

        //Set up Mixes
        // 3 cyclic channels
        md=setDest(0, MIXSRC_CYC1); // md->weight=100;
        md=setDest(1, MIXSRC_CYC2); // md->weight=100;
        md=setDest(2, MIXSRC_CYC3); // md->weight=100;

        // rudder
        md=setDest(3, MIXSRC_Rud); // md->weight=100;

        // throttle
#if defined(PCBTARANIS)
        // TODO
#else
        md=setDest(4, MIXSRC_Thr); md->swtch=SWSRC_ID0; mixSetCurve(md, 0); md->carryTrim=TRIM_OFF;
        md=setDest(4, MIXSRC_Thr); md->swtch=SWSRC_ID1; mixSetCurve(md, 1); md->carryTrim=TRIM_OFF;
        md=setDest(4, MIXSRC_Thr); md->swtch=SWSRC_ID2; mixSetCurve(md, 2); md->carryTrim=TRIM_OFF;
#endif
        md=setDest(4, MIXSRC_MAX); mixSetWeight(md, -100); md->swtch=SWSRC_THR;  md->mltpx=MLTPX_REP;

        // gyro gain
        md=setDest(5, MIXSRC_MAX); md->weight= 30; md->swtch=-SWSRC_GEA;
        md=setDest(5, MIXSRC_MAX); mixSetWeight(md, -30); md->swtch= SWSRC_GEA;
   
        // collective
#if defined(PCBTARANIS)
        // TODO
#else
        md=setDest(10, MIXSRC_Thr); /*md->weight= 100;*/ md->swtch=SWSRC_ID0; mixSetCurve(md, 3); md->carryTrim=TRIM_OFF;
        md=setDest(10, MIXSRC_Thr); /*md->weight= 100;*/ md->swtch=SWSRC_ID1; mixSetCurve(md, 4); md->carryTrim=TRIM_OFF;
        md=setDest(10, MIXSRC_Thr); /*md->weight= 100;*/ md->swtch=SWSRC_ID2; mixSetCurve(md, 5); md->carryTrim=TRIM_OFF;
#endif

        g_model.swashR.collectiveSource = MIXSRC_CH11;
        g_model.swashR.type = SWASH_TYPE_120;

        // curves
        setCurve(0, heli_ar1);
        setCurve(1, heli_ar2);
        setCurve(2, heli_ar3);
        setCurve(3, heli_ar4);
        setCurve(4, heli_ar5);
        setCurve(5, heli_ar5);
        break;

      // Servo Test
      case TMPL_SERVO_TEST:
        md=setDest(NUM_CHNOUT-1, MIXSRC_SW1, true); md->weight=110; md->mltpx=MLTPX_ADD; md->delayUp = 6; md->delayDown = 6; md->speedUp = 8; md->speedDown = 8;
        setLogicalSwitch(1, LS_FUNC_VNEG, MIXSRC_LAST_CH, 0);
        break;

    default:
        break;

    }

    eeDirty(EE_MODEL);
}
Esempio n. 2
0
void applyTemplate(uint8_t idx)
#endif
{
    MixData *md = &g_model.mixData[0];

    //CC(STK)   -> vSTK
    //ICC(vSTK) -> STK
#define ICC(x) icc[(x)-1]
    uint8_t icc[4] = {0};
    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;


#ifndef NO_TEMPLATES
    uint8_t j = 0;

    //Simple 4-Ch
    if(idx==j++)
    {
#endif
        clearMixes();
        md=setDest(ICC(STK_RUD));
        md->srcRaw=CM(STK_RUD);
        md=setDest(ICC(STK_ELE));
        md->srcRaw=CM(STK_ELE);
        md=setDest(ICC(STK_THR));
        md->srcRaw=CM(STK_THR);
        md=setDest(ICC(STK_AIL));
        md->srcRaw=CM(STK_AIL);

#ifndef NO_TEMPLATES
    }

    //T-Cut
    if(idx==j++)
    {
        md=setDest(ICC(STK_THR));
        md->srcRaw=MIX_MAX;
        md->weight=-100;
        md->swtch=DSW_THR;
        md->mltpx=MLTPX_REP;
    }

    //sticky t-cut
    if(idx==j++)
    {
        md=setDest(ICC(STK_THR));
        md->srcRaw=MIX_MAX;
        md->weight=-100;
        md->swtch=DSW_SWC;
        md->mltpx=MLTPX_REP;
        md=setDest(14);
        md->srcRaw=CH(14);
        md=setDest(14);
        md->srcRaw=MIX_MAX;
        md->weight=-100;
        md->swtch=DSW_SWB;
        md->mltpx=MLTPX_REP;
        md=setDest(14);
        md->srcRaw=MIX_MAX;
        md->swtch=DSW_THR;
        md->mltpx=MLTPX_REP;

        setSwitch(0xB,CS_VNEG, CM(STK_THR), -99);
        setSwitch(0xC,CS_VPOS, CH(14), 0);
    }

    //V-Tail
    if(idx==j++)
    {
        clearMixes();
        md=setDest(ICC(STK_RUD));
        md->srcRaw=CM(STK_RUD);
        md=setDest(ICC(STK_RUD));
        md->srcRaw=CM(STK_ELE);
        md->weight=-100;
        md=setDest(ICC(STK_ELE));
        md->srcRaw=CM(STK_RUD);
        md=setDest(ICC(STK_ELE));
        md->srcRaw=CM(STK_ELE);
    }

    //Elevon\\Delta
    if(idx==j++)
    {
        clearMixes();
        md=setDest(ICC(STK_ELE));
        md->srcRaw=CM(STK_ELE);
        md=setDest(ICC(STK_ELE));
        md->srcRaw=CM(STK_AIL);
        md=setDest(ICC(STK_AIL));
        md->srcRaw=CM(STK_ELE);
        md=setDest(ICC(STK_AIL));
        md->srcRaw=CM(STK_AIL);
        md->weight=-100;
    }


    //Heli Setup
    if(idx==j++)
    {
        clearMixes();  //This time we want a clean slate
        clearCurves();

        //Set up Mixes
        //3 cyclic channels
        md=setDest(1);
        md->srcRaw=MIX_CYC1;
        md=setDest(2);
        md->srcRaw=MIX_CYC2;
        md=setDest(3);
        md->srcRaw=MIX_CYC3;

        //rudder
        md=setDest(4);
        md->srcRaw=CM(STK_RUD);

        //Throttle
        md=setDest(5);
        md->srcRaw=CM(STK_THR);
        md->swtch= DSW_ID0;
        md->curve=CV(1);
        md->carryTrim=TRIM_OFF;
        md=setDest(5);
        md->srcRaw=CM(STK_THR);
        md->swtch= DSW_ID1;
        md->curve=CV(2);
        md->carryTrim=TRIM_OFF;
        md=setDest(5);
        md->srcRaw=CM(STK_THR);
        md->swtch= DSW_ID2;
        md->curve=CV(3);
        md->carryTrim=TRIM_OFF;
        md=setDest(5);
        md->srcRaw=MIX_MAX;
        md->weight=-100;
        md->swtch= DSW_THR;
        md->mltpx=MLTPX_REP;

        //gyro gain
        md=setDest(6);
        md->srcRaw=MIX_FULL;
        md->weight=30;
        md->swtch=-DSW_GEA;

        //collective
        md=setDest(11);
        md->srcRaw=CM(STK_THR);
        md->weight=70;
        md->swtch= DSW_ID0;
        md->curve=CV(4);
        md->carryTrim=TRIM_OFF;
        md=setDest(11);
        md->srcRaw=CM(STK_THR);
        md->weight=70;
        md->swtch= DSW_ID1;
        md->curve=CV(5);
        md->carryTrim=TRIM_OFF;
        md=setDest(11);
        md->srcRaw=CM(STK_THR);
        md->weight=70;
        md->swtch= DSW_ID2;
        md->curve=CV(6);
        md->carryTrim=TRIM_OFF;

        g_model.swashType = SWASH_TYPE_120;
        g_model.swashCollectiveSource = CH(11);

        //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(6),heli_ar5);
    }

    //Gyro Gain
    if(idx==j++)
    {
        md=setDest(6);
        md->srcRaw=STK_P2;
        md->weight= 50;
        md->swtch=-DSW_GEA;
        md->sOffset=100;
        md=setDest(6);
        md->srcRaw=STK_P2;
        md->weight=-50;
        md->swtch= DSW_GEA;
        md->sOffset=100;
    }

    //Servo Test
    if(idx==j++)
    {
        md=setDest(15);
        md->srcRaw=CH(16);
        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;
        md=setDest(16);
        md->srcRaw=MIX_MAX;
        md->weight= 110;
        md->swtch=DSW_SW3;
        md->mltpx=MLTPX_REP;

        setSwitch(1,CS_LESS,CH(15),CH(16));
        setSwitch(2,CS_VPOS,CH(15),   105);
        setSwitch(3,CS_VNEG,CH(15),  -105);
    }



    STORE_MODELVARS;
    eeWaitComplete() ;

#endif

}