Skip to content

Commit 84b8c25

Browse files
MrServoHains
authored andcommitted
[LCD4linux] v5.0-r25 bugfix for Display AX206 (480x320)
- new display name '**AX206**' (former '**Pearl**' 480x320) - bugfixed code for **DPF-displays** (e.g. Pearl & AX206) HINT: **LCD4linux** is still working under Python2 and Python3
1 parent c51ef42 commit 84b8c25

4 files changed

Lines changed: 189 additions & 161 deletions

File tree

lcd4linux/src/Photoframe.py

Lines changed: 74 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55
from usb.util import get_string
66
from PIL import Image
77
from struct import pack
8-
from six.moves import cStringIO as StringIO
8+
from six import ensure_binary
9+
from six.moves import cStringIO
910

1011

1112
def write_jpg2frame(dev, pic):
12-
"""Attach header to picture, pad with zeros if necessary, and send to frame"""
13+
# Attach header to picture, pad with zeros if necessary, and send to frame
1314
# create header and stack before picture
1415
# middle 4 bytes have size of picture
1516
rawdata = b"\xa5\x5a\x18\x04" + pack('<I', len(pic) + 14) + b"\x48\x00\x00\x00" + pic
@@ -22,95 +23,96 @@ def write_jpg2frame(dev, pic):
2223

2324

