Jump to content

Steel Battalion controller and win 7 64-Bit drivers


417 replies to this topic

#301 HackNFly

    Member

  • PipPipPipPipPip
  • 131 posts

Posted 08 October 2014 - 07:06 PM

I was asking because typically what I do in these situations is point someone in the right direction, not necessarily write the config file. I'll give you a few hints if you're willing to try it on your own.

If you look at MWO-mouse.cs that came with the 2.1_candidate download you'll see this in the mainLoop:
 
            // Pedals Section
if ((jj == 0) && (lPedal > (maxAxisValue*0.10))) // Left pedal pressed
            {
                controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Space);
                jj = 1;
            }
            else if ((jj == 1) && (lPedal < (maxAxisValue*0.10))) // Left pedal released
            {
                controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Space);
                jj = 0;
            }


So whats happening here is that higher up we grab the pedal value:
int lPedal = scaleValue(controller.LeftPedal,30,1022);


I think the values 30, and 1022 were attained experimentally, if you calibrate in Windows, it shouldn't matter, you can just use that utility, either way doesn't matter that much.

The real point is that we have a value, jj that is being used so we don't spam the space bar whenever we press down the left pedal more than 10% (maxAxisValue*0.10). We send a keypress down once and a keypress up once we're done.

Everything else you mention in your post is feasible and mostly not that hard. I'm willing to help if you're willing to try. I just wouldn't be as motivated to do it on my own since I don't own the game, and the few times I've played the game, it was with a DK2, which makes all the extra buttons of the SB controller kinda moot since I can't see them with the headset on.

~Hack

#302 Max Gordon

    Member

  • Pip
  • 11 posts

Posted 09 October 2014 - 12:23 PM

Ok Hack,

Thanks for pointing me to the MWO file, it was very useful

I've gotten pretty far on my own from stuff I've been copying here and there, and apart from the dial everything seems to be working fine (when tested on a notepad document). Elite is still in Beta and some keys that register fine in an empty notepad document don't seem to have the same effect ingame.

Anyways here's my code thus far, and I am very pleased with it, since I don't need to change a lot of default values from what comes with the game.

I have 2 additional questions and 1 request if I may.

Question 1: How do you set the keys in the CS file for the top row on the keyboard, the 1-0 keys I mean underneath the F1 keys since Elite uses those, but I don't know how to enter them. It would also be good to know what the keys are named on the numpad.

so for example; this presses down on the N key:

controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.N);


How would you make that work for a Numpad one, numpad equals; or a 1 a 2 etc (the top row on the keyboard)


Question 2:

I would like to light up a specific button: for example the "override button" on the function switches in the Center Block. I know how to light them all up but how do you just light one up, or make it brighter?

Question 3:

Can you help me with the dial, since I have no point of reference on how to start with that. If I can make it register as an axis, that would do it I think.

And here is the code thusfar

using System;
using Microsoft.DirectX.DirectInput;
namespace SBC{
public class DynamicClass
{
SteelBattalionController controller;
bool currentResetValue;
bool lastResetValue;//used in assessing when to flip lights
vJoy joystick;
bool acquired;
int boost = 0;
int combatspeed = 0;
 
const int refreshRate = 30;//number of milliseconds between call to mainLoop
const int maxAxisValue = 32768;
//this gets called once by main program
	public void Initialize()
	{
  controller = new SteelBattalionController();
  controller.Init(30);//50 is refresh rate in milliseconds
 
// Right Block
 
  // joystick
		controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, Microsoft.DirectX.DirectInput.Key.LeftControl, true); // fire primary weapon
  controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, Microsoft.DirectX.DirectInput.Key.RightControl,true); // fire secondary weapon or next fire group
		controller.AddButtonKeyMapping(ButtonEnum.RightJoyLockOn, Microsoft.DirectX.DirectInput.Key.B, true); // mouselook view
		// buttons right
  controller.AddButtonKeyLightMapping(ButtonEnum.Eject, true, 3, Microsoft.DirectX.DirectInput.Key.J, true); // frameshift drive
  controller.AddButtonKeyLightMapping(ButtonEnum.CockpitHatch, true, 3, Microsoft.DirectX.DirectInput.Key.Insert, true); // Landing gear
		controller.AddButtonKeyLightMapping(ButtonEnum.Ignition, true, 3, Microsoft.DirectX.DirectInput.Key.Home, true); // cargo scoop
		controller.AddButtonKeyLightMapping(ButtonEnum.Start, true, 3, Microsoft.DirectX.DirectInput.Key.U, true); //deploy/stow hardpoints
  // buttons middle
  controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonOpenClose, true, 3, Microsoft.DirectX.DirectInput.Key.M, true);  // open galaxy map
		/*
  controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonMapZoomInOut, true, 3, Microsoft.DirectX.DirectInput.Key.I, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonModeSelect, true, 3, Microsoft.DirectX.DirectInput.Key.Q, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonSubMonitor, true, 3, Microsoft.DirectX.DirectInput.Key.X, true);
  */
  controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomIn, true, 3, Microsoft.DirectX.DirectInput.Key.PageDown, true);  // scanner zoom in
		controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomOut, true, 3, Microsoft.DirectX.DirectInput.Key.PageUp, true);   // scanner zoom out
 
// Center Block
 
  // Function matrix
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF1, true, 3, Microsoft.DirectX.DirectInput.Key.F1, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.FunctionTankDetach, true, 3, Microsoft.DirectX.DirectInput.Key.W, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionFSS, true, 3, Microsoft.DirectX.DirectInput.Key.F3, true);
 
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF2, true, 3, Microsoft.DirectX.DirectInput.Key.A, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.FunctionOverride, true, 3, Microsoft.DirectX.DirectInput.Key.S, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionManipulator, true, 3, Microsoft.DirectX.DirectInput.Key.D, true);
 
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF3, true, 4, Microsoft.DirectX.DirectInput.Key.Q, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionNightScope, true, 3, Microsoft.DirectX.DirectInput.Key.Space, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionLineColorChange, true, 3, Microsoft.DirectX.DirectInput.Key.E, true);
	  
  // buttons bottom
  controller.AddButtonKeyLightMapping(ButtonEnum.Washing, true, 3, Microsoft.DirectX.DirectInput.Key.I, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.Extinguisher, true, 3, Microsoft.DirectX.DirectInput.Key.T, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.Chaff, true, 3, Microsoft.DirectX.DirectInput.Key.H, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMain, true, 3, Microsoft.DirectX.DirectInput.Key.K, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConSub, true, 3, Microsoft.DirectX.DirectInput.Key.Y, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMagazine, true, 3, Microsoft.DirectX.DirectInput.Key.N, true);
 
 
// Left Block
  controller.AddButtonKeyMapping(ButtonEnum.ToggleBufferMaterial,  Microsoft.DirectX.DirectInput.Key.V, true); // fire heatsink
  controller.AddButtonKeyMapping(ButtonEnum.ToggleFilterControl,   Microsoft.DirectX.DirectInput.Key.Delete, true); // flight assist
  controller.AddButtonKeyMapping(ButtonEnum.ToggleOxygenSupply,	Microsoft.DirectX.DirectInput.Key.C, true); // silent running
   joystick = new vJoy();
   acquired = joystick.acquireVJD(1);
   joystick.resetAll();//have to reset before we use it
}
 
//this is necessary, as main program calls this to know how often to call mainLoop
public int getRefreshRate()
{
  return refreshRate;
}
 
