Skip to content

Commit fdf627c

Browse files
author
nils.meier@gmail.com
committed
add left handed mouse for in-falcon control, rework module syn/exit
git-svn-id: https://fscode.googlecode.com/svn/trunk@447 400e30b4-3047-0410-9b5d-373f348d38bd
1 parent 99c10bf commit fdf627c

7 files changed

Lines changed: 41 additions & 20 deletions

File tree

modules/falcon.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,6 @@ class FLIGHTDATA(ctypes.Structure):
101101
_pFlightData2 = None
102102
_pOSBData = None
103103

104-
def sync():
105-
pass
106-
107104
def getFlightData():
108105

109106
global _pFlightData

modules/keyboard.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,6 @@ def isDown(c):
227227
def isToggled(c):
228228
return bool(ctypes.windll.user32.GetKeyState(c) & 0x0001)
229229

230-
def sync():
231-
pass
232230

233231

234232

modules/log.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,3 @@ def log(level, *args):
1919
frm = frm.f_back
2020
logging.getLogger(name).log(level, *args)
2121

22-
def sync():
23-
pass

modules/mouse.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,26 @@ def lowLevelMouseProc(self, nCode, wParam, lParam):
6363
_hWheel = _Atomic(0)
6464
_wheel = _Atomic(0)
6565
_hook = _Hook()
66+
_mouseSwapped = False
6667

68+
''' returns current vertical mouse wheel position '''
6769
def getWheel():
6870
return _wheel.set(0)
6971

72+
''' returns current horizontal mouse wheel position '''
7073
def getHWheel():
7174
return _hWheel.set(0)
7275

73-
def swapMouseButtons(leftIsRight):
74-
return ctypes.windll.user32.SwapMouseButton(leftIsRight)
76+
''' swaps left and right mouse button for one cycle '''
77+
def swapMouseButtons():
78+
global _mouseSwapped
79+
_mouseSwapped = True
7580

7681
def sync():
77-
pass
82+
global _mouseSwapped
83+
ctypes.windll.user32.SwapMouseButton(_mouseSwapped)
84+
_mouseSwapped = False
85+
86+
def exit():
87+
ctypes.windll.user32.SwapMouseButton(False)
88+

modules/state.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ def _init():
8484
__dict = dict()
8585
__holds = dict()
8686

87-
def sync():
88-
pass
89-
9087
_init()
9188

9289

scripts/myfalcon.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
# Map Push Button into Button (Missile Uncage)
1515
# Map Rotation into Axis (Missile Acquisition Sound Level)
1616
#
17-
import joysticks, phidgets, state, log, keyboard, falcon, time
17+
import joysticks, phidgets, state, log, keyboard, falcon, time, mouse
1818

1919
# Throttle Quadrant
2020
CURSOR_WE_AXIS_OUT = 0
@@ -45,7 +45,6 @@
4545
OVERRIDE_DOG_BUTTON_OUT = 7
4646
OVERRIDE_HOLD_SECONDS = 0.1
4747

48-
4948
# sticks
5049
vjoy = joysticks.get('vJoy Device')
5150
combatstick = joysticks.get("CH Combatstick USB")
@@ -85,6 +84,9 @@
8584
flightData = falcon.getFlightData()
8685
if flightData.gearPos and flightData.vt>0: # might be taxiing w/brakes
8786
zoom = state.get("zoom")
87+
88+
# if we're in Falcon we assume left handed mouse
89+
mouse.swapMouseButtons()
8890
except:
8991
pass
9092

simscript.py

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,21 @@ def actions():
215215
for handle in filter(lambda n: n.endswith('.py'), os.listdir("scripts")):
216216
actions.append( (handle, None, script and os.path.basename(script.file)==handle, lambda f=handle: switch(f)) )
217217
return actions
218+
219+
def sync(mod):
220+
try:
221+
method = mod.sync
222+
except AttributeError:
223+
return
224+
method()
225+
226+
def exit(mod):
227+
try:
228+
method = mod.exit
229+
except AttributeError:
230+
return
231+
method()
232+
218233

219234
tray = windows.TrayIcon("SimScript", os.path.abspath('simscript.ico'), actions) if windows else None
220235

@@ -225,30 +240,33 @@ def actions():
225240
try:
226241

227242
# take time
228-
sync = (time.clock()+(1.0/hertz))
243+
next = (time.clock()+(1.0/hertz))
229244

230245
# pump our threads messages
231246
if windows: windows.pumpMessages(False)
232247

233248
# sync modules
234-
for mod in modules: mod.sync()
249+
for mod in modules:
250+
sync(mod)
235251

236252
# run script
237253
if script: script.run()
238254

239-
# sync time
240-
wait = sync-time.clock()
255+
# check time
256+
wait = next-time.clock()
241257
if wait>=0 :
242258
time.sleep(wait)
243259
else:
244-
log.info("%s executions took longer than sync frequency (%dms>%dms)" % ( script, (1.0/hertz-wait)*1000, 1.0/hertz*1000))
260+
log.info("%s executions took longer than next frequency (%dms>%dms)" % ( script, (1.0/hertz-wait)*1000, 1.0/hertz*1000))
245261

246262
except KeyboardInterrupt:
247263
log.info("Interrupted")
248264
active = False
249265

250266
# Cleanup
251267
log.info("Exiting")
268+
for mod in modules:
269+
exit(mod)
252270
tray.close()
253271
logfile.hide()
254272

0 commit comments

Comments
 (0)