2425
def get_known_devices():
25-
"""Return a dict of photo frames"""
26-
dList = []
26+
# Return a dict of photo frames
27+
dlist = []
2728
# listed as: Name, idVendor, idProduct, [width , height - in pixel if applicable]
28-
#
29+
2930
#0,1 Samsung SPF-75H/76H (23)
30-
dList.append({'name': "SPF75H/76H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200f, 'width': 800, 'height': 480})
31-
dList.append({'name': "SPF75H/76H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200e})
31+
dlist.append({'name': "SPF75H/76H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200f, 'width': 800, 'height': 480})
32+
dlist.append({'name': "SPF75H/76H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200e})
3233

3334
#2,3 Samsung SPF-87H (24)
34-
dList.append({'name': "SPF87H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2034, 'width': 800, 'height': 480})
35-
dList.append({'name': "SPF87H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2033})
35+
dlist.append({'name': "SPF87H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2034, 'width': 800, 'height': 480})
36+
dlist.append({'name': "SPF87H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2033})
3637

3738
#4,5 Samsung SPF-87Hold (25)
38-
dList.append({'name': "SPF87Hold Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2026, 'width': 800, 'height': 480})
39-
dList.append({'name': "SPF87Hold Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2025})
39+
dlist.append({'name': "SPF87Hold Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2026, 'width': 800, 'height': 480})
40+
dlist.append({'name': "SPF87Hold Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2025})
4041

4142
#6,7 Samsung SPF-83H (26)
42-
dList.append({'name': "SPF83H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200d, 'width': 800, 'height': 600})
43-
dList.append({'name': "SPF83H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200c})
43+
dlist.append({'name': "SPF83H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200d, 'width': 800, 'height': 600})
44+
dlist.append({'name': "SPF83H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200c})
4445

4546
#8,9 Samsung SPF-107H (27)
46-
dList.append({'name': "SPF107H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2036, 'width': 1024, 'height': 600})
47-
dList.append({'name': "SPF107H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2035})
47+
dlist.append({'name': "SPF107H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2036, 'width': 1024, 'height': 600})
48+
dlist.append({'name': "SPF107H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2035})
4849

4950
#10,11 Samsung SPF-105P (28)
50-
dList.append({'name': "SPF105P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x201b, 'width': 1024, 'height': 600})
51-
dList.append({'name': "SPF105P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x201c})
51+
dlist.append({'name': "SPF105P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x201b, 'width': 1024, 'height': 600})
52+
dlist.append({'name': "SPF105P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x201c})
5253

5354
#12,13 Samsung SPF-85H/86H (29)
54-
dList.append({'name': "SPF85H/86H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2013, 'width': 800, 'height': 600})
55-
dList.append({'name': "SPF85H/86H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2012})
55+
dlist.append({'name': "SPF85H/86H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2013, 'width': 800, 'height': 600})
56+
dlist.append({'name': "SPF85H/86H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2012})
5657

5758
#14,15 Samsung SPF-72H (210)
58-
dList.append({'name': "SPF72H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200b, 'width': 800, 'height': 480})
59-
dList.append({'name': "SPF72H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200a})
59+
dlist.append({'name': "SPF72H Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x200b, 'width': 800, 'height': 480})
60+
dlist.append({'name': "SPF72H Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x200a})
6061

6162
#16,17 Samsung SPF-700T (211)
62-
dList.append({'name': "SPF700T Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2050, 'width': 800, 'height': 600})
63-
dList.append({'name': "SPF700T Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x204f})
63+
dlist.append({'name': "SPF700T Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2050, 'width': 800, 'height': 600})
64+
dlist.append({'name': "SPF700T Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x204f})
6465

6566
#18,19 Samsung SPF-85P/86P (212)
66-
dList.append({'name': "SPF85P/86P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2017, 'width': 800, 'height': 600})
67-
dList.append({'name': "SPF85P/86P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2016})
67+
dlist.append({'name': "SPF85P/86P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2017, 'width': 800, 'height': 600})
68+
dlist.append({'name': "SPF85P/86P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2016})
6869

6970
#20,21 Samsung SPF-107Hold (213)
70-
dList.append({'name': "SPF107Hold Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2028, 'width': 1024, 'height': 600})
71-
dList.append({'name': "SPF107Hold Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2027})
71+
dlist.append({'name': "SPF107Hold Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2028, 'width': 1024, 'height': 600})
72+
dlist.append({'name': "SPF107Hold Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2027})
7273

7374
#22,23 Samsung SPF-1000P (214)
74-
dList.append({'name': "SPF1000P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2040, 'width': 1024, 'height': 600})
75-
dList.append({'name': "SPF1000P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2039})
75+
dlist.append({'name': "SPF1000P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2040, 'width': 1024, 'height': 600})
76+
dlist.append({'name': "SPF1000P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2039})
7677

7778
#24,25 Samsung SPF-800P (215)
78-
dList.append({'name': "SPF800P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2038, 'width': 800, 'height': 480})
79-
dList.append({'name': "SPF800P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2037})
79+
dlist.append({'name': "SPF800P Mini Monitor", 'idVendor': 0x04e8, 'idProduct': 0x2038, 'width': 800, 'height': 480})
80+
dlist.append({'name': "SPF800P Mass Storage", 'idVendor': 0x04e8, 'idProduct': 0x2037})
81+
82+
# Amazon Fire 7 (9th Generation 2019)
83+
dlist.append({'name': "Amazon Fire 7 Mini Monitor", 'idVendor': 0x1949, 'idProduct': 0x03C3, 'width': 1024, 'height': 600})
84+
dlist.append({'name': "Amazon Fire 7 Mass Storage", 'idVendor': 0x1949, 'idProduct': 0x03C1})
8085

8186
# Pearl DPF for Testing
82-
dList.append({'name': "Pearl DPF", 'idVendor': 0x1908, 'idProduct': 0x0102, 'width': 320, 'height': 240})
83-
dList.append({'name': "Pearl DPF", 'idVendor': 0x1908, 'idProduct': 0x0102, 'width': 320, 'height': 240})
87+
dlist.append({'name': "Pearl DPF", 'idVendor': 0x1908, 'idProduct': 0x0102, 'width': 320, 'height': 240})
88+
dlist.append({'name': "Pearl DPF", 'idVendor': 0x1908, 'idProduct': 0x0102, 'width': 320, 'height': 240})
8489

85-
return dList
90+
return dlist
8691

8792

88-
def find_device(Anzahl, device, device2):
89-
"""Try to find device on USB bus."""
93+
def find_device(anzahl, device, device2):
94+
# Try to find device on USB bus.
9095
try:
91-
print("[LCD4linux] looking for frame", Anzahl, device['name'], device['idVendor'], device['idProduct'], device2['idProduct'])
92-
if Anzahl == 2:
96+
print("[LCD4linux] looking for frame", anzahl, device['name'], device['idVendor'], device['idProduct'], device2['idProduct'])
97+
if anzahl == 2:
9398
d = list(find(idVendor=device['idVendor'], idProduct=device['idProduct'], find_all=True)) + list(find(idVendor=device2['idVendor'], idProduct=device2['idProduct'], find_all=True))
9499
if isinstance(d, list):
95-
if len(d) >= 2:
96-
d = d[1]
97-
else:
98-
d = None
100+
d = d[1] if len(d) >= 2 else None
99101
else:
100102
d = None
101103
else:
102104
d = list(list(find(idVendor=device['idVendor'], idProduct=device['idProduct'], find_all=True)) + list(find(idVendor=device2['idVendor'], idProduct=device2['idProduct'], find_all=True)))[0]
103-
except:
105+
except Exception:
104106
from traceback import format_exc
105107
print("[LCD4linux] find exception")
106108
print("Error: %s" % format_exc())
107109
d = None
108110
return d
109111

110112

111-
def init_device(Anzahl, device0, device1):
112-
"""First try Mini Monitor mode, then Mass storage mode"""
113-
dev = find_device(Anzahl, device0, device1)
113+
def init_device(anzahl, device0, device1):
114+
# First try Mini Monitor mode, then Mass storage mode
115+
dev = find_device(anzahl, device0, device1)
114116

115117
if dev is not None:
116118
## found it, trying to init it
@@ -124,7 +126,7 @@ def init_device(Anzahl, device0, device1):
124126
ts = time()
125127
while True:
126128
# may need to burn some time
127-
dev = find_device(Anzahl, device0, device1)
129+
dev = find_device(anzahl, device0, device1)
128130
if dev is not None and dev.idProduct == device0["idProduct"]:
129131
#switching successful
130132
break
@@ -140,55 +142,66 @@ def init_device(Anzahl, device0, device1):
140142

141143

142144
def frame_init(dev):
143-
"""Init device so it stays in Mini Monitor mode"""
145+
# Init device so it stays in Mini Monitor mode
144146
# this is the minimum required to keep the frame in Mini Monitor mode!!!
145-
# dev.ctrl_transfer(0xc0, 4 )
146-
# dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 )
147+
# dev.ctrl_transfer(0xc0, 4 )
148+
# dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x09, 0x04 )
147149
dev.ctrl_transfer(0xc0, 0x01, 0x00, 0x00, 0x02)
148150

149151

150152
def frame_switch(dev):
151-
"""Switch device from Mass Storage to Mini Monitor"""
153+
CTRL_TYPE_VENDOR = (2 << 5)
154+
CTRL_IN = 0x80
155+
CTRL_RECIPIENT_DEVICE = 0
152156
try:
153-
sleep(0.5)
157+
time.sleep(0.5)
158+
s = "\x00" * 251
154159
dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, 0xfe)
155-
except:
160+
# dev.ctrl_transfer(0x00|0x80, 0x06, 0xfe, 0xfe, s, 0xfe )
161+
# dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1)
162+
# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1)
163+
# expect(result, [ 0x03 ])
164+
# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x01, 0x00, 0x00, 2)
165+
# expect(result, [ 0x09, 0x04 ])
166+
# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x02, 0x00, 0x00, 1)
167+
# expect(result, [ 0x46 ])
168+
# settling of the bus and frame takes about 0.42 sec
169+
# give it some extra time, but then still make sure it has settled
170+
except Exception:
156171
print("[LCD4linux] switching ERROR")
172+
# from traceback import format_exc
173+
# print format_exc()
157174
finally:
158175
sleep(2)
159176

160177

161178
def name(dev):
162179
try:
163180
return get_string(dev, 1)
164-
except:
181+
except Exception:
165182
try:
166183
return get_string(dev, 256, 2)
167-
except:
184+
except Exception:
168185
return None
169186

170187

171188
def main():
172189
global dev, known_devices_list
173-
174190
known_devices_list = get_known_devices()
175-
176191
# define which frame to use, here use Samsung SPF-87H
177192
device0 = known_devices_list[0] # Mini Monitor mode
178193
device1 = known_devices_list[1] # Mass Storage mode
179-
180194
dev = init_device(1, device0, device1)
181195
print("Frame is in Mini Monitor mode and initialized. Sending pictures now")
182-
183196
image = Image.open("mypicture.jpg")
184197
#manipulations to consider:
185198
# convert
186199
# thumbnail
187200
# rotate
188201
# crop
189202
image = image.resize((800, 480))
190-
output = StringIO.StringIO()
191-
image.save(output, "JPEG", quality=94)
203+
output = cStringIO()
204+
image.save(ensure_binary(output), "JPEG", quality=94)
192205
pic = output.getvalue()
193206
output.close()
194207
write_jpg2frame(dev, pic)

lcd4linux/src/dpf.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
from six import PY2
33
try:
44
from . import dpflib
5-
except:
5+
except Exception:
66
print("[LCD4linux] dpflib-Error")
77

88
PROPERTY_BRIGHTNESS = 0x01
@@ -15,7 +15,7 @@ def setBacklight(dev, value):
1515
try:
1616
dev.setProperty(PROPERTY_BRIGHTNESS, value)
1717
return True
18-
except:
18+
except Exception:
1919
print("[LCD4linux] Error set Backlight")
2020
return False
2121

@@ -29,17 +29,17 @@ def showImage(dev, image):
2929
else:
3030
dev.showRGBAImage(0, 0, x, y, ir.tobytes())
3131
return True
32-
except:
32+
except Exception:
3333
print("[LCD4linux] Error writing DPF Device")
3434
return False
3535

3636

3737
def open(usb):
3838
try:
3939
d = dpflib.open(usb)
40-
d.setProperty(PROPERTY_ORIENTATION, 1)
40+
# d.setProperty(PROPERTY_ORIENTATION, 1)
4141
print("[LCD4linux] open %s" % usb)
42-
except:
42+
except Exception:
4343
d = None
4444
print("[LCD4linux] open Error: %s" % usb)
4545
return d
@@ -49,5 +49,5 @@ def close(dev):
4949
try:
5050
if dev is not None:
5151
dev.close()
52-
except:
52+
except Exception:
5353
pass

lcd4linux/src/module.py

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ def getHold(self):
7979
return L4Lelement.Hold
8080

8181
def setHold(self, H):
82-
print("[LCD4linuxE] Hold: %s" % H)
82+
print("[LCD4linuxE] hold: %s" % H)
8383
L4Lelement.Hold = H
8484

8585
def getHoldKey(self):
8686
return L4Lelement.HoldKey
8787

8888
def setHoldKey(self, H=False):
89-
print("[LCD4linuxE] HoldKey: %s" % H)
89+
print("[LCD4linuxE] holdkey: %s" % H)
9090
L4Lelement.HoldKey = H
9191

9292
def getFont(self, F="0"):
@@ -102,19 +102,15 @@ def getScreen(self):
102102
return L4Lelement.Screen
103103

104104
def setScreen(self, S, Lcd="", Hold=False):
105-
if Lcd != "":
106-
if len(str(Lcd)) > 1 or int(Lcd) > 3:
107-
Lcd = "1"
105+
if Lcd != "" and len(str(Lcd)) > 1 or int(Lcd) > 3:
106+
Lcd = "1"
108107
L4Lelement.Screen = str(S)
109108
L4Lelement.LCD = str(Lcd)
110109
L4Lelement.Hold = Hold
111110
L4Lelement.Refresh = True
112111

113-
def resetBrightness(self, AKT=""):
114-
if len(AKT) == 3:
115-
L4Lelement.BrightAkt = AKT
116-
else:
117-
L4Lelement.Bright = [-1, -1, -1]
112+
def resetBrightness(self, AKT=[0, 0, 0]):
113+
L4Lelement.Bright = [-1, -1, -1]
118114

119115
def setBrightness(self, LCD, BRI=-1):
120116
if int(LCD) < 1 or int(LCD) > 3:
@@ -145,14 +141,13 @@ def getstatusoutput(cmd):
145141
sts = pipe.close()
146142
if sts is None:
147143
sts = 0
148-
if text[-1:] == '\n':
144+
if text.endswith == '\n':
149145
text = text[:-1]
150146
except Exception:
151147
sts = 1
152148
text = "- -"
153149
print("[LCD4linux] Error on os-call")
154-
finally:
155-
return sts, text
150+
return sts, text
156151

157152

158153
def L4LVtest(VV):
@@ -172,6 +167,7 @@ def L4LVtest(VV):
172167
if O != "":
173168
try:
174169
f = open(L4Linfo % (O, P))
170+
B = f.readline()
175171
OO = f.readline().strip().split()[1].startswith(VV[1:])
176172
f.close()
177173
except Exception:

0 commit comments

Comments
 (0)