private uint getDegrees(double x,double y)
{
  uint temp = (uint)(System.Math.Atan(y/x)* (180/Math.PI));
  if(x < 0)
   temp +=180;
  if(x > 0 && y < 0)
   temp += 360;
  
  temp += 90;//origin is vertical on POV not horizontal
  
  if(temp > 360)//by adding 90 we may have gone over 360
   temp -=360;
 
  temp*=100;
 
  if (temp > 35999)
   temp = 35999;
  if (temp < 0)
   temp = 0;
  return temp;
}
 
public int scaleValue(int value, int low, int high)
  {
   double temp;
  
   temp = ((double)(value - low) / (double)(high - low) * 0.5)*maxAxisValue;
   //clamp for extraneous values
   if(temp > maxAxisValue)
	temp = maxAxisValue;
   if(temp < 0)
	temp = 0;
   return (int) temp;
  }
//this gets called once every refreshRate milliseconds by main program
public void mainLoop()
{
  joystick.setAxis(1,controller.AimingX,HID_USAGES.HID_USAGE_X);
  joystick.setAxis(1,controller.AimingY,HID_USAGES.HID_USAGE_Y);
  joystick.setAxis(1,(controller.RightPedal - controller.MiddlePedal),HID_USAGES.HID_USAGE_Z);//throttle
  joystick.setAxis(1,controller.RotationLever,HID_USAGES.HID_USAGE_RZ);
  joystick.setAxis(1,controller.SightChangeX,HID_USAGES.HID_USAGE_SL0);
  joystick.setAxis(1,controller.SightChangeY,HID_USAGES.HID_USAGE_RX);  
  joystick.setAxis(1,controller.LeftPedal,HID_USAGES.HID_USAGE_RY);	
  joystick.setAxis(1,controller.GearLever,HID_USAGES.HID_USAGE_SL1);
  joystick.setContPov(1,getDegrees(controller.SightChangeX,controller.SightChangeY),1);
  int lPedal = scaleValue(controller.LeftPedal,30,1022);
  // Start of ELITE DANGEROUS Setup
 
  //controller lights are on by default but FUELFLOWRATE switch brightens them up and also turns on exterior floodlights on the ship ingame on line 92.
  int switchOnLineIntensity = 5;
  for(int i=1;i<=32;i++)
  {  
		  if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate))
	controller.SetLEDState((ControllerLEDEnum)(i), switchOnLineIntensity, true);
				else
			   controller.SetLEDState((ControllerLEDEnum)(i), 2, true);
  }
 
		//bool bBoost = false;
 
  // Depending on FUELFLOWRATE switch state, exterior floodlight will be switched on ingame.
   if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate)) //ToggleFuelFlowRate turns on the lights
	{
	controller.AddButtonKeyMapping(ButtonEnum.ToggleFuelFlowRate,	Microsoft.DirectX.DirectInput.Key.L, true);
	}
   else //ToggleFuelFlowRate turns off the lights
	{
	controller.AddButtonKeyMapping(ButtonEnum.ToggleFuelFlowRate,	Microsoft.DirectX.DirectInput.Key.L, false);
	}
 
   /* Depending on TOGGLEVTLOCATION switch state, two sets of keys will be used/
	-WSAD keys for vertical and lateral thrust.
	-poweristribution UP DOWN LEFT RIGHT
   */
   if (controller.GetButtonState(ButtonEnum.ToggleVTLocation))
	{
  
	int thumbstickDeadZone = 75;
	SBC.POVdirection lastDirection = controller.POVhat;
	 // picks up the direction you are switching the POV or ...
	 if (((Math.Abs(controller.SightChangeX) > thumbstickDeadZone) || (Math.Abs(controller.SightChangeY) > thumbstickDeadZone)))
	 {
	  if (Math.Abs(controller.SightChangeX) > Math.Abs(controller.SightChangeY))
	   if (controller.SightChangeX < 0)
		controller.POVhat = SBC.POVdirection.LEFT;
	   else
		controller.POVhat = SBC.POVdirection.RIGHT;
	  else
	   if (controller.SightChangeY < 0)
		controller.POVhat = SBC.POVdirection.DOWN;
	  else
	   controller.POVhat = SBC.POVdirection.UP;
	 }
	 else // ... centers it
	 {
	  controller.POVhat = SBC.POVdirection.CENTER;
	 }
	 // POWER DISTRIBUTION
	  {
	  switch (controller.POVhat)
	   {
	   case SBC.POVdirection.LEFT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Left);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Left);
		break;
	   case SBC.POVdirection.RIGHT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Right);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Right);
		break;
	   case SBC.POVdirection.DOWN:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Up);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Up);
		break;
	   case SBC.POVdirection.UP:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Down);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Down);
		break;
	   case SBC.POVdirection.CENTER:
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Up);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Right);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Left);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Down);
		break;
	   }
	  }
	}
		else
	{
	int thumbstickDeadZone = 75;
	SBC.POVdirection lastDirection = controller.POVhat;
	if (((Math.Abs(controller.SightChangeX) > thumbstickDeadZone) || (Math.Abs(controller.SightChangeY) > thumbstickDeadZone)))
	 {
	  if (Math.Abs(controller.SightChangeX) > Math.Abs(controller.SightChangeY))
	   if (controller.SightChangeX < 0)
		controller.POVhat = SBC.POVdirection.LEFT;
	   else
		controller.POVhat = SBC.POVdirection.RIGHT;
	  else
	   if (controller.SightChangeY < 0)
		controller.POVhat = SBC.POVdirection.DOWN;
	  else
	   controller.POVhat = SBC.POVdirection.UP;
	 }
	 else // ... centers it
	 {
	  controller.POVhat = SBC.POVdirection.CENTER;
	 }
	  {
	// LATERAL/VERTICAL THRUST
	  switch (controller.POVhat)
	
	   {
	   case SBC.POVdirection.LEFT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Q);
		//controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Q);
		break;
	   case SBC.POVdirection.RIGHT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.D);
		//controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.D);
		break;
	   case SBC.POVdirection.DOWN:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.S);
		//controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.S);
		break;
	   case SBC.POVdirection.UP:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Z);
		//controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Z);
		break;
	   case SBC.POVdirection.CENTER:
		int litIntensive = 15;
		for(int i=1;i<=32;i++)
		 {
		 controller.SetLEDState((ControllerLEDEnum)(i), litIntensive, true); // this switches them all on, not exactly what I prefer
		 //controller.SetLEDState((ButtonEnum.FunctionOverride)(i), litIntensive, true); // this doesnt work however
		 /* since I want to give visual feedback on the controller that your lateral and vertical thrusters are working
		 if the POV is centered, the middle button of the function switch matrix should light up
		
		 If you move POV; the tank detach lights
		 if you move POV down the nightscope lights
		 if you move POV right, the manipulator lights up
		 if you move POV left, the F2 lights up
		 */
		 }
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.S);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Z);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.D);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Q);
		//controller.SetLEDState((ButtonEnum.FunctionManipulator)(i), litIntensity, true);
		break;
	   }
	  }
	}
 
  if ((lPedal > (maxAxisValue*0.50) && (boost == 0))) // Left pedal pressed completely boost on
			{
				controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Tab);
	boost = 2;
			}
  if ((lPedal <= (maxAxisValue*0.50) && lPedal > (maxAxisValue*0.25) && (boost == 2))) // Left pedal pressed half no boost but combat speed
			{
				controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Tab);
	controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.P);
	boost = 1;
			}
  if ((lPedal <= (maxAxisValue*0.25) && (boost == 1))) // Left pedal not pressed no action
			{
				controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Tab);
	controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.P);
	boost = 0;
			}
  joystick.sendUpdate(1);
}
 
//this gets called at the end of the program and must be present, as it cleans up resources
public void shutDown()
{
  controller.UnInit();
  joystick.Release(1);
}
 
}
}


There is some commented stuff in the file in the Lateral/Horizontal thruster section.

All help is welcome.

Thx

Edited by Max Gordon, 09 October 2014 - 12:24 PM.


#303 HackNFly

    Member

  • PipPipPipPipPip
  • 131 posts

Posted 09 October 2014 - 12:45 PM

Nice work!

Certainly looks like its getting there.

Should have pointed this link to you earlier.
https://code.google....i/Configuration

Maybe you've read it, as it seems you've made a lot of progress. As far as the keys, in the middle of that page theres a link out.
http://msdn.microsof...4(v=vs.85).aspx

Which lists all the directx enumerated keys.
D0 - D9 should be the numbers on the top of the keyboard, numpad should be
NumPad0 - NumPad9

As far as setting the button light the command, this might work.
int LEDNum = (int)(ButtonEnum.Eject) + 1;
controller.SetLEDState((ControllerLEDEnum)(LEDNum),2,true));

I have to actually try it to make sure I'm not off by 1. Theres a difference of 1 in the listing of the buttons vs their lights. Can't remember why that ocurred, but I just accounted for it. Possibly bad design on my part, or it may have been the way it was listed in the usb descriptor.

Also, it seems you have the code to set the LEDs in the mainloop, which means they will all be reset every loop, might not be what you are going for, if you are individually trying to set them.

I'll try and answer more of your questions when I have some more time later.

~Hack

#304 Max Gordon

    Member

  • Pip
  • 11 posts

Posted 09 October 2014 - 07:29 PM

Hey HnF,

Thanks again for the code support, and for the documents which I had not seen or known about before, they were very helpful thanks.

Well, this is as far as I got and it almost covers it all. The lighting matrix works great ingame, and you have now the necessary and welcome feedback for the two modes power distribution (no matrix lit) and Lat/Vert thrust control ( matrix lit according to where you are going). The code up there had a ")" too much, but after removing it, it worked like a charm. The leds being in the loop makes them flash, which is Exactly what I wanted, although it is not really intended here.

I also commented the code on the pedals, since it was not working properly ingame. Something I might be using when Elite is out of Beta.

For now, it works with the standard setup in Elite itself.

You will see that I changed the gear lever for the tunerdial in the config, but it only detects one instead of all notches on the Dial, It would be cool if that could be done.

That is the only challenge that remains as far as I can see now. Maybe later on I will need to reprogram other toggle switches if Frontier Devs add more functions to the controls. The nexus will probably be used for something else ingame. Dunno what at the moment, since I have all the buttons I need.

Thanks for the quick responses HnF, will definitely credit you when I release this config for fellow Eliters on the ED forum.

Later

using System;
using Microsoft.DirectX.DirectInput;
namespace SBC{
public class DynamicClass
{
SteelBattalionController controller;
bool currentResetValue;
bool lastResetValue;//used in assessing when to flip lights
vJoy joystick;
bool acquired;
int boost = 0;
int combatspeed = 0;
 
const int refreshRate = 30;//number of milliseconds between call to mainLoop
const int maxAxisValue = 32768;
//this gets called once by main program
	public void Initialize()
	{
  controller = new SteelBattalionController();
  controller.Init(30);//50 is refresh rate in milliseconds
 
// Right Block
 
  // joystick
		controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, Microsoft.DirectX.DirectInput.Key.LeftControl, true); // fire primary weapon
  controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, Microsoft.DirectX.DirectInput.Key.RightControl,true); // fire secondary weapon or next fire group
		controller.AddButtonKeyMapping(ButtonEnum.RightJoyLockOn, Microsoft.DirectX.DirectInput.Key.B, true); // mouselook view
		// buttons right
  controller.AddButtonKeyLightMapping(ButtonEnum.Eject, true, 3, Microsoft.DirectX.DirectInput.Key.J, true); // frameshift drive
  controller.AddButtonKeyLightMapping(ButtonEnum.CockpitHatch, true, 3, Microsoft.DirectX.DirectInput.Key.Insert, true); // Landing gear
		controller.AddButtonKeyLightMapping(ButtonEnum.Ignition, true, 3, Microsoft.DirectX.DirectInput.Key.Home, true); // cargo scoop
		controller.AddButtonKeyLightMapping(ButtonEnum.Start, true, 3, Microsoft.DirectX.DirectInput.Key.U, true); //deploy/stow hardpoints
  // buttons middle
  controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonOpenClose, true, 3, Microsoft.DirectX.DirectInput.Key.M, true);  // open galaxy map
		/*Unused
  controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonMapZoomInOut, true, 3, Microsoft.DirectX.DirectInput.Key.I, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonModeSelect, true, 3, Microsoft.DirectX.DirectInput.Key.Q, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonSubMonitor, true, 3, Microsoft.DirectX.DirectInput.Key.X, true);
  */
  controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomIn, true, 3, Microsoft.DirectX.DirectInput.Key.PageDown, true);  // scanner zoom in
		controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomOut, true, 3, Microsoft.DirectX.DirectInput.Key.PageUp, true);   // scanner zoom out
 
// Center Block
 
  // Function matrix
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF1, true, 3, Microsoft.DirectX.DirectInput.Key.D1, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.FunctionTankDetach, true, 3, Microsoft.DirectX.DirectInput.Key.W, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionFSS, true, 3, Microsoft.DirectX.DirectInput.Key.D3, true);
 
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF2, true, 3, Microsoft.DirectX.DirectInput.Key.A, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.FunctionOverride, true, 3, Microsoft.DirectX.DirectInput.Key.Space, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionManipulator, true, 3, Microsoft.DirectX.DirectInput.Key.D, true);
 
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF3, true, 4, Microsoft.DirectX.DirectInput.Key.Q, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionNightScope, true, 3, Microsoft.DirectX.DirectInput.Key.S, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionLineColorChange, true, 3, Microsoft.DirectX.DirectInput.Key.E, true);
	  
  // buttons bottom
  controller.AddButtonKeyLightMapping(ButtonEnum.Washing, true, 3, Microsoft.DirectX.DirectInput.Key.I, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.Extinguisher, true, 3, Microsoft.DirectX.DirectInput.Key.T, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.Chaff, true, 3, Microsoft.DirectX.DirectInput.Key.H, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMain, true, 3, Microsoft.DirectX.DirectInput.Key.K, true);
		controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConSub, true, 3, Microsoft.DirectX.DirectInput.Key.Y, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMagazine, true, 3, Microsoft.DirectX.DirectInput.Key.N, true);
 
  controller.AddButtonKeyLightMapping(ButtonEnum.Comm1, true, 3, Microsoft.DirectX.DirectInput.Key.Escape, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.Comm5, true, 3, Microsoft.DirectX.DirectInput.Key.Escape, true);
 
// Left Block
  controller.AddButtonKeyMapping(ButtonEnum.ToggleBufferMaterial,  Microsoft.DirectX.DirectInput.Key.V, true); // fire heatsink
  controller.AddButtonKeyMapping(ButtonEnum.ToggleFilterControl,   Microsoft.DirectX.DirectInput.Key.Delete, true); // flight assist
  controller.AddButtonKeyMapping(ButtonEnum.ToggleOxygenSupply,	Microsoft.DirectX.DirectInput.Key.C, true); // silent running
   joystick = new vJoy();
   acquired = joystick.acquireVJD(1);
   joystick.resetAll();//have to reset before we use it
}
 
