
BTW, did you see what Skillfulest is trying to do? I gave him everything I could think of but he is still stuck. I honestly don't even know if it'll work...
Posted 23 January 2016 - 03:00 PM
Posted 24 January 2016 - 01:30 PM
Skillfulist, on 20 January 2016 - 05:01 AM, said:
double combinedValue = controller.Scaled.AimingX*0.9 + controller.Scaled.SightChangeX*0.1; joystick.setAxis(1,(int)combinedValue ,HID_USAGES.HID_USAGE_X);
controller.AddButtonKeyLightMapping(ButtonEnum.CockpitHatch, true, 3, SBC.Key.A, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF1, true, 3, Microsoft.DirectX.DirectInput.Key.BackSpace, true);
controller.AddButtonKeyLightMapping(ButtonEnum.CockpitHatch, false, 3, SBC.Key.A, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF1, false, 3, Microsoft.DirectX.DirectInput.Key.BackSpace, true);
Edited by HackNFly, 24 January 2016 - 01:34 PM.
Posted 02 February 2016 - 09:02 PM
//if(controller.GetButtonState(ButtonEnum.ToggleFilterControl)) //FILT Toggle { controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, SBC.Key.D2, true); //joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire),1,15); } //else { controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, SBC.Key.NoConvert, true); //joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire),1,0); } //if(controller.GetButtonState(ButtonEnum.ToggleOxygenSupply)) // O2 Supply Toggle { controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, SBC.Key.D2, true); } //else { controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, SBC.Key.D3, true); } currentResetValue = controller.GetButtonState((int)ButtonEnum.ToggleFuelFlowRate); if(currentResetValue != lastResetValue && currentResetValue) { controller.TestLEDs(1);//reset lights
Posted 02 February 2016 - 09:21 PM
Posted 03 February 2016 - 07:39 AM
HackNFly, on 02 February 2016 - 09:21 PM, said:
Posted 04 February 2016 - 11:23 PM
// MWO Config File // version 0.7 // by von Pilsner (thanks to HackNFly!@!!!) // // Uses default MWO keybindings as of Sept 26, 2012 // You must map the 'throttle' axis in-game though... // // For use with Steel-Batallion-64_v2_pre.zip // 64 bit driver code/glue by HackNFly http://code.google.com/p/steel-batallion-64/ // // add the folowing to user.cfg // // cl_joystick_gain = 1.35 // cl_joystick_invert_throttle = 0 // cl_joystick_invert_pitch = 1 // cl_joystick_invert_yaw = 0 // cl_joystick_invert_turn = 0 // cl_joystick_throttle_range = 0 // // updated by Santiago Saldana Sept, 27, 2012 using SBC; using System; namespace SBC { public class DynamicClass { SteelBattalionController controller; vJoy joystick; bool acquired; bool jumpPressed = false; bool stopPressed = false;//used in special handling of left pedal bool currentResetValue; bool lastResetValue;//used in assessing when to flip lights int pedalTriggerLevel = 50;//used in special handling of left pedal, SBC.Key jumpKey = SBC.Key.Space; SBC.Key stopKey = SBC.Key.X; const int refreshRate = 30;//number of milliseconds between call to mainLoop //this gets called once by main program public void Initialize() { int baseLineIntensity = 3;//just an average value for LED intensity //int emergencyLightIntensity = 15;//for stuff like eject,cockpit Hatch,Ignition, and Start 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 for(int i=4;i<4+30;i++) { if (i != (int)ButtonEnum.Eject)//excluding eject since we are going to flash that one controller.AddButtonLightMapping((ButtonEnum)(i-1),(ControllerLEDEnum)(i),true,baseLineIntensity); } controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, SBC.Key.D4, true); controller.AddButtonKeyMapping(ButtonEnum.RightJoyLockOn, SBC.Key.R, true); controller.AddButtonKeyLightMapping(ButtonEnum.Eject, true, 3, SBC.Key.O, true); controller.AddButtonKeyLightMapping(ButtonEnum.Ignition, true, 3, SBC.Key.P, true); //controller.AddButtonKeyLightMapping(ButtonEnum.Start, true, 3, SBC.Key.X, true); controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonOpenClose, true, 3, SBC.Key.B, true); controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonMapZoomInOut, true, 3, SBC.Key.B, true); //controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonModeSelect, true, 3, SBC.Key.X, true); //controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonSubMonitor, true, 3, SBC.Key.X, true); controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomIn, true, 3, SBC.Key.Z, true); controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomOut, true, 3, SBC.Key.V, true); //controller.AddButtonKeyLightMapping(ButtonEnum.FunctionFSS, false, 13, SBC.Key.D6, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionManipulator, true, 13, SBC.Key.LeftShift, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionLineColorChange, false, 13, SBC.Key.H, true); controller.AddButtonKeyLightMapping(ButtonEnum.Washing, true, 3, SBC.Key.C, true); controller.AddButtonKeyLightMapping(ButtonEnum.Extinguisher, true, 3, SBC.Key.O, true); controller.AddButtonKeyLightMapping(ButtonEnum.Chaff, true, 13, SBC.Key.J, true); //controller.AddButtonKeyLightMapping(ButtonEnum.FunctionTankDetach, true, 3, SBC.Key.X, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionOverride, true, 3, SBC.Key.O, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionNightScope, false, 13, SBC.Key.N, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF1, true, 3, SBC.Key.Tab, true); //controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF2, true, 3, SBC.Key.X, true); //controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF3, true, 3, SBC.Key.LeftControl, true); controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMain, true, 3, SBC.Key.RightControl, true); controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConSub, true, 3, SBC.Key.BackSpace, true); //controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMagazine, true, 3, SBC.Key.X, true); controller.AddButtonKeyLightMapping(ButtonEnum.Comm1, true, 3, SBC.Key.F6, true); controller.AddButtonKeyLightMapping(ButtonEnum.Comm2, true, 3, SBC.Key.F8, true); controller.AddButtonKeyLightMapping(ButtonEnum.Comm3, true, 3, SBC.Key.F9, true); //controller.AddButtonKeyLightMapping(ButtonEnum.Comm4, true, 3, SBC.Key.X, true); controller.AddButtonKeyLightMapping(ButtonEnum.Comm5, true, 3, SBC.Key.RightBracket, true); controller.AddButtonKeyMapping(ButtonEnum.LeftJoySightChange, SBC.Key.Z, true); controller.AddButtonKeyMapping(ButtonEnum.ToggleVTLocation, SBC.Key.Q, true); controller.AddButtonKeyMapping(ButtonEnum.ToggleFilterControl, SBC.Key.D6, true); 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 void updatePOVhat() { int thumbstickDeadZone = 44; 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 { controller.POVhat = SBC.POVdirection.CENTER; } if(lastDirection != controller.POVhat) { switch(lastDirection) { case SBC.POVdirection.LEFT: controller.sendKeyUp(SBC.Key.Left); break; case SBC.POVdirection.RIGHT: controller.sendKeyUp(SBC.Key.Right); break; case SBC.POVdirection.DOWN: controller.sendKeyUp(SBC.Key.Up); break; case SBC.POVdirection.UP: controller.sendKeyUp(SBC.Key.Down); break; } } else { switch(controller.POVhat) { case SBC.POVdirection.LEFT: controller.sendKeyDown(SBC.Key.Left); break; case SBC.POVdirection.RIGHT: controller.sendKeyDown(SBC.Key.Right); break; case SBC.POVdirection.DOWN: controller.sendKeyDown(SBC.Key.Up); break; case SBC.POVdirection.UP: controller.sendKeyDown(SBC.Key.Down); break; } } } public void evaluateLeftPedal() { if(controller.LeftPedal > pedalTriggerLevel) { //take care of the button logic separately, to be less confusing if(!jumpPressed)//if not currently holding down jump key { if(controller.RightPedal > pedalTriggerLevel || controller.MiddlePedal > pedalTriggerLevel) { controller.sendKeyDown(jumpKey); jumpPressed = true; } } else//jump button was pressed { //adding these so that else if won't get optimized into one statement if(controller.RightPedal < pedalTriggerLevel && controller.MiddlePedal < pedalTriggerLevel) { controller.sendKeyUp(jumpKey); jumpPressed = false; } } if(!stopPressed)//if not currently holding down stop key { if(controller.RightPedal < pedalTriggerLevel && controller.MiddlePedal < pedalTriggerLevel) { controller.sendKeyDown(stopKey);//send fullstop command stopPressed = true; } } else//stop button was pressed { if(controller.RightPedal > pedalTriggerLevel || controller.MiddlePedal > pedalTriggerLevel) { controller.sendKeyUp(stopKey); stopPressed = false; } } } else { if(stopPressed) { controller.sendKeyUp(stopKey); stopPressed = false; } if(jumpPressed) { controller.sendKeyUp(jumpKey); jumpPressed = false; } } } //this gets called once every refreshRate milliseconds by main program public void mainLoop() { updatePOVhat(); joystick.setAxis(1,controller.Scaled.AimingX,HID_USAGES.HID_USAGE_X); joystick.setAxis(1,controller.Scaled.AimingY,HID_USAGES.HID_USAGE_Y); joystick.setAxis(1,-1*(controller.Scaled.RotationLever),HID_USAGES.HID_USAGE_Z); joystick.setAxis(1,-1*(controller.Scaled.SightChangeX),HID_USAGES.HID_USAGE_RX); joystick.setAxis(1,controller.Scaled.SightChangeY,HID_USAGES.HID_USAGE_RY); joystick.setAxis(1,controller.Scaled.RightMiddlePedal,HID_USAGES.HID_USAGE_RZ);//throttle joystick.setAxis(1,controller.Scaled.LeftPedal,HID_USAGES.HID_USAGE_SL0); joystick.setAxis(1,controller.Scaled.GearLever,HID_USAGES.HID_USAGE_SL1); //joystick.setContPov(1,getDegrees(controller.SightChangeX,controller.SightChangeY),1); // toggle tricks!!! if(controller.GetButtonState(ButtonEnum.ToggleFilterControl)) //FILT Toggle { controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, SBC.Key.D2, true); joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire),1,15); } else { controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, SBC.Key.NoConvert, true); joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire),1,0); } if(controller.GetButtonState(ButtonEnum.ToggleOxygenSupply)) // O2 Supply Toggle { controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, SBC.Key.D2, true); } else { controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, SBC.Key.D3, true); } currentResetValue = controller.GetButtonState((int)ButtonEnum.ToggleFuelFlowRate); if(currentResetValue != lastResetValue && currentResetValue) { controller.TestLEDs(1);//reset lights } lastResetValue = currentResetValue; evaluateLeftPedal(); 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.sendKeyUp(SBC.Key.LeftControl); controller.UnInit(); joystick.Release(1); } } }
Posted 05 February 2016 - 12:16 PM
currentResetValue = controller.GetButtonState((int)ButtonEnum.ToggleFuelFlowRate);
currentResetValue = controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate);
Posted 09 February 2016 - 11:28 PM
Posted 20 February 2016 - 10:40 PM
if(controller.GetButtonState(ButtonEnum.ToggleFilterControl)) //FILT Toggle
controller.GetButtonState(ButtonEnum.ToggleFilterControl) //FILT Toggle
c:\Users\J-Golden\AppData\Local\Temp\3jb5g3hi.0.cs(271,61) : error CS1002: ; expected c:\Users\J-Golden\AppData\Local\Temp\3jb5g3hi.0.cs(276,4) : error CS1525: Invalid expression term 'else' c:\Users\J-Golden\AppData\Local\Temp\3jb5g3hi.0.cs(276,8) : error CS1002: ; expected c:\Users\J-Golden\AppData\Local\Temp\3jb5g3hi.0.cs(282,60) : error CS1002: ; expected c:\Users\J-Golden\AppData\Local\Temp\3jb5g3hi.0.cs(286,4) : error CS1525: Invalid expression term 'else' c:\Users\J-Golden\AppData\Local\Temp\3jb5g3hi.0.cs(286,8) : error CS1002: ; expected
Posted 29 February 2016 - 10:13 PM
Posted 07 April 2016 - 10:05 PM
Posted 08 April 2016 - 04:19 AM
Golden Gun, on 29 February 2016 - 10:13 PM, said:
Posted 10 April 2016 - 11:55 AM
evilC, on 08 April 2016 - 04:19 AM, said:
Posted 11 April 2016 - 03:41 AM
Edited by evilC, 11 April 2016 - 03:55 AM.
Posted 11 April 2016 - 12:47 PM
Posted 12 April 2016 - 03:22 AM
Quote
Quote
Quote
Posted 12 April 2016 - 09:20 AM
; Limit the amount of movement for this tick to the MAX_TWIST_RATE delta_move[A_Index] := abs(delta_move[A_Index]) > MAX_TWIST_RATE ? MAX_TWIST_RATE * sgn(delta_move[A_Index]) : delta_move[A_Index]
// MWO Config File // version 3.1 (WiP) // by von Pilsner (thanks to HackNFly!@!!!) // // NOTE: Calibrate using BvP-Simple-3.0.cs // Or your pedals may not work properly!! // // Uses default MWO keybindings and axis as of Jan 28, 2013 // // For use with Steel-Batallion-64_v2_beta.zip // 64 bit driver code/glue by HackNFly http://code.google.com/p/steel-batallion-64/ // // I suggest you add the folowing to user.cfg (remove the //'s) // // cl_joystick_gain = 5.05 // cl_joystick_sensitivity = 1.00 // cl_joystick_invert_throttle = 0 // cl_joystick_invert_pitch = 1 // cl_joystick_invert_yaw = 0 // cl_joystick_invert_turn = 0 // cl_joystick_throttle_range = 0 // // ; Joystick DeadZone, requires both the i and cl lines to make the joystick deadzone change work // ; Increase in 0.02 incriments if you get an unstable center point on either stick (0.08 works for some). // i_joystick_deadzone = 0.04 // cl_joystick_deadzone = 0.04 // using SBC; using System; namespace SBC { public class DynamicClass { SteelBattalionController controller; vJoy joystick; bool acquired; String debugString = ""; int desiredX; int desiredY; int currentX = 0; int currentY = 0; int numPixelX = 600;//number of pixels to move in X direction int numPixelY = 300;//number of pixels to move in X direction int numPixelExtraX = 25;//used at extreme edges, number of pixels per poll int numPixelExtraY = 20;//used at extreme edges const int refreshRate = 30; // Number of milliseconds between call to mainLoop const int maxAxisValue = 32768; double sideZone = 0.05;//percent of swing that will cause mouse to move continuously int jj = 0; bool startedTracking = false;//used to make switching mouse on and off not jumpy // This gets called once by main program public void Initialize() { int baseLineIntensity = 3; // Just an average value for LED intensity int emergencyLightIntensity = 15; // For stuff like eject,cockpit Hatch,Ignition, and Start controller = new SteelBattalionController(); controller.Init(30); // 50 is refresh rate in milliseconds //set all buttons by default to light up only when you press them down for (int i = 4; i < 4 + 30; i++) { if (i != (int)ButtonEnum.Eject) // Excluding eject since we are going to flash that one controller.AddButtonLightMapping((ButtonEnum)(i - 1), (ControllerLEDEnum)(i), true, baseLineIntensity); } // Button Bindings controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, Microsoft.DirectX.DirectInput.Key.D1,true); controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, Microsoft.DirectX.DirectInput.Key.D2,true); controller.AddButtonKeyMapping(ButtonEnum.RightJoyLockOn, Microsoft.DirectX.DirectInput.Key.R, true); controller.AddButtonKeyLightMapping(ButtonEnum.Eject, true, 3, Microsoft.DirectX.DirectInput.Key.O, true); controller.AddButtonKeyLightMapping(ButtonEnum.Ignition, true, 3, Microsoft.DirectX.DirectInput.Key.P, true); //controller.AddButtonKeyLightMapping(ButtonEnum.CockpitHatch, true, 3, Microsoft.DirectX.DirectInput.Key.X, true); //controller.AddButtonKeyLightMapping(ButtonEnum.Start, true, 3, Microsoft.DirectX.DirectInput.Key.X, true); controller.AddButtonKeyLightMapping(ButtonEnum.MultiMonOpenClose, true, 3, Microsoft.DirectX.DirectInput.Key.B, true); 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.Z, true); controller.AddButtonKeyLightMapping(ButtonEnum.MainMonZoomOut, true, 3, Microsoft.DirectX.DirectInput.Key.V, true); //controller.AddButtonKeyLightMapping(ButtonEnum.FunctionFSS, true, 3, Microsoft.DirectX.DirectInput.Key.X, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionManipulator, true, 3, Microsoft.DirectX.DirectInput.Key.J, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionLineColorChange, true, 3, Microsoft.DirectX.DirectInput.Key.H, true); controller.AddButtonKeyLightMapping(ButtonEnum.Washing, true, 3, Microsoft.DirectX.DirectInput.Key.C, true); controller.AddButtonKeyLightMapping(ButtonEnum.Extinguisher, true, 3, Microsoft.DirectX.DirectInput.Key.Delete, true); //controller.AddButtonKeyLightMapping(ButtonEnum.Chaff, true, 3, Microsoft.DirectX.DirectInput.Key.X, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionTankDetach, true, 3, Microsoft.DirectX.DirectInput.Key.Slash, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionOverride, true, 3, Microsoft.DirectX.DirectInput.Key.O, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionNightScope, true, 3, Microsoft.DirectX.DirectInput.Key.N, true); controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF1, true, 3, Microsoft.DirectX.DirectInput.Key.Tab, true); //controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF2, true, 3, Microsoft.DirectX.DirectInput.Key.X, true); //controller.AddButtonKeyLightMapping(ButtonEnum.FunctionF3, true, 4, Microsoft.DirectX.DirectInput.Key.LeftControl, true); controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMain, true, 3, Microsoft.DirectX.DirectInput.Key.RightControl, true); controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConSub, true, 3, Microsoft.DirectX.DirectInput.Key.BackSpace, true); //controller.AddButtonKeyLightMapping(ButtonEnum.WeaponConMagazine, true, 3, Microsoft.DirectX.DirectInput.Key.X, true); //controller.AddButtonKeyLightMapping(ButtonEnum.ToggleBufferMaterial, true, 3, Microsoft.DirectX.DirectInput.Key.LeftShift, true); // controller.AddButtonKeyMapping(ButtonEnum.LeftJoySightChange, Microsoft.DirectX.DirectInput.Key.V, true); controller.AddButtonKeyMapping(ButtonEnum.LeftJoySightChange, Microsoft.DirectX.DirectInput.Key.Z, true); joystick = new vJoy(); acquired = joystick.acquireVJD(1); joystick.resetAll(); //have to reset before we use it joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_SL1); joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_X); joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_Y); joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_Z);//throttle joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_RZ); joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_SL0); joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_RX); joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_RY); } //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; } // POV to Arrow Keys public void updatePOVhat() { 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 { controller.POVhat = SBC.POVdirection.CENTER; } if (lastDirection != controller.POVhat) { switch (lastDirection) { case SBC.POVdirection.LEFT: controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Left); break; case SBC.POVdirection.RIGHT: controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Right); break; case SBC.POVdirection.DOWN: controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Up); break; case SBC.POVdirection.UP: controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Down); break; } } else { switch (controller.POVhat) { case SBC.POVdirection.LEFT: controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Left); break; case SBC.POVdirection.RIGHT: controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Right); break; case SBC.POVdirection.DOWN: controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Up); break; case SBC.POVdirection.UP: controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Down); break; } } } private double expo(int value) { double tempIn = ((double)value / (double)maxAxisValue)*2 - 1;//scale to -1 to 1 tempIn *= tempIn * 0.5;//this applies expo, we get 0 to 1 regardless of sign then multiply by 0.5 since it only represents //half of the value tempIn = Math.Abs(tempIn); if(value >= maxAxisValue/2) tempIn += 0.5; else tempIn = 0.5 - tempIn; //debugString += "value:" + value.ToString() + " tempIn : " + tempIn.ToString() + "\n"; return tempIn; } public int scaleValue(int value, int low, int middle, int high, int deadzone) { double temp; debugString += value + " " + low + " " + middle + " " + high + " " + deadzone + "\n"; if(Math.Abs(value - middle) < deadzone) temp = ((middle-low)/(double)(high - low))*maxAxisValue; else { if(value < middle) temp = ((double)(value - low) / (double)(middle - low) * 0.5)*maxAxisValue; else temp = ((double)(value - middle) / (double)(high - middle) * 0.5 + 0.5)*maxAxisValue; } //clamp for extraneous values if(temp > maxAxisValue) temp = maxAxisValue; if(temp < 0) temp = 0; return (int) 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; } private int getDeltaS(int axisVal, int desiredVal, int currentVal,int pixelExtra) { int delta = desiredVal - currentVal; //int temp = (int) (expo(axisVal)*pixels); //debugString += "axisVal" + axisVal.ToString() + " " + expo(axisVal).ToString() + " temp " + temp.ToString() + " " //+ "desiredVal:" + desiredVal.ToString() + " currentVal : " + currentVal.ToString() + "\n"; double tempD = (double)axisVal/(double)maxAxisValue; if(tempD > (1 - sideZone))//sidezone is a percentage, i.e. 0.05 for 5 percent { tempD = (tempD - (1- sideZone)); tempD = tempD/sideZone * pixelExtra;//defined at top return (int)tempD; } if(tempD < sideZone) { tempD = (sideZone - tempD)/sideZone * pixelExtra; return (int)(-1*tempD); } return delta; } private int reverse(int val) { return (maxAxisValue - val); } /* //new optional function used for debugging purposes, comment out when running in game as it causes issues public String getDebugString() { return debugString; } */ //this gets called once every refreshRate milliseconds by main program public void mainLoop() { debugString = ""; //updatePOVhat(); int aimingX = scaleValue(controller.AimingX,1,512,1023,5); int aimingY = reverse(scaleValue(controller.AimingY,1,512,1021,5));//calibration values int rAxis = scaleValue(controller.RotationLever,-421,1,510,5);//calibration values int sCX = scaleValue(controller.SightChangeX,-461,0,470,5); int sCY = scaleValue(controller.SightChangeX,-480,-5,463,5); int lPedal = scaleValue(controller.LeftPedal,30,1022); int mPedal = scaleValue(controller.MiddlePedal,128,1021); int rPedal = scaleValue(controller.RightPedal,0,1020); desiredX = (int)(expo(aimingX)*numPixelX);//numPixels stores resolution, i.e. how much we move mouse desiredY = (int)(expo(aimingY)*numPixelY); rAxis = (int)(expo(rAxis)*maxAxisValue); debugString += "expoX " + expo(aimingX) + "\n"; debugString += "expoY " + expo(aimingY) + "\n"; debugString += "expoR " + expo(rAxis) + "\n"; if((bool)controller.GetButtonState(ButtonEnum.ToggleBufferMaterial)) { //debugString += "aimingX:" + aimingX.ToString() + " desiredX : " + desiredX.ToString() + "currentX " + currentX.ToString() + "\n"; //debugString += "aimingY:" + aimingY.ToString() + " desiredY : " + desiredY.ToString() + "currentY " + currentY.ToString() + "\n"; int deltaX = getDeltaS(aimingX,desiredX,currentX,numPixelExtraX); int deltaY = getDeltaS(aimingY,desiredY,currentY,numPixelExtraY); currentX = desiredX; currentY = desiredY; if(startedTracking)//makes it so you can flip the switch and recenter the joystick InputSimulator.MoveMouseBy(deltaX,deltaY); else startedTracking = true; } else { startedTracking = false; } // Joystick Axes debugString += "rAxis = " + rAxis + "\n"; //joystick.setAxis(1, xaxis, HID_USAGES.HID_USAGE_X); //joystick.setAxis(1, yaxis, HID_USAGES.HID_USAGE_Y); joystick.setAxis(1, rAxis, HID_USAGES.HID_USAGE_RZ); //joystick.setAxis(1, sCX, HID_USAGES.HID_USAGE_SL1); //joystick.setAxis(1, sCY, HID_USAGES.HID_USAGE_RX); joystick.setAxis(1,(rPedal - mPedal) + maxAxisValue/2,HID_USAGES.HID_USAGE_SL0);//throttle //joystick.setAxis(1, controller.GearLever, HID_USAGES.HID_USAGE_SL0); joystick.setContPov(1, getDegrees(controller.SightChangeX, controller.SightChangeY), 1); // 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; } 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 HackNFly, 12 April 2016 - 09:42 AM.
Posted 12 April 2016 - 10:22 AM
Edited by GreenHell, 12 April 2016 - 10:28 AM.
Posted 12 April 2016 - 10:49 AM
Edited by evilC, 12 April 2016 - 10:54 AM.
Posted 12 April 2016 - 10:52 AM
GreenHell, on 12 April 2016 - 10:22 AM, said:
GreenHell, on 12 April 2016 - 10:22 AM, said:
0 members, 1 guests, 0 anonymous users