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 GizmoDeviceStrings import *
00035
00036
00037
00038
00039
00040 class DeviceType:
00041 """
00042 Types of visualizations
00043 """
00044
00045 Keyboard = "Keyboard"
00046 Mouse = "Mouse"
00047 Powermate = "Powermate"
00048 ATIX10 = "ATIX10"
00049 LIRC = "LIRC"
00050 Standard = "Standard"
00051
00052
00053
00054
00055
00056 class GizmoRegistrar:
00057 """
00058 This class is responsible for any book keeping that needs to occur
00059 after a new device has been registered with the system, and when a
00060 device is being disconnected.
00061
00062 This is where individual devices are chosen based on their device name,
00063 product code, vendor ID, etc.
00064
00065 So for example, a device with "Keyboard" in the name is registered
00066 as a Keyboard with Gizmo Daemon.
00067 """
00068
00069
00070
00071
00072
00073 def handleDeviceAddition(self):
00074 """
00075 Add the appropriate device to our internal list of devices
00076 base on the actual type of the device.
00077 """
00078
00079 if self.DeviceType == DeviceType.Keyboard:
00080 Gizmod.printNiceScriptRegister(0, "Keyboard", self.Device.DeviceName, self.Device.FileName, hex((self.Device.DeviceIDVendor)), hex((self.Device.DeviceIDProduct)))
00081 Gizmod.Keyboards.append(self.Device)
00082 elif self.DeviceType == DeviceType.Mouse:
00083 Gizmod.printNiceScriptRegister(0, "Mouse", self.Device.DeviceName, self.Device.FileName, hex((self.Device.DeviceIDVendor)), hex((self.Device.DeviceIDProduct)))
00084 Gizmod.Mice.append(self.Device)
00085 elif self.DeviceType == DeviceType.Powermate:
00086 Gizmod.printNiceScriptRegister(0, "Powermate", self.Device.DeviceName, self.Device.FileName, hex((self.Device.DeviceIDVendor)), hex((self.Device.DeviceIDProduct)))
00087 Gizmod.Powermates.append(self.Device)
00088 self.Device.setRotateSensitivity(POWERMATE_ROTATE_SENSITIVITY)
00089 elif self.DeviceType == DeviceType.ATIX10:
00090 Gizmod.printNiceScriptRegister(0, "ATI X10", self.Device.DeviceName, self.Device.FileName, hex((self.Device.DeviceIDVendor)), hex((self.Device.DeviceIDProduct)))
00091 Gizmod.ATIX10Remotes.append(self.Device)
00092
00093 self.Device.grabExclusiveAccess(True)
00094 elif self.DeviceType == DeviceType.LIRC:
00095 Gizmod.printNiceScriptRegister(0, "LIRC", self.Device.DeviceName, self.Device.FileName, hex((self.Device.DeviceIDVendor)), hex((self.Device.DeviceIDProduct)))
00096 else:
00097 Gizmod.printNiceScriptRegister(0, "Standard", self.Device.DeviceName, self.Device.FileName, hex((self.Device.DeviceIDVendor)), hex((self.Device.DeviceIDProduct)))
00098
00099 def handleDeviceRemoval(self):
00100 """
00101 Remove the appropriate device from our internal list of devices
00102 """
00103
00104 if self.DeviceType == DeviceType.Keyboard:
00105 for item in Gizmod.Keyboards:
00106 if item.FileName == self.Device.FileName:
00107 Gizmod.Keyboards.remove(item)
00108 print "Removed Keyboard Device: " + self.Device.DeviceName + " [" + self.Device.FileName + "]"
00109 elif self.DeviceType == DeviceType.Mouse:
00110 for item in Gizmod.Mice:
00111 if item.FileName == self.Device.FileName:
00112 Gizmod.Mice.remove(item)
00113 print "Removed Mouse Device: " + self.Device.DeviceName + " [" + self.Device.FileName + "]"
00114 elif self.DeviceType == DeviceType.Powermate:
00115 for item in Gizmod.Powermates:
00116 if item.FileName == self.Device.FileName:
00117 Gizmod.Powermates.remove(item)
00118 print "Removed Powermate Device: " + self.Device.DeviceName + " [" + self.Device.FileName + "]"
00119 elif self.DeviceType == DeviceType.ATIX10:
00120
00121 self.Device.grabExclusiveAccess(False)
00122 for item in Gizmod.ATIX10Remotes:
00123 if item.FileName == self.Device.FileName:
00124 Gizmod.ATIX10Remotes.remove(item)
00125 print "Removed ATI X10 Device: " + self.Device.DeviceName + " [" + self.Device.FileName + "]"
00126 elif self.DeviceType == DeviceType.LIRC:
00127 print "Removed LIRC Device: " + self.Device.DeviceName + " [" + self.Device.FileName + "]"
00128 else:
00129 print "Removed Device: " + self.Device.DeviceName + " [" + self.Device.FileName + "]"
00130
00131
00132
00133
00134
00135 def __init__(self, Device):
00136 """
00137 Default Constructor
00138 """
00139
00140 self.Device = Device
00141 self.DeviceType = "Unknown"
00142 self.__setDeviceType()
00143
00144 def __checkDeviceType(self, DeviceTypes):
00145 """ check a device type """
00146
00147 Result = False
00148 for i in DeviceTypes:
00149
00150 NegativeMatch = False
00151 if i[0] == "!":
00152 NegativeMatch = True
00153 i = i[1 : len(i)]
00154 if self.Device.DeviceName.lower().find(i.lower()) > -1:
00155 if NegativeMatch:
00156 return False
00157 else:
00158 Result = True
00159
00160 elif self.Device.FileName.lower().find(i.lower()) > -1:
00161 Result = True
00162 else:
00163
00164 cPos = i.find(":")
00165 if cPos > -1:
00166 Vendor = i[0 : cPos]
00167 Product = i[cPos + 1 : len(i)]
00168 if Vendor == str(hex(self.Device.DeviceIDVendor)) and Product == str(hex(self.Device.DeviceIDProduct)):
00169 Result = True
00170 return Result
00171
00172 def __setDeviceType(self):
00173 """
00174 Set the device type
00175 """
00176
00177 if self.__checkDeviceType(KEYBOARD_GIZMOS):
00178 self.DeviceType = DeviceType.Keyboard
00179 elif self.__checkDeviceType(MOUSE_GIZMOS):
00180 self.DeviceType = DeviceType.Mouse
00181 elif self.__checkDeviceType(POWERMATE_GIZMOS):
00182 self.DeviceType = DeviceType.Powermate
00183 elif self.__checkDeviceType(ATIX10_GIZMOS):
00184 self.DeviceType = DeviceType.ATIX10
00185 elif self.__checkDeviceType(LIRC_GIZMOS):
00186 self.DeviceType = DeviceType.LIRC
00187 else:
00188 self.DeviceType = DeviceType.Standard
00189
00190
00191
00192
00193
00194 for Mixer in DEFAULT_MIXERS:
00195 Gizmod.registerDefaultMixerPriority(Mixer)