Exemple #1
0
 def do_GET(self):
     
     action = self.path.strip("/")
     
     if DEBUG:
         print("Path: %s" % action)
     
     commands = action.split("/")
     
     try:
     
         if commands[0] == "default.css":
             self.serveFile("Ressources/default.css")
             
         elif commands[0] == "apple-touch-icon.png":
             self.serveFile("Ressources/apple-touch-icon.png")
 
         elif commands[0] == "one_color" or commands[0] == "xcolors":
             
             lights = []
             
             if commands[0] == "xcolors":
                 
                 for i in range(len(lightchain)):
                     lights.append(lightchain[i])
                     
             else:
                 
                 cluster = FnordCluster()
                 
                 for i in range(len(lightchain)):
                     cluster.registerLight(lightchain[i])
                     
                 lights.append(cluster)
                 
             fader = FnordFaderArray(lights, commands[1])
                 
             # Launch thread
             worker.setPayload(fader)
             worker.go()
             
             # Display UI
             self.sendHTMLUI("Fader changed to %s" % commands[1])
         
         elif commands[0] == "speed":
             
             try:
                 speed = int(commands[1])
             except:
                 speed = 100
             
             if speed < 25:
                 speed = 25
             elif speed > 400:
                 speed = 400
                 
             speed = 100.0 / speed
             
             # Part 1: Change speed
             worker.setSpeed(speed)
             
             # Part 2: Display UI
             self.sendHTMLUI("Speed changed to %s" % (1 / speed))
         
         elif commands[0] == "highlight":
             
             if commands[1] == "fireworks":
                 
                 controller = FireWorks(lightchain)
                 worker.setPayload(controller)
                 worker.go()
 
             elif commands[1] == "x-mas":
                 
                 controller = XMas(lightchain)
                 worker.setPayload(controller)
                 worker.go()
                 
             elif commands[1] == "raindrops":
                 
                 mode = int(commands[2])
                 
                 controller = Raindrops(lightchain, mode)
                 worker.setPayload(controller)
                 worker.go()
             
             
             self.sendHTMLUI("Switched to %s" % commands[1])
             
         else:
             
             self.sendHTMLUI()
             
             
     except IndexError:
         
         self.sendHTMLUI("Error: Invalid parameters")
Exemple #2
0
    def run(self):
        
        self.enable()
        
        while self.running:        
            
            if self.mode == 1:
                
                nr_of_lights = random.randint(1, 3)
                
                lights = []
                
                # Select the lights, but not the same light twice
                for i in range(nr_of_lights):
                    
                    needNewLight = True
                    
                    while needNewLight:
                        
                        light = self.lights[self.selectOrigin()]
                        
                        try:
                            lights.index(light)
                            #Bad, the list contains the light
                            needNewLight = True
                        except:
                            # Good, the light is not alreay in the list
                            
                            needNewLight = False
                            
                    lights.append(light)  
                        
                
                for light in lights:
                    
                    # Turn on light
                    r, g, b = self.helper.getRandomColor()
                    r, g, b = self.helper.getMaxBright(r, g, b)
                    
                    light.fade_rgb(r, g, b, 50, 0)
                    
                sleep(0.05)
                #self.wait(0.05)
                
                for light in lights:
                    # Fade the light totally
                    light.fade_rgb(0, 0, 0, 2, 0)
                    
                #sleep(0.5)
                self.wait(0.125)
                
            elif self.mode == 2:

                mylights = []
                
                cluster1 = FnordCluster()
                cluster1.registerLight(self.lights[3])
                cluster1.registerLight(self.lights[5])
                
                cluster2 = FnordCluster()
                cluster2.registerLight(self.lights[2])
                cluster2.registerLight(self.lights[6])
                
                cluster3 = FnordCluster()
                cluster3.registerLight(self.lights[1])
                cluster3.registerLight(self.lights[7])
                
                cluster4 = FnordCluster()
                cluster4.registerLight(self.lights[0])
                cluster4.registerLight(self.lights[8])
                
                mylights.append(self.lights[4])
                mylights.append(cluster1)
                mylights.append(cluster2)
                mylights.append(cluster3)
                mylights.append(cluster4)
                 
                
                for light in mylights:
                    
                    if not self.running:
                        break
                
                    # Turn on light
                    r, g, b = self.helper.getRandomColor()
                    r, g, b = self.helper.getMaxBright(r, g, b)
                    
                    light.fade_rgb(r, g, b, 50, 0)
                    
                    sleep(0.05)
                    #self.wait(0.05)
                    
                    # Fade the light totally
                    light.fade_rgb(0, 0, 0, 2, 1)
                    
                    #sleep(0.5)
                    self.wait(0.75, False)
Exemple #3
0
# Setup for the new year

# Layout:
#
#0 1 2 3 4 ---------- 0 1 2 3 4
#=========            =========
#  Bus 1                Bus 2

bus1 = FnordBus("/dev/ttyUSB0")
bus2 = FnordBus("/dev/ttyUSB1")

for i in range(4):
    lightchain.append(bus1.getFnordLight(i))
    
cluster = FnordCluster()

cluster.registerLight(bus1.getFnordLight(4))
cluster.registerLight(bus2.getFnordLight(0))

lightchain.append(cluster)

for i in range(4):
    lightchain.append(bus2.getFnordLight(i + 1))


helper = FnordHelper()
worker = WorkerThread()

worker.daemon = 1
worker.start()