def __init__ (self, win, PlayViewObj=None, device='RUMBLEPAD'): self.joystick = vizjoy.add() self.view = win.getView() self.window = win self.toolActive = 0 self.moveCursor = False self.filter = LowPassDynamicFilter(0.5, 5, 10.0, 200.0) self.player = PlayViewObj #Call super class constructor to create different callbacks for every joystick viz.EventClass.__init__(self) self.callback(vizjoy.BUTTONDOWN_EVENT, self.joydown) self.callback(vizjoy.BUTTONUP_EVENT, self.joyup) self.callback(vizjoy.HAT_EVENT, self.joyhat) #decide the button actions based on the joystick self._updateFunc = vizact.onupdate(0, self.UpdateJoystick) if 'Rumblepad' in self.joystick.getName(): self.device = 'RUMBLEPAD' self.actions = {'prev':[1,5], 'next':[3,6], 'pick':[2, 7, 8, 11, 12], 'drop':4, 'hud':9} elif 'XBOX' in self.joystick.getName().upper(): self.device = 'XBOX' self.actions = {'prev':[3], 'next':[2], 'pick':[1, 9, 10, 5, 6], 'drop':4, 'hud':7} self.triggerActive = True #False after trigger buttons are pressed #Create a callback to handle the expiring trigger (de)activation events self.callback(viz.TIMER_EVENT, self.timerExpire) else: self.device = 'XBOX' vizinput.message('Joystick not detected! Xbox will be used instead with limited functionality.')
def onExit(): global gLogSaved if studyMode and trial: #log data only for main trial try: gLogSaved except NameError: print "SAVING data on exit!" SaveLoggedData() vizinput.message('Thank you for playing the Olive Oil Game!!!')
import time import struct import viz, vizinput, vizact import os viz.go() vrpn = viz.add('vrpn7.dle') #Check the name of your PPT machine and change the name in the line below if necessary tracker = vrpn.addTracker('PPT0@WORLDVIZ-PC',0) print(tracker.getVerbose); if tracker.valid(): vizinput.message('Connection established to PPT marker 1') else: vizinput.message('Failed to detect PPT marker 1') print("about to start while loop") filePath = os.path.join(os.getcwd(), 'coordinates.txt') def io(): try: f = open(filePath, 'wb') f.seek(0) f.truncate() position = tracker.getPosition()
def onInit(): if studyMode and trial: #ensure user position is logged vizinput.message('User location is not logged!')