//this is necessary, as main program calls this to know how often to call mainLoop
public int getRefreshRate()
{
  return refreshRate;
}
 
private uint getDegrees(double x,double y)
{
  uint temp = (uint)(System.Math.Atan(y/x)* (180/Math.PI));
  if(x < 0)
   temp +=180;
  if(x > 0 && y < 0)
   temp += 360;
  
  temp += 90;//origin is vertical on POV not horizontal
  
  if(temp > 360)//by adding 90 we may have gone over 360
   temp -=360;
 
  temp*=100;
 
  if (temp > 35999)
   temp = 35999;
  if (temp < 0)
   temp = 0;
  return temp;
}
 
public int scaleValue(int value, int low, int high)
  {
   double temp;
  
   temp = ((double)(value - low) / (double)(high - low) * 0.5)*maxAxisValue;
   //clamp for extraneous values
   if(temp > maxAxisValue)
	temp = maxAxisValue;
   if(temp < 0)
	temp = 0;
   return (int) temp;
  }
//this gets called once every refreshRate milliseconds by main program
public void mainLoop()
{
  joystick.setAxis(1,controller.AimingX,HID_USAGES.HID_USAGE_X);
  joystick.setAxis(1,controller.AimingY,HID_USAGES.HID_USAGE_Y);
  joystick.setAxis(1,(controller.RightPedal - controller.MiddlePedal),HID_USAGES.HID_USAGE_Z);//throttle
  joystick.setAxis(1,controller.RotationLever,HID_USAGES.HID_USAGE_RZ);
  joystick.setAxis(1,controller.SightChangeX,HID_USAGES.HID_USAGE_SL0);
  joystick.setAxis(1,controller.SightChangeY,HID_USAGES.HID_USAGE_RX);  
  joystick.setAxis(1,controller.LeftPedal,HID_USAGES.HID_USAGE_RY);	
  joystick.setAxis(1,controller.TunerDial,HID_USAGES.HID_USAGE_SL1);
  joystick.setContPov(1,getDegrees(controller.SightChangeX,controller.SightChangeY),1);
  int lPedal = scaleValue(controller.LeftPedal,30,1022);
  // Start of ELITE DANGEROUS Setup
 
  //controller lights are on by default but FUELFLOWRATE switch brightens them up and also turns on exterior floodlights on the ship ingame on line 92.
  int switchOnLineIntensity = 5;
  for(int i=1;i<=32;i++)
  {  
		  if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate))
	controller.SetLEDState((ControllerLEDEnum)(i), switchOnLineIntensity, true);
				else
			   controller.SetLEDState((ControllerLEDEnum)(i), 2, true);
  }
 
		//bool bBoost = false;
 
  // Depending on FUELFLOWRATE switch state, exterior floodlight will be switched on ingame.
   if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate)) //ToggleFuelFlowRate turns on the lights
	{
	controller.AddButtonKeyMapping(ButtonEnum.ToggleFuelFlowRate,	Microsoft.DirectX.DirectInput.Key.L, true);
	}
   else //ToggleFuelFlowRate turns off the lights
	{
	controller.AddButtonKeyMapping(ButtonEnum.ToggleFuelFlowRate,	Microsoft.DirectX.DirectInput.Key.L, false);
	}
 
   /* Depending on TOGGLEVTLOCATION switch state, two sets of keys will be used/
	-WSAD keys for vertical and lateral thrust.
	-poweristribution UP DOWN LEFT RIGHT
   */
   if (controller.GetButtonState(ButtonEnum.ToggleVTLocation))
	{
  
	int thumbstickDeadZone = 75;
	SBC.POVdirection lastDirection = controller.POVhat;
	 // picks up the direction you are switching the POV or ...
	 if (((Math.Abs(controller.SightChangeX) > thumbstickDeadZone) || (Math.Abs(controller.SightChangeY) > thumbstickDeadZone)))
	 {
	  if (Math.Abs(controller.SightChangeX) > Math.Abs(controller.SightChangeY))
	   if (controller.SightChangeX < 0)
		controller.POVhat = SBC.POVdirection.LEFT;
	   else
		controller.POVhat = SBC.POVdirection.RIGHT;
	  else
	   if (controller.SightChangeY < 0)
		controller.POVhat = SBC.POVdirection.DOWN;
	  else
	   controller.POVhat = SBC.POVdirection.UP;
	 }
	 else // ... centers it
	 {
	  controller.POVhat = SBC.POVdirection.CENTER;
	 }
	 // POWER DISTRIBUTION
	  {
	  switch (controller.POVhat)
	   {
	   case SBC.POVdirection.LEFT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Left);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Left);
		break;
	   case SBC.POVdirection.RIGHT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Right);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Right);
		break;
	   case SBC.POVdirection.DOWN:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Up);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Up);
		break;
	   case SBC.POVdirection.UP:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Down);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Down);
		break;
	   case SBC.POVdirection.CENTER:
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Up);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Right);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Left);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Down);
		break;
	   }
	  }
	}
		else
	{
	int thumbstickDeadZone = 75;
	SBC.POVdirection lastDirection = controller.POVhat;
	if (((Math.Abs(controller.SightChangeX) > thumbstickDeadZone) || (Math.Abs(controller.SightChangeY) > thumbstickDeadZone)))
	 {
	  if (Math.Abs(controller.SightChangeX) > Math.Abs(controller.SightChangeY))
	   if (controller.SightChangeX < 0)
		controller.POVhat = SBC.POVdirection.LEFT;
	   else
		controller.POVhat = SBC.POVdirection.RIGHT;
	  else
	   if (controller.SightChangeY < 0)
		controller.POVhat = SBC.POVdirection.DOWN;
	  else
	   controller.POVhat = SBC.POVdirection.UP;
	 }
	 else // ... centers it
	 {
	  controller.POVhat = SBC.POVdirection.CENTER;
	 }
	  {
	// LATERAL/VERTICAL THRUST
	  switch (controller.POVhat)
	
	   {
	  
	   case SBC.POVdirection.LEFT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Q);
		 int LEDNum_LFT = (int)(ButtonEnum.FunctionF2) + 1;
		 controller.SetLEDState((ControllerLEDEnum)(LEDNum_LFT),15,true);
		break;
	   case SBC.POVdirection.RIGHT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.D);
		 int LEDNum_RGT = (int)(ButtonEnum.FunctionManipulator) + 1;
		 controller.SetLEDState((ControllerLEDEnum)(LEDNum_RGT),15,true);
		break;
	   case SBC.POVdirection.DOWN:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.S);
		 int LEDNum_DWN = (int)(ButtonEnum.FunctionTankDetach) + 1;
		 controller.SetLEDState((ControllerLEDEnum)(LEDNum_DWN),15,true);
		break;
	   case SBC.POVdirection.UP:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Z);
		 int LEDNum_UP = (int)(ButtonEnum.FunctionNightScope) + 1;
		 controller.SetLEDState((ControllerLEDEnum)(LEDNum_UP),15,true);
		break;
	   case SBC.POVdirection.CENTER:
		int LEDNum_Center = (int)(ButtonEnum.FunctionOverride) + 1;
		controller.SetLEDState((ControllerLEDEnum)(LEDNum_Center),10,true);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.S);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Z);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.D);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Q);
		break;
	   }
	  }
	}
  /*
  if ((lPedal > (maxAxisValue*0.50) && (boost == 0))) // Left pedal pressed completely boost on
			{
				controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Tab);
	boost = 2;
			}
  if ((lPedal <= (maxAxisValue*0.50) && lPedal > (maxAxisValue*0.25) && (boost == 2))) // Left pedal pressed half no boost but combat speed
			{
				controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Tab);
	controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.P);
	boost = 1;
			}
  if ((lPedal <= (maxAxisValue*0.25) && (boost == 1))) // Left pedal not pressed no action
			{
				controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Tab);
	controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.P);
	boost = 0;
			}
  */
  joystick.sendUpdate(1);
}
 
