Guest User

lemurcan FA-off relative toggle ver 1.0

a guest
Sep 18th, 2022
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.06 KB | None | 0 0
  1. # Edited dual-axis output program for E:D, by lemurcan, credit to Andrea Spada for original program
  2. # Requirements: vJoy and freePie
  3. # This edit fixes a few fundamental issues with Andrea's program, most notably the behavior of the
  4. # relative-mouse emulation.
  5. # 1. Previously in the program, relative mouse was emulated with a "fixed" return to center rate. This meant that for
  6. # minor movements amounting to less than this fixed value, they would be cancelled out by the next poll of the program.
  7. # This severely hindered fine control and combined with the following flaw, did not accurately emulate the game's
  8. # relative mouse function.
  9. # 2. The previous relative mouse implementation incorporated an "idle check" that would make it so the return force only
  10. # activated when there was no new movement. It did this by having alternating checks, one at a 30ms poll and another 60ms;
  11. # this effectively meant that the return motion would only occur once your mouse had been still for 30ms. This, as per my
  12. # own experimental testing with the official in-game relative mouse, is also inaccurate. The ingame return force is always
  13. # active and has no waiting-for-idle component.
  14. # 3. This is a relatively minor flaw but the previous program only polled at a 4ms rate; I have upped this to 1ms to improve
  15. # input delay and be on-par with the standard for most "gaming-grade" mice. This also helps account, in my view, for Python's
  16. # timing inconsistencies. Do note that the logarithmic curve implemented for relative mouse is scaled accordingly, and
  17. # adjusting this poll rate will necessitate an inverse multiplication of rel_factor.
  18. #
  19. # Short documentation of relevant variables:
  20. # absolute_sens and relative_sens adjust each axes' mouse sensitivity in a linear fashion
  21. # pradius is the absolute mouse deadzone; do note that this is respective to the vjoy output, which is 0 to +- 16k
  22. # smart_speed is the rate of return within the absolute mouse deadzone
  23. # rel_factor is the logarithmic factor for the constant relative mouse return force. 200 is roughly equal to max relative mouse
  24. # in-game.
  25. # curve determines the steepness of the mild exponential curve per Andrea's absolute mouse implementation; implementation is
  26. # not entirely clear and the default of 3 seems functional and noninterfering with gameplay; may implement true linear later.
  27. #
  28. # Lower in the program are values to be edited according to your keybinds: line 166 has an entry point for keys that will
  29. # hard-center the mouse; think menu or flight mode toggles.
  30.  
  31.  
  32. # Original credit below:
  33. #
  34. # Title: Trackball/Mouse to Analog Axis for Elite: Dangerous, with "Relative Mouse" additional axis.
  35. # Author: Andrea Spada
  36. # Version: 3.3
  37. #
  38. # Features: Simulate analog axis from mouse for yaw and pitch. It use vJoy.
  39. #
  40. # Each mouse direction is mapped to two axis. So, for lateral movement, we have both X and RX axis.
  41. # Vertical movements are mapped to Y and RY.
  42. #
  43. # X and Y give absolute mouse movement, like an analog joystick. They are smart auto-centering when near the center.
  44. # The range of this self-centering (mostly for aim purpouse) is defined by a customizable radius.
  45. # They also has a small exponential curve, so near zaro they give a smooth movement. The farther, the coarser.
  46. #
  47. # RX and RY axis give relative mouse movement, not unlike a directional pad. It's perfect for flying FA-Off, or for
  48. # more precise situations: mining, landing, etc...
  49. #
  50. # Both movement can be easily tweaked in sensitivity.
  51.  
  52.  
  53.  
  54.  
  55. from System import Int16
  56.  
  57. if starting:
  58.     # Timer, for auto-centering
  59.     system.setThreadTiming(TimingTypes.HighresSystemTimer)
  60.     system.threadExecutionInterval = 1 # loop delay
  61.    
  62.     # Devices and axis initializing
  63.     max =  Int16.MaxValue*0.5+0.5   #  16384
  64.     min = -Int16.MaxValue*0.5-0.5   # -16384
  65.     mouseX    = 0
  66.     mouseY    = 0
  67.     mouseXcurved = 0
  68.     mouseYcurved = 0
  69.     mouseRX    = 0
  70.     mouseRY    = 0
  71.    
  72.     # Coordinates for self centering
  73.     a = 0
  74.     b = 0
  75.     c = 0
  76.     d = 0
  77.    
  78.    
  79. global absolute_sens, relative_sens, smart_speed, rel_speed, curve, pradius, nradius
  80.  
  81.  
  82. absolute_sens = 30            # absolute mouse mode sensitivity
  83. relative_sens = 30            # relative mouse mode sensitivity
  84. smart_speed = 25             # smart-centering speed, in absolute mouse mode
  85. rel_factor = 200            # hard-centering factor, in relative mouse mode
  86.  
  87.  
  88. curve = 3                 # exponential factor for the axis curve
  89.  
  90.  
  91. pradius = 50                      # smart self-centering radius, for absolute mouse
  92. nradius = pradius - (pradius *2)    #
  93.  
  94.  
  95. #
  96. ###
  97. ##### Mouse
  98.  
  99.  
  100. # axis definition
  101. mouseX += mouse.deltaX * absolute_sens      # absolute mouse, lateral
  102. mouseY += mouse.deltaY * absolute_sens      #                 vertical
  103. mouseRX += mouse.deltaX * relative_sens     # relative mouse, lateral
  104. mouseRY += mouse.deltaY * relative_sens     #                 vertical
  105.  
  106.  
  107. # define a range and limit the axis values
  108. if (mouseX > max):
  109.   mouseX = max
  110. elif (mouseX < min):
  111.   mouseX = min
  112.  
  113.  
  114. if (mouseY > max):
  115.   mouseY = max
  116. elif (mouseY < min):
  117.   mouseY = min
  118.  
  119.  
  120. if (mouseRX > max):
  121.   mouseRX = max
  122. elif (mouseRX < min):
  123.   mouseRX = min
  124.  
  125.  
  126. if (mouseRY > max):
  127.   mouseRY = max
  128. elif (mouseRY < min):
  129.   mouseRY = min
  130.  
  131.  
  132. #
  133. ##
  134. ### Absolute Mouse
  135.  
  136.  
  137. # smart centering
  138. if (mouseX < pradius) and (mouseX > 0):
  139.     mouseX = mouseX - smart_speed
  140. elif (mouseX > nradius) and (mouseX < 0):
  141.     mouseX = mouseX + smart_speed
  142.  
  143.  
  144. if (mouseY < pradius) and (mouseY > 0):
  145.     mouseY = mouseY - smart_speed
  146. elif (mouseY > nradius) and (mouseY < 0):
  147.     mouseY = mouseY + smart_speed
  148.  
  149.  
  150. # lightly exponential curved axis
  151. if (mouseX > 0):
  152.     mouseXcurved = math.floor((math.sqrt(( mouseX ** curve )) /2 ) / 64)
  153. if (mouseX < 0):
  154.     mouseXn = mouseX * -1
  155.     mouseXcurved = math.floor((math.sqrt(( mouseXn ** curve )) / 2 ) * -1 / 64)
  156.  
  157.  
  158. if (mouseY > 0):
  159.     mouseYcurved = math.floor((math.sqrt(( mouseY ** curve )) /2 ) / 64)
  160. if (mouseY < 0):
  161.     mouseYn = mouseY * -1
  162.     mouseYcurved = math.floor((math.sqrt(( mouseYn ** curve )) / 2 ) * -1 / 64)
  163.  
  164.  
  165. # Hard Mouse Centering (By press an hotkey)
  166. # Useful when you need your mouse to return to the center, like when you switch workspaces or exiting galaxy map...
  167. if keyboard.getKeyDown(Key.LeftControl) or keyboard.getKeyDown(Key.Backspace):
  168.     mouseX = 0
  169.     mouseY = 0
  170.     mouseXcurved = 0
  171.     mouseYcurved = 0
  172.  
  173.  
  174.  
  175. # Mouse Output - Absolute Movement
  176. vJoy[0].x = filters.deadband(mouseXcurved, 10)
  177. vJoy[0].y = filters.deadband(mouseYcurved, 10)
  178.  
  179.  
  180. #
  181. ##
  182. ### Relative Mouse
  183.  
  184.  
  185. # Self Centering Alternate Axis
  186.  
  187. if mouseRX != 0:
  188.     mouseRX -= (mouseRX / rel_factor)
  189. if mouseRY != 0:
  190.     mouseRY -= (mouseRY / rel_factor)
  191.    
  192.  
  193.  
  194. # Mouse Output - Relative Movement
  195. vJoy[0].rx = filters.deadband(mouseRX, 50)
  196. vJoy[0].ry = filters.deadband(mouseRY, 50)
  197.  
  198.  
  199. #####
  200. ###
  201. #
  202.  
  203.  
  204.  
  205.  
  206. #
  207. ###
  208. ##### Diagnostics
  209.  
  210.  
  211. # Mouse
  212. diagnostics.watch(vJoy[0].x)
  213. diagnostics.watch(vJoy[0].y)
  214. diagnostics.watch(vJoy[0].rx)
  215. diagnostics.watch(vJoy[0].ry)
  216.  
  217. diagnostics.watch(mouse.deltaX)
  218. diagnostics.watch(mouse.deltaY)
  219.  
Advertisement
Add Comment
Please, Sign In to add comment