//this gets called once every refreshRate milliseconds by main program public void mainLoop() { updatePOVhat(); 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); // toggle tricks!!! if (controller.GetButtonState(ButtonEnum.ToggleFilterControl)) //FILT Toggle { controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, Microsoft.DirectX.DirectInput.Key.BackSlash, true); joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire), 1, 15); } else { controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, Microsoft.DirectX.DirectInput.Key.NoConvert, true); joystick.setButton(controller.GetButtonState(ButtonEnum.RightJoyFire), 1, 0); } if (controller.GetButtonState(ButtonEnum.ToggleOxygenSupply)) // O2 Supply Toggle { controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, Microsoft.DirectX.DirectInput.Key.D6, true); } else { controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, Microsoft.DirectX.DirectInput.Key.D5, 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 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); for (int i = 1; i <= 32; i++) { joystick.setButton((bool)controller.GetButtonState(i - 1), (uint)1, (char)(i - 1)); } joystick.sendUpdate(1); }
//this gets called once every refreshRate milliseconds by main program public void mainLoop() { float lowValue = 124; float highValue = 255; int gearValue; if (controller.GearLever == -2)//R { gearValue = -255; } else if (controller.GearLever == -1)//N { gearValue = 124; } else { gearValue = (int)(lowValue + (highValue - lowValue) * ((controller.GearLever - 1.0) / 4.0)); } joystick.setAxis(1, controller.GearLever, HID_USAGES.HID_USAGE_SL1); joystick.setAxis(1, controller.AimingX, HID_USAGES.HID_USAGE_X); joystick.setAxis(1, controller.AimingY, HID_USAGES.HID_USAGE_Y); joystick.setAxis(1, -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.setContPov(1, getDegrees(controller.SightChangeX, controller.SightChangeY), 1); for (int i = 1; i <= 32; i++) { joystick.setButton((bool)controller.GetButtonState(i - 1), (uint)1, (char)(i - 1)); } joystick.sendUpdate(1); }
//this gets called once every refreshRate milliseconds by main program public void mainLoop() { updatePOVhat(); int loopdelay = 2; // My pedal timer... this allows slow pedal updating with fast controller polling if (ticka > 0) { loopa++; if (loopa > loopdelay) { ticka = 0; loopa = 0; } } if (tickb > 0) { loopb++; if (loopb > loopdelay) { tickb = 0; loopb = 0; } } if (tickc > 0) { loopc++; if (loopc > loopdelay) { tickc = 0; loopc = 0; } } // Joystick Axes 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_SL1); 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_SL0); joystick.setContPov(1, getDegrees(controller.SightChangeX, controller.SightChangeY), 1); // toggle tricks!!! if (controller.GetButtonState(ButtonEnum.ToggleFilterControl)) //FILT Toggle { controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, Microsoft.DirectX.DirectInput.Key.BackSlash, true); // Alpha Strike joystick.setButton((bool)controller.GetButtonState(ButtonEnum.RightJoyFire), (uint)1, (char)(15)); // unused button (placeholder) } else { controller.AddButtonKeyMapping(ButtonEnum.RightJoyFire, Microsoft.DirectX.DirectInput.Key.NoConvert, true); // unused button (placeholder) joystick.setButton((bool)controller.GetButtonState(ButtonEnum.RightJoyFire), (uint)1, (char)(0)); // Fire Selected Weapon (joystick button 0) } if (controller.GetButtonState(ButtonEnum.ToggleOxygenSupply)) // O2 Supply Toggle { controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, Microsoft.DirectX.DirectInput.Key.D6, true); } else { controller.AddButtonKeyMapping(ButtonEnum.RightJoyMainWeapon, Microsoft.DirectX.DirectInput.Key.D5, true); } // Pedals Section if ((jj == 1) && ((controller.LeftPedal) < 50)) // Left pedal released { controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.Space); jj = 0; } if (((controller.LeftPedal) > 50) && (ticka == 0)) // Left pedal pressed { if (controller.GetButtonState(ButtonEnum.ToggleFuelFlowRate)) // Is the FUEL Flow toggle UP? { controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.Space); ticka = 0; // bypass timer so we can jump! loopa = 0; jj = 1; // Jets are on... } else // FUEL Flow toggle must be down... { controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.X); ticka = 1; loopa = 0; controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.X); } } if (((controller.MiddlePedal) > 50) && (tickb == 0)) // Middle pedal pressed { controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.S); tickb = 1; loopb = 0; controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.S); } if (((controller.RightPedal) > 50) && (tickc == 0)) // Right pedal pressed { controller.sendKeyDown(Microsoft.DirectX.DirectInput.Key.W); tickc = 1; loopc = 0; controller.sendKeyUp(Microsoft.DirectX.DirectInput.Key.W); } joystick.sendUpdate(1); }
/* * //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); }
// private int scaledValue(int min, int middle, int max, int deadZone) //this gets called once every refreshRate milliseconds by main program public void mainLoop() { float lowValue = 124; float highValue = 255; int gearValue; int numPixels = 600; desiredX = (int)((controller.AimingX / 1024.0) * numPixels); desiredY = (int)((controller.AimingY / 1024.0) * numPixels); if (controller.GearLever == -2)//R { gearValue = -255; } else if (controller.GearLever == -1)//N { gearValue = 124; } else { gearValue = (int)(lowValue + (highValue - lowValue) * ((controller.GearLever - 1.0) / 4.0)); } debugString = "not in"; if ((bool)controller.GetButtonState(ButtonEnum.RightJoyMainWeapon)) { debugString = "RightJoyMainWeapon"; desiredX = currentX; desiredY = currentY; } if ((bool)controller.GetButtonState(ButtonEnum.RightJoyLockOn)) { int deltaX = desiredX - currentX; int deltaY = desiredY - currentY; currentX = desiredX; currentY = desiredY; //debugString = "in"; InputSimulator.MoveMouseBy(deltaX, deltaY); } /* * joystick.setAxis(1,controller.GearLever,HID_USAGES.HID_USAGE_SL1); * * //joystick.setAxis(1,controller.AimingX,HID_USAGES.HID_USAGE_X); * //joystick.setAxis(1,controller.AimingY,HID_USAGES.HID_USAGE_Y); * * * * * joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_X); * joystick.setAxis(1,32768/2,HID_USAGES.HID_USAGE_Y); * * joystick.setAxis(1,-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.setContPov(1, getDegrees(controller.SightChangeX, controller.SightChangeY), 1); for (int i = 1; i <= 32; i++) { joystick.setButton((bool)controller.GetButtonState(i - 1), (uint)1, (char)(i - 1)); } joystick.sendUpdate(1); }