Skip to content

Commit f0e3916

Browse files
MrServoHains
authored andcommitted
[LCD4linux] v5.0-r25 bugfixed
- bugfixed troubles with some Samsung-Displays - some general bugfixes HINT: **LCD4linux** is still working under Python2 and Python3
1 parent 0b582fd commit f0e3916

File tree

3 files changed

+91
-81
lines changed

3 files changed

+91
-81
lines changed

lcd4linux/src/Photoframe.py

Lines changed: 71 additions & 57 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 import ensure_binary
89
from six.moves import cStringIO as StringIO
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,46 +142,58 @@ 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+
# Switch device from Mass Storage to Mini Monitor
154+
CTRL_TYPE_VENDOR = (2 << 5)
155+
CTRL_IN = 0x80
156+
CTRL_RECIPIENT_DEVICE = 0
152157
try:
153158
sleep(0.5)
159+
s = "\x00" * 251
154160
dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, 0xfe)
155-
except:
161+
# dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, s, 0xfe )
162+
# dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1)
163+
# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x04, 0x00, 0x00, 1)
164+
# expect(result, [ 0x03 ])
165+
# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x01, 0x00, 0x00, 2)
166+
# expect(result, [ 0x09, 0x04 ])
167+
# result = dev.ctrl_transfer(CTRL_TYPE_VENDOR | CTRL_IN | CTRL_RECIPIENT_DEVICE, 0x02, 0x00, 0x00, 1)
168+
# expect(result, [ 0x46 ])
169+
# settling of the bus and frame takes about 0.42 sec
170+
# give it some extra time, but then still make sure it has settled
171+
except Exception:
156172
print("[LCD4linux] switching ERROR")
173+
# from traceback import format_exc
174+
# print format_exc()
157175
finally:
158176
sleep(2)
159177

160178

161179
def name(dev):
162180
try:
163181
return get_string(dev, 1)
164-
except:
182+
except Exception:
165183
try:
166184
return get_string(dev, 256, 2)
167-
except:
185+
except Exception:
168186
return None
169187

170188

171189
def main():
172190
global dev, known_devices_list
173-
174191
known_devices_list = get_known_devices()
175-
176192
# define which frame to use, here use Samsung SPF-87H
177193
device0 = known_devices_list[0] # Mini Monitor mode
178194
device1 = known_devices_list[1] # Mass Storage mode
179-
180195
dev = init_device(1, device0, device1)
181196
print("Frame is in Mini Monitor mode and initialized. Sending pictures now")
182-
183197
image = Image.open("mypicture.jpg")
184198
#manipulations to consider:
185199
# convert

lcd4linux/src/module.py

Lines changed: 12 additions & 17 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,25 +102,20 @@ 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=[]):
113+
L4Lelement.BrightAkt = AKT if len(AKT) == 3 else [-1, -1, -1]
118114

119115
def setBrightness(self, LCD, BRI=-1):
120-
if int(LCD) < 1 or int(LCD) > 3:
121-
return
122-
L4Lelement.Bright[int(LCD) - 1] = int(BRI)
123-
L4Lelement.Refresh = True
116+
if int(LCD) > 0 and int(LCD) < 4:
117+
L4Lelement.Bright[int(LCD) - 1] = int(BRI)
118+
L4Lelement.Refresh = True
124119

125120
def getBrightness(self, LCD=0, ORG=True):
126121
if int(LCD) > 0 and int(LCD) < 4:
@@ -145,14 +140,13 @@ def getstatusoutput(cmd):
145140
sts = pipe.close()
146141
if sts is None:
147142
sts = 0
148-
if text[-1:] == '\n':
143+
if text.endswith == '\n':
149144
text = text[:-1]
150145
except Exception:
151146
sts = 1
152147
text = "- -"
153148
print("[LCD4linux] Error on os-call")
154-
finally:
155-
return sts, text
149+
return sts, text
156150

157151

158152
def L4LVtest(VV):
@@ -172,6 +166,7 @@ def L4LVtest(VV):
172166
if O != "":
173167
try:
174168
f = open(L4Linfo % (O, P))
169+
B = f.readline()
175170
OO = f.readline().strip().split()[1].startswith(VV[1:])
176171
f.close()
177172
except Exception:

lcd4linux/src/plugin.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2698,7 +2698,8 @@ def getFB2(check):
26982698

26992699

27002700
def BRI(w1, w2):
2701-
return int(w1) if L4LElist.getBrightness(w2, False) == -1 else int(L4LElist.getBrightness(w2, False))
2701+
gb = L4LElist.getBrightness(w2, False)
2702+
return int(w1) if gb == -1 else gb
27022703

27032704

27042705
def virtBRI(LCD):
@@ -3129,9 +3130,9 @@ def writeHelligkeit(hell, night, STOP):
31293130
global AktHelligkeit
31303131
global AktNight
31313132
R = ""
3132-
h1 = BRI(int(hell[0]), 1)
3133-
h2 = BRI(int(hell[1]), 2)
3134-
h3 = BRI(int(hell[2]), 3)
3133+
h1 = BRI(hell[0], 1)
3134+
h2 = BRI(hell[1], 2)
3135+
h3 = BRI(hell[2], 3)
31353136
if isOffTime(L4LMoon, L4LSun, L4LMoon, L4LSun):
31363137
if int(night[0]) != 0:
31373138
h1 = max(h1 - int(night[0]), 0)
@@ -9150,10 +9151,10 @@ def ServiceChange(self):
91509151
self.LsreftoString = sref.toString()
91519152
if self.LsreftoString is not None:
91529153
self.LsrefFile = self.LsreftoString[self.LsreftoString.rfind(":") + 1:]
9153-
if self.LsrefFile.endswith("/"):
9154+
if self.LsrefFile.startswith("/"):
91549155
tsref = self.LsreftoString[:-len(self.LsrefFile) - 1]
91559156
tsref = tsref[tsref.rfind(":") + 1:]
9156-
if tsref.starts("/"):
9157+
if tsref.startswith("/"):
91579158
self.LsrefFile = tsref
91589159
else:
91599160
self.LsrefFile = ""
@@ -12307,7 +12308,7 @@ def putProgress(workaround, draw, im):
1230712308
try:
1230812309
length = self.Llength
1230912310
position = self.Lposition
12310-
if length and length[1] > 0 and position:
12311+
if length and (length[1] > 0 and position):
1231112312
if ConfigType[0] in ["2", "4", "6", "8", "9", "A"]:
1231212313
if ConfigType[0] in ["8", "9", "A"] or length[0] == 1:
1231312314
dur = int(position[1] / 90000)

0 commit comments

Comments
 (0)