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 from VisualizerDefault import *
00036 import sys
00037
00038 ENABLED = True
00039 VERSION_NEEDED = 3.1
00040
00041
00042
00043
00044
00045 class KeyboardVisualizer(VisualizerDefault):
00046 """
00047 Keyboard Visualization Handler
00048 """
00049
00050
00051
00052
00053
00054 def applyVisualizationCPUUsage(self, Event):
00055 """
00056 Set the Keyboards' LEDs to the current system CPU Usage
00057 """
00058
00059 self.__setLEDsPercent(Event.getCPUUsageAvg(0))
00060
00061 def applyVisualizationVolume(self):
00062 """
00063 Set the Keyboards' LEDs to the Default playback volume mixer's level
00064 """
00065
00066
00067 if not Gizmod.DefaultMixerVolume:
00068 return
00069
00070
00071 if Gizmod.DefaultMixerSwitch.SwitchPlayback:
00072
00073 self.__setLEDsPercent(Gizmod.DefaultMixerVolume.VolumePlaybackPercent)
00074 else:
00075
00076 self.__setLEDsPercent(0)
00077
00078 def applyVisualizationSound(self, Event):
00079 """
00080 Set the Keyboards' LEDs to the sound level
00081 """
00082
00083 self.__setLEDsPercent(Event.VUCombined * 100.0)
00084
00085
00086
00087
00088
00089 def __setLEDsPercent(self, Percent):
00090 """
00091 Set the keyboard LEDs to a percentage
00092 """
00093
00094 CurVal = 0
00095 for i in range(len(KEYBOARD_LEDS)):
00096 if Percent >= CurVal and Percent >= 7.5:
00097 if self.LEDs[i] != 1:
00098 Gizmod.Keyboards[0].createEventRaw(GizmoEventType.EV_LED, KEYBOARD_LEDS[i], 1)
00099 self.LEDs[i] = 1
00100 else:
00101 if self.LEDs[i] != 0:
00102 Gizmod.Keyboards[0].createEventRaw(GizmoEventType.EV_LED, KEYBOARD_LEDS[i], 0)
00103 self.LEDs[i] = 0
00104 CurVal += self.RangePerLED
00105
00106 def __init__(self):
00107 """
00108 Default Constructor
00109 """
00110
00111
00112 VisualizerDefault.__init__(self)
00113
00114
00115 Gizmod.printNiceScriptInit(1, self.__class__.__name__, self.__class__.__doc__, str(len(Gizmod.Keyboards)) + " Keyboards")
00116
00117
00118 self.RangePerLED = 100.0 / float(len(KEYBOARD_LEDS))
00119
00120
00121 self.LEDs = []
00122 for i in range(len(KEYBOARD_LEDS)):
00123 self.LEDs.append(0)
00124 Gizmod.Keyboards[0].createEventRaw(GizmoEventType.EV_LED, i, 0)
00125
00126
00127
00128
00129
00130
00131 if ENABLED and Gizmod.UseKeyboardLEDs:
00132 if not Gizmod.checkVersion(VERSION_NEEDED, False):
00133 Gizmod.printNiceScriptInit(1, " * KeyboardVisualizer", "NOT LOADED", "Version Needed: " + str(VERSION_NEEDED))
00134 else:
00135 Gizmod.Dispatcher.userScripts.append(KeyboardVisualizer())