Fix last commit

master
Raphaël Vinot 2015-03-17 00:00:47 +01:00
parent e0cbe48414
commit f1b708db97
3 changed files with 43 additions and 36 deletions

View File

@ -60,16 +60,15 @@
#include "OctoWS2811.h" #include "OctoWS2811.h"
int height; int height = 0;
int width; int width = 0;
int ledsPerStrip; int ledsPerStrip = 0;
int count = 0; int count = 0;
DMAMEM int* displayMemory = 0; DMAMEM int* displayMemory;
int* drawingMemory = 0; int* drawingMemory;
elapsedMicros elapsedUsecSinceLastFrameSync = 0; elapsedMicros elapsedUsecSinceLastFrameSync = 0;
const int config = WS2811_800kHz; // color config is on the PC side const int config = WS2811_800kHz; // color config is on the PC side
OctoWS2811 leds; OctoWS2811 leds;
@ -77,16 +76,16 @@ OctoWS2811 leds;
void setup() { void setup() {
pinMode(13, OUTPUT); pinMode(13, OUTPUT);
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
Serial.setTimeout(50000); Serial.setTimeout(5000);
// delay(1000); //delay(1000);
Serial.readBytes((char *)&height, 4); Serial.readBytes((char *)&height, sizeof(height));
Serial.write(height); Serial.write((char *)&height, sizeof(height));
Serial.readBytes((char *)&width, 4); Serial.readBytes((char *)&width, sizeof(width));
Serial.write(width); Serial.write((char *)&width, sizeof(width));
digitalWrite(13, LOW); digitalWrite(13, LOW);
pinMode(12, INPUT_PULLUP); // Frame Sync //pinMode(12, INPUT_PULLUP); // Frame Sync
Serial.setTimeout(50); Serial.setTimeout(50);
ledsPerStrip = width * height / 8; ledsPerStrip = width * height;
displayMemory = new int[ledsPerStrip*6]; displayMemory = new int[ledsPerStrip*6];
drawingMemory = new int[ledsPerStrip*6]; drawingMemory = new int[ledsPerStrip*6];
leds.attach(ledsPerStrip, displayMemory, drawingMemory, config); leds.attach(ledsPerStrip, displayMemory, drawingMemory, config);
@ -97,26 +96,29 @@ void setup() {
void loop() { void loop() {
int startChar = Serial.read(); int startChar = Serial.read();
if (startChar == 42) { if (startChar == '*') {
unsigned int startAt = micros(); unsigned int startAt = micros();
unsigned int usecUntilFrameSync = 0; unsigned int usecUntilFrameSync = 0;
count = Serial.readBytes((char *)drawingMemory, sizeof(drawingMemory)); count = Serial.readBytes((char *)drawingMemory, sizeof(int) * ledsPerStrip*6);
if (count >= sizeof(drawingMemory)) { Serial.write((char *)drawingMemory, sizeof(int) * ledsPerStrip*6);
if (count >= sizeof(int) * ledsPerStrip*6) {
unsigned int endAt = micros(); unsigned int endAt = micros();
unsigned int usToWaitBeforeSyncOutput = 100; unsigned int usToWaitBeforeSyncOutput = 100;
if (endAt - startAt < usecUntilFrameSync) { if (endAt - startAt < usecUntilFrameSync) {
usToWaitBeforeSyncOutput = usecUntilFrameSync - (endAt - startAt); usToWaitBeforeSyncOutput = usecUntilFrameSync - (endAt - startAt);
} }
digitalWrite(12, HIGH); //digitalWrite(12, HIGH);
pinMode(12, OUTPUT); //pinMode(12, OUTPUT);
delayMicroseconds(usToWaitBeforeSyncOutput); delayMicroseconds(usToWaitBeforeSyncOutput);
digitalWrite(12, LOW); //digitalWrite(12, LOW);
// WS2811 update begins immediately after falling edge of frame sync // WS2811 update begins immediately after falling edge of frame sync
digitalWrite(13, HIGH); digitalWrite(13, HIGH);
leds.show(); leds.show();
digitalWrite(13, LOW); digitalWrite(13, LOW);
} }
} else if (startChar >= 0) { } else if (startChar >= 0) {
//Serial.write(startChar);
//Serial.flush()
//digitalWrite(13, HIGH); //digitalWrite(13, HIGH);
//delay(100); //delay(100);
//digitalWrite(13, LOW); //digitalWrite(13, LOW);

View File

@ -5,22 +5,25 @@ import time
from serial import Serial, SerialException from serial import Serial, SerialException
import sys import sys
height = 5 height = 50
width = 8 width = 20
def send(r, s): def send(r, s):
if not r.exists('new'): print(r.llen('new'))
return None
data = r.rpop('new') data = r.rpop('new')
if data is not None and len(data) > 0: if data is not None and len(data) > 0:
s.write(data.encode()) a = bytes([ord('*')]) + bytearray(data)
#la = len(a)
s.write(a)
#time.sleep(.05)
#data = s.read(la)
#print(data)
# size = s.write(data) # size = s.write(data)
# print('Data sent ({} bytes)'.format(size)) # print('Data sent ({} bytes)'.format(size))
def serialConfigure(port_name, baudrate=9600): def serialConfigure(port_name, baudrate=38400):
''' '''
We use a very low baudrate by default because the USB port on the teensy We use a very low baudrate by default because the USB port on the teensy
enforce this value: http://www.pjrc.com/teensy/td_serial.html enforce this value: http://www.pjrc.com/teensy/td_serial.html
@ -35,20 +38,23 @@ def serialConfigure(port_name, baudrate=9600):
sys.stderr.write("Could not open serial port %s: %s\n" % (ser.portstr, e)) sys.stderr.write("Could not open serial port %s: %s\n" % (ser.portstr, e))
return return
print(height, width)
ser.write(height.to_bytes(4, byteorder='little')) ser.write(height.to_bytes(4, byteorder='little'))
print(int.from_bytes(ser.read(4), byteorder='little')) data = ser.read(4)
print(data, int.from_bytes(data, byteorder='little'))
ser.write(width.to_bytes(4, byteorder='little')) ser.write(width.to_bytes(4, byteorder='little'))
print(int.from_bytes(ser.read(4), byteorder='little')) data = ser.read(4)
print(data, int.from_bytes(data, byteorder='little'))
ser.timeout = 1 ser.timeout = 1
return ser return ser
if __name__ == "__main__": if __name__ == "__main__":
r = redis.Redis() r = redis.Redis()
r.hset('config', 'imgsize', height * width * 24 + 1) r.hset('config', 'imgsize', height * width * 24)
s = serialConfigure('/dev/ttyACM0') s = serialConfigure('/dev/ttyACM0')
while True: while True:
while r.llen('new') > 0: while r.llen('new') > 0:
send(r, s) send(r, s)
time.sleep(10) time.sleep(1)

View File

@ -23,7 +23,7 @@ def TCPConfigure(server, port):
ledTCP = Client(this, server, port) ledTCP = Client(this, server, port)
def image2data(data): def image2data(data):
offset = 1 offset = 0
pixel_nb = 0 pixel_nb = 0
for x in range(0, height): for x in range(0, height):
pixel_line = pixels[pixel_nb:pixel_nb+width] pixel_line = pixels[pixel_nb:pixel_nb+width]
@ -58,18 +58,17 @@ def colorWiring(c):
def send_TCP(): def send_TCP():
image2data(data) image2data(data)
println(data) #println(data)
ledTCP.write(data) ledTCP.write(data)
def prepare_data(): def prepare_data():
global data global data
data = jarray.zeros(dimension * 24 + 1 , "b") data = jarray.zeros(dimension * 24, "b")
data[0] = ord('*')
def setup(): def setup():
global gammatable global gammatable
global dimension global dimension
size(5, 8) size(50, 30)
dimension = width * height dimension = width * height
frameRate(framerate) frameRate(framerate)
TCPConfigure("127.0.0.1", 9999) TCPConfigure("127.0.0.1", 9999)