include "target.tmh" //default Thrustmaster function code 

int Eject ;
int Flare ;
int Chaff ;

int main() 
{ 

Configure(&LMFD,MODE_EXCLUDED); 
Configure(&RMFD,MODE_EXCLUDED);
Configure(&HCougar,MODE_EXCLUDED);
Configure(&T16000,MODE_EXCLUDED);
Configure(&T16000L,MODE_EXCLUDED);
Configure(&TFRPRudder,MODE_EXCLUDED);

if(Init(&EventHandle)) return 1; //event handler, return on error  

//shift button
SetShiftButton(&Joystick,S4);

//set pulse and delay lengths
SetKBRate(50,100);

//LED init state
ActKey(PULSE+KEYON+LED(&Throttle, LED_INTENSITY, 214)); //set Throttle backlight power to 5/6
ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED0)); //set backlight OFF
ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED1)); //set LED 1 OFF
ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED2)); //set LED 2 OFF
ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED3)); //set LED 3 OFF
ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED4)); //set LED 4 OFF
ActKey(PULSE+KEYON+LED(&Throttle, LED_ONOFF, LED_CURRENT-LED5)); //set LED 5 OFF


/////////////////////////////////////////
//Joystick and Throttle Axis Definitions/
/////////////////////////////////////////
MapAxis(&Joystick, JOYX, DX_X_AXIS); 
MapAxis(&Joystick, JOYY, DX_Y_AXIS); 
MapAxis(&Throttle, THR_LEFT, DX_ZROT_AXIS); 
MapAxis(&Throttle, THR_RIGHT, DX_Z_AXIS); 

//Shift slew to mouse with S4, Shift slider axe to mouse wheel with S4
MapKey(&Joystick, S4, EXEC("MapAxis(&Throttle,SCX,MOUSE_X_AXIS,AXIS_NORMAL,MAP_RELATIVE);"
"SetSCurve(&Throttle, SCX, 0, 10, 0, 0, -5);"
"MapAxis(&Throttle, SCY, MOUSE_Y_AXIS, AXIS_NORMAL, MAP_RELATIVE);"
"SetSCurve(&Throttle, SCY, 0, 10, 0, 0, -5);"
"MapAxis(&Throttle, THR_FC, DX_THROTTLE_AXIS);"
));

MapKeyR(&Joystick, S4, EXEC("MapAxis(&Throttle, SCX, DX_XROT_AXIS, AXIS_NORMAL, MAP_ABSOLUTE);"
"SetSCurve(&Throttle, SCX, 0, 0, 0, 0, 0);"
"MapAxis(&Throttle, SCY, DX_YROT_AXIS, AXIS_NORMAL, MAP_ABSOLUTE);"
"SetSCurve(&Throttle, SCY, 0, 0, 0, 0, 0);"
"MapAxis(&Throttle, THR_FC, DX_SLIDER_AXIS);"
));

//Slew
MapAxis(&Throttle, SCX, DX_XROT_AXIS, AXIS_NORMAL, MAP_ABSOLUTE);
SetSCurve(&Throttle, SCX, 0, 0, 0, 0, 0);
MapAxis(&Throttle, SCY, DX_YROT_AXIS, AXIS_NORMAL, MAP_ABSOLUTE);
SetSCurve(&Throttle, SCY, 0, 0, 0, 0, 0);
   
//Slew click
MapKeyIO(&Throttle,SC,MOUSE_LEFT,USB[0x5D]); //mouse click, usb code 'num5' for trackir center

//Assign RADAR ELEVATION to throttle friction lever in DCS
MapAxis(&Throttle, THR_FC, DX_SLIDER_AXIS);

printf("   \xa");
printf(" --------[ NOiD Su27 / Su33 Profile 2.8 ]-------- \xa");
printf("   \xa");

//////////////////////////////
//Joystick Button Definitions/
//////////////////////////////

