int CenterPositTrimmer = 50 ;
// Allows TARGET based Central Position Trimmer Mode (CPTM) for helicopters. Positive value is polling time in ms for neutral retrimming; set 0 to disable.
// If enabled, be sure to disable CPTM in DCS Options.
int CenterPositTempo = 500;
// Default TEMPO value (TEMPO short will be standard trimmer for minor changes, long for CPTM)
int CenterPositRudder = 0 ;
// If 1, TARGET-based CPTM also trims rudder.
int CenterPositZone = 2000 ;
// "Dead Zone" for CPTM recentering. Value between 0 and 32768 (lower is smaller dead zone).
int CPTM_Trim(int trim, int prof=0, int poll=2)
//poll = 2 because that is the REXEC flag for both polling trimmers.
{
if ( (prof == 2) & (!CenterPositRudder) )
//if rudder trim disengaged this will still kill rudder trim to BS2 regardless of TEMPO or setting.
//Forum note: prof == 2 is the BS2 profile.
//Forum note: this condition is now obsolete with selectable rudder trim for the Ka-50 in DCS
{
ActKey(CHAIN( KEYON+D(),
KEYON+PULSE+Rudder_Left,
KEYON+D(),
KEYON+PULSE+Rudder_Right ));
}
if (CenterPositTrimmer)
{
StopAutoRepeat(poll); //should stop any polling of previous trimmers
if (trim) //trim enabled (doesn't need to be CPTM TEMPO)
{
if (CPTM_Engaged) //forces axis trim if TEMPO long
//nested if/then to exit routine if TEMPO short
{
//divide by 32 because the axis has 65536 values and trim has 2048
TrimDXAxis(DX_X_AXIS, SET(-HCougar[JOYX]/32));
TrimDXAxis(DX_Y_AXIS, SET(-HCougar[JOYY]/32));
if (CenterPositRudder) TrimDXAxis(DX_ZROT_AXIS, SET(-HCougar[RUDDER]/32));
}
}
else //trim reset
{
TrimDXAxis(DX_X_AXIS, SET(0));
TrimDXAxis(DX_Y_AXIS, SET(0));
if (CenterPositRudder) TrimDXAxis(DX_ZROT_AXIS, SET(0));
}
CPTM_Engaged = 0;
CPTM_Mapping(trim, MFD_Var); //Forum Note: MFD_Var indicates aircraft profile
}
}
int CPTM_Recenter_Active()
{
TrimDXAxis(DX_X_AXIS, SET(-HCougar[JOYX]/32));
TrimDXAxis(DX_Y_AXIS, SET(-HCougar[JOYY]/32));
if (CenterPositRudder) TrimDXAxis(DX_ZROT_AXIS, SET(-HCougar[RUDDER]/32));
}
int CPTM_Center_Poll(int dz) //dz is deadzone value
{
if ( (abs(HCougar[JOYX]) < dz) & (abs(HCougar[JOYY]) < dz) &
( ((CenterPositRudder) & (abs(HCougar[RUDDER]) < dz))
| (!CenterPositRudder) ) ) //all axes within dead zone
CPTM_Trim(0);
}
int CPTM_Mapping(int trim, int prof = 0)
//Forum Note: my actual profile remaps TG1/2, S1 and S2 to prevent my CommState routine (which remaps Hats 2-4 to F1-F12 for the comms menu) from engaging. These are likely unnecessary for your own uses and are omitted.
{
if (CenterPositTrimmer)
{
if (trim)
{
MapKey (&HCougar, H4D, CHAIN(EXEC("StopAutoRepeat(2);"), D(30), REXEC(2,CenterPositTrimmer,"CPTM_Recenter_Active();")));
MapKeyR (&HCougar, H4D, EXEC("CPTM_Trim(0);"));
MapKey (&HCougar, S3, CHAIN(DX30,EXEC("StopAutoRepeat(2);"), D(30), REXEC(2,CenterPositTrimmer, "CPTM_Recenter_Active();")));
MapKeyR (&HCougar, S3, EXEC("CPTM_Trim(0);"));
}
else //release
{
H4UD_CPTM(prof); //Forum Note: prof is the designated aircraft profile
MapKey (&HCougar, S3, CHAIN(DX30,TEMPO(DX3, EXEC("S3S4Shifted();"), 300)));
//DX3 short, long for modifier and eject check (forum note: another routine that includes eject check; just set this to your default S3 functionality instead)
MapKeyR (&HCougar, S3, EXEC("S3Release();"));
//forum note: another routine that includes eject check
}
}
}
//Forum Note: this routine reassigns H4U/H4D functionality after trimming is finished. You can customize this liberally for your own uses, though keep the CPTM values and routines in place.
int H4UD_CPTM(int prof = 0)
{
if (prof == 2)
{
MapKeyIO(&HCougar, H4U, TEMPO(EXEC("SnapViewModRelease(KBPress);"), EXEC("SetSnapViewT(8);")),
TEMPO(CHAIN(EXEC("CPTM_Engaged = 0;"),DX15),CHAIN(EXEC("CPTM_Engaged = 1;"),DX15),CenterPositTempo)); //Snapview8 or DX15 (force trim)
MapKeyRIO(&HCougar, H4U, 0, CHAIN(EXEC("CPTM_Trim(1,2);"),REXEC(2, CenterPositTrimmer, "CPTM_Center_Poll(CenterPositZone);")));
MapKey (&HCougar, H4D, DX17);
MapKeyRIO(&HCougar, H4D, EXEC("CPTM_Trim(0);"),0);
//Forum Note: S3+DX17 is used for reset trim in BS2
}
else
{
MapKey (&HCougar, H4U, TEMPO(CHAIN(EXEC("CPTM_Engaged = 0;"),DX15), CHAIN(EXEC("CPTM_Engaged = 1;"),DX15),CenterPositTempo)); //Force Trim Set; shift reset
MapKeyRIO(&HCougar, H4U, EXEC("CPTM_Trim(0);"),
CHAIN( EXEC("CPTM_Trim(1);"), REXEC(2, CenterPositTrimmer, "CPTM_Center_Poll(CenterPositZone);")));
if (prof == 6)
{
MapKeyIO(&HCougar, H4D, CHAIN( PULSE+DX17,D(200),
PULSE+DX17,D(200),
PULSE+DX17,D(200),
PULSE+DX17,D(200),
PULSE+DX17), DX17); //flare; shift for 5x flares
MapKeyR (&HCougar, H4D, 0);
}
else
{
MapKey (&HCougar, H4D, DX17);
MapKeyR (&HCougar, H4D, 0);
}
}
}