Previous Thread
Next Thread
Print Thread
Rate This Thread
Hop To
Page 2 of 2 1 2
#4458670 - 01/25/19 09:27 PM Re: Set an axis to a particular value [Re: Joao Muas]  
Joined: Jul 2016
Posts: 61
Drakoz Offline
Junior Member
Drakoz  Offline
Junior Member

Joined: Jul 2016
Posts: 61
Yes, #2 (TM Axis == DX Axis) is the problem. burnout

Otherwise, I think you get the idea. My original method was to say

if ( (TM Axis > (DX Axis - 100)) & (TM Axis < (DX Axis + 100)) .... (the axis are synced)

A +/-100 point range around DX Axis worked most the time. But a 1% to 2% range (+/- 655 to +/- 1310 out of 65532) will probably work 99% of the time or better. Again, you get the idea, and you can adjust the range to fit your needs. That is the easiest way to do it for sure. You don't even need to use AXMAP. For myself, though, I was looking for a way to make it bullet proof.

The method I used above needs to know if the previous TM Axis position was less than or greater than the DX Axis. So the idea of using AXMAP1() (the directional version of AXMAP) allows me figure out which way the TM Axis needs to move, and then only enable AXMAP1 to trigger when the TM Axis moves in the direction that moves it toward DX Axis. But I'm sure this is probably more complicated than it needs to be.

Inline advert (2nd and 3rd post)

#4458964 - 01/27/19 09:36 PM Re: Set an axis to a particular value [Re: Joao Muas]  
Joined: May 2001
Posts: 468
Joao Muas Offline
Member
Joao Muas  Offline
Member

Joined: May 2001
Posts: 468
Portugal
I did this, and it actually works but it needs further testing...

It is not fully complete because I got stuck by not knowing how to set arguments for MapAxisInSync(...) when it's inside an EXEC...

I want this to re-map several axis, so please check it out and tell me out to set the DX_axis argument for MapAxisInSync.

(It's a bit messy, sorry about that)

Code
include "target.tmh"

int flag; // to define where THR is in relation to DX (left or right)

int main()
{
	
//declare the event handler, return on error	
	if(Init(&EventHandle)) return 1;
	
	//  Initial axis definition
	MapAxis(&T16000, THR, DX_SLIDER_AXIS, AXIS_REVERSED, MAP_ABSOLUTE);
	
//	B13 to re-map to DX_THROTTLE_AXIS

	MapKey(&T16000, B13, EXEC("MapAxisSync(DX_THROTTLE_AXIS);"));
	
//	B14 to re-map to DX_SLIDER_AXIS - NOT TESTED

	MapKey(&T16000, B14, EXEC("MapAxisSync(DX_SLIDER_AXIS);"));	

}

int MapAxisSync(char DX_axis)
{
	MapAxis(&T16000, THR, 0, 0, 0); // de-map current axis
	if(T16000[THR] <= -Axis[DX_axis].pos) {	// check if THR is to the left of DX (the "-" is because THR is reversed)	
		flag = 1;	// sets flag left
		KeyAxis(&T16000, THR, 0, AXMAP1(99, EXEC("MapAxisInSync(DX_THROTTLE_AXIS);"), 0));	// sets AXMAP1 on alert
	}
	else if(T16000[THR] >= -Axis[DX_axis].pos) {	// check if THR is to the right of DX (the "-" is because THR is reversed)
		flag = 2;	// sets flag right	
		KeyAxis(&T16000, THR, 0, AXMAP1(99, 0, EXEC("MapAxisInSync(DX_THROTTLE_AXIS);")));	// sets AXMAP1 on alert
	}
}

int MapAxisInSync(char DX_axis)
{
	if (flag == 1) {	// THR is to the left of DX, sweeping to the right 
		if(T16000[THR] >= -Axis[DX_axis].pos) { // THR as passed over DX let's capture it
			MapAxis(&T16000, THR, DX_axis, AXIS_REVERSED, MAP_ABSOLUTE); // re-maps new axis
			KeyAxis(&T16000, THR, 0, AXMAP1(1, 0, 0)); // sets AXMAP1 off
		}
	}
	else if (flag == 2) {	// THR is to the right of DX, sweeping to the left  
		if(T16000[THR] <= -Axis[DX_axis].pos) { // THR as passed over DX let's capture it
			MapAxis(&T16000, THR, DX_axis, AXIS_REVERSED, MAP_ABSOLUTE); // re-maps new axis
			KeyAxis(&T16000, THR, 0, AXMAP1(1, 0, 0)); // sets AXMAP1 off
		}
	}
}

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

#4459648 - 02/02/19 10:51 AM Re: Set an axis to a particular value [Re: Joao Muas]  
Joined: May 2001
Posts: 468
Joao Muas Offline
Member
Joao Muas  Offline
Member

Joined: May 2001
Posts: 468
Portugal
OK. I finally made it, following the discussed concept:

  • making use of existing TARGET functions
  • works without any concern for the previous axis
  • no code in EventHandle() is required

Here is the code:

Code
//T16000M FCS script to re-map physical THR axis between 4 different virtual axis

include "target.tmh"

int virtual_axis; 	// virtual axis number
			// 5 - DX_YROT_AXIS
			// 6 - DX_ZROT_AXIS
			// 7 - DX_THROTTLE_AXIS
			// 8 - DX_SLIDER_AXIS					

int main()
{

//excluding unused devices
	Configure(&HCougar, MODE_EXCLUDED);
	Configure(&Joystick, MODE_EXCLUDED);
	Configure(&Throttle, MODE_EXCLUDED);
	Configure(&T16000L, MODE_EXCLUDED);
	Configure(&LMFD, MODE_EXCLUDED);
	Configure(&RMFD, MODE_EXCLUDED);
	Configure(&TFRPRudder, MODE_EXCLUDED);
	Configure(&TWCSThrottle, MODE_EXCLUDED);
	
//declare the event handler, return on error	
	if(Init(&EventHandle)) return 1;
	
	SetShiftButton(&T16000, B5); // B5 is ahift button
	
	//  Default axis definition
	MapAxis(&T16000, THR, DX_SLIDER_AXIS, AXIS_REVERSED, MAP_ABSOLUTE);
	
//	B13 axis control

	MapKeyIO(&T16000, B13,
	EXEC("if (virtual_axis != 5) {virtual_axis = 5; MapAxisSync(virtual_axis);}"), 	// for DX_YROT_AXIS
	EXEC("if (virtual_axis != 7) {virtual_axis = 7; MapAxisSync(virtual_axis);}")); // for DX_THROTTLE_AXIS
	
//	B14 axis control

	MapKeyIO(&T16000, B14,
	EXEC("if (virtual_axis != 6) {virtual_axis = 6; MapAxisSync(virtual_axis);}"), 	// for DX_ZROT_AXIS
	EXEC("if (virtual_axis != 8) {virtual_axis = 8; MapAxisSync(virtual_axis);}")); // for DX_SLIDER_AXIS (default)	

}

int MapAxisSync(int virtual_axis)
{
	MapAxis(&T16000, THR, 0, 0, 0); // de-map current axis
	if(T16000[THR] <= -Axis[virtual_axis].pos) {	// check if THR is to the left of the virtual axis	
		KeyAxis(&T16000, THR, 0, AXMAP1(99,	// Sets AXMAP1 on alert
		EXEC("if(T16000[THR] >= -Axis[virtual_axis].pos) MapAxisInSync(virtual_axis);"), 0)); // sweeping right
			}
	else if(T16000[THR] >= -Axis[virtual_axis].pos) {	// check if THR is to the right of the virtual axis
		KeyAxis(&T16000, THR, 0, AXMAP1(99, 0,		// Sets AXMAP1 on alert
		EXEC("if(T16000[THR] <= -Axis[virtual_axis].pos) MapAxisInSync(virtual_axis);"))); // sweeping left
			}
}

int MapAxisInSync(int virtual_axis)  // when THR passes over the virtual axis, axis will be in sync
{
	MapAxis(&T16000, THR, virtual_axis, AXIS_REVERSED, MAP_ABSOLUTE); // re-maps new axis
	KeyAxis(&T16000, THR, 0, AXMAP1(1, 0, 0)); // sets AXMAP1 off
}

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

So that is it. Axxis captured and remapped smoothly - no jumps.

Thank you Drakoz for your precious help.

#4506052 - 02/03/20 10:38 PM Re: Set an axis to a particular value [Re: Joao Muas]  
Joined: Jul 2016
Posts: 61
Drakoz Offline
Junior Member
Drakoz  Offline
Junior Member

Joined: Jul 2016
Posts: 61
Nice. Glad I could help. Sorry for not responding sooner. Had a rocky 2019 due to an injury (broke some bones). All is better now.

I have a T16000 stick and throttle arriving today which I bought on eBay cheap. Thought it would be nice to have just for playing around with in TARGET and adding an extra throttle axis to some of my sims. I also have a better idea on how to make the non-DirectX hats work as 8 way hats as you were asking about. It might take me a while to get to it, but I will revisit the issue eventually.

#4506074 - 02/04/20 08:15 AM Re: Set an axis to a particular value [Re: Joao Muas]  
Joined: May 2001
Posts: 468
Joao Muas Offline
Member
Joao Muas  Offline
Member

Joined: May 2001
Posts: 468
Portugal
Hi.

Glad to hear you are doing well, and "back to business".

We'll keep in touch.

Page 2 of 2 1 2

Moderated by  RacerGT 

Quick Search
Recent Articles
Support SimHQ

If you shop on Amazon use this Amazon link to support SimHQ
.
Social


Recent Topics
Actors portraying US Presidents
by PanzerMeyer. 04/19/24 12:19 PM
Dickey Betts was 80
by Rick_Rawlings. 04/19/24 01:11 AM
Exodus
by RedOneAlpha. 04/18/24 05:46 PM
Grumman Wildcat unique landing gear
by Coot. 04/17/24 03:54 PM
Peter Higgs was 94
by Rick_Rawlings. 04/17/24 12:28 AM
Whitey Herzog was 92
by F4UDash4. 04/16/24 04:41 PM
Anyone can tell me what this is?
by NoFlyBoy. 04/16/24 04:10 PM
10 Years ago MV Sewol
by wormfood. 04/15/24 08:25 PM
Copyright 1997-2016, SimHQ Inc. All Rights Reserved.

Powered by UBB.threads™ PHP Forum Software 7.6.0