From a821b22cad5649d88622ccb8eabf1400396e7bb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Vinot?= Date: Tue, 3 Mar 2015 01:12:31 +0100 Subject: [PATCH] add python example. Partially working. --- .../processing/pic2serialpy/pic2serialpy.pyde | 95 ++++++++++++++++++ .../processing/pic2serialpy/sketch.properties | 2 + v2/backend/processing/pic2serialpy/test1.png | Bin 0 -> 170 bytes 3 files changed, 97 insertions(+) create mode 100644 v2/backend/processing/pic2serialpy/pic2serialpy.pyde create mode 100644 v2/backend/processing/pic2serialpy/sketch.properties create mode 100644 v2/backend/processing/pic2serialpy/test1.png diff --git a/v2/backend/processing/pic2serialpy/pic2serialpy.pyde b/v2/backend/processing/pic2serialpy/pic2serialpy.pyde new file mode 100644 index 0000000..5186e31 --- /dev/null +++ b/v2/backend/processing/pic2serialpy/pic2serialpy.pyde @@ -0,0 +1,95 @@ +add_library('serial') +import math +import struct +import jarray + +gamma = 1.7 + +framerate = 0.0 +brightness = 4 +errorCount = 0 +gammatable = [0 for i in range(0, 256)] +s = None +img = None +ledSerial = None + +def setup(): + global img + global gammatable + listserials = Serial.list() + delay(20) + #print("Serial Ports List:") + #print(listserials) + serialConfigure("/dev/ttyACM0") + if (errorCount > 0): + exit() + gammatable = [math.pow(i / 255.0, gamma) * 255.0 + 0.5 for i in range(0, 256)] + + size(40, 1) + img = loadImage("test1.png") + +def image2data(data): + offset = 0 + for x in range(0, img.width): + pixel = [colorWiring(img.pixels[x]) for i in range(0, 8)] + imgmask = 0x800000 + while imgmask != 0: + b = 0 + for i in range(0, 8): + if ((pixel[i] & imgmask) != 0): + b |= (1 << i) + if b == 255: + b = -1 + data[offset] = b + offset += 1 + imgmask >>= 1 + +def colorWiring(c): + red = (c & 0xFF0000) >> 16 + green = (c & 0x00FF00) >> 8 + blue = (c & 0x0000FF) + red = gammatable[red] + green = gammatable[green] + blue = gammatable[blue] + red = int(red * brightness) >> 8 + green = int(green * brightness) >> 8 + blue = int(blue * brightness) >> 8 + return (green << 16) | (red << 8) | (blue) + +def serialConfigure(portName): + global ledSerial + try: + ledSerial = Serial(this, portName) + if ledSerial is None: + raise NullPointerException() + ledSerial.write('?') + except Exception as e: + println("Serial port " + portName + " does not exist or is non-functional") + errorCount += 1 + return + delay(50); + line_serial = ledSerial.readStringUntil(10) + if (line is None): + println("Serial port " + portName + " is not responding.") + println("Is it really a Teensy 3.0 running VideoDisplay?") + errorCount += 1 + return + + param = line_serial.split(",") + if (len(param) != 12): + println("Error: port " + portName + " did not respond to LED config query") + errorCount += 1 + return + +def draw(): + global img + image(img, 0, 0) + data = jarray.zeros(img.width * 24 + 3, "b") + image2data(data) + data[0] = ord('*') + framerate = 30.0 + usec = int((1000000.0 / framerate) * 0.75) + data[1] = usec /2000 + data[2] = usec >> 8 + ledSerial.write(data) + diff --git a/v2/backend/processing/pic2serialpy/sketch.properties b/v2/backend/processing/pic2serialpy/sketch.properties new file mode 100644 index 0000000..8175853 --- /dev/null +++ b/v2/backend/processing/pic2serialpy/sketch.properties @@ -0,0 +1,2 @@ +mode.id=jycessing.mode.PythonMode +mode=Python diff --git a/v2/backend/processing/pic2serialpy/test1.png b/v2/backend/processing/pic2serialpy/test1.png new file mode 100644 index 0000000000000000000000000000000000000000..022374119ccc7d828901b7feb1e425e255f56de2 GIT binary patch literal 170 zcmeAS@N?(olHy`uVBq!ia0vp^B0$W@!2~1&KS&kFdgVpP5lqUG7!;caToW64!_l=ltB<)VvY~=c3falGGH1 z^30M91$R&1fbd2>aiAh0PZ!4!j_b*Pq|crD^4**{l7V608s^aBTc14x$})Jm`njxg HN@xNAL-H>b literal 0 HcmV?d00001