Jump to content

TARGET - Advanced programming


ivanwfr

Recommended Posts

This looks so complicated ... I will never be able to learn to use Target, let's hope my Cougar never dies and lasts for ever :)

 

For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra

For Gaming: 34" Monitor - Ryzen 3600X - 32 GB DDR4 2400 - nVidia GTX1070ti - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar - Oculus Rift CV1

Mobile: iPad Pro 12.9" of 256 GB

Link to comment
Share on other sites

This looks so complicated ... I will never be able to learn to use Target, let's hope my Cougar never dies and lasts for ever :)

 

Here's the thing: you don't need to know this to use TARGET. For simple macros, it isn't much worse than Foxy. However, it does empower you to do complicated things that you can't do with Foxy because you were limited to assembly-level functions that had to be flashed to the hardware.

 

When it comes down to it, there isn't much difference between

USE S1 AS DX5

and

MapKey(&HCougar, S1, DX5);

 

or

 

BTN S1 /I TrackIRPause
/O TrackIRCenter

and

MapKeyIO(&HCougar, S1, TrackIRPause, TrackIRCenter);

 

It's just that TARGET uses C architecture, so you have to be aware of the rules (like semicolons at the end of lines). But it also allows you a lot more power and flexibility.


Edited by Home Fries
Link to comment
Share on other sites

Thanks for the explanation ... tough it still looks like you have to be a computer programmer in order to use Target effectively :)

 

For work: iMac mid-2010 of 27" - Core i7 870 - 6 GB DDR3 1333 MHz - ATI HD5670 - SSD 256 GB - HDD 2 TB - macOS High Sierra

For Gaming: 34" Monitor - Ryzen 3600X - 32 GB DDR4 2400 - nVidia GTX1070ti - SSD 1.25 TB - HDD 10 TB - Win10 Pro - TM HOTAS Cougar - Oculus Rift CV1

Mobile: iPad Pro 12.9" of 256 GB

Link to comment
Share on other sites

Any reason you set GS as a char?

 

Pulled it right off page 44 of the editor manual. Under Logical flags.

include "target.tmh"
char flag1; //we create a flag called flag1
int main()
{
if(Init(&EventHandle)) return 1;
flag1=0; //set the flag1 value to 0 at startup of the configuration
MapKey(&Joystick, S4, EXEC("flag1=1;")); //set the flag1 to 1 (true) when S4 is pressed
MapKeyR(&Joystick, S4, EXEC("flag1=0;")); //set the flag1 to 0 (false) when S4 is released
MapKey(&Joystick, S1, EXEC("if(flag1) ActKey(PULSE+KEYON+'a');")); //If flag1 true (=1) press “a” keystroke
when S1 is pressed.
}
int EventHandle(int type, alias o, int x)
{
DefaultMapping(&o, x);
}

 

That works like a charm.

Can you fix my code so I can see what you mean?

 

and as I write this I think that it doesn't work, because all button pushes in AXMAP2 are PULSE+. Could that be the culprit?

Night Ops in the Harrier

IYAOYAS


 
Link to comment
Share on other sites

Thanks for the explanation ... tough it still looks like you have to be a computer programmer in order to use Target effectively :)

 

 

It helps to know programming, C in particular to do what HomeFries does. But to crate macros, there's a GUI driven point and click that's as simple as Foxy.

 

I guess it comes down to what the definition of effectively.

 

Same question can be said about ED/DCS. Lua code will look very complicated to the lay person, but if you know any programming, it's not that bad. Again, degrees of difficulty.

hsb

HW Spec in Spoiler

---

 

i7-10700K Direct-To-Die/OC'ed to 5.1GHz, MSI Z490 MB, 32GB DDR4 3200MHz, EVGA 2080 Ti FTW3, NVMe+SSD, Win 10 x64 Pro, MFG, Warthog, TM MFDs, Komodo Huey set, Rverbe G1

 

Link to comment
Share on other sites

That works like a charm.

Can you fix my code so I can see what you mean?

 

and as I write this I think that it doesn't work, because all button pushes in AXMAP2 are PULSE+. Could that be the culprit?

 

I've been so swamped at work I haven't had a chance to analyze this until now. There should be nothing wrong with using char, but I like to use int for values I know are Boolean because they have numeric properties and I can toggle them by saying GS = abs(GS-1).

 

However, I found what is up with your routine. PULSE+ can be used and probably should be in this case. When you just say

if(GS) ActKey(Arresting_Hook_Button);

this actually releases the key.

 

if(GS) ActKey(KEYON+Arresting_Hook_Button);

pushes and holds the key, while

if(GS) ActKey(KEYON+PULSE+Arresting_Hook_Button);

pulses the key.

 

 

Here's how I would do it (changes in bold):

include "target.tmh"
include "DCS_F-5ESim_Macro.ttm"

[b]int[/b] GS;  //we create a flag called GS (Gear State)

<...>

