Fix last commit
parent
e0cbe48414
commit
f1b708db97
|
@ -60,16 +60,15 @@
|
|||
|
||||
#include "OctoWS2811.h"
|
||||
|
||||
int height;
|
||||
int width;
|
||||
int ledsPerStrip;
|
||||
int height = 0;
|
||||
int width = 0;
|
||||
int ledsPerStrip = 0;
|
||||
|
||||
int count = 0;
|
||||
DMAMEM int* displayMemory = 0;
|
||||
int* drawingMemory = 0;
|
||||
DMAMEM int* displayMemory;
|
||||
int* drawingMemory;
|
||||
elapsedMicros elapsedUsecSinceLastFrameSync = 0;
|
||||
|
||||
|
||||
const int config = WS2811_800kHz; // color config is on the PC side
|
||||
|
||||
OctoWS2811 leds;
|
||||
|
@ -77,16 +76,16 @@ OctoWS2811 leds;
|
|||
void setup() {
|
||||
pinMode(13, OUTPUT);
|
||||
digitalWrite(13, HIGH);
|
||||
Serial.setTimeout(50000);
|
||||
// delay(1000);
|
||||
Serial.readBytes((char *)&height, 4);
|
||||
Serial.write(height);
|
||||
Serial.readBytes((char *)&width, 4);
|
||||
Serial.write(width);
|
||||
Serial.setTimeout(5000);
|
||||
//delay(1000);
|
||||
Serial.readBytes((char *)&height, sizeof(height));
|
||||
Serial.write((char *)&height, sizeof(height));
|
||||
Serial.readBytes((char *)&width, sizeof(width));
|
||||
Serial.write((char *)&width, sizeof(width));
|
||||
digitalWrite(13, LOW);
|
||||
pinMode(12, INPUT_PULLUP); // Frame Sync
|
||||
//pinMode(12, INPUT_PULLUP); // Frame Sync
|
||||
Serial.setTimeout(50);
|
||||
ledsPerStrip = width * height / 8;
|
||||
ledsPerStrip = width * height;
|
||||
displayMemory = new int[ledsPerStrip*6];
|
||||
drawingMemory = new int[ledsPerStrip*6];
|
||||
leds.attach(ledsPerStrip, displayMemory, drawingMemory, config);
|
||||
|
@ -97,26 +96,29 @@ void setup() {
|
|||
void loop() {
|
||||
int startChar = Serial.read();
|
||||
|
||||
if (startChar == 42) {
|
||||
if (startChar == '*') {
|
||||
unsigned int startAt = micros();
|
||||
unsigned int usecUntilFrameSync = 0;
|
||||
count = Serial.readBytes((char *)drawingMemory, sizeof(drawingMemory));
|
||||
if (count >= sizeof(drawingMemory)) {
|
||||
count = Serial.readBytes((char *)drawingMemory, sizeof(int) * ledsPerStrip*6);
|
||||
Serial.write((char *)drawingMemory, sizeof(int) * ledsPerStrip*6);
|
||||
if (count >= sizeof(int) * ledsPerStrip*6) {
|
||||
unsigned int endAt = micros();
|
||||
unsigned int usToWaitBeforeSyncOutput = 100;
|
||||
if (endAt - startAt < usecUntilFrameSync) {
|
||||
usToWaitBeforeSyncOutput = usecUntilFrameSync - (endAt - startAt);
|
||||
}
|
||||
digitalWrite(12, HIGH);
|
||||
pinMode(12, OUTPUT);
|
||||
//digitalWrite(12, HIGH);
|
||||
//pinMode(12, OUTPUT);
|
||||
delayMicroseconds(usToWaitBeforeSyncOutput);
|
||||
digitalWrite(12, LOW);
|
||||
//digitalWrite(12, LOW);
|
||||
// WS2811 update begins immediately after falling edge of frame sync
|
||||
digitalWrite(13, HIGH);
|
||||
leds.show();
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
} else if (startChar >= 0) {
|
||||
//Serial.write(startChar);
|
||||
//Serial.flush()
|
||||
//digitalWrite(13, HIGH);
|
||||
//delay(100);
|
||||
//digitalWrite(13, LOW);
|
||||
|
|
|
@ -5,22 +5,25 @@ import time
|
|||
from serial import Serial, SerialException
|
||||
import sys
|
||||
|
||||
height = 5
|
||||
width = 8
|
||||
height = 50
|
||||
width = 20
|
||||
|
||||
|
||||
def send(r, s):
|
||||
if not r.exists('new'):
|
||||
return None
|
||||
|
||||
print(r.llen('new'))
|
||||
data = r.rpop('new')
|
||||
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)
|
||||
# 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
|
||||
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))
|
||||
return
|
||||
|
||||
print(height, width)
|
||||
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'))
|
||||
print(int.from_bytes(ser.read(4), byteorder='little'))
|
||||
data = ser.read(4)
|
||||
print(data, int.from_bytes(data, byteorder='little'))
|
||||
|
||||
ser.timeout = 1
|
||||
return ser
|
||||
|
||||
if __name__ == "__main__":
|
||||
r = redis.Redis()
|
||||
r.hset('config', 'imgsize', height * width * 24 + 1)
|
||||
r.hset('config', 'imgsize', height * width * 24)
|
||||
s = serialConfigure('/dev/ttyACM0')
|
||||
while True:
|
||||
while r.llen('new') > 0:
|
||||
send(r, s)
|
||||
time.sleep(10)
|
||||
time.sleep(1)
|
||||
|
|
|
@ -23,7 +23,7 @@ def TCPConfigure(server, port):
|
|||
ledTCP = Client(this, server, port)
|
||||
|
||||
def image2data(data):
|
||||
offset = 1
|
||||
offset = 0
|
||||
pixel_nb = 0
|
||||
for x in range(0, height):
|
||||
pixel_line = pixels[pixel_nb:pixel_nb+width]
|
||||
|
@ -58,18 +58,17 @@ def colorWiring(c):
|
|||
|
||||
def send_TCP():
|
||||
image2data(data)
|
||||
println(data)
|
||||
#println(data)
|
||||
ledTCP.write(data)
|
||||
|
||||
def prepare_data():
|
||||
global data
|
||||
data = jarray.zeros(dimension * 24 + 1 , "b")
|
||||
data[0] = ord('*')
|
||||
data = jarray.zeros(dimension * 24, "b")
|
||||
|
||||
def setup():
|
||||
global gammatable
|
||||
global dimension
|
||||
size(5, 8)
|
||||
size(50, 30)
|
||||
dimension = width * height
|
||||
frameRate(framerate)
|
||||
TCPConfigure("127.0.0.1", 9999)
|
||||
|
|
Loading…
Reference in New Issue