//this gets called at the end of the program and must be present, as it cleans up resources
public void shutDown()
{
  controller.UnInit();
  joystick.Release(1);
}
 
}
}

Edited by Max Gordon, 09 October 2014 - 07:30 PM.


#305 Golden Gun

    Member

  • PipPipPip
  • Legendary Founder
  • Legendary Founder
  • 87 posts
  • LocationIdaho

Posted 19 October 2014 - 02:41 PM

Hey, I've been reading in the background and between you two there's been some really cool ideas poping up!

Max: did you get everything working for ya? How is Elite Dangerous? I played the first two on my Amiga back in the day and have yet to find a sim that plays the same (the X series comes close).

Hack: I can not thank you enough for constantly helping people out with this over the years. I know you get zero dollars for all the effort you put into it but I can tell you I've ahd my sticks hooked up to my PC ever since I found this thread!

Keep up the great work and thanks again!

#306 HackNFly

    Member

  • PipPipPipPipPip
  • 131 posts

Posted 19 October 2014 - 04:25 PM

Sorry I haven't responded for a while. Max Gordon looks like you've done some good work there. I have a side project at work that is taking all my free time. And I have the sbc tucked away in the closet. I do plan on working on the tuning dial issue for your code it just may be a few weeks. That project plus baby have kept me busy.

I would love it if you post a video of it at some point it would be neat to see it in action.

Golden Gun, I'm glad you have enjoyed the software. I'm just happy to have produced a useful program while introducing some people to scripting.

#307 Max Gordon

    Member

  • Pip
  • 11 posts

Posted 23 October 2014 - 06:36 AM

Hi Golden Gun,

Well it's playing pretty nice even on my laptop, and although I don't get the really high FPS rates, even at 20 FPS the game is very playable. I am also approaching my forties fast and I have played Elite back in the day on the Commodore 64, and after that Frontier Elite (very cool at the time) and First Encounters (which I didn't like that much) on the PC.

Although I have been playing both Chris Roberts games in the past, I chose to go for Elite Dangerous, and have not regretted the 250 Pounds I put in the alpha and the additional 13 Pounds for the limited wireframe skin for the Cobra Mk3. Both games deserve the crowdfunding they are getting, but Elite floats my boat a little more than Star Citizen.

If you like Elite: have a look at my creation of the Cobra Mk3 for Oolite:



That being said, back to the subject at hand:

I have tested the script above thoroughly and have found it creates some lag in the response of the joystick axis, when tested in the "usb controller setup" screen in windows. This was due to the constant blinking of the controller in action.

Below is a movie that still uses the old scripts (with the blinking lights) that I have uploaded about two weeks ago:



Below is a revised script; The matrix keys do no longer blink now, but just light up solid depending on which way your (lateral and vertical) thrusters are fired. The good thing is though, that it produces no lag anymore on both sticks and that is a big plus; especially at slow speeds (and low framerates).

using System;
using Microsoft.DirectX.DirectInput;
namespace SBC{
public class DynamicClass
{
SteelBattalionController controller;
bool currentResetValue;
bool lastResetValue;//used in assessing when to flip lights
vJoy joystick;
bool acquired;
const int refreshRate = 50;//number of milliseconds between call to mainLoop
 
//this gets called once by main program
	public void Initialize()
	{
  controller = new SteelBattalionController();
  controller.Init(50);//50 is refresh rate in milliseconds
  //set all buttons by default to light up only when you press them down
  // Right Block
 
  // joystick
		controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, Microsoft.DirectX.DirectInput.Key.LeftControl, true); // fire primary weapon
  controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, Microsoft.DirectX.DirectInput.Key.RightControl,true); // fire secondary weapon or next fire group
		controller.AddButtonKeyMapping(ButtonEnum.RightJoyLockOn, Microsoft.DirectX.DirectInput.Key.Z, true); // mouselook view
		// buttons right
  controller.AddButtonKeyLightMapping(ButtonEnum.Eject, false, 3, Microsoft.DirectX.DirectInput.Key.J, true); // frameshift drive
  controller.AddButtonKeyLightMapping(ButtonEnum.CockpitHatch, false, 3, Microsoft.DirectX.DirectInput.Key.Insert, true); // Landing gear
		controller.AddButtonKeyLightMapping(ButtonEnum.Ignition, false, 3, Microsoft.DirectX.DirectInput.Key.Home, true); // cargo scoop
		controller.AddButtonKeyLightMapping(ButtonEnum.Start, false, 3, Microsoft.DirectX.DirectInput.Key.U, true); //deploy/stow hardpoints
  // buttons middle
  controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonOpenClose, false, 3, Microsoft.DirectX.DirectInput.Key.M, true);  // open galaxy map
	  
  controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonMapZoomInOut, false, 3, Microsoft.DirectX.DirectInput.Key.D2, true); //Scanner Focus
	  
  controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonModeSelect, false, 3, Microsoft.DirectX.DirectInput.Key.D3, true);
	  
  controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonSubMonitor, false, 3, Microsoft.DirectX.DirectInput.Key.B, true);
  controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomIn, false, 3, Microsoft.DirectX.DirectInput.Key.PageDown, true);  // scanner zoom in
		controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomOut, false, 3, Microsoft.DirectX.DirectInput.Key.PageUp, true);   // scanner zoom out
 
// Center Block
 
  // Function matrix
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF1, false, 3, Microsoft.DirectX.DirectInput.Key.D1, true);  //Navigation screen (left)
		controller.AddButtonKeyLightMapping(ButtonEnum.FunctionTankDetach, false, 3, Microsoft.DirectX.DirectInput.Key.W, true); //go menu up
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionFSS, false, 3, Microsoft.DirectX.DirectInput.Key.D4, true); //System screen (right)
 
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF2, false, 3, Microsoft.DirectX.DirectInput.Key.A, true); //go menu left
		controller.AddButtonKeyLightMapping(ButtonEnum.FunctionOverride, false, 3, Microsoft.DirectX.DirectInput.Key.Space, true); // menu select enter
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionManipulator, false, 3, Microsoft.DirectX.DirectInput.Key.D, true); // go menu right
 
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF3, false, 3, Microsoft.DirectX.DirectInput.Key.Q, true);  // go previous menu tab
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionNightScope, false, 3, Microsoft.DirectX.DirectInput.Key.S, true); // go menu down
  controller.AddButtonKeyLightMapping(ButtonEnum.FunctionLineColorChange, false, 3, Microsoft.DirectX.DirectInput.Key.E, true);  //go next menu tab
	  
  // buttons bottom
  controller.AddButtonKeyLightMapping(ButtonEnum.Washing, false, 3, Microsoft.DirectX.DirectInput.Key.I, true);  // previous hostile
		controller.AddButtonKeyLightMapping(ButtonEnum.Extinguisher, false, 3, Microsoft.DirectX.DirectInput.Key.T, true); // target ahead
		controller.AddButtonKeyLightMapping(ButtonEnum.Chaff, false, 3, Microsoft.DirectX.DirectInput.Key.H, true); // next hostile
  controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMain, false, 3, Microsoft.DirectX.DirectInput.Key.K, true); // previous subsystem
		controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConSub, false, 3, Microsoft.DirectX.DirectInput.Key.Y, true); // Next subsystem
  controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMagazine, false, 3, Microsoft.DirectX.DirectInput.Key.N, true); // next firegroup
 
  controller.AddButtonKeyLightMapping(ButtonEnum.Comm1, false, 3, Microsoft.DirectX.DirectInput.Key.Escape, true); //escape key
  controller.AddButtonKeyLightMapping(ButtonEnum.Comm5, false, 3, Microsoft.DirectX.DirectInput.Key.Escape, true);
 
