Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using SBC;
- using System;
- namespace SBC{
- public class DynamicClass
- { String debugString = "";
- SteelBattalionController controller;
- vJoy joystick;
- bool acquired;
- int vJoyButtons = 39;//change to 39 to fully support SBC, need to use vJoy config to change
- //number of buttons to 39.
- const int refreshRate = 1;//number of milliseconds between call to mainLoop
- const int iGlowyGoodnessMin = 1; //0-15 for glow effect
- const int iGlowyGoodnessMax = 15;
- const double dGlowySpeed = 0.1;
- double dGlowyGoodness;
- //this gets called once by main program
- public void Initialize()
- {
- int baseLineIntensity = 15;//just an average value for LED intensity
- controller = new SteelBattalionController();
- controller.Init(1);//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);
- }
- 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;
- }
- //this gets called once every refreshRate milliseconds by main program
- public void mainLoop()
- {
- dGlowyGoodness = (dGlowyGoodness + dGlowySpeed) % 360;
- joystick.setAxis(1,controller.Scaled.GearLever,HID_USAGES.HID_USAGE_SL1);
- 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,controller.Scaled.RightMiddlePedal,HID_USAGES.HID_USAGE_Z);//throttle
- joystick.setAxis(1,controller.Scaled.RotationLever,HID_USAGES.HID_USAGE_RZ);
- joystick.setAxis(1,controller.Scaled.SightChangeX,HID_USAGES.HID_USAGE_SL0);
- joystick.setAxis(1,controller.Scaled.SightChangeY,HID_USAGES.HID_USAGE_RX);
- joystick.setAxis(1,controller.Scaled.LeftPedal,HID_USAGES.HID_USAGE_RY);
- for (int i = 1; i <= vJoyButtons; i++)
- {
- joystick.setButton((bool)controller.GetButtonState(i - 1), (uint)1, (char)(i - 1));
- }
- joystick.sendUpdate(1);
- }
- public int getGlowy(int iOffset) {
- double angle = ((dGlowyGoodness + iOffset) % 360)*System.Math.PI/180.0;
- return (System.Math.Abs((int)System.Math.Sin(angle))
- * (iGlowyGoodnessMax-iGlowyGoodnessMin)) + iGlowyGoodnessMin;
- }
- //new necessary function used for debugging purposes
- public String getDebugString()
- {
- return debugString;
- }
- //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);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment