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 PowermateVisualizer(VisualizerDefault):
00046 """
00047 Powermate Visualization Handler
00048 """
00049
00050
00051
00052
00053
00054 def applyVisualizationCPUUsage(self, Event):
00055 """
00056 Set the Powermates' LEDs to the current system CPU Usage
00057 """
00058
00059 Count = 0
00060 for Powermate in Gizmod.Powermates:
00061 if Count >= Event.NumCPUs:
00062 Count = 0
00063 else:
00064 Count += 1
00065 Powermate.LEDPercent = Event.getCPUUsageAvg(Count)
00066
00067 def applyVisualizationVolume(self):
00068 """
00069 Set the Powermates' LEDs to the Default playback volume mixer's level
00070 """
00071
00072
00073 if not Gizmod.DefaultMixerVolume or not Gizmod.DefaultMixerSwitch:
00074 return
00075
00076
00077 if Gizmod.DefaultMixerSwitch.SwitchPlayback:
00078
00079 for Powermate in Gizmod.Powermates:
00080 Powermate.LEDPercent = Gizmod.DefaultMixerVolume.VolumePlaybackPercent
00081 else:
00082
00083 for Powermate in Gizmod.Powermates:
00084 Powermate.pulseLED(255, 257, 2)
00085
00086 def applyVisualizationSound(self, Event):
00087 """
00088 Set the Powermates' LEDs to the sound level
00089 """
00090
00091 if len(Gizmod.Powermates) == 1:
00092 Gizmod.Powermates[0].LEDPercent = Event.VUCombined * 100.0
00093 else:
00094 Gizmod.Powermates[0].LEDPercent = Event.VULeft * 100.0
00095 Gizmod.Powermates[1].LEDPercent = Event.VURight * 100.0
00096
00097
00098
00099
00100
00101 def __init__(self):
00102 """
00103 Default Constructor
00104 """
00105
00106
00107 VisualizerDefault.__init__(self)
00108
00109
00110 Gizmod.printNiceScriptInit(1, self.__class__.__name__, self.__class__.__doc__, str(len(Gizmod.Powermates)) + " Powermates")
00111
00112
00113
00114
00115
00116
00117 if ENABLED:
00118 if not Gizmod.checkVersion(VERSION_NEEDED, False):
00119 Gizmod.printNiceScriptInit(1, " * PowermateVisualizer", "NOT LOADED", "Version Needed: " + str(VERSION_NEEDED))
00120 else:
00121 Gizmod.Dispatcher.userScripts.append(PowermateVisualizer())