Skip to content

Instantly share code, notes, and snippets.

@candera
Created August 17, 2015 01:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save candera/b93ae437cd7203f39c92 to your computer and use it in GitHub Desktop.
Save candera/b93ae437cd7203f39c92 to your computer and use it in GitHub Desktop.
import time
class Utils:
@staticmethod
def mapmouse(val):
if abs(val) <= 13:
return val * 128
elif abs(val) <= 25:
return val * 256
else:
return val * 512
if starting:
x = 0
y = 0
timeout = 0.1 # seconds
lastNonZeroX = time.clock()
lastNonZeroY = time.clock()
# Use the mouse to control the radar cursor
deltaX = mouse.deltaX
deltaY = mouse.deltaY
now = time.clock()
if (deltaX != 0) or (lastNonZeroX < (now - timeout)):
x = deltaX
if (deltaX != 0):
lastNonZeroX = now
if (deltaY != 0) or (lastNonZeroY < (now - timeout)):
y = deltaY
if (deltaY != 0):
lastNonZeroY = now
#diagnostics.debug(Utils.mapmouse(x))
#diagnostics.debug(Utils.mapmouse(y))
vJoy[0].x = Utils.mapmouse(x)
vJoy[0].y = Utils.mapmouse(y)
# Second throttle hat
#vJoy[0].setButton(0, joystick[5].getDown(28))
#vJoy[0].setButton(1, joystick[5].getDown(29))
#vJoy[0].setButton(2, joystick[5].getDown(30))
#vJoy[0].setButton(3, joystick[5].getDown(31))
# Speedbrake switch
vJoy[0].setButton(4, joystick[5].getDown(39))
vJoy[0].setButton(5, joystick[5].getDown(40))
# Console safe switch
vJoy[0].setButton(6, joystick[5].getDown(45))
# Console T switches
vJoy[0].setButton(7, joystick[5].getDown(41))
vJoy[0].setButton(8, joystick[5].getDown(42))
vJoy[0].setButton(9, joystick[5].getDown(43))
vJoy[0].setButton(10, joystick[5].getDown(44))
# Cursor enable
vJoy[0].setButton(11, joystick[5].getDown(36))
# Third throttle hat
vJoy[0].setButton(12, joystick[5].getDown(32))
vJoy[0].setButton(13, joystick[5].getDown(33))
vJoy[0].setButton(14, joystick[5].getDown(34))
vJoy[0].setButton(15, joystick[5].getDown(35))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment