Guest User

GlovePIE script with MIDI ABS for AC and other racing sims

a guest
Nov 20th, 2014
352
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.82 KB | None | 0 0
  1. // Binds
  2. var.throttle = keyboard.A
  3. var.brake = keyboard.Z
  4. var.clutch = keyboard.X
  5. var.handbrake = keyboard.R
  6. var.steering = mouse.x
  7. var.shiftup = mouse.LeftButton
  8. var.shiftdown = mouse.RightButton
  9.  
  10. // Sensitivities
  11. var.throttleincreaserate = 0.1
  12. var.throttledecreaserate = 0.1
  13. var.brakeincreaserate = 0.05
  14. var.brakedecreaserate = 0.05
  15. var.clutchincreaserate = 0.4
  16. var.clutchdecreaserate = 0.2
  17. var.handbrakeincreaserate = 0.4
  18. var.handbrakedecreaserate = 0.4
  19. var.throttleblip = 0.4
  20. var.brakeratemax = 1
  21. var.braketrail = 0.2
  22. var.braketraillow = 0.4
  23. var.braketrailrate = -0.002
  24. var.throttletrailmax = -1
  25. var.throttlecut = -0.8
  26.  
  27. // Script
  28.  
  29. // Throttle
  30. if var.throttle > 0 && ppjoy.Analog0 < 1 && var.brake == 0 then
  31. ppjoy.Analog0 += var.throttleincreaserate
  32. var.throttletrail = 0
  33. endif
  34. if var.throttle == 0 && ppjoy.Analog0 > -1 && var.throttletrail == 0 then ppjoy.Analog0 -= var.throttledecreaserate
  35.  
  36. // Brake
  37.  
  38. // *** This section is a special case that is only applicable to Assetto Corsa *** //
  39. // The on/off status of C5 (can be any MIDI signal) is read to produce a simple form
  40. // of ABS. When C5 is on, wheels are locking so we reduce braking force, and vice versa.
  41. // The on/off state of C5 is set by a Python script running as an AC client app, and
  42. // uses the Python API's tyre slip values to detect wheel locking. Modification necessary
  43. // if using real MIDI devices or multiple virtual ones. I use loopMIDI.
  44. // Comment this section out if not using, and there are problems related to it
  45. // (i.e., I don't know whether it *needs* to be commented out.
  46. midi.DeviceOut = 2 // device number to use
  47. midi.DeviceIn = 0
  48. midi.DefaultChannel = 1
  49.  
  50. if var.brake && midi.c5 then
  51. var.cadence = ppjoy.Analog1
  52. ppjoy.Analog1 -= var.brakedecreaserate/4
  53. if var.tempBrake > var.braketraillow then var.tempBrake -= 0.005
  54. endif
  55.  
  56. if var.brake && var.cadence > -1 && not midi.c5 then ppjoy.Analog1 += var.brakeincreaserate/10
  57. // *** END MIDI SECTION *** //
  58.  
  59. if var.brake && var.cadence == -1 then ppjoy.Analog1 += var.brakeincreaserate
  60. if ppjoy.Analog1 > var.tempBrake then ppjoy.Analog1 = var.tempBrake
  61.  
  62. if var.brake == 0 then
  63. var.tempBrake = var.brakeratemax
  64. if var.cadence != -1 then var.cadence = -1
  65. if ppjoy.Analog1 > -1 then ppjoy.Analog1 -= var.brakedecreaserate
  66. if ppjoy.Analog0 == -1 then var.throttletrail = 0
  67. endif
  68.  
  69. if var.brake && var.throttletrail == 0 then
  70. ppjoy.Analog0 = var.throttletrailmax
  71. var.throttletrail = 1
  72. endif
  73.  
  74. if var.throttletrail then ppjoy.Analog0 -= var.throttledecreaserate/10
  75. if var.brake && ppjoy.Analog1 < var.braketraillow then ppjoy.Analog1 = var.braketraillow
  76.  
  77. // Clutch
  78. if var.clutch > 0 && ppjoy.Analog2 < 1 then ppjoy.Analog2 += var.clutchincreaserate
  79. if var.clutch == 0 && ppjoy.Analog2 > -1 then ppjoy.Analog2 -= var.clutchdecreaserate
  80.  
  81. // Handbrake
  82. if var.handbrake > 0 && ppjoy.Analog3 < 1 then ppjoy.Analog3 += var.handbrakeincreaserate
  83. if var.handbrake == 0 && ppjoy.Analog3 > -1 then ppjoy.Analog3 -= var.handbrakedecreaserate
  84.  
  85. // Shift up & throttle cut
  86. ppjoy.Digital0 = var.shiftup
  87. if var.throttlecut != 0 && var.shiftup > 0 then ppjoy.analog0 = var.throttlecut
  88.  
  89. // Shift down
  90. ppjoy.Digital1 = var.shiftdown
  91.  
  92. // Blip
  93. if var.throttleblip != -1 && var.shiftdown then
  94. ppjoy.Analog0 = var.blipthreshold
  95. var.throttletrail = 0
  96. endif
  97.  
  98. // Steering
  99. var.foo = (mouse.x - 0.5) * 4
  100. var.foo = (var.foo * var.foo) / 20
  101. if mouse.x < 0.5 then var.foo = -var.foo
  102.  
  103. // Additional steering lock adjustment. 1 to 1 means that maximum lock is achieved
  104. // at the edge of the screen, 0 is middle.
  105. //var.foo = MapRange(var.foo, -0.20, 0.20, -0.7, 0.7)
  106. var.foo = MapRange(var.foo, -0.20, 0.20, -0.8, 0.8)
  107. //var.foo = MapRange(var.foo, -0.20, 0.20, -0.9, 0.9)
  108. //var.foo = MapRange(var.foo, -0.20, 0.20, -1, 1)
  109.  
  110. ppjoy.analog4 = var.foo
  111. debug = ppjoy.Analog4
Advertisement
Add Comment
Please, Sign In to add comment