Skip to content

Commit 0b582fd

Browse files
MrServoHains
authored andcommitted
[LCD4linux] v5.0-r25 two files reverted
1 parent 84b8c25 commit 0b582fd

File tree

2 files changed

+74
-83
lines changed

2 files changed

+74
-83
lines changed

lcd4linux/src/Photoframe.py

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

1110

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

2423

2524
def get_known_devices():
26-
# Return a dict of photo frames
27-
dlist = []
25+
"""Return a dict of photo frames"""
26+
dList = []
2827
# listed as: Name, idVendor, idProduct, [width , height - in pixel if applicable]
29-
28+
#
3029
#0,1 Samsung SPF-75H/76H (23)
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})
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})
3332

3433
#2,3 Samsung SPF-87H (24)
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})
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})
3736

3837
#4,5 Samsung SPF-87Hold (25)
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})
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})
4140

4241
#6,7 Samsung SPF-83H (26)
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})
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})
4544

4645
#8,9 Samsung SPF-107H (27)
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})
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})
4948

5049
#10,11 Samsung SPF-105P (28)
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})
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})
5352

5453
#12,13 Samsung SPF-85H/86H (29)
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})
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})
5756

5857
#14,15 Samsung SPF-72H (210)
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})
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})
6160

6261
#16,17 Samsung SPF-700T (211)
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})
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})
6564

6665
#18,19 Samsung SPF-85P/86P (212)
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})
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})
6968

7069
#20,21 Samsung SPF-107Hold (213)
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})
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})
7372

7473
#22,23 Samsung SPF-1000P (214)
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})
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})
7776

7877
#24,25 Samsung SPF-800P (215)
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})
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})
8580

8681
# Pearl DPF for Testing
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})
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})
8984

90-
return dlist
85+
return dList
9186

9287

93-
def find_device(anzahl, device, device2):
94-
# Try to find device on USB bus.
88+
def find_device(Anzahl, device, device2):
89+
"""Try to find device on USB bus."""
9590
try:
96-
print("[LCD4linux] looking for frame", anzahl, device['name'], device['idVendor'], device['idProduct'], device2['idProduct'])
97-
if anzahl == 2:
91+
print("[LCD4linux] looking for frame", Anzahl, device['name'], device['idVendor'], device['idProduct'], device2['idProduct'])
92+
if Anzahl == 2:
9893
d = list(find(idVendor=device['idVendor'], idProduct=device['idProduct'], find_all=True)) + list(find(idVendor=device2['idVendor'], idProduct=device2['idProduct'], find_all=True))
9994
if isinstance(d, list):
100-
d = d[1] if len(d) >= 2 else None
95+
if len(d) >= 2:
96+
d = d[1]
97+
else:
98+
d = None
10199
else:
102100
d = None
103101
else:
104102
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]
105-
except Exception:
103+
except:
106104
from traceback import format_exc
107105
print("[LCD4linux] find exception")
108106
print("Error: %s" % format_exc())
109107
d = None
110108
return d
111109

112110

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

117115
if dev is not None:
118116
## found it, trying to init it
@@ -126,7 +124,7 @@ def init_device(anzahl, device0, device1):
126124
ts = time()
127125
while True:
128126
# may need to burn some time
129-
dev = find_device(anzahl, device0, device1)
127+
dev = find_device(Anzahl, device0, device1)
130128
if dev is not None and dev.idProduct == device0["idProduct"]:
131129
#switching successful
132130
break
@@ -142,66 +140,55 @@ def init_device(anzahl, device0, device1):
142140

143141

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

151149

152150
def frame_switch(dev):
153-
CTRL_TYPE_VENDOR = (2 << 5)
154-
CTRL_IN = 0x80
155-
CTRL_RECIPIENT_DEVICE = 0
151+
"""Switch device from Mass Storage to Mini Monitor"""
156152
try:
157-
time.sleep(0.5)
158-
s = "\x00" * 251
153+
sleep(0.5)
159154
dev.ctrl_transfer(0x00 | 0x80, 0x06, 0xfe, 0xfe, 0xfe)
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:
155+
except:
171156
print("[LCD4linux] switching ERROR")
172-
# from traceback import format_exc
173-
# print format_exc()
174157
finally:
175158
sleep(2)
176159

177160

178161
def name(dev):
179162
try:
180163
return get_string(dev, 1)
181-
except Exception:
164+
except:
182165
try:
183166
return get_string(dev, 256, 2)
184-
except Exception:
167+
except:
185168
return None
186169

187170

188171
def main():
189172
global dev, known_devices_list
173+
190174
known_devices_list = get_known_devices()
175+
191176
# define which frame to use, here use Samsung SPF-87H
192177
device0 = known_devices_list[0] # Mini Monitor mode
193178
device1 = known_devices_list[1] # Mass Storage mode
179+
194180
dev = init_device(1, device0, device1)
195181
print("Frame is in Mini Monitor mode and initialized. Sending pictures now")
182+
196183
image = Image.open("mypicture.jpg")
197184
#manipulations to consider:
198185
# convert
199186
# thumbnail
200187
# rotate
201188
# crop
202189
image = image.resize((800, 480))
203-
output = cStringIO()
204-
image.save(ensure_binary(output), "JPEG", quality=94)
190+
output = StringIO.StringIO()
191+
image.save(output, "JPEG", quality=94)
205192
pic = output.getvalue()
206193
output.close()
207194
write_jpg2frame(dev, pic)

lcd4linux/src/module.py

Lines changed: 13 additions & 9 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,15 +102,19 @@ def getScreen(self):
102102
return L4Lelement.Screen
103103

104104
def setScreen(self, S, Lcd="", Hold=False):
105-
if Lcd != "" and len(str(Lcd)) > 1 or int(Lcd) > 3:
106-
Lcd = "1"
105+
if Lcd != "":
106+
if len(str(Lcd)) > 1 or int(Lcd) > 3:
107+
Lcd = "1"
107108
L4Lelement.Screen = str(S)
108109
L4Lelement.LCD = str(Lcd)
109110
L4Lelement.Hold = Hold
110111
L4Lelement.Refresh = True
111112

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

115119
def setBrightness(self, LCD, BRI=-1):
116120
if int(LCD) < 1 or int(LCD) > 3:
@@ -141,13 +145,14 @@ def getstatusoutput(cmd):
141145
sts = pipe.close()
142146
if sts is None:
143147
sts = 0
144-
if text.endswith == '\n':
148+
if text[-1:] == '\n':
145149
text = text[:-1]
146150
except Exception:
147151
sts = 1
148152
text = "- -"
149153
print("[LCD4linux] Error on os-call")
150-
return sts, text
154+
finally:
155+
return sts, text
151156

152157

153158
def L4LVtest(VV):
@@ -167,7 +172,6 @@ def L4LVtest(VV):
167172
if O != "":
168173
try:
169174
f = open(L4Linfo % (O, P))
170-
B = f.readline()
171175
OO = f.readline().strip().split()[1].startswith(VV[1:])
172176
f.close()
173177
except Exception:

0 commit comments

Comments
 (0)