// Left Block
  controller.AddButtonKeyMapping(ButtonEnum.ToggleBufferMaterial,  Microsoft.DirectX.DirectInput.Key.V, true); // fire heatsink
  controller.AddButtonKeyMapping(ButtonEnum.ToggleFilterControl,   Microsoft.DirectX.DirectInput.Key.Delete, true); // flight assist
  controller.AddButtonKeyMapping(ButtonEnum.ToggleOxygenSupply,	Microsoft.DirectX.DirectInput.Key.D0, true); // silent running
  controller.AddButtonKeyMapping(ButtonEnum.ToggleFuelFlowRate,  Microsoft.DirectX.DirectInput.Key.L, true);
 
  int litIntensity = 3;
  int baseLineIntensity = 7;
	for(int i=1;i<=32;i++)
	{
 
	 if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate))
	
	  controller.SetLEDState((ControllerLEDEnum)(i), baseLineIntensity, true);
						  
	 else
	
	  controller.SetLEDState((ControllerLEDEnum)(i), litIntensity, true);
	
	}
 
 
 
 
 
 
  /*
  int baseLineIntensity = 15;//just an average value for LED intensity
		//int emergencyLightIntensity = 15;//for stuff like eject,cockpit Hatch,Ignition, and Start
  int litIntensity = 10;
 
  for(int i=1;i<=32;i++)
  {
	if ((bool)controller.GetButtonState(i + 1))
										controller.SetLEDState((ControllerLEDEnum)(i), litIntensity, false);
								else
								{
										if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate))
										  controller.SetLEDState((ControllerLEDEnum)(i), baseLineIntensity, true);
										else
										 controller.SetLEDState((ControllerLEDEnum)(i), 0, true);
								}
  }
  */
		 //controller.AddButtonKeyLightMapping(ButtonEnum.CockpitHatch, true, 10, Microsoft.DirectX.DirectInput.Key.A, true);//last true means if you hold down the button,
   joystick = new vJoy();
   acquired = joystick.acquireVJD(1);
   joystick.resetAll();//have to reset before we use it
}
 
//this is necessary, as main program calls this to know how often to call mainLoop
public int getRefreshRate()
{
  return refreshRate;
}
 
private uint getDegrees(double x,double y)
{
  uint temp = (uint)(System.Math.Atan(y/x)* (180/Math.PI));
  if(x < 0)
   temp +=180;
  if(x > 0 && y < 0)
   temp += 360;
  
  temp += 90;//origin is vertical on POV not horizontal
  
  if(temp > 360)//by adding 90 we may have gone over 360
   temp -=360;
 
  temp*=100;
 
  if (temp > 35999)
   temp = 35999;
  if (temp < 0)
   temp = 0;
  return temp;
}
//this gets called once every refreshRate milliseconds by main program
public void mainLoop()
{
 
  joystick.setAxis(1,controller.AimingX,HID_USAGES.HID_USAGE_X);
  joystick.setAxis(1,controller.AimingY,HID_USAGES.HID_USAGE_Y);
  joystick.setAxis(1,(controller.RightPedal - controller.MiddlePedal),HID_USAGES.HID_USAGE_Z);//throttle
  joystick.setAxis(1,controller.RotationLever,HID_USAGES.HID_USAGE_RZ);
  joystick.setAxis(1,controller.SightChangeX,HID_USAGES.HID_USAGE_SL0);
  joystick.setAxis(1,controller.SightChangeY,HID_USAGES.HID_USAGE_RX);  
  joystick.setAxis(1,controller.LeftPedal,HID_USAGES.HID_USAGE_RY);	
  joystick.setAxis(1,controller.GearLever,HID_USAGES.HID_USAGE_SL1);
  joystick.setContPov(1,getDegrees(controller.SightChangeX,controller.SightChangeY),1);
 
  if (controller.GetButtonState(ButtonEnum.RightJoyMainWeapon))
	{
  
	int thumbstickDeadZone = 75;
	SBC.POVdirection lastDirection = controller.POVhat;
	 // picks up the direction you are switching the POV or ...
	 if (((Math.Abs(controller.SightChangeX) > thumbstickDeadZone) || (Math.Abs(controller.SightChangeY) > thumbstickDeadZone)))
	 {
	  if (Math.Abs(controller.SightChangeX) > Math.Abs(controller.SightChangeY))
	   if (controller.SightChangeX < 0)
		controller.POVhat = SBC.POVdirection.LEFT;
	   else
		controller.POVhat = SBC.POVdirection.RIGHT;
	  else
	   if (controller.SightChangeY < 0)
		controller.POVhat = SBC.POVdirection.DOWN;
	  else
	   controller.POVhat = SBC.POVdirection.UP;
	 }
	 else // ... centers it
	 {
	  controller.POVhat = SBC.POVdirection.CENTER;
	 }
	 // POWER DISTRIBUTION
	  {
	  switch (controller.POVhat)
	   {
	   case SBC.POVdirection.LEFT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Left);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Left);
		break;
	   case SBC.POVdirection.RIGHT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Right);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Right);
		break;
	   case SBC.POVdirection.DOWN:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Up);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Up);
		break;
	   case SBC.POVdirection.UP:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Down);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Down);
		break;
	   case SBC.POVdirection.CENTER:
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Up);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Right);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Left);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Down);
		break;
	   }
	  }
	}
		else
	{
	int thumbstickDeadZone = 75;
	SBC.POVdirection lastDirection = controller.POVhat;
	if (((Math.Abs(controller.SightChangeX) > thumbstickDeadZone) || (Math.Abs(controller.SightChangeY) > thumbstickDeadZone)))
	 {
	  if (Math.Abs(controller.SightChangeX) > Math.Abs(controller.SightChangeY))
	   if (controller.SightChangeX < 0)
		controller.POVhat = SBC.POVdirection.LEFT;
	   else
		controller.POVhat = SBC.POVdirection.RIGHT;
	  else
	   if (controller.SightChangeY < 0)
		controller.POVhat = SBC.POVdirection.DOWN;
	  else
	   controller.POVhat = SBC.POVdirection.UP;
	 }
	 else // ... centers it
	 {
	  controller.POVhat = SBC.POVdirection.CENTER;
	 }
	  {
	// LATERAL/VERTICAL THRUST
	  switch (controller.POVhat)
	
	   {
	  
	   case SBC.POVdirection.LEFT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Q);
		 int LEDNum_LFT = (int)(ButtonEnum.FunctionF2) + 1;
		 controller.SetLEDState((ControllerLEDEnum)(LEDNum_LFT),15,true);
		break;
	   case SBC.POVdirection.RIGHT:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.E);
		 int LEDNum_RGT = (int)(ButtonEnum.FunctionManipulator) + 1;
		 controller.SetLEDState((ControllerLEDEnum)(LEDNum_RGT),15,true);
		break;
	   case SBC.POVdirection.DOWN:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.R);
		 int LEDNum_DWN = (int)(ButtonEnum.FunctionTankDetach) + 1;
		 controller.SetLEDState((ControllerLEDEnum)(LEDNum_DWN),15,true);
		break;
	   case SBC.POVdirection.UP:
		controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.F);
		 int LEDNum_UP = (int)(ButtonEnum.FunctionNightScope) + 1;
		 controller.SetLEDState((ControllerLEDEnum)(LEDNum_UP),15,true);
		break;
	   case SBC.POVdirection.CENTER:
		int LEDNum_Center = (int)(ButtonEnum.FunctionOverride) + 1;
		controller.SetLEDState((ControllerLEDEnum)(LEDNum_Center),10,true);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.F);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.R);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.E);
		controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Q);
		int LEDNum_UP2 = (int)(ButtonEnum.FunctionNightScope) + 1;
		int LEDNum_DWN2 = (int)(ButtonEnum.FunctionTankDetach) + 1;
		int LEDNum_RGT2 = (int)(ButtonEnum.FunctionManipulator) + 1;
		int LEDNum_LFT2 = (int)(ButtonEnum.FunctionF2) + 1;
		controller.SetLEDState((ControllerLEDEnum)(LEDNum_UP2),5,true);
		controller.SetLEDState((ControllerLEDEnum)(LEDNum_DWN2),5,true);
		controller.SetLEDState((ControllerLEDEnum)(LEDNum_RGT2),5,true);
		controller.SetLEDState((ControllerLEDEnum)(LEDNum_LFT2),5,true);
		break;
	   }
	  }
	}
  
	/*
	if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate)) //ToggleFuelFlowRate turns on the lights
	{
	controller.AddButtonKeyMapping(ButtonEnum.ToggleFuelFlowRate,	Microsoft.DirectX.DirectInput.Key.L, true);
	}
   else //ToggleFuelFlowRate turns off the lights
	{
	controller.AddButtonKeyMapping(ButtonEnum.ToggleFuelFlowRate,	Microsoft.DirectX.DirectInput.Key.L, false);
	}
	*/
		// toggle switching buttons
  /*
		if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate)) //ToggleFuelFlowRate to JoyFire
		{
			if (controller.GetButtonState(ButtonEnum.RightJoyFire))
				joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire), 1, 5);
		}
		else
		{
			if (controller.GetButtonState(ButtonEnum.RightJoyFire))
			joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire), 1, 1);
		}
		currentResetValue = controller.GetButtonState((int)ButtonEnum.ToggleVTLocation);
		if (currentResetValue != lastResetValue && currentResetValue)
		{
			controller.TestLEDs(1);//reset lights
		}
  */
		lastResetValue = currentResetValue;
 
		//Toggles Management (toggle = 1 button mapp on key )
		//controller.AddButtonKeyLightMapping(ButtonEnum.ToggleFilterControl, true, 10, Microsoft.DirectX.DirectInput.Key.F1, true);
		//controller.AddButtonKeyLightMapping(ButtonEnum.ToggleOxygenSupply, true, 10, Microsoft.DirectX.DirectInput.Key.F2, true);
  //Toggles Management (toggle = 1 button mapp on key )
	   // controller.AddButtonKeyMapping(ButtonEnum.ToggleFilterControl,Microsoft.DirectX.DirectInput.Key.F1, true);
	   // controller.AddButtonKeyMapping(ButtonEnum.ToggleOxygenSupply, Microsoft.DirectX.DirectInput.Key.F2, true);
 
  joystick.sendUpdate(1);
}
 