MapKeyIO(&Joystick,TG1,USB[0x2A],USB[0x28]); //UNLOCK usb code 'Backspace', LOCK usb code 'Return' 1st trigger
MapKey(&Joystick,TG2,USB[0x2C]); //FIRE usb code t'SPC' 2nd trigger
MapKeyIO(&Joystick,S1,TEMPO(PULSE+L_ALT+USB[0x34],PULSE+USB[0x18],500),TEMPO(PULSE+USB[0x07],PULSE+USB[0x22],500)); //usb code ''' refuel reload-lONG PRESS :CARRIER START POS 'u', CYCLE WEAPON usb code 'd'-lONG PRESS : HMD usb code '5'
MapKeyIO(&Joystick,S2,PULSE+L_ALT+USB[0x1A],USB[0x2C]); // OVERRIDE LAUNCH CLEARANCE usb code 'w', FIRE usb code 'SPC'
MapKeyIO(&Joystick,S3,L_CTL+USB[0x06],L_ALT+USB[0x14]); //usb code 'c' open canopy, usb code 'q' (NWS)

//trim
MapKeyIO(&Joystick,H1U,R_CTL+USB[0x33],USB[0x60]); //trim up usb code ';', view up usb code 'num8'
MapKeyIO(&Joystick,H1D,R_CTL+USB[0x37],USB[0x5A]); //trim down usb code '.', view down usb code 'num2' 
MapKeyIO(&Joystick,H1L,R_CTL+USB[0x36],USB[0x5C]); //trim left usb code ',', view left usb code 'num4'
MapKeyIO(&Joystick,H1R,R_CTL+USB[0x38],USB[0x5E]); //trim right usb code '/', view right usb code 'num6'

//tms
MapKeyIO(&Joystick,H2U,USB[0x54],TEMPO(PULSE+USB[0x1E],PULSE+L_CTL+USB[0x35],500)); //ZOOM-usb code '*', MODE NAV usb code '1' -lONG PRESS : WAYPOINT + '`'
MapKeyIO(&Joystick,H2D,USB[0x55],TEMPO(PULSE+USB[0x1F],PULSE+L_SHIFT+USB[0x35],500)); //ZOOM+ usb code '/', MODE BVR usb code '2' -lONG PRESS : WAYPOINT - '`'
MapKeyIO(&Joystick,H2L,TEMPO(PULSE+USB[0x20],L_CTL+USB[0x17],500),PULSE+USB[0x24]); //MODE VSCAN usb code '3' -lONG PRESS : RESET TRIM 't', MODE AG usb code '7' 
MapKeyIO(&Joystick,H2R,TEMPO(PULSE+USB[0x21],PULSE+L_ALT+USB[0x0C],500),PULSE+USB[0x25]); //MODE BORE usb code '4' -lONG PRESS : ENIGNE INLET GRID 'i', MODE GUN usb code '8'

//dms
MapKeyIO(&Joystick,H3U,PULSE+USB[0x23],USB[0x33]); //MISSILE LONGITUDINAL AIMING usb code '6', usb code ';' TDC UPt
MapKeyIO(&Joystick,H3D,R_CTL+USB[0x0C],USB[0x37]); //TDC Center usb code 'i', usb code '.' TDC DOWN
MapKeyIO(&Joystick,H3L,R_SHIFT+USB[0x36],USB[0x36]); //RADAR SCAN LEFT usb code ',', usb code ',' TDC LEFT
MapKeyIO(&Joystick,H3R,R_SHIFT+USB[0x38],USB[0x38]); //RADAR SCAN RIGHT usb code '/' , usb code '/' TDC RIGHT

