Skip to content

Commit

Permalink
Initial code: Reads EEPROM, displays test image.
Browse files Browse the repository at this point in the history
  • Loading branch information
lonetech committed Dec 29, 2018
0 parents commit b0841ab
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 0 deletions.
62 changes: 62 additions & 0 deletions lgdisplaytest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
#! /usr/bin/env python3

# Run with DISPLAY=:0.1 to place on screen 1
# (you can check with xdpyinfo that your LG is that screen)
# DISPLAY=:0.1 xrandr --listmonitors --verbose
# That shows the EDID, which should include the name.
# Mine is named: Toshiba LKG01Do12HjQE
# LKG01 is likely identifying Looking Glass.

import json
import pygame
from math import *

lgeeprom = json.load(open("lookingglasseeprom.json"))
def v(n):
return lgeeprom[n]['value']

# Panel resolution
size = (int(v('screenW')), int(v('screenH')))
# Physical image width
screenInches = size[0]/v('DPI')
pitch = v('pitch') * screenInches * cos(atan(1.0/v('slope')))
tilt = size[1]/(size[0]*v('slope'))
subp = 1.0 / (3*size[0])
center = v('center')

# Note: The tilt applies to the lenses, so
# the transition from one view to the next is not a
# vertical line!

pygame.init()

screen = pygame.display.set_mode(size, pygame.FULLSCREEN)
pygame.mouse.set_visible(False)
surface = pygame.display.get_surface()

surface.fill(pygame.Color('red'))

def frac(n):
return n - floor(n)

# Next task: Calculate per-pixel colours.
for y in range(size[1]):
# Flip because Pygame has Y going down, GL has Y going up
ty = 1-float(y)/size[1]
for x in range(size[0]):
rgb=[x%256,y%256,0]
tx = float(x)/size[0]
for i in range(3):
a = (tx + i*subp + ty*tilt) * pitch - center
# Sample view: white if viewed from right,
# black if viewed from left,
# disturbing if viewed head on
rgb[i] = 255 if frac(a)<0.5 else 0
surface.set_at((x,y), pygame.Color(*rgb))
pygame.display.update()

while True:
e = pygame.event.wait()
if e.type in (pygame.QUIT, pygame.KEYDOWN):
break

45 changes: 45 additions & 0 deletions lgeeprom.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from pprint import pprint
import json
import struct

import hid

def rp(dev, addr=0, size=64):
send = bytearray(struct.pack('>BBH64x', 0, 0, addr))
#print repr(send)
#print len(send)
dev.send_feature_report(send)
r = bytearray(dev.read(64, 1000))
r += bytearray(dev.read(3+1, 1000))
#print "read: ", len(r), r
assert r[:4] == send[:4]
return r[4:4+size]

def loadconfig(dev):
jsonlen=struct.unpack('>I',rp(dev, 0, 4))[0] + 4
assert jsonlen != 0xffffffff
#print jsonlen
json=bytearray()
while len(json)<jsonlen:
page=len(json)//64
l=min(64,jsonlen-64*page)
json[64*page:] = rp(dev, page, l)
#print json
return json[4:]

def read_eeprom(devinfo):
dev = hid.device()
dev.open_path(devinfo['path'])
dev.set_nonblocking(1)
#r=True
#while r:
# r = bytearray(dev.read(64+3+1, 1000))
# #print r
cfg = json.loads(loadconfig(dev).decode('ascii'))
pprint(cfg)
return cfg

for dev in hid.enumerate(vendor_id=0x04d8, product_id=0xef7e):
if dev['product_string'] == u'HoloPlay':
read_eeprom(dev)

0 comments on commit b0841ab

Please sign in to comment.