-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathplanar.py
293 lines (191 loc) · 7.2 KB
/
planar.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
"""
Raw raster scan driver for controllerless
Planar EL320.240 electroluminescent display
Copyright (c) 2006 spacemarmot@users.sourceforge.net
This file is released under the GNU Lesser General Public Licence.
See the file LICENSE for details.
"""
import time
VSYNC_LO = 0x0
VSYNC_HI = 0x20
HSYNC_LO = 0x0
HSYNC_HI = 0x40
CLOCK_LO = 0
CLOCK_HI = 0x80
DATA0 = 0x01
DATA1 = 0x02
DATA2 = 0x04
DATA3 = 0x08
#____ abstract base class ______________________________________________________
class EL320_240(object):
def __init__(self):
self.W = 320
self.H = 240
#
# send a monochrome bitmap, stored in an 8-bit string, to the display
#
def write(self, data, address=0):
# convert the 8-bit input into the display's 4-bit format
out = []
for byte in data:
b = ord(byte)
hi = (b>>4) & 0x0F
out.append(VSYNC_HI | hi)
lo = b & 0x0F
out.append(VSYNC_HI | lo)
# write the update frame out to the display
self.buildFrame(out, address/(self.W/8))
self.send(self.frame)
self.send(self.frame)
#
# the core raster scan algorithm
#
def hsync(self):
self.frame.append(VSYNC_HI | HSYNC_HI)
self.frame.append(VSYNC_HI | HSYNC_LO)
def vsync(self):
self.frame.append(VSYNC_LO | HSYNC_LO)
self.frame.append(VSYNC_LO | HSYNC_HI)
self.frame.append(VSYNC_LO | HSYNC_LO)
def data(self, data=[0]):
for byte in data:
self.frame.append(CLOCK_HI|byte)
self.frame.append(CLOCK_LO|byte)
def buildFrame(self, data, start=0):
W = self.W/4
self.frame = []
stop = start + len(data)/W
if start == 0:
# clock the first scanline in
self.data(data[0:W])
start = 1
# emit a vsync pulse to latch the first row
self.vsync()
# for each scan line in the upper margin
for row in xrange(1, start):
# emit a hsync pulse, but skip the row
self.hsync()
# for each scan line in the update region
for row in xrange(start, stop):
offset = (row-start) * W
# clock the row data in
self.data(data[offset:offset+W])
# emit a hsync pulse to latch in the row
self.hsync()
for row in xrange(stop, self.H):
self.hsync()
class EL640_200SK(object):
def __init__(self):
self.W = 640
self.H = 200
def write(self, data, address=0):
# convert the 8-bit input into the display's 4-bit format
out = []
for byte in data:
b = ord(byte)
hi = (b>>4) & 0x0F
out.append(VSYNC_LO | hi)
lo = b & 0x0F
out.append(VSYNC_LO | lo)
# write the update frame out to the display
self.buildFrame(out, address/(self.W/8))
self.send(self.frame)
self.send(self.frame)
def data(self, data=[0]):
for byte in data:
self.frame.append(CLOCK_HI|byte)
self.frame.append(CLOCK_LO|byte)
def hsync(self):
self.frame.append(VSYNC_LO | HSYNC_HI)
self.frame.append(VSYNC_LO | HSYNC_LO)
def vsync(self):
self.frame.append(VSYNC_HI | HSYNC_LO)
self.frame.append(VSYNC_HI | HSYNC_HI)
self.frame.append(VSYNC_HI | HSYNC_LO)
def buildFrame(self, data, start=0):
W = self.W/4
self.frame = []
stop = start + len(data)/W
if start == 0:
# clock the first scanline in
self.data(data[0:W])
start = 1
# emit a vsync pulse to latch the first row
self.vsync()
# for each scan line in the upper margin
for row in xrange(1, start):
# emit a hsync pulse, but skip the row
self.hsync()
# for each scan line in the update region
for row in xrange(start, stop):
offset = (row-start) * W
# clock the row data in
self.data(data[offset:offset+W])
# emit a hsync pulse to latch in the row
self.hsync()
for row in xrange(stop, self.H+1):
self.hsync()
#____ USB ______________________________________________________________________
try:
import ftdi
class EL320_240_USB(EL320_240):
def __init__(self, dev=0):
super(EL320_240USB, self).__init__()
device = ftdi.getFtdiDevices()
self.usb = ftdi.FT232R(device[dev])
self.usb.enableBitBang()
def send(self):
try: self.usb.write(self.frame)
except: pass
except: print 'EL320_240 FTDI USB not available'
#____ parallel _________________________________________________________________
try:
import os
import fcntl
import struct
class EL320_240_Par(EL320_240):
def __init__(self, dev=0):
super(EL320_240_Par, self).__init__()
self.fd = os.open('/dev/parport%d' % dev, os.O_RDWR)
fcntl.ioctl(self.fd, 0x0000708F) # mark parport as exclusive
fcntl.ioctl(self.fd, 0x0000708B) # claim the parport
#fcntl.ioctl(self.fd, 0x40047090, struct.pack('i',0)) # set data dir to out
#fcntl.ioctl(self.fd, 0x40047080, struct.pack('i',1<<8)) # set mode to 'compat'
def data(self, data=[0]):
self.frame.extend(data)
def send(self, data):
fmt = '%c'*len(data)
s = fmt % tuple(data)
os.write(self.fd, s)
class EL640_200SK_Par(EL640_200SK):
def __init__(self, dev=0):
super(EL640_200SK_Par, self).__init__()
self.fd = os.open('/dev/parport%d' % dev, os.O_RDWR)
fcntl.ioctl(self.fd, 0x0000708F) # mark parport as exclusive
fcntl.ioctl(self.fd, 0x0000708B) # claim the parport
def data(self, data=[0]):
self.frame.extend(data)
def send(self, data):
fmt = '%c'*len(data)
s = fmt % tuple(data)
os.write(self.fd, s)
except: print 'Planar parallel not available'
if __name__ == '__main__':
#d = EL320_240_USB()
#d = EL320_240_Par(dev=2)
#
#length = d.W/8
#
#while True:
#
# d.write('\x11'*length, 2400)
# d.write('\x22'*length, 2400)
# d.write('\x44'*length, 2400)
# d.write('\x88'*length, 2400)
d = EL640_200SK_Par(dev=2)
length = d.W / 8 * 20
while True:
d.write('\x11'*length, length)
d.write('\x22'*length, length)
d.write('\x44'*length, length)
d.write('\x88'*length, length)