From cb69d2e1c7ced951cbf7a31ee286b0ed92cab8a8 Mon Sep 17 00:00:00 2001 From: rcoh Date: Fri, 18 Feb 2011 16:56:43 -0500 Subject: Adding Epydoc generated docs. --- html/SmootLight.util.PacketComposition-pysrc.html | 202 ++++++++++++++++++++++ 1 file changed, 202 insertions(+) create mode 100644 html/SmootLight.util.PacketComposition-pysrc.html (limited to 'html/SmootLight.util.PacketComposition-pysrc.html') diff --git a/html/SmootLight.util.PacketComposition-pysrc.html b/html/SmootLight.util.PacketComposition-pysrc.html new file mode 100644 index 0000000..31aec2c --- /dev/null +++ b/html/SmootLight.util.PacketComposition-pysrc.html @@ -0,0 +1,202 @@ + + + + + SmootLight.util.PacketComposition + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + Package SmootLight :: + Package util :: + Module PacketComposition + + + + + + +
[hide private]
[frames] | no frames]
+
+

Source Code for Module SmootLight.util.PacketComposition

+
+ 1  import struct 
+ 2  VERSION = 0x0001 
+ 3  MAGIC = 0x4adc0104 
+ 4  PORTOUT = 0x0108 
+ 5  UNI = 0 
+ 6  import pdb 
+ 7  import util.TimeOps as timeops 
+ 8  argDict = {'flags': 0, 'startcode': 0x0fff, 'pad':0} 
+
9 +10 -def composePixelStripData(pixelStrip,currentTime=timeops.time()): +
11 packet = bytearray() +12 for light in pixelStrip: +13 color = light.state(currentTime) +14 for channel in color: #skip the last value, its an +15 #alpha value +16 packet.append(struct.pack('B', channel)) +17 return packet +
18 # packet = [0]*len(pixelStrip.pixels)*3 #preallocate for speed +19 # for i in range(len(pixelStrip.pixels)): +20 #color = pixelStrip.pixels[i].state() +21 #packet[i:i+2] = color +22 # return bytearray(packet) +23 +24 cache = {} +
25 -def memoize(f): +
26 def helper(x): +27 if x not in cache: +28 cache[x] = f(x) +29 return cache[x] +
30 return helper +31 +
32 @memoize +33 -def cachePacketHeader(port): +
34 packet = bytearray() +35 subDict = dict(argDict) +36 subDict['len'] = 150 #I have no idea why this works. +37 subDict['port'] = port +38 packet.extend(portOutPacket(subDict)) +39 # packet.append(0x0) +40 return packet +
41 +
42 -def composePixelStripPacket(pixelStrip,port, currentTime): +
43 packet = bytearray(cachePacketHeader(port)) +44 data = composePixelStripData(pixelStrip, currentTime) +45 packet.extend(data) +46 return packet +
47 +
48 -def packheader(): +
49 header = bytearray() +50 header.extend(struct.pack('L', MAGIC)) +51 header.extend(struct.pack('H', VERSION)) +52 header.extend(struct.pack('H', PORTOUT)) +53 header.extend(struct.pack('L', 0)) +54 return header +
55 +
56 -def portOut(): +
57 header = packheader() +58 header.extend(struct.pack('L', UNI)) +59 return header +
60 +
61 -def portOutPayload(argDict): +
62 payload = bytearray() +63 payload.extend(struct.pack('B', argDict['port'])) +64 payload.extend(struct.pack('B',0)) +65 payload.extend(struct.pack('H', argDict['flags'])) +66 payload.extend(struct.pack('H', argDict['len'])) +67 payload.extend(struct.pack('H', argDict['startcode'])) +68 return payload +
70 header = bytearray() +71 header.extend(struct.pack('L', MAGIC)) +72 header.extend(struct.pack('H', VERSION)) +73 header.extend(struct.pack('H', 0x0109)) +74 header.extend(struct.pack('L', 0)) +75 header.extend(struct.pack('L', 0)) +76 return header +
77 +
78 -def portOutPacket(payloadArgs): +
79 packet = bytearray() +80 packet.extend(portOut()) +81 packet.extend(portOutPayload(payloadArgs)) +82 return packet +
83 +
+
+ + + + + + + + + + + + + + + + + + + + + + + +
+ + + + -- cgit v1.2.3