//cms
MapKeyIO(&Joystick,H4U,PULSE+L_ALT+USB[0x0F],PULSE+USB[0x0C]); //Torch on/off usb code 'L', RADAR ON/OFF usb code 'i' 
MapKeyIO(&Joystick,H4D,PULSE+USB[0x0F],PULSE+R_ALT+USB[0x0C]); //Cockpit lights usb code 'l', RWS/TWS usb code 'i'
MapKeyIO(&Joystick,H4L,TEMPO(PULSE+R_ALT+USB[0x0F],R_CTL+R_SHIFT+USB[0x0B],500),TEMPO(PULSE+USB[0x12],PULSE+L_SHIFT+USB[0x04],500)); //LANDING LIGHTS usb code 'l' -lONG PRESS : HUD light - 'h', EOS usb code 'o' -LONG PRESS: AP OVERRIDE usb code 'a'
MapKeyIO(&Joystick,H4R,TEMPO(PULSE+R_CTL+USB[0x0F],R_SHIFT+R_ALT+USB[0x0B],500),TEMPO(PULSE+R_SHIFT+USB[0x0C],PULSE+L_ALT+USB[0x20],500)); //NAVLIGHTS usb code 'l' -lONG PRESS : HUD light + 'h', RADAR FREQUENCY usb code 'i' -LONG PRESS: AP LEVEL usb code '3'
MapKeyIO(&Joystick,H4P,TEMPO(USB[0x43],PULSE+USB[0x29],500),TEMPO(USB[0x10],PULSE+USB[0x48],500)); //usb code 'F10' map -LONG PRESS: Escape, mirror on/off usb code 'M'  -LONG PRESS: Pause

//MapKey(&Joystick,S4,0); //neutralize S4 for shiftstate if needed

//////////////////////////////
//Throttle Button Definitions/
//////////////////////////////

Eject = CHAIN(PULSE+LED(&Throttle,LED_ONOFF,LED_CURRENT^LED0),PULSE+L_CTL+USB[0x08]); //Chain needed for the ejection sequence on button "LTB"
Flare = CHAIN(PULSE+LED(&Throttle,LED_ONOFF,LED_CURRENT^LED4),D(),PULSE+USB[0x4C]); //FLARE PROGRAM LED 4 INVERT usb code 'Del'
Chaff = CHAIN(PULSE+LED(&Throttle,LED_ONOFF,LED_CURRENT^LED4),D(),PULSE+USB[0x49]); //CHAFF PROGRAM LED 4 INVERT usb code 'Insert'

//MIC
MapKeyIO(&Throttle,MSU,L_CTL+L_SHIFT+USB[0x3A],L_CTL+L_ALT+USB[0x35]); //usb code 'F1' for trackirpause, usb code '`' teamspeack whisper
MapKeyIO(&Throttle,MSD,0,USB[0x35]); //FREE usb code '',usb code '`' teamspeack/Radio 1 Simple  Radio
MapKeyIO(&Throttle,MSL,R_CTL+USB[0x2D],USB[0x2D]); //radar range - usb code '-', Screen zoom - usb code '-'
MapKeyIO(&Throttle,MSR,R_CTL+USB[0x2E],USB[0x2E]); //radar range + usb code '=', Screen zoom + usb code '='
MapKeyIO(&Throttle,MSP,R_ALT+USB[0x35],DX2); //L_ALT+USB[0x35] Radio 2 Simple  Radio, comm menu (in DCS)

//speedbrake
MapKeyIO(&Throttle,SPDB,PULSE+USB[0x16],PULSE+R_CTL+USB[0x15]); //ASC Direct Law (COBRA) usb code 's', ASC Refuel usb code 'r'
MapKey(&Throttle,SPDM,CHAIN(PULSE+L_CTL+USB[0x05],LED(&Throttle,LED_ONOFF,LED_CURRENT-LED3))); // NEUTRAL LED3 OFF
MapKeyIO(&Throttle,SPDF,PULSE+L_SHIFT+USB[0x08],CHAIN(PULSE+L_SHIFT+USB[0x05],LED(&Throttle,LED_ONOFF,LED_CURRENT+LED3))); //EMERGENCY POWER usb code 'e', SPEEDBRAKE usb code 'b' LED3 ON 

//Boat switch
MapKeyIO(&Throttle,BSB,0,REXEC(0, 300, "ActKey(KEYON+Flare);")); //FLARE PROGRAM LED 4 BLINK
MapKeyIO(&Throttle,BSF,0,REXEC(0, 300, "ActKey(KEYON+Chaff);")); //CHAFF PROGRAM LED 4 BLINK
MapKey(&Throttle,BSM,PULSE+LED(&Throttle,LED_ONOFF,LED_CURRENT-LED4)); //NEUTRAL LED 4 OFF

