5
5
from usb .util import get_string
6
6
from PIL import Image
7
7
from struct import pack
8
+ from six import ensure_binary
8
9
from six .moves import cStringIO as StringIO
9
10
10
11
11
12
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
13
14
# create header and stack before picture
14
15
# middle 4 bytes have size of picture
15
16
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):
22
23
23
24
24
25
def get_known_devices ():
25
- """ Return a dict of photo frames"""
26
- dList = []
26
+ # Return a dict of photo frames
27
+ dlist = []
27
28
# listed as: Name, idVendor, idProduct, [width , height - in pixel if applicable]
28
- #
29
+
29
30
#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 })
32
33
33
34
#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 })
36
37
37
38
#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 })
40
41
41
42
#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 })
44
45
45
46
#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 })
48
49
49
50
#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 })
52
53
53
54
#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 })
56
57
57
58
#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 })
60
61
61
62
#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 })
64
65
65
66
#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 })
68
69
69
70
#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 })
72
73
73
74
#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 })
76
77
77
78
#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 })
80
85
81
86
# 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 })
84
89
85
- return dList
90
+ return dlist
86
91
87
92
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.
90
95
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 :
93
98
d = list (find (idVendor = device ['idVendor' ], idProduct = device ['idProduct' ], find_all = True )) + list (find (idVendor = device2 ['idVendor' ], idProduct = device2 ['idProduct' ], find_all = True ))
94
99
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
99
101
else :
100
102
d = None
101
103
else :
102
104
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 :
104
106
from traceback import format_exc
105
107
print ("[LCD4linux] find exception" )
106
108
print ("Error: %s" % format_exc ())
107
109
d = None
108
110
return d
109
111
110
112
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 )
114
116
115
117
if dev is not None :
116
118
## found it, trying to init it
@@ -124,7 +126,7 @@ def init_device(Anzahl, device0, device1):
124
126
ts = time ()
125
127
while True :
126
128
# may need to burn some time
127
- dev = find_device (Anzahl , device0 , device1 )
129
+ dev = find_device (anzahl , device0 , device1 )
128
130
if dev is not None and dev .idProduct == device0 ["idProduct" ]:
129
131
#switching successful
130
132
break
@@ -140,46 +142,58 @@ def init_device(Anzahl, device0, device1):
140
142
141
143
142
144
def frame_init (dev ):
143
- """ Init device so it stays in Mini Monitor mode"""
145
+ # Init device so it stays in Mini Monitor mode
144
146
# 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 )
147
149
dev .ctrl_transfer (0xc0 , 0x01 , 0x00 , 0x00 , 0x02 )
148
150
149
151
150
152
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
152
157
try :
153
158
sleep (0.5 )
159
+ s = "\x00 " * 251
154
160
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 :
156
172
print ("[LCD4linux] switching ERROR" )
173
+ # from traceback import format_exc
174
+ # print format_exc()
157
175
finally :
158
176
sleep (2 )
159
177
160
178
161
179
def name (dev ):
162
180
try :
163
181
return get_string (dev , 1 )
164
- except :
182
+ except Exception :
165
183
try :
166
184
return get_string (dev , 256 , 2 )
167
- except :
185
+ except Exception :
168
186
return None
169
187
170
188
171
189
def main ():
172
190
global dev , known_devices_list
173
-
174
191
known_devices_list = get_known_devices ()
175
-
176
192
# define which frame to use, here use Samsung SPF-87H
177
193
device0 = known_devices_list [0 ] # Mini Monitor mode
178
194
device1 = known_devices_list [1 ] # Mass Storage mode
179
-
180
195
dev = init_device (1 , device0 , device1 )
181
196
print ("Frame is in Mini Monitor mode and initialized. Sending pictures now" )
182
-
183
197
image = Image .open ("mypicture.jpg" )
184
198
#manipulations to consider:
185
199
# convert
0 commit comments