Created
February 3, 2013 07:03
-
-
Save tony56a/4700805 to your computer and use it in GitHub Desktop.
Quick and Dirty Testing thingy for a custom USB Display thing using PyUSB
Display accepts a full display of 320*240*2 bytes in a 16 bit RGB format sequence. Test script pulls an image from lorempixel.com and sends it to the screen. Uses bitmap bit conversion functions from Logitech-G19-Linux-Daemon by MultiCoreNop
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from PIL import Image | |
import urllib | |
import usb.core, usb.util | |
dev = usb.core.find(idVendor = 0x1cbe, idProduct=0x0003) | |
def download_image(): | |
urllib.urlretrieve ("http://lorempixel.com/640/480/", "image.jpg") | |
def rgb_to_uint16(r,g,b): | |
rbit = r*2**5/255 | |
gbit = g*2**6/255 | |
bbit = b*2**5/255 | |
rbit = rbit if rbit <= 0b00011111 else 0b00011111 | |
gbit = gbit if gbit <= 0b00111111 else 0b00111111 | |
bbit = bbit if bbit <= 0b00011111 else 0b00011111 | |
valueH = (rbit << 3) | (gbit >> 3) | |
valueL = (gbit << 5) | bbit | |
return valueL << 8 | valueH | |
def init_usb(): | |
dev.set_configuration() | |
def convert_image(): | |
img = Image.open('image.jpg') | |
access = img.load() | |
if img.size != (320, 240): | |
img = img.resize((320, 240), Image.CUBIC) | |
access = img.load() | |
data = [] | |
for x in range(320): | |
for y in range(240): | |
r,g,b = access[319-x,y] | |
val = rgb_to_uint16(r,g,b) | |
data.append((val >> 8) & 0xff) | |
data.append((val & 0xff)) | |
data.reverse() | |
dev.write(1,data,0) | |
def main(): | |
init_usb() | |
download_image() | |
convert_image() | |
if __name__ == '__main__': | |
main() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment