Skip to content
Browse files

moved hue update to use only 1.5 bytes per light. no speed improvemen…

…t\! need to remove ACK...
  • Loading branch information...
1 parent 271978c commit 9e5aec277920a4693a55ddd4b3e447a853c0d76a @sbma44 committed
Showing with 32 additions and 8 deletions.
  1. +15 −0 benchmark.py
  2. +6 −4 color_effects_lights.pde
  3. +11 −4 gecoloreffects.py
View
15 benchmark.py
@@ -0,0 +1,15 @@
+import gecoloreffects, time
+
+BENCHMARK_SIZE = 250
+
+if __name__ == '__main__':
+ con = gecoloreffects.Controller()
+
+ start_time = time.time()
+ for i in range(0, BENCHMARK_SIZE):
+ for j in range(0, len(con.lights)):
+ con.lights[j] = (i%2)==0 and gecoloreffects.Light.XMAS_COLOR_YELLOW() or gecoloreffects.Light.XMAS_COLOR_GREEN()
+ con.update_hue()
+ end_time = time.time()
+
+ print "Hue update: %0.2f FPS" % (BENCHMARK_SIZE / (end_time - start_time))
View
10 color_effects_lights.pde
@@ -170,16 +170,18 @@ void loop()
Serial.println('#');
}
else if(command=='H') {
- // wait until there's 100 bytes of hue data -- 2 bytes per light
- while(Serial.available()<(XMAS_LIGHT_COUNT*2)) {
+ // wait until there's 75 bytes of hue data -- 12 bits per light
+ while(Serial.available()<(XMAS_LIGHT_COUNT*1.5)) {
delayMicroseconds(5);
}
// read the hue data and assign it
- for(int i=0;i<XMAS_LIGHT_COUNT;i++) {
+ for(int i=0;i<(XMAS_LIGHT_COUNT/2);i++) {
byte b1 = Serial.read();
byte b2 = Serial.read();
- light_hue_array[i] = xmas_color((0xF & (b1>>4)), (b1 & 0xF), (0xF & b2));
+ byte b3 = Serial.read();
+ light_hue_array[i*2] = xmas_color((b1>>4), (b1 & 0xF), (b2>>4));
+ light_hue_array[(i*2)+1] = xmas_color((0xF & b2), (b3>>4), (0xF & b3));
}
changed = true;
Serial.println('#');
View
15 gecoloreffects.py
@@ -60,6 +60,7 @@ def get_intensity(self):
self.safe()
return 0xFF & self.intensity
+ # deprecated
def get_color(self):
self.safe()
return ( (0xFF & ((self.r << 4) | self.g)), (0xFF & self.b) )
@@ -92,10 +93,16 @@ def update_intensity(self):
def update_hue(self):
self.ser.write('H')
- for l in self.lights:
- color_bytes = l.get_color()
- self.ser.write(chr(color_bytes[0]))
- self.ser.write(chr(color_bytes[1]))
+ for i in range(0, len(self.lights)/2):
+ light_a = self.lights[i*2]
+ light_b = self.lights[(i*2)+1]
+
+ light_a.safe()
+ light_b.safe()
+
+ self.ser.write(chr((light_a.r<<4) | light_a.g))
+ self.ser.write(chr((light_a.b<<4) | light_b.r))
+ self.ser.write(chr((light_b.g<<4) | light_b.b))
# wait for ack
self.ser.readline()

0 comments on commit 9e5aec2

Please sign in to comment.
Something went wrong with that request. Please try again.