00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 """
00013
00014 Copyright (c) 2007, Gizmo Daemon Team
00015 Licensed under the Apache License, Version 2.0 (the "License");
00016 you may not use this file except in compliance with the License.
00017 You may obtain a copy of the License at
00018
00019 http://www.apache.org/licenses/LICENSE-2.0
00020
00021 Unless required by applicable law or agreed to in writing, software
00022 distributed under the License is distributed on an "AS IS" BASIS,
00023 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00024 See the License for the specific language governing permissions and
00025 limitations under the License.
00026
00027 """
00028
00029
00030
00031
00032
00033 from GizmoDaemon import *
00034 from GizmoScriptActiveApplication import *
00035
00036 ENABLED = True
00037 VERSION_NEEDED = 3.3
00038 INTERESTED_CLASSES = [GizmoEventClass.Standard]
00039 INTERESTED_PRODUCTS = [51715]
00040 INTERESTED_VENDORS = [1133]
00041
00042
00043
00044
00045
00046 class MomoRacing(GizmoScriptDefault):
00047 """
00048 Logitech Momo Racing Event Mapping
00049 """
00050
00051
00052
00053
00054
00055 def onDeviceEvent(self, Event, Gizmo = None):
00056 """
00057 Called from Base Class' onEvent method.
00058 See GizmodDispatcher.onEvent documention for an explanation of this function
00059 """
00060
00061
00062 if Gizmo.DeviceIDVendor in INTERESTED_VENDORS and Gizmo.DeviceIDProduct in INTERESTED_PRODUCTS:
00063
00064 if Event.Type == GizmoEventType.EV_ABS and Event.Code == 0x01:
00065 self.scrollSpeed = 0x7f - Event.Value
00066 self.setScrolling()
00067 return True
00068 return False
00069
00070 def setScrolling(self):
00071 """ Start / Stop scrolling """
00072
00073
00074 if self.scrollSpeed == 0:
00075 if self.scrollTimer:
00076 self.scrollTimer.cancel()
00077 self.scrollTimer = None
00078 return
00079
00080
00081 ss = abs(self.scrollSpeed)
00082 self.scrollTimeout = 250.0 / (ss * ss)
00083 if self.scrollSpeed < 0:
00084 self.scrollValue = -1
00085 else:
00086 self.scrollValue = 1
00087
00088 if not self.scrollTimer:
00089 self.scrollTimer = GizmodTimer(self.scrollTimeout, self.__timerCallback, -1, None)
00090 self.scrollTimer.start()
00091 else:
00092 self.scrollTimer.setTime(self.scrollTimeout)
00093
00094
00095
00096
00097
00098 def __doScroll(self):
00099 """ scroll via the mouse """
00100 Gizmod.Mice[0].createEventRaw(GizmoEventType.EV_REL, GizmoMouseAxis.WHEEL, -self.scrollValue)
00101
00102 def __init__(self):
00103 """
00104 Default Constructor
00105 """
00106
00107 GizmoScriptDefault.__init__(self, ENABLED, VERSION_NEEDED, INTERESTED_CLASSES)
00108 self.scrollSpeed = 0
00109 self.scrollTimer = None
00110
00111 def __timerCallback(self, UserData):
00112 """ Callback function for the timer """
00113
00114 if self.scrollSpeed == 0:
00115 return
00116
00117
00118 self.__doScroll()
00119 self.setScrolling()
00120
00121
00122
00123
00124
00125
00126 MomoRacing()