//China hat
MapKeyIO(&Throttle,CHB,TEMPO(PULSE+USB[0x17],USB[0x13],500),PULSE+USB[0x08]); //SMOKE on/off usb code 't' -lONG PRESS : DRAG CHUTE 'p', JAMMER usb code 'e'
MapKeyIO(&Throttle,CHF,PULSE+R_CTL+USB[0x19],PULSE+USB[0x06]); //Salvo usb code 'v', Gun usb code 'c'

//Pinkie
MapKey(&Throttle,PSB,R_CTL+USB[0x2D]); //TARGET SIZE - usb code ']' 
MapKey(&Throttle,PSM,0); //NEUTRAL
MapKey(&Throttle,PSF,R_CTL+USB[0x2E]); //TARGET SIZE + usb code '['

//Left ap button
MapKeyIO(&Throttle,LTB,REXEC(0, 90, "ActKey(KEYON+Eject);"),TEMPO(USB[0x04],PULSE+L_ALT+USB[0x26],500)); //Ejection script and BACKLIGHT BLINK usb code 'e', usb code 'a' AP ON -lONG PRESS : AP STOP '9'


//Coolie
MapKeyIO(&Throttle,CSU,TEMPO(PULSE+USB[0x3A],AXIS(MOUSE_Z_AXIS, 2, 100),500),PULSE+USB[0x2F]); //view cockpit usb code 'F1' -LONG PRESS:SCROLLWHEEL UP, Planchette  previous usb code '['
MapKeyIO(&Throttle,CSD,TEMPO(PULSE+USB[0x3B],AXIS(MOUSE_Z_AXIS, -2, 100),500),PULSE+USB[0x30]); //view external usb code 'F2' -LONG PRESS:SCROLLWHEEL DOWN, Planchette  next usb code ']'
MapKeyIO(&Throttle,CSL,PULSE+USB[0x3C],USB[0x1C]); //view flyby usb code 'F3', STICK LIMITS OVERRIDE usb code 'y'
MapKeyIO(&Throttle,CSR,PULSE+USB[0x3D],PULSE+R_SHIFT+USB[0x0E]); //view arcade usb code 'F4',Planchette  on/off usb code 'k'

//base
MapKeyIO(&Throttle,EFLNORM,0,CHAIN(PULSE+L_CTL+USB[0x15],LED(&Throttle,LED_ONOFF,LED_CURRENT+LED5))); //REFUEL BOOM usb code 'r' LED5 ON 
MapKeyIO(&Throttle,EFLOVER,0,CHAIN(PULSE+L_CTL+USB[0x15],LED(&Throttle,LED_ONOFF,LED_CURRENT-LED5))); //REFUEL BOOM usb code 'r' LED5 OFF
MapKeyIO(&Throttle,EFRNORM,0,PULSE+L_ALT+USB[0x15]); //REFUEL LIGHT usb code 'r'
MapKeyIO(&Throttle,EFROVER,0,PULSE+L_ALT+USB[0x15]); //REFUEL LIGHT usb code 'r'
MapKeyIO(&Throttle,EOLNORM,0,0); //NEUTRAL
MapKeyIO(&Throttle,EORNORM,0,0); //NEUTRAL
MapKeyIO(&Throttle,EOLMOTOR,0,PULSE+R_SHIFT+USB[0x15]); // RWR SPO usb code 'r'
MapKeyIO(&Throttle,EORMOTOR,0,PULSE+USB[0x0D]); // AUTOTHRUST usb code 'j'
MapKeyIO(&Throttle,EOLIGN,R_ALT+USB[0x36],L_CTL+USB[0x36]); // RWRSPO Volume - usb code ',' , AUTOTHRUST speed - usb code ','
MapKeyIO(&Throttle,EORIGN,R_ALT+USB[0x37],L_CTL+USB[0x37]); // RWRSPO Volume + usb code '.' , AUTOTHRUST speed + usb code '.'
MapKeyIO(&Throttle,APUON,0,CHAIN(PULSE+R_SHIFT+USB[0x0F],LED(&Throttle,LED_ONOFF,LED_CURRENT+LED1))); //BATTERY usb code 'l' LED1 ON 
MapKeyIO(&Throttle,APUOFF,0,CHAIN(PULSE+R_SHIFT+USB[0x0F],LED(&Throttle,LED_ONOFF,LED_CURRENT-LED1)));  //BATTERY usb code 'l' LED1 OFF 
MapKeyIO(&Throttle,LDGH,PULSE+L_CTL+USB[0x1A],PULSE+R_SHIFT+USB[0x11]); //EXTERNAL STORES JETTISON usb code 'w', RESET MASTER WARNING usb code 'n'
MapKeyIO(&Throttle,FLAPU,0,CHAIN(PULSE+L_CTL+USB[0x0A],LED(&Throttle,LED_ONOFF,LED_CURRENT-LED2))); //GEAR UP usb code 'g' LED2 OFF 
MapKeyIO(&Throttle,FLAPM,0,CHAIN(PULSE+L_SHIFT+USB[0x0A],LED(&Throttle,LED_ONOFF,LED_CURRENT+LED2))); //GEAR DOWN usb code 'g' LED2 ON 
MapKeyIO(&Throttle,FLAPD,0,CHAIN(PULSE+R_CTL+USB[0x13],LED(&Throttle,LED_ONOFF,LED_CURRENT+LED2))); //GEAR DOWN WING FOLD ON usb code 'f' ON LED2 ON
MapKeyRIO(&Throttle,FLAPD,0,CHAIN(PULSE+R_CTL+USB[0x13],LED(&Throttle,LED_ONOFF,LED_CURRENT+LED2))); //GEAR DOWN WING FOLD OFF usb code 'f' ON LED2 ON
MapKeyIO(&Throttle,EACON,0,PULSE+L_SHIFT+USB[0x09]); // FLAPS LANDING usb code 'f'
MapKeyIO(&Throttle,EACOFF,0,PULSE+L_CTL+USB[0x09]); // FLAPS UP usb code 'f'
MapKeyIO(&Throttle,RDRNRM,0,PULSE+L_ALT+USB[0x0A]); //TAIL HOOK  usb code 'g'
MapKeyIO(&Throttle,RDRDIS,0,PULSE+L_ALT+USB[0x0A]); //TAIL HOOK  usb code 'g'
MapKeyIO(&Throttle,APENG,PULSE+L_ALT+USB[0x24],PULSE+L_ALT+USB[0x23]); //AP GROUND AVOIDANCE usb code '7', AP ROUTE FOLLOW usb code '6' 
MapKeyIO(&Throttle,APPAT,0,PULSE+L_ALT+USB[0x1E]); // AP path usb code '1'
MapKeyIO(&Throttle,APAH,0,PULSE+L_ALT+USB[0x1F]); // AP ALT/HDG usb code '2' 
MapKeyIO(&Throttle,APALT,0,PULSE+USB[0x0B]); // AP BARO ALT usb code 'h'
MapKey(&Throttle,IDLELON,CHAIN(PULSE+R_ALT+USB[0x4D],D(),LED(&Throttle,LED_ONOFF,LED_CURRENT-LED0))); //Idle->off BACKLIGHT OFF STOP ENGINE, usb code 'end'
MapKey(&Throttle,IDLERON,CHAIN(PULSE+R_CTL+USB[0x4D],D(),LED(&Throttle,LED_ONOFF,LED_CURRENT-LED0))); //Idle->off BACKLIGHT OFF STOP ENGINE, usb code 'end'
MapKey(&Throttle,IDLELOFF,CHAIN(LED(&Throttle,LED_ONOFF,LED_CURRENT+LED0),D(),PULSE+R_ALT+USB[0x4A])); //off->Idle BACKLIGHT ON START ENGINE, usb code 'home'
MapKey(&Throttle,IDLEROFF,CHAIN(LED(&Throttle,LED_ONOFF,LED_CURRENT+LED0),D(),PULSE+R_CTL+USB[0x4A])); //off->Idle BACKLIGHT ON START ENGINE, usb code 'home'

}

int EventHandle(int type, alias o, int x) 
{ 
DefaultMapping(&o, x); 
}