Forums » Technology » Flight Sim Controllers » T.A.R.G.E.T. (Thrustmaster) » Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? Active Topics You are not logged in. [Log In] [Register User]
Page 1 of 2 1 2 >
Topic Options
Rate This Topic
Hop to:
#3316861 - 06/12/11 12:04 AM Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET?
Lancelot Offline
Member

Registered: 01/02/01
Posts: 1104
Loc: Buenos Aires, Argentina
I tried using the same as foxy, and compiled fine, but when i run the script i get a runtime error indicating that does not recognize the symbol (H1UR, or H1DR, or H1DL or H1UL).

Code example
MapKeyIO(&HCougar, H1UR, View_Right_Front_Up,
View_Front_Right);


I searched the entire manual but could not find it.

Thanks in advance. smile
_________________________
Si hay que huir, YO PRIMERO!!!

Top
#3317229 - 06/12/11 03:11 PM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: Lancelot]
ivanwfr Offline
Junior Member

Registered: 05/09/11
Posts: 6
The mistake is: H1UR

This switch is not right, Throttle and Joystick switch numbers are declared in the file defines.tmh which is in the script folder near target.tmh included file.

Code:
// ------- Warthog Joystick -------------
.../...
define H1U                              29
define H1R                              30
define H1D                              31
define H1L                              32
.../...


But you can handle cornered hat:
Code:

include "target.tmh"
int main() {
    if(Init(&EventHandle)) return 1;
}

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

    if     ((&o==&Joystick) & (x>=H1U) & (x<=H1L))  // H1[URDL]
        handleHat(H1U);
    else if((&o==&Joystick) & (x>=H2U) & (x<=H2L))  // H2[URDL]
        handleHat(H2U);
    else if((&o==&Joystick) & (x>=H3U) & (x<=H3L))  // H3[URDL]
        handleHat(H3U);
    else if((&o==&Joystick) & (x>=H4U) & (x<=H4P))  // H4[URDLP] = [14-18]  -- !order=URDL  -- @see defines.tmh
        handleHat(H4U);
    else
        DefaultMapping(&o, x);
}

int ActHatKeyCalled = 0;

int handleHat(int hat)
{
    if( !ActHatKeyCalled ) {
        ActHatKeyCalled = 1;
        DeferCall(2 * kb_delay, &ActHatKey, hat);
    }
    else {
        // just wait for the pending one to happen
    }

}
int ActHatKey(int hat) {

    int u   = Joystick[hat  ];
    int r   = Joystick[hat+1];
    int d   = Joystick[hat+2];
    int l   = Joystick[hat+3];

    int num = 0;
    if     (u & r) num = 9;
    else if(u & l) num = 7;

    else if(d & l) num = 1;
    else if(d & r) num = 3;

    else if( u   ) num = 8;
    else if( d   ) num = 2;
    else if( l   ) num = 4;
    else if( r   ) num = 6;

    if(num != 0) {
        if(num == view_locked)  unlock_view();
        else                                    lock_view(hat, num);
    }

    ActHatKeyCalled = 0;

}

int view_locked = 0;
int lock_view(int hat, int num)
{
    // Enter/Keep "snap view mode"
    if(view_locked==0) {
        printf("[SNAP ON-%d]", hat);
        ActKey(LOCK);
        ActKey(KEYON+ R_CTL+   0);
        ActKey(KEYON+        KP0); Sleep( 10 );
        ActKey(              KP0);
        ActKey(       R_CTL+   0);
    }
    if(num) {
        ActKey(LOCK);
        ActKey(KEYON+ KPENT+num); Sleep( kb_delay );
        ActKey(       KPENT+num);
        ActKey(LOCK);
        view_locked = num;
        printf(" %d", view_locked);
    }
}
int unlock_view()
{
    // Leave "snap view mode"
    printf(" OFF]\xa", view_locked);
    ActKey(LOCK);
    ActKey(KEYON+ KP0  ); Sleep( kb_delay );
    ActKey(       KP0  );
    ActKey(LOCK);
    view_locked = 0;
}



Edited by ivanwfr (06/14/11 01:45 PM)
Edit Reason: added example

Top
#3322177 - 06/18/11 10:54 PM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: Lancelot]
Lancelot Offline
Member