//this gets called at the end of the program and must be present, as it cleans up resources
public void shutDown()
{
  controller.UnInit();
  joystick.Release(1);
}
 
}
}


I have taken the time to comment the ingame bind of each keypress, so you will get the idea.

What I also noticed is that one control can be mapped to two or three keys pressed at once ingame, in the ED config screen. Below you will find some examples in which this is a paramount requirement.

In ED there is forward thrust and forward throttle. Forward throttle is constant, forward thrust is not, it will only work as long as you keep the control pressed. You use forward throttle to fly around, but docking for example needs little amounts of thrust to get above the correct position above the landing pad.

Now, since I want to keep the script nice and simple I am just using 2 pedals and not the middle one.

I have experimented with different setups, and this IMHO is the most workable settings in ED control config screen:

- Right pedal: throttle (forward only, inverted)

Forward only, meaning the same pedal does not control reverse; and I don't need to judge where to hover the pedal midway on its axis to come to a halt and fully depress it to go full forward and letting it go to go backward. I judge that flying backwards constantly using throttle is not necessary, but that's just me talking.
Inverted: This means you don't have to hold the throttle all the time to go forward (works a bit like an automatic transmission) and you have to press it completely to come to a halt. The SB pedals require quite some muscle if used constantly, and I don't need a workout (yet) during gaming.

- Left pedal + Lockon button: Boost

ED has an override set of controls for landing (basically when the landing gear is completely down) the pedals can be assigned to forward and backward thrust. Of course since those controls only kick in when the landing gear is fully deployed and not just when the landing light is on, having the left pedal alone mapped to "Engage Boosters" without the gear down is a big NO-NO which will definitely at some point result in an unvoluntary boost when you don't need it; inside the docking bay. As long as ED has not solved that the override kicks in when the landing light is active, I am not using the overrides.
However I have solved this differently, and using these two buttons will engage boost. Perfectly safe.

- Right pedal solo: Rear Thrust

Rear thrust is needed for combat situations (to not overshoot the target once you boost after it) and also is usful if you overshot the landing pad, this time without having to worry about the full extension of the landing gear and unvoluntary boost.

- Left stick: Roll
I set the deadzone to zero in the ED config screen. No further explanation required.

- Right Stick: x-axis Yaw; y-axis Pitch (inverted)

Inverted here since this is not an xbox controller, and pushing the stick down should make the ships nose go down, not the other way round.

- POV (solo): thrust UP/DOWN/LEFT/RIGHT

I have mapped the POV switch on their own to different keypresses. These keypresses are assigned to Thrust Up, Thrust Left, Thrust Right, and Thrust Down in the ED config screen.

- POV + mainweapon button: Power distribution settings

Left: power to systems / Right: power to weapons / Up; power to engines / Down: power balanced.

Extra Note:

By assigning the mouselook view to a button on the SB controller, you can also use one of the two POV keysettings to look around the cockpit. I haven't got any track IR and I am waiting for a proper Oculus Rift release, so still playing on a 23' monitor.

- The keys in the config are the defaults used by ED after installation, so minimum reconfig of the ingame buttons is required.

- When calibrating this in windows, I found it that commenting out the keys for the pov helps a lot with the calibration. Uncomment again when calibration is complete, and then launch the game.

Now if this thing would have force feedback, it would really rock, but I am pretty happy about the results so far.

@HackNFly,

I have a RL project on the way as well, so I know what that feels like, I haven't found the time to finish the 3D model of the station I was making for Oolite and If I were in your situation with a baby on top of all that, I understand that some things have priority over others. Nevertheless I thank you for all the help and I have credited you in the youtube description of the video as promised.

Till soon.

Max

Edited by Max Gordon, 23 October 2014 - 07:26 AM.


#308 Golden Gun

    Member

  • PipPipPip
  • Legendary Founder
  • Legendary Founder
  • 87 posts
  • LocationIdaho

Posted 27 October 2014 - 06:19 PM

Okay! Just found out that they are re-releasing X-Wing and Tie Fighter on GOG.com tomorrow!!!!!

I'm so excited if you can't tell ;)

I have both still in their boxes, on floppies and with the control guide. Guess I have my own project to get started on, eh?

#309 Max Gordon

    Member

  • Pip
  • 11 posts

Posted 29 October 2014 - 05:22 AM

Hey Goldengun,

Looks like we have the same gameplay tastes;

That's excellent news, GOG is epic and so is Tie Fighter. Never really connected with X-wing. Hopefully they'll release XVT on GOG too. I still have all the boxes; unfortunately my T-F floppies are gone, the only one I still have is the expansions disk with the first 3 addon campaigns and the guide to that. Also X-wing Vs Tie Fighter and X-Wing Alliance followed suit.

I am very interested in seeing what you come up with as a controller scheme for that; since at some point I will finish the XVT Tie Fighter conversion campaigns I have been working on.

On a sidenote IIRC:

I see GOG released the windows version as well; the models used in that version are the same as Xwing Vs Tie fighter, meaning that you can upgrade the 3d models of the fighters so they will look a lot better. Different models have been redone by these folks:

http://xvtedicion.es...ngles/index.htm

On this page you will find a collection of OPT files that can be used to overwrite the vanilla ones to upgrade your 3D models. Screenshots of how they look can be seen with every download:

Here is a screenshot of the tie fighter:
Posted Image

However if you like to go retro and play with the vanilla models, feel free to ignore.

If GOG and spacesims are your thing, don't forget to check out I-War and I-War 2.

Have fun

Max

#310 Max Gordon

    Member

  • Pip
  • 11 posts

Posted 29 October 2014 - 03:03 PM

Although the latest Tie Fighter game (TF95) has the same engine as XVT, and I was able to use upgraded models in that engine in the past; but I fail to succeed now. Maybe some thing were changed in the GOG version.
Oh well, no harm done; please share your sb controller scheme for tie fighter when you get it done. Would really love to try that out.

Max

#311 Nydo

    Member

  • Pip
  • 11 posts

Posted 08 November 2014 - 05:13 PM

Goog work gordon, seem you find some usefull part in my own code for lights =)
I'm happy to see that people are stille enjoying this awesome pad and that hack'nfly is still helping =D

#312 CrackMouse

    Rookie

  • 1 posts

Posted 20 December 2014 - 12:24 PM

Hi guys... this is great stuff.
HackNFly, Max Gordon, and Nydo - and all the others that have contributed to getting this controller working: I tip my hat to you.
I'm no coder and i've been muddling my way through a very basic setup for Elite Dangerous.
There's a thread with someone asking about SBC for ED on the forum at Frontier.co.uk.
Would it be OK to re-post the script from a few posts back so that the folk over there, me included, can get started with something an order of magnitude more advanced than the simple.cs with toggles added!?

#313 Garthak

    Member

  • PipPip
  • 33 posts

Posted 18 January 2015 - 08:21 PM

So now that Vjoy is offically signed, do we still need test mode for the LibUSB.NET or is there a newer, more updated version somewhere? Do we still even need LibUSB.NET?


I am trying gordans script on an older space game, freespace 2, while I wait for star citizen. I got the buttons to work, but it seems like the pedals and the joysticks arn't working.

Edited by Garthak, 18 January 2015 - 09:05 PM.


#314 Golden Gun

    Member

  • PipPipPip
  • Legendary Founder
  • Legendary Founder
  • 87 posts
  • LocationIdaho

Posted 19 January 2015 - 10:59 PM

Garthak,

AFAIK you still need to run in Test mode and have everything loaded as before. I tried to run my normally working setup w/o test mode and it failed.

Are you calibrating your Joystick and peddles each time you start up Windows? I know I have to, even if I'm not using them. ;)

#315 Garthak

    Member

  • PipPip
  • 33 posts

Posted 20 January 2015 - 02:36 PM

I would try to calibrate and it wouldn't even read it before. I think it was because I was trying to use the 2.1 release canidate instead of the 2.0.1, because I reinstalled everything and ran that, and now everything seems to work fine.

#316 Golden Gun

    Member

  • PipPipPip
  • Legendary Founder
  • Legendary Founder
  • 87 posts
  • LocationIdaho

Posted 21 January 2015 - 07:00 PM

Just to clarify, you are saying that 2.0.1 works without being set to test mode, correct?

#317 Garthak

    Member

  • PipPip
  • 33 posts

Posted 21 January 2015 - 07:52 PM

No, I put it in test mode before I started installing anything, I was just curious was all, there was talk that getting vjoy signed would fix that, but nothing afterwords about anything dealing with test mode. Thought I'd ask for future reference.

#318 Golden Gun

    Member

  • PipPipPip
  • Legendary Founder
  • Legendary Founder
  • 87 posts
  • LocationIdaho

Posted 28 January 2015 - 11:19 PM

Now that they announced the Urbanmech with its 360 degree rotation, do you think we'll ever see a true joystick solution?

#319 Steel Battalion LoC

    Member

  • PipPip
  • The Devoted
  • The Devoted
  • 30 posts

Posted 30 January 2015 - 04:24 PM

Hey guys!

I tried this out about a year and a half ago. I was so excited it worked, that i forgot to come on the forums and thank you guys for all your hard work. I took off to college and put MWO and other games behind and cracked down on schoolwork. I just recently have had some spare time and started to dig my feet back into MWO.

So much has changed! 12 vs 12's!?!?

They were a bit weird at first, but now i am loving it!

I had to re-install windows 7... So I am going to try and set this up again.

I have been learning C++ and teaching myself C# on the side, but programming can be both fun and aggravating. The worst feeling in the world is when you are missing a ; ... Then the best feeling in the world is when you find it and the program works :P.

To be completely honest, there really are no words or expressions to say to thank you guys for keeping this 43 button controller alive haha.

PS: I hope to see you in the battle field Golden Gun. That modified SB stick is amazing :lol:.

#320 Scum of the Earth

    Member

  • PipPipPipPipPip
  • The Hungry
  • The Hungry
  • 106 posts
  • LocationMidwest, USA

Posted 06 March 2015 - 08:10 AM

To my fellow MWO friends here...

I was feeling quite lucky here having discover MWO a few months ago and then someone posting this topic of how to turn my Steel Battalion controller into a MW Windows controller. So, I was very excited to go on Amazon and order an Xbox to USB cable and when it arrived, I pulled my Steel Battalion controller out of storage.

Much to my disappointment, I have found one of the five switched on the left side controller to be broken. I took it apart and pulled out the board and unsoldered the switch from the board and discovered that it was a plastic weld that had broken.

So, I am kind of at an impasse at the moment. The switch and the board had no parts number on it. I have looked for an exploded view of the controller online but the few I have found for THIS controller have only been circuit pathways, no parts. This switch is too small and delicate that there is no means in my possession that I can do to fix it (glue, pinning, or welding).

If someone could be so kindly, would someone know where I could buy a replacement part OR have a parts number for me to look up OR maybe even a fix for the switch? I hope there's someone here that more dedicated geek then I am to help me out... =) Thanks guys.





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users