forcedreg

Untitled

Apr 20th, 2024
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. using SBC;
  2. using System;
  3. namespace SBC{
  4. public class DynamicClass
  5. { String debugString = "";
  6. SteelBattalionController controller;
  7. vJoy joystick;
  8. bool acquired;
  9. int vJoyButtons = 39;//change to 39 to fully support SBC, need to use vJoy config to change
  10. //number of buttons to 39.
  11. const int refreshRate = 1;//number of milliseconds between call to mainLoop
  12.  
  13. const int iGlowyGoodnessMin = 1; //0-15 for glow effect
  14. const int iGlowyGoodnessMax = 15;
  15. const double dGlowySpeed = 0.1;
  16.  
  17. double dGlowyGoodness;
  18.  
  19.  
  20. //this gets called once by main program
  21. public void Initialize()
  22. {
  23.  
  24. int baseLineIntensity = 15;//just an average value for LED intensity
  25.  
  26. controller = new SteelBattalionController();
  27. controller.Init(1);//50 is refresh rate in milliseconds
  28. //set all buttons by default to light up only when you press them down
  29.  
  30. for (int i = 4; i < 4 + 30; i++)
  31. {
  32. if (i != (int)ButtonEnum.Eject)//excluding eject since we are going to flash that one
  33. controller.AddButtonLightMapping((ButtonEnum)(i - 1), (ControllerLEDEnum)(i), true, baseLineIntensity);
  34. }
  35.  
  36. joystick = new vJoy();
  37. acquired = joystick.acquireVJD(1);
  38. joystick.resetAll();//have to reset before we use it
  39.  
  40. }
  41.  
  42. //this is necessary, as main program calls this to know how often to call mainLoop
  43. public int getRefreshRate()
  44. {
  45. return refreshRate;
  46. }
  47.  
  48. //this gets called once every refreshRate milliseconds by main program
  49. public void mainLoop()
  50. {
  51. dGlowyGoodness = (dGlowyGoodness + dGlowySpeed) % 360;
  52. joystick.setAxis(1,controller.Scaled.GearLever,HID_USAGES.HID_USAGE_SL1);
  53. joystick.setAxis(1,controller.Scaled.AimingX,HID_USAGES.HID_USAGE_X);
  54. joystick.setAxis(1,controller.Scaled.AimingY,HID_USAGES.HID_USAGE_Y);
  55. joystick.setAxis(1,controller.Scaled.RightMiddlePedal,HID_USAGES.HID_USAGE_Z);//throttle
  56. joystick.setAxis(1,controller.Scaled.RotationLever,HID_USAGES.HID_USAGE_RZ);
  57. joystick.setAxis(1,controller.Scaled.SightChangeX,HID_USAGES.HID_USAGE_SL0);
  58. joystick.setAxis(1,controller.Scaled.SightChangeY,HID_USAGES.HID_USAGE_RX);
  59. joystick.setAxis(1,controller.Scaled.LeftPedal,HID_USAGES.HID_USAGE_RY);
  60.  
  61.  
  62. for (int i = 1; i <= vJoyButtons; i++)
  63. {
  64. joystick.setButton((bool)controller.GetButtonState(i - 1), (uint)1, (char)(i - 1));
  65. }
  66.  
  67. joystick.sendUpdate(1);
  68. }
  69.  
  70. public int getGlowy(int iOffset) {
  71. double angle = ((dGlowyGoodness + iOffset) % 360)*System.Math.PI/180.0;
  72. return (System.Math.Abs((int)System.Math.Sin(angle))
  73. * (iGlowyGoodnessMax-iGlowyGoodnessMin)) + iGlowyGoodnessMin;
  74. }
  75.  
  76. //new necessary function used for debugging purposes
  77. public String getDebugString()
  78. {
  79. return debugString;
  80. }
  81.  
  82. //this gets called at the end of the program and must be present, as it cleans up resources
  83. public void shutDown()
  84. {
  85. controller.UnInit();
  86. joystick.Release(1);
  87. }
  88. }
  89. }
Advertisement
Add Comment
Please, Sign In to add comment