Registered: 01/02/01
Posts: 1104
Loc: Buenos Aires, Argentina
Thanks ivanwfr, but... Do i have to use all that code to handle diagonal positions of the trim hat? (cornered hat as you put it?.
Cant i just define H1UR, H1DR, H1DL and H1UL on the "defines.tmh" file and use those names on the tmc file?

Also, where are defined KP+, KP-. KP/, KP* and KP. (or KP DEL)?
_________________________
Si hay que huir, YO PRIMERO!!!

Top
#3323163 - 06/20/11 11:33 AM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: Lancelot]
Nicu Offline
Junior Member

Registered: 10/31/10
Posts: 70
TARGET converts HAT1 8 positions in 4 virtual buttons (H1U, H1R, H1D, H1L).
You still can use corners with EXEC, like in the following example, which presses the key 'a' while H1UR is pressed:

Code:
define H1URKey 'a'
...

MapKey(&Joystick, H1U, EXEC("if(Joystick[H1R]) ActKey(KEYON+H1URKey);", "if(Joystick[H1R]) ActKey(H1URKey);"));
MapKey(&Joystick, H1R, EXEC("if(Joystick[H1U]) ActKey(KEYON+H1URKey);", "if(Joystick[H1U]) ActKey(H1URKey);"));


This construct can be used also for non real hat controls (which have only 4 positions, not 8 like a real HAT), like H2, H3, H4.

If only pulses are required, you can write more simpler:

Code:
MapKey(&Joystick, H1U, EXEC("if(Joystick[H1R]) ActKey(KEYON+PULSE+H1URKey);"));
MapKey(&Joystick, H1R, EXEC("if(Joystick[H1U]) ActKey(KEYON+PULSE+H1URKey);"));


If you don't know how to produce a certain key, you can use the TARGET GUI and the virtual keyboard. Then you generate the script and view it. It is possible some keys to be accessible only with the USB code.


Edited by Nicu (06/20/11 11:47 AM)

Top
#3329853 - 06/27/11 07:29 PM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: Lancelot]
Lancelot Offline
Member

Registered: 01/02/01
Posts: 1104
Loc: Buenos Aires, Argentina
Thanks Nicu, i will try it!
_________________________
Si hay que huir, YO PRIMERO!!!

Top
#3331343 - 06/29/11 12:38 PM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: Lancelot]
ivanwfr Offline
Junior Member

Registered: 05/09/11
Posts: 6
Hi Lancelot, sorry, I'm late but these SimHQ forum is so quiet compared to ED forums that I miss some new messages here.

The code I mentioned above is the result of a study about what we can expect from TM hats
and the way to handle the different cases. There are only 2 good reasons to use this complicated
code instead of Nicu's macros.

1- Some hats can activate only one of their 4 switches a any single time and others can close 2
of them when pushed into a corner. You can monitor this with DeviceAnalyzer. It means that you
will sometimes have 2 depressed switches when you push a hat into a corner.
Which comes first is random... I don't like random when selecting TAD or HUD as SOI.
That lead you to random MVCD display... not good!

2- ActKey() is MUCH quicker than EXEC macros... here too random missing key press drive me crazy.

But I agree, this is not casual programming and if you want to understand all of it, it's another
layer of hard work for this sim, again!

But you don't really need to. We have 2 options here:
1. Either keep it simple enough to master it and keep it bellow the pain in the ass threshold.
2. Or just ask some geeks like me for something cool you would like to experiment.

For option 2, I opened a thread in ED forum. But it happens to be scary enough to drive readers away wink
TARGET - Advanced programming
...My own code is attached at the bottom of first thread and I keep it up to date with new experimentation.
Currently trying to "Export.lua" DCS parameters to TARGET and see where it can get us.

Top
#3333125 - 07/01/11 07:46 PM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: Lancelot]
Lancelot Offline
Member

Registered: 01/02/01
Posts: 1104
Loc: Buenos Aires, Argentina
Thanks Ivan for all the clarifications, they are very welcome.
I will start to follow your thread on ED forums, i'm very interested on learning deeply target, my biggest problem its my lack of time and the fact i'm very untalented about programming. biggrin.
_________________________
Si hay que huir, YO PRIMERO!!!

Top
#3998970 - 08/21/14 03:02 PM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: Lancelot]
aw65863 Offline
Junior Member

Registered: 08/21/14
Posts: 2
Loc: New York
Apologies for necro, have not been able to find any other place where HAT diagonals is discussed in depth. I copied one of the suggestions above and made a test script. the weird thing is that when i map the 4 axis only 3 of the 4 actually work. whatever one I place first ion my test program always fails. i post it here to see if anyone can comment.

Code:
include "target.tmh"


alias T16001; // second T16000 handle, which will be used all mapping commands

// Define virtual diagonal HAT key and its keyboard mapping
define H1URKey 't' // upper right = cycle hostile
define H1LRKey 'g' // lower right = pin target
define H1ULKey 'r' // upper left = next target
define H1LLKey 'y' // lower left = cycle friendlies

//program startup
int main()
{
    if(Init(&EventHandle)) return 1; // declare the event handler, return on error
	
	//add initialization code here for the second T16000 I am running, you can remove
	&T16001 = GetIndexJoy (SelectUsbDevice ("VID_044F&PID_B10A")); //pc expects a joystick on this adress
	

	// mapping for diagonal HAT upper left
	MapKey(&T16000, H1U, EXEC("if(T16000[H1L]) ActKey(KEYON+PULSE+H1ULKey);"));
	MapKey(&T16000, H1L, EXEC("if(T16000[H1U]) ActKey(KEYON+PULSE+H1ULKey);"));
	
	// mapping for diagonal HAT lower left
	MapKey(&T16000, H1D, EXEC("if(T16000[H1L]) ActKey(KEYON+PULSE+H1LLKey);"));
	MapKey(&T16000, H1L, EXEC("if(T16000[H1D]) ActKey(KEYON+PULSE+H1LLKey);"));

	// mapping for diagonal HAT upper right
	MapKey(&T16000, H1U, EXEC("if(T16000[H1R]) ActKey(KEYON+PULSE+H1URKey);"));
	MapKey(&T16000, H1R, EXEC("if(T16000[H1U]) ActKey(KEYON+PULSE+H1URKey);"));

	// mapping for diagonal HAT lower right
	MapKey(&T16000, H1D, EXEC("if(T16000[H1R]) ActKey(KEYON+PULSE+H1LRKey);"));
	MapKey(&T16000, H1R, EXEC("if(T16000[H1D]) ActKey(KEYON+PULSE+H1LRKey);"));
	
	
}

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

Top
#4014910 - 09/26/14 07:04 PM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: Lancelot]
RogueSqdn Offline
USAF Veteran
Member

Registered: 12/31/00
Posts: 319
Loc: Clemmons, NC
That's failing because you have buttons programmed twice. It's only recognizing the last one in the file.


Edited by RogueSqdn (09/26/14 07:05 PM)
_________________________
Jared
-----
FalconNW MachV, 40" Sony LCD, Obutto R3volution, HOTAS Warthog, FSSB R3, RS TUSBA

DEFENSOR FORTIS


Top
#4017626 - 10/03/14 12:18 PM Re: Correct sintax for diagonal positions of Hat 1 of Cougar on TARGET? [Re: RogueSqdn]
aw65863 Offline
Junior Member

Registered: 08/21/14
Posts: 2
Loc: New York
Originally Posted By: RogueSqdn
That's failing because you have buttons programmed twice. It's only recognizing the last one in the file.


I do not understand your feedback. Can you be more specific?

Top
Page 1 of 2 1 2 >
Topic Options
Rate This Topic
Hop to:

Moderator:  EinsteinEP, RacerGT 
 
Quick Search
Recent Articles
Support SimHQ
.
Social


Recent Topics
Is conversing with the opposite sex on line. cheating on your partner
by marko1231123
10:53 PM
Guy ACES G-Force test!
by Linebacker
09:04 PM
Sneeze Reaction - Adorable!
by Robbster
06:07 PM
F-117A Nighthawk Stealth Fighter 2.0 / Fleet Defender: The F-14 Tomcat Simulation on Steam
by Bib4Tuna
04:43 PM
Icewind Dale EE out now for PC...
by Magnum
01:50 PM
Steam Halloween Sale
by Bib4Tuna
01:06 PM
The picture of a cyberthief.
by Desert Eagle
09:49 AM
Russian bombers intercepted off the coast of Portugal
by Desert Eagle
07:06 AM
Is this the beginning of a bad disaster movie?
by Security_Device_Enclosed
06:43 AM
No one yet...?
by malibu43
01:44 AM
 

Forum Use Agreement | Privacy Statement
Copyright 1997-2014, SimHQ Inc. All Rights Reserved.