MapKey(&Joystick, S1, EXEC("if(GS) ActKey([b]KEYON+PULSE+[/b]Arresting_Hook_Button);")); //If GS true (=1) press “h” keystroke when S1 is pressed.

 

EDIT:

If for whatever reason you want to hold Arresting_Hook_Button for the duration you press S1, do the following:

MapKey (&Joystick, S1, EXEC("if(GS) ActKey(KEYON+Arresting_Hook_Button);"));
MapKeyR(&Joystick, S1, UP+Arresting_Hook_Button);

The MapKeyR is necessary to release the button upon releasing S1.


Edited by Home Fries
  • Like 1
Link to comment
Share on other sites

Lol. After spending about an hour on this, and also wondering what was going on, HomeFries posts the solution.

 

I got this far:

[color=#1e90ff][b]include[/b][/color] [color=#a52a2a]"target.tmh"[/color]

[color=#1e90ff][b]char[/b][/color] GS; [color=#32cd32]//we create a flag called GS (Gear State)[/color]

[color=#32cd32]//program startup[/color]
[color=#1e90ff][b]int[/b][/color] main()
{
   [color=#1e90ff][b]if[/b][/color][color=#ffffff]([/color]Init(&EventHandle)) [color=#1e90ff][b]return[/b][/color] [color=#ffffff]1[/color]; [color=#32cd32]// declare the event handler, return on error[/color]
   
GS[color=#ffffff]=[/color][color=#ffffff]0[/color]; [color=#32cd32]//set the GS value to 0 at startup of the configuration[/color]

MapAxis(&Throttle, THR_FC, DX_SLIDER_AXIS);
   KeyAxis(
       &Throttle,
       THR_FC,
       [color=#ffffff]0[/color],
       AXMAP2(
       [color=#ffffff]3[/color],
       CHAIN[color=#ffffff]([/color]EXEC([color=#a52a2a]"GS=0;"[/color]),PULSE+[color=#a52a2a]'g'[/color]),
       [color=#ffffff]0[/color], 
       CHAIN[color=#ffffff]([/color]EXEC([color=#a52a2a]"GS=1;"[/color]),PULSE+[color=#a52a2a]'G'[/color]) 
               ) 
       );

MapKey(&Joystick, TG1, EXEC(
                           [color=#a52a2a]"if (GS) printf(\"I've just pressed TG1.. GS is %d \\xa\", GS); else printf(\"I've just pressed TG1.. GS is %d \\xa\", GS);"[/color]
                           ));                            [color=#32cd32]//If GS true (=1) press “h” keystroke when S1 is pressed.[/color]

}

[color=#32cd32]//event handler[/color]
[color=#1e90ff][b]int[/b][/color] EventHandle[color=#ffffff]([/color][color=#1e90ff][b]int[/b][/color] type, [color=#1e90ff][b]alias[/b][/color] o, [color=#1e90ff][b]int[/b][/color] x)
{
   DefaultMapping(&o, x);
   
   [color=#32cd32]//add event handling code here[/color]
}

This proved that all the logic was working, as I was getting the message in the Output Window. Which, as HomeFries states, means there is a problem with the ActKey code.

 

Perhaps a nicer way to toggle a flag:

   KeyAxis(
       &Throttle,
       THR_FC,
       [color=#ffffff]0[/color],
       AXMAP2(
       [color=#ffffff]3[/color],
       CHAIN[color=#ffffff]([/color]EXEC([color=#a52a2a]"GS = !GS;"[/color]),PULSE+[color=#a52a2a]'g'[/color]),    // Toggle the "GS" flag
       [color=#ffffff]0[/color], 
       CHAIN[color=#ffffff]([/color]EXEC([color=#a52a2a]"GS= !GS;"[/color]),PULSE+[color=#a52a2a]'g'[/color])      // Toggle the "GS" flag
               ) 
       );                                           

This works with either "char" or "int" as the flag type.


Edited by Thermal
Link to comment
Share on other sites

Okay.. I am just trying to get to grips with the TARGET script, and am happliy chugging along, when all of a sudden I get this message, even though I have not even touched the target.tmh:

 

Running script: C:\Users\username\Saved Games\TARGET Profiles\F5_E_Rev_1.tmc

*** Allocated ProcInstances found from the previous run: use FreeProcInstance() ***

Mapped plugin module "C:\Program Files (x86)\Thrustmaster\TARGET\Plugins\sys.dll"

Compile Succeeded.

Physical USB HID devices managed by script!

Currently plugged USB HID devices[2]:

1: "Joystick - HOTAS Warthog" - "USB\VID_044F&PID_0402&REV_0100"

2: "Throttle - HOTAS Warthog" - "USB\VID_044F&PID_0404&REV_0100"

USB HID device "Throttle - HOTAS Warthog"(USB\VID_044F&PID_0404\6&1C446172&0&3) selected

USB HID device "Joystick - HOTAS Warthog"(USB\VID_044F&PID_0402\7&2DA72DBE&0&2) selected

USB HID device with hardware id "VID_044F&PID_b351" cannot be found

USB HID device with hardware id "VID_044F&PID_b352" cannot be found

USB HID device with hardware id "VID_044F&PID_0400" cannot be found

USB HID device with hardware id "VID_044F&PID_B10A" cannot be found

USB HID device with hardware id "VID_044F&PID_B10B" cannot be found

USB HID device with hardware id "VID_044F&PID_B687" cannot be found

USB HID device with hardware id "VID_044F&PID_B679" cannot be found

Virtual HID devices managed by script!

Connecting virtual joystick...Done

Device name set to Thrustmaster Combined

Connecting virtual keyboard...Done

Connecting virtual mouse (absolute axes)...Done

Script stopped!

 

Runtime Error: Index out of bounds for: joy2 in MapKeyIOUMD ( line 329 in target.tmh )

 

 

Now WTF???

 

Looking at the line in question is all chinese to me.

I have just been doing Keymapping for the F5E, and experimenting with the shifted function.

 

My profile looks like this:

 

include "target.tmh"

include "F5_E_Macros.ttm"

 

int main()

{

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

// ALL AXIS MAPPING TO BE DONE WITHIN DCS

 

//Axis mapping Thrustmaster Warthog Joystick

MapAxis(&Joystick, JOYX, DX_X_AXIS,AXIS_NORMAL,MAP_ABSOLUTE);

MapAxis(&Joystick, JOYY, DX_Y_AXIS,AXIS_NORMAL,MAP_ABSOLUTE);

 

// Axis mapping Thrustmaster Warthog Throttle

MapAxis(&Throttle, THR_LEFT, DX_ZROT_AXIS,AXIS_NORMAL,MAP_ABSOLUTE);

MapAxis(&Throttle, THR_RIGHT, DX_Z_AXIS,AXIS_NORMAL,MAP_ABSOLUTE);

//MapAxis(&Throttle, SCX, DX_XROT_AXIS,AXIS_NORMAL,MAP_ABSOLUTE);

//MapAxis(&Throttle, SCY, DX_YROT_AXIS,AXIS_NORMAL,MAP_ABSOLUTE);

//MapAxis(&Throttle, THR_FC, DX_SLIDER_AXIS,AXIS_NORMAL,MAP_ABSOLUTE);

 

//Shift Key Map

 

SetShiftButton(&Joystick,S4); //Turns the paddle switch into the shift button

 

//Key Mapping Thrustmaster Warthog Joystick

MapKey(&Joystick,TG1,PULSE+Cannon_First_Detent); // Fire the Cannon, First stage of the trigger

MapKey(&Joystick,TG2,Fire_Cannon); // Second stage of the trigger

MapKey(&Joystick,S2,Release_Weapon); //Release missiles or bombs

MapKey(&Joystick,S1,PULSE+Kneeboard_PosMark); //Mark Position on Map on Kneeboard

MapKey(&Joystick,S3,NWS); //Engage Nosewheel steering

MapKey(&Joystick,S4,Aileron_Limiter); //Shift Function for other Switches.

 

//Trim Button

MapKey(&Joystick,H1U,Trim_Up); //TrimHat Nose Up

MapKey(&Joystick,H1D,Trim_Down); //TrimHat Nose Down

MapKey(&Joystick,H1L,Trim_Left); //TRimHat Nose Left

MapKey(&Joystick,H1R,Trim_Right); //TrimHat Nose Right //COMPLETED

 

//TMS 4 Way Switch

MapKeyIO(&Joystick,H2U,Ret_inc,CRS_sel_inc); //TMS Up

MapKeyIO(&Joystick,Ret_dec,H2D,CRS_sel_dec); //TMS Down

MapKeyIO(&Joystick,SightMode_ccw,H2L,HDG_bug_inc); //TMS Left

MapKeyIO(&Joystick,H2R,SightMode_cw,HDG_buc_dec); //TMS Right

 

//DMS 4 Way Switch

MapKeyIO(&Joystick,H3U,Radar_rng_inc,Kneeboard_toggle); // DMS Up

MapKeyIO(&Joystick,H3D,Radar_rng_dec,Kneeboard_glance); // DMS Down

MapKeyIO(&Joystick,H3L,Radar_sel_ccw,Kneeboard_nextPage); // DMS Left

MapKeyIO(&Joystick,H3R,Radar_sel_cw,Kneeboard_prevPage); // DMS Right

 

//CMS 4 Way Switch and push

MapKeyIO(&Joystick,H4U,TAC_ch_10s_Inc,Dogfight_Resume_DM); //CMS Up

MapKeyIO(&Joystick,H4D,TAC_ch_10s_Dec,Dogfight_Resume_DG); //CMS Down

MapKeyIO(&Joystick,H4P,TAC_xy_sel,Dogfight_Resume_Search); //CMS Press

MapKeyIO(&Joystick,H4L,TAC_ch_1s_Inc,Target_Lock); //CMS Left

MapKeyIO(&Joystick,H4R,TAC_ch_1s_Dec,Target_Unlock); //CMS Right //COMPLETED

 

//Key Mapping Thrustmaster Warthog Throttle Base

 

MapKey(&Throttle,APUON,

CHAIN(PULSE+PWR_ON,

D(50),

LED(&Throttle,LED_INTENSITY,129))); //SWITCHES ON MAIN POWER AND COCKPIT LIGHTS plus Background light on Throttle

MapKey(&Throttle,APUOFF,

CHAIN(PULSE+PWR_ON,

LED(&Throttle,LED_INTENSITY,0))); // Switches off the power and background light on Throttle Base. //COMPLETED

 

//ENGINE FUEL SWITCHES

MapKey(&Throttle,EFLNORM,PULSE+NoseStrut_ext); //Extends Nose Strut

MapKey(&Throttle,EFLOVER,PULSE+NoseStrut_ret); //Retracts Nose Strut

MapKey(&Throttle,EFRNORM,PULSE+PitotHeat);

MapKey(&Throttle,EFROVER,PULSE+PitotHeat); //COMPLETED

 

//ENGINE START AND MOTOR SWITCHES

MapKey(&Throttle,EOLIGN,Engine_L_START); //Starts Left Engine

MapKey(&Throttle,EOLNORM);

MapKey(&Throttle,EOLMOTOR);

MapKey(&Throttle,EORIGN,Engine_R_START); //Starts Right Engine //COMPLETED

MapKey(&Throttle,EORNORM);

MapKey(&Throttle,EOLMOTOR);

 

//LDG HORN MUTE BUTTON

MapKey(&Throttle,LDGH,PULSE+Audible_Warn_Reset); //Resets Master Caution and Audible Warning //COMPLETED

 

//FLAP HANDLE

MapKey(&Throttle,FLAPU,CHAIN(PULSE+Flaps_Emer_UP,D(),Landing_Light_Toggle)); //Selects Flaps Up

MapKey(&Throttle,FLAPM,PULSE+Flaps_ThumbSwitch); //Toggles Gear and Landing light

MapKey(&Throttle,FLAPD,PULSE+Flaps_FULL); //Sets TakeOffFlaps and Landing Ligths //COMPLETED

 

//EAC SWITCHES

MapKey(&Throttle,EACON,PULSE+Canopy_CLS); //Closes Canopy

MapKey(&Throttle,EACOFF,PULSE+Canopy_OPN); //Opens Canopy //COMPLETED

 

//RDR ALTM

MapKey(&Throttle,RDRNRM,PULSE+Beacon_ON); //

MapKey(&Throttle,RDRDIS,PULSE+Beacon_OFF); // //COMPLETED

 

// AP ENG BUTTON

MapKey(&Throttle,APENG,TEMPO(PULSE+Jettison_Stores, //Short Push Jettisons External Tanks

CHAIN(PULSE+Eject, //Long Push (1 sec) Eject!

D(),

PULSE+Eject,

D(),

PULSE+Eject),

1000)); //COMPLETED

MapKey(&Throttle,APDIS);

 

//AP MODE TOGGLE

MapKey(&Throttle,APPAT,PULSE+Gear_Up);

MapKey(&Throttle,APAH);

MapKey(&Throttle,APALT,PULSE+Gear_Down); //COMPLETED

 

//ENGINE TRHUST LEVERS CUTOFF

MapKeyR(&Throttle,IDLELOFF,Engine_L_STOP); //Shutdown Left Engine

MapKeyR(&Throttle,IDLEROFF,Engine_R_STOP); //Shutdown Right Engine //COMPLETED

 

//Key Mapping Thrustmaster Warthog Throttle Throttles

 

//COOLIE SWITCH, Switched function. TDC control and Radar Scan Zone in Switched Mode

MapKey(&Throttle,CSU,TDC_up);

MapKey(&Throttle,CSD,TDC_dn);

MapKey(&Throttle,CSR,TDC_r);

MapKey(&Throttle,CSL,TDC_l);

 

//SLEW CONTROL

MapKey(&Throttle,SC);

 

//LEFT THROTTLE BUTTON

MapKey(&Throttle,LTB);

 

//PINKY SWITCH

MapKey(&Throttle,PSF);

MapKey(&Throttle,PSM);

MapKey(&Throttle,PSB);

 

//MIC SWITCH

MapKey(&Throttle,MSP);

MapKey(&Throttle,MSU);

MapKey(&Throttle,MSR);

MapKey(&Throttle,MSD);

MapKey(&Throttle,MSL);

 

//SPEEDBRAKE

MapKey(&Throttle,SPDF,PULSE+Airbrake_OFF);

MapKey(&Throttle,SPDM);

MapKey(&Throttle,SPDB,PULSE+Airbrake_ON); //COMPLETED

 

//BOAT SWITCH

MapKey(&Throttle,BSF,CHAIN(PULSE+Flaps_S_UP,

D(),

PULSE+Landing_light_Toggle));

MapKey(&Throttle,BSM,PULSE+Flaps_S_Auto);

MapKey(&Throttle,BSB,CHAIN(PULSE+Flaps_S_Fixed,

D(),

PULSE+Landing_Light_Toggle));

 

//CHINA HAT

MapKey(&Throttle,CHF,PULSE+ChaffFlare);

MapKey(&Throttle,CHM);

MapKey(&Throttle,CHB,PULSE+ChaffFlare); //COMPLETED

 

//add initialization code here

}

 

//event handler

int EventHandle(int type, alias o, int x)

{

DefaultMapping(&o, x);

 

//add event handling code here

}

 

And the macros file like this:

 

// Keys are defined as USB and should be independent of keyboard type.

 

 

// Definitions Weapons

define Fire_Cannon USB[0X2C] // SPACE

define Cannon_First_Detent USB[0X0C] // I

define Release_Weapon R_ALT+USB[0X2C]

 

// Definitions Flight Control

 

define Trim_Up R_CTL+USB[0x33]

define Trim_Down R_CTL+USB[0x37]

define Trim_Left R_CTL+USB[0x36]

define Trim_Right R_CTL+USB[0x38]

define Aileron_Limiter USB[0X0F] // L //okay

 

// Definitions Systems

 

define Airbrake_ON L_SHIFT+USB[0X05] //B+LEFT SHIFT

define Airbrake_OFF L_CTL+USB[0X05] //B+LEFT CONTROL

 

define Flaps_FULL L_CTL+USB[0X07] //LEFT CTL + D

define Flaps_Emer_UP L_SHIFT+USB[0X07] //d+LEFT SHIFT

define Flaps_ThumbSwitch USB[0X07] // d

define Flaps_S_Fixed L_CTL+USB[0X09]

define Flaps_S_UP L_SHIFT+USB[0X09]

define Flaps_S_Auto USB[0X09]

define Gear_Down L_SHIFT+USB[0X0A] //G+LEFT SHIFT

define Gear_Up L_CTL+USB[0X0A] //G+LEFT CONTROL

 

define NavLights_ON R_CTL+USB[0X0F] //L+RIGHT CONTROL

define NavLights_OFF R_CTL+USB[0X0F] // TOGGLE AS ABOVE

 

define Landing_Light_Toggle L_CTL+L_SHIFT+USB[0X1D] //L_CTL+L_SHIFT Z TOGGLES Landing Light.

 

define NWS USB[0X16] // S

define NoseStrut_ext L_ALT+USB[0X14]

define NoseStrut_ret R_ALT+USB[0X14]

define Canopy_OPN L_CTL+USB[0X06] //C+LEFT CONTROL

define Canopy_CLS L_CTL+USB[0X06] //TOGGLE ABOVE

 

define DragChute_handle_pull_push USB[0X13] //P

 

define Engine_L_START L_CTL+L_SHIFT+USB[0X06] // L CTRL L SHIFT C

define Engine_R_START L_CTL+L_SHIFT+USB[0X19] //L CTRL L SHIFT V

 

define Engine_L_STOP R_ALT+USB[0X4D] //RAlt END

define Engine_R_STOP R_SHIFT+USB[0X4D] //END RIGHT Shift

define Engine_L_IDLE R_ALT+USB[0X4A] //RAlt Home

define Engine_R_IDLE R_SHIFT+USB[0X4A] //RShift Home

 

define Eject L_CTL+USB[0X08] //L CTRL AND E X3

 

define Batt_ON R_CTL+R_SHIFT+USB[0X05] // RIGHT CTL + RIGHT SHIFT B (SHOULD ALSO POWER OFF AND ON THE BACKLIGHT ON THE THROTTLE BASE)

 

define Beacon_OFF R_CTL+R_ALT+USB[0X13] // RIGHT CTL + RIGHT ALT P

define Beacon_ON L_CTL+L_ALT+USB[0X13] // RIGHT CTL + RIGHT ALT P

 

define Nose_Strut L_ALT+L_CTL+USB[0X14] //L ALT + L CTL Q

define PitotHeat R_CTL+R_SHIFT+USB[0X09]

define Seat_adjust_UP L_SHIFT+USB[0X19] //L SHIFT W

define Seat_adjust_DN USB[0X19] // W

 

define Jettison_Stores L_CTL+L_SHIFT+USB[0X07] // L CTRL LSHIFT D

 

define Audible_Warn_Reset R_ALT+USB[0X38] //RIGHT ALT /

 

 

//Definitions Weapons Modes

define SightMode_sel_cw R_ALT+USB[0X1F]

define SightMode_sel_ccw R_ALT+USB[0X1E]

define Ret_dec R_CTL+USB[0X2F]

define Ret_inc R_CTL+USB[0X30]

 

//Definitions Sensors

define Radar_rng_inc USB[0X2E] //=

define Radar_rng_dec USB[0X2D] //-

define Radar_mode_sel_cw USB[0X27] // 0

define Radar_mode_sel_ccw USB[0X26] // 9

 

define TDC_up USB[0X33]

define TDC_dn USB[0X37]

define TDC_l USB[0X36]

define TDC_r USB[0X38]

 

define Target_ACQ USB[0X28] // ENTER

define Target_Unlock USB[0X2A] // BACK

define Radar_Sel_CW USB[0X26] // 9

define Radar_Sel_CCW USB[0X27] // 0

 

define Dogfight_Resume_DG USB[0X23] // 6, Gun mode

define Dogfight_Resume_DM USB[0X22] // 5, Missile

define Dogfight_Resume_SEARCH USB[0X15] // 5, Radar to resume Search

//Definitions Countermeasures

 

define ChaffFlare USB[0X14]// Q

 

 

 

//Define Navigation, TACAN

define TAC_ch_10s_Inc L_SHIFT+USB[0X26] // L SHIFT 9

define TAC_ch_10s_Dec L_CTL+USB[0X26] // L CTRL 9

define TAC_ch_1s_Inc L_SHIFT+USB[0X25] // L SHFITF 8

define TAC_ch_1s_Dec L_CTL++USB[0X25] // L CTL 8

define TAC_xy_sel L_SHIFT+USB[0X1C] // L SHIFT Y

 

define CRS_sel_inc L_ALT+L_SHIFT+USB[0X21] // L ALT L SHIFT 4

define CRS_sel_dec L_ALT+L_SHIFT+USB[0X20] //L ALT L SHIFT 3

define HDG_bug_inc L_ALT+L_SHIFT+USB[0X1F] //L ALT L SHIFT 2

define HDG_bug_dec L_ALT+L_SHIFT+USB[0X1E] //L ALT L SHIFT 1

 

//Define Kneeboard Settings

 

define Kneeboard_toggle R_SHIFT+USB[0X0E]

define Kneeboard_nextPage USB[0X30]

define Kneeboard_prevPage USB[0X2F]

define Kneeboard_glance USB[0X0E]

 

define Kneeboard_PosMark R_CTL+USB[0X0E]

 

Now, where did I botch up the target.tmh????

[sIGPIC]If you are still under control you are not going fast enough[/sIGPIC]

Link to comment
Share on other sites

 

//TMS 4 Way Switch

MapKeyIO(&Joystick,H2U,Ret_inc,CRS_sel_inc); //TMS Up

MapKeyIO(&Joystick,Ret_dec,H2D,CRS_sel_dec); //TMS Down

MapKeyIO(&Joystick,SightMode_ccw,H2L,HDG_bug_inc); //TMS Left

MapKeyIO(&Joystick,H2R,SightMode_cw,HDG_buc_dec); //TMS Right

 

 

Looks like a bad cut n paste job in the TMS section. I've done it enough times to know that compiler won't catch everything.

 

You have a button names that don't exist infront of the buttons your trying to map.

Night Ops in the Harrier

IYAOYAS


 
Link to comment
Share on other sites

Looks like a bad cut n paste job in the TMS section. I've done it enough times to know that compiler won't catch everything.

 

You have a button names that don't exist infront of the buttons your trying to map.

 

 

 

HAH. this proves the value of these fora. Thanks. I had stared myself blind on that one.

 

 

Sent from my iPad using Tapatalk

[sIGPIC]If you are still under control you are not going fast enough[/sIGPIC]

Link to comment
Share on other sites

Thanks Home Fries,

Got it working just fine. Hope I explained it well enough below.

 

However, I found what is up with your routine. PULSE+ can be used and probably should be in this case. When you just say

if(GS) ActKey(Arresting_Hook_Button);

this actually releases the key.

 

if(GS) ActKey(KEYON+Arresting_Hook_Button);

pushes and holds the key, while

if(GS) ActKey(KEYON+PULSE+Arresting_Hook_Button);

pulses the key.

 

 

Here's how I would do it (changes in bold):

include "target.tmh"
include "DCS_F-5ESim_Macro.ttm"

[b]int[/b] GS;  //we create a flag called GS (Gear State)

<...>

MapKey(&Joystick, S1, EXEC("if(GS) ActKey([b]KEYON+PULSE+[/b]Arresting_Hook_Button);")); //If GS true (=1) press “h” keystroke when S1 is pressed.

 

After several attempts to use your code changes, I found that PULSE+ will result in a key being pressed, but will not trigger the desired result.

Example:

MapKey(&Joystick, S1, EXEC("if(GS) ActKey([b]KEYON+PULSE+[/b]Arresting_Hook_Button);"))

The Hook won't drop. You can see in the cockpit, the the button is pushed ever so slightly and momentarily lights. Then goes dark. It should stay lit.

 

Then I tried your alternative

If for whatever reason you want to hold Arresting_Hook_Button for the duration you press S1, do the following:

MapKey (&Joystick, S1, EXEC("if(GS) ActKey(KEYON+Arresting_Hook_Button);"));
MapKeyR(&Joystick, S1, UP+Arresting_Hook_Button);

The MapKeyR is necessary to release the button upon releasing S1.

 

That worked like a charm. Even got the parachute to fire with S4 shift state command on the same button.

The code I implemented:

MapKeyIO(&Joystick, S1, EXEC("if(GS) ActKey(KEYON+Drag_Chute_T_Handle_PULL_PUSH);"),  //If GS true (=1) press “p” keystroke when S1 is pressed.
                       EXEC("if(GS) ActKey(KEYON+Arresting_Hook_Button);")); //If GS true (=1) press “h” keystroke when S1 is pressed.
MapKeyR(&Joystick, S1, UP+Arresting_Hook_Button);
MapKeyR(&Joystick, S1, Drag_Chute_T_Handle_PULL_PUSH);

OK,

After more extensive testing, the above code does not work. Using MapKeyR twice for the same button "S1", will only result in the first instance

[b]MapKeyR(&Joystick, S1, UP+Arresting_Hook_Button);
[/b]MapKeyR(&Joystick, S1, Drag_Chute_T_Handle_PULL_PUSH);

being read. Resulting in "Drag_Chute_T_Handle_PULL_PUSH" bieng held down.

 

Looking through the target.tmh I found MapKeyRIO. Set it up just as it was a MapKeyIO like this:

MapKeyRIO(&Joystick, S1, UP+Arresting_Hook_Button,UP+Drag_Chute_T_Handle_PULL_PUSH);

This so far is working.

 

Next thing is to get some wheels up functionality.


Edited by SGT Coyle

Night Ops in the Harrier

IYAOYAS


 
Link to comment
Share on other sites

  • 3 weeks later...

Why does this throw out error?

 

include "target.tmh"
include "WinKeyTest_Macro.ttm"
char Flap;  //Flap will either be 1(Up),2(middle),or 3(down)
int Flaps_UP_A, Flaps_DN_A;  //function to encapsulae CHAIN function.

//program startup
int main()
{
Flaps_UP_A = CHAIN(PULSE+'f',D(),PULSE+'f');

   if(Init(&EventHandle)) return 1; // declare the event handler, return on error
   
   //add initialization code here
Flap = 2;    
   
   MapKey(&Throttle,FLAPU, CHAIN(
                   EXEC("if(Flap > 2) ActKey(KEYON+Flaps_UP_A); else ActKey(PULSE+KEYON+FlapUP);"),
                   EXEC("Flap = 1")
                   ));
   
                                   
}

//event handler
int EventHandle(int type, alias o, int x)
{
   DefaultMapping(&o, x);
   
   //add event handling code here
}

 

Error:

Runtime Error: Incorrect parameters number for: CHAIN in main ( line 11 in Win Key test.tmc )

 

Been pulling out hair again

Night Ops in the Harrier

IYAOYAS


 
Link to comment
Share on other sites

A few things to try for the line 11 error:

1) Add an actual value in D()

2) remove: include "WinKeyTest_Macro.ttm"

3) Put line 11 the other side of the if(Init(&Event line....

 

Edit: It looks like it works if you do (3). With (1), there is a default defined in target.tmh, so its not that.


Edited by Thermal
Link to comment
Share on other sites

Still pulling hair, but for different reasons.

Try this:

 

include "target.tmh"
include "WinKeyTest_Macro.ttm"
char Flap;  //Flap will either be 1(Up),2(middle),or 3(down)
int Flaps_UP_A, Flaps_DN_A;  //function to encapsulae CHAIN function.

//program startup
int main()
{


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

Flaps_UP_A = CHAIN(PULSE + FlapUp, D(50), PULSE + FlapUp);
Flaps_DN_A = CHAIN(PULSE + FlapDown, D(50), PULSE + FlapDown);
Flap = 3;    
   
   MapKey(&Throttle,FLAPU, CHAIN(
                   EXEC("if(Flap > 2) ActKey(KEYON+Flaps_UP_A); else ActKey(PULSE+KEYON+FlapUp);"),
                   EXEC("Flap = 1;")
                   ));
                   
   MapKey(&Throttle,FLAPM, CHAIN(
                   EXEC("if(Flap > 2) ActKey(PULSE+KEYON+FlapUp); else ActKey(PULSE+KEYON+FlapDown);"),
                     EXEC("Flap = 2;")
                    ));
                   
   MapKey(&Throttle,FLAPD, CHAIN(
                   EXEC("if(Flap < 2) ActKey(KEYON+Flaps_DN_A); else ActKey(PULSE+KEYON+FlapDown);"),
                   EXEC("Flap = 3;")
                   ));                
                                   
}

//event handler
int EventHandle(int type, alias o, int x)
{
   DefaultMapping(&o, x);
   
   //add event handling code here
}

accompanying .ttm

define    FlapUp    'f'
define    FlapDown    L_SHIFT + "f"    

Using the event tester-

 

If I run this with the line blocks 23-26 and 28-31 commented out, script runs fine. Block 18-21 runs as it should.

 

If I run the above without those blocks commented out and Flap lever in the middle pos at start, I get:

 

Flap lever from FLAPM -> FLAPU = f , f pressed and released.

 

Flap lever from FLAPU -> FLAPM = L_ALT, R_ALT, L_CTL, R_CTL, R_WIN pressed but not released.

 

Some strange behavior.

I've restarted TARGET several times, I've re-plugged in my Warthog several times, restarted system twice, and ran the repaired TARGET. Always the same result.

 

???

 

 

p.s.

 

ivanwfr,

I'm rereading your original post with a better, if not nearly enough, programming knowledge. Very much trying to understand how TARGET and C are related and where they split.

Thanks for starting this thread.

 

Thermal,

Never got around to thanking you for your help on my F5 landing gear "Gear State" problem. Although Homefries was most helpful with the problem itself, you gave me a better understanding of how to use the "printF" command.

Thanks


Edited by SGT Coyle

Night Ops in the Harrier

IYAOYAS


 
Link to comment
Share on other sites

I've not dug into your script closely, but I had a more high level thought about what you want to achieve.

 

You could try running:

MapKey(&Throttle, FLAPU, CHAIN(FlapUp, D(), FlapUp);

MapKeyR(&Throttle, FLAPU, FlapDown);

 

MapKey(&Throttle, FLAPD, CHAIN(FlapDown, D(), FlapDown);

MapKeyR(&Throttle, FLAPD, FlapUp)

 

Its self-synchronizing with the aircraft, and it wont care what your starting state is.

Link to comment
Share on other sites

  • 2 months later...

I started using the script editor today and I'm stuck with something. Basically I want to execute a command indefinitely with some delay if a 2-way switch is in the forward position, and stop if it's in the backward position. I thought I would do this with a function and a while loop but it's not working and I honestly have no idea why. The current target application is to cycle through waypoints in both directions using the fuel flow switches on the throttle.

 

This is what it looks like currently (key pressed is just randomly 'a' for testing purposes):

 

...  main

MapKey(&Throttle, EFRNORM, EXEC("WP_INC();"));

...

int WP_INC()
{
int delay = 1000;
while(Throttle[EFRNORM])
{		
	ActKey(DeferCall(delay, &ActKey, PULSE+KEYON+'a'));	
}
}

...

 

Help is appreciated! For now I'll probably settle for making a simple CHAIN, but it won't look pretty :)

Link to comment
Share on other sites

The command you're looking for is REXEC. It repeats an EXEC at a specified increment for as long as the switch is held, and you can also use the StopAutoRepeat() command if you need to force terminate the REXEC.

 

Here's how I would do your routine:

MapKey(&Throttle, EFRNORM, REXEC(6, 1000, "ActKey(KEYON+PULSE+'a');")	);	
MapKey(&Throttle, EFROVER,  EXEC("StopAutoRepeat(6);")	);

the '6' in the REXEC is just a process identifier; you can use whatever you want (use different numbers if you have different REXECs going at the same time). You probably don't need the StopAutoRepeat() command, but i put it in my routines just to be sure.

Link to comment
Share on other sites

Thanks! Works like a charm. Is there any reference other than the official script manual? It would be great to have a full list of commands' date=' button position names, etc? I was using another forum post here for the button names.[/quote']

In the Thrustmaster\TARGET\Resources folder, there are PDFs for each of the controllers with the switch/button names on them. For everything else, I just usually Google how to do something in C.

Link to comment
Share on other sites

Thanks! Works like a charm. Is there any reference other than the official script manual? It would be great to have a full list of commands' date=' button position names, etc? I was using another forum post here for the button names.[/quote']

 

It is also very helpful to review the TARGET include files (C:\Program Files (x86)\Thrustmaster\TARGET\scripts\...) as there are a lot of defines, axis names, and other details in these files that are useful. When I am doing some of my more advanced scripts, I tend to keep these files open in my text editor and refer to them a lot.

 

The 4 files are:

 

defines.tmh

Includes all the names for the DirectX axis and buttons, as well as the axis and button names for all the supported Thrustmaster game controllers.

 

sys.tmh

Includes the definition of many of the generic C functions that you can use in TARGET. Not much documentation on the functions, but at least let's you know what functions you can expect to use. Most of them are TARGET versions of common C functions (string functions, math functions, file open/close/editing functions, and even functions that would allow you to access Windows standard libraries (.DLL's).

 

target.tmh

Of course this is the main file for those that really want to get into the deep details of TARGET. This is where all the functions are defined (MapKey(), MapAxis(), etc.), but also includes a lot of other functions which are not documented in the PDF files, but which may be useful.

 

hid.tmh

Contains a lot of obscure defines and other function calls dealing with the Windows hid interface for TARGET. This is probably some of the most advanced stuff in TARGET, but the least useful for more generic advanced TARGET scripts. I.e. understanding target.tmh is the one that will really give you an understanding of advanced TARGET programming. Understanding hid.tmh is not so critical.

Link to comment
Share on other sites

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...