Skip to content
Browse files

Make udp listener fast, still need to fix data formatter.

  • Loading branch information...
1 parent 2539c81 commit 5af7e8ab02e236ac67198c7adf379f88f5809962 @cibomahto cibomahto committed May 18, 2012
Showing with 45 additions and 11 deletions.
  1. +7 −3 README.md
  2. +22 −6 host/LedStrips.py
  3. +16 −2 host/domelistener.py
  4. 0 host/{host_test.py → test_LedStrips.py}
View
10 README.md
@@ -1,18 +1,22 @@
domeFirmware
============
-LED driver for the dome project. Each board can control 8 LED strips, each of which is
+LED driver for the dome project. Each board can control 8 LED strips, each of which is up to 5m long.
## host
A python server that listens on UDP for a serialized 24bit RGB stream (8 bits per channel) that describes a 24 wide by 160 high image from top left to bottom right. (Yo dawg your aspect ratio is wrong). The data is then output to a Teensy over a high-speed serial port.
Usage:
- cd host
- python host.py -p /dev/tty.usb*
+```python
+ python domelistener.py
+```
## board
PCB design for the breakout board
## firmware
Firmware that should be compiled using the Makefile, then uploaded to the teensy using the teensy utility.
+
+## mounting hardware
+3d models for whatever mounts.
View
28 host/LedStrips.py
@@ -1,11 +1,13 @@
import serial
import time
-import struct
-import binascii
import optparse
-import random
class LedStrips:
+
+ frame_count = 0
+ format_time_total = 0
+
+
def __init__(self, image_width, offset):
"""
Initialize an med strip
@@ -34,7 +36,7 @@ def RgbRowToStrips(self, data):
# Green byte
output += '\xFF'
for bit_index in range(7, 0, -1):
- c = 0x00
+ c = '\x00'
for pixel_index in range(0, 8):
c |= (ord(data[1+3*pixel_index]) >> bit_index & 1) << pixel_index
output += chr(c)
@@ -74,15 +76,29 @@ def load_data(self, data):
s = ''
+ format_time = 0
# for each 'row' in the data, assemble a byte stream for it.
for row in range(0,len(data)/3/self.image_width):
start_index = (self.image_width*row + self.offset)*3
+ format_start_time = time.time()
s += self.RgbRowToStrips(data[start_index:start_index+24])
+ format_time += time.time() - format_start_time
- for x in range(0, len(s)/64): # TODO: What this means?
+ # Send the data out in 64-byte chunks
+ output_start_time = time.time()
+ for x in range(0, len(s)/64):
t = s[64 * x : (64 * x) + 64]
-
self.ser.write(t)
+ output_time = time.time() - output_start_time
+
+ self.format_time_total += format_time
+ self.frame_count += 1
+
+ if self.frame_count > 30:
+ average_time = self.format_time_total/self.frame_count
+ self.frame_count = 0
+ self.format_time_total = 0
+ print average_time
def flip(self):
# TODO: Why does 20 work? it make a'no sense.
View
18 host/domelistener.py
@@ -71,6 +71,7 @@ def run(self):
frame_count = 0
while 1:
data, addr = sock.recvfrom(buffer_size)
+ update_start_time = time.time()
if not data:
print "no data."
@@ -86,20 +87,33 @@ def run(self):
continue
# print "Send draw"
+ send_draw_start_time = time.time()
# Clock out the previous frame
new_data_event.clear()
draw_event.set()
+ send_draw_time = time.time() - send_draw_start_time
# Load in the next frame
- for pos in range(0, image_width*image_height*3):
- image_data[pos] = data[pos+1]
+ load_frame_start_time = time.time()
+ image_data[:] = data[1:]
+# for pos in range(0, image_width*image_height*3):
+# image_data[pos] = data[pos+1]
+ load_frame_time = time.time() - load_frame_start_time
# print "Send data--"
+ send_data_start_time = time.time()
draw_event.clear()
new_data_event.set()
+ send_data_time = time.time() - send_data_start_time
frame_count = (frame_count + 1) % 30
if (frame_count == 0):
print "Frame rate: %3.1f"%(30/(time.time() - start_time))
start_time = time.time()
+# print 'update_time=%4.4f, send_draw=%4.4f, load_frame=%4.4f, send_data=%4.4f'%(
+# time.time() - update_start_time,
+# send_draw_time,
+# load_frame_time,
+# send_data_time
+# )
View
0 host/host_test.py → host/test_LedStrips.py
File renamed without changes.

0 comments on commit 5af7e8a

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