-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvestactrl.py
More file actions
228 lines (204 loc) · 8.93 KB
/
vestactrl.py
File metadata and controls
228 lines (204 loc) · 8.93 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import serial
import serial.rs485
import sys
import time
import packet
import string
ser = None
def read_and_print(sport, print_it=False):
s = sport.read(6)
barr = bytearray(s)
ll = (barr[5]<<8) + barr[4]
s2 = sport.read(ll+4)
barr += bytearray(s2)
#if print_it:
#print('Rx:'),
#for b in barr:
#print(" %02x" % b),
#print('')
return barr
def color_handling(s):
b = bytearray(s)
for idx in range(len(b)):
if chr(b[idx]) == '`':
b[idx+1] = int(chr(b[idx+1]))
s=b.translate(None,'`')
return s
def send_packet(s):
ser.rts = False # Set high... logic is inverted
ser.write([s[0]])
for c in s[1:]:
if c == 0xfe or c == 0xff:
#print('escape')
ser.write([0xfe])
ser.write([c])
time.sleep(.005) # Delay
ser.rts = True # Set low... logic is inverted
def test (string, print_it):
time.sleep(.5)
s = color_handling(string)
# 6 rows instead of 7 now
val = ' '*(6-len(s))+s
send_packet(packet.set_targets(0x0001, val, print_it))
read_and_print(ser, print_it)
send_packet(packet.arm(0x0001, print_it))
read_and_print(ser, print_it)
send_packet(packet.go(0x0001, print_it))
read_and_print(ser, print_it)
time.sleep(12)
# 6 rows insteaad of 7 now
for i in range(6):
send_packet(packet.reg_read(0x0001, packet.REG_REV_COUNT_0+i, print_it))
res = read_and_print(ser, print_it)
count = (res[9]<<8)+res[8]
#print('%d,' % count),
#print('%s,' % string)
# 22 col instead of 23 now
all_columns = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22]
#all_columns = [1, 2, 3, 4, 5, 6, 7, 8]
def init_all_columns():
for c in all_columns:
send_packet(packet.reg_write(c, packet.REG_INDEX_ADJUST, 20))
read_and_print(ser)
send_packet(packet.reg_write(c, packet.REG_ROTATE_NOP, 0))
read_and_print(ser)
send_packet(packet.reg_write(c, packet.REG_ONE_REV_MIN, 0))
read_and_print(ser)
#send_packet(packet.reg_write(c, packet.REG_FREQ_D, 5))
#read_and_print(ser)
#send_packet(packet.reg_write(c, packet.REG_FREQ_N, 2))
#read_and_print(ser)
def print_board(rows,print_it=True):
if print_it:
print('#'*24)
for l in rows:
# 22 col insteaed of 23 now
print '#' + ('%-22s' % l) + '#'
print('#'*24)
for l in rows:
print " ".join("{:02x}".format(ord(c)) for c in l)
def setup_digits(strings, left_to_right_swap = False, real_hw=True):
#print('string sent in app: %s') % strings
#print('string length: %d') % len(strings)
print_it = True
# digits raw major
# 22 col instead of 23 and 6 rows instead of now
#drm = ['\x00'*22, '\x00'*22, '\x00'*22, '\x00'*22, '\x00'*22, '\x00'*22]
drm = [' '*22, ' '*22, ' '*22, ' '*22, ' '*22, ' '*22]
# 6 rows instead of 7 now
offset = (6-len(strings))/2
max_len = 0
for idx in range(len(strings)):
s = strings[idx]
# 22 col instaed of 23 now
s = color_handling(s)[:22]
if left_to_right_swap:
s = s[::-1]
if len(s) > max_len:
max_len = len(s)
# 22 col insteaad of 23 now
drm[offset+idx] = ('%-22s' % s)
#print_board(drm)
#print('Length of DRM: %d') % len(drm)
for idx in range(len(drm)):
#print('IDX: %d') % idx
initial_length = len(drm[idx])
whitespace_number = drm[idx].count(' ')
final_length = initial_length - whitespace_number
left_side = (22-final_length)/2
#print('left side: %d') % left_side
right_side = 22 - left_side - final_length
#print('right side: %d') % right_side
# 22 col instead of 23 now
drm[idx] = drm[idx].replace(' ', '')
drm[idx] = ('%-22s' % (('\x00'*(left_side)) + drm[idx] + ('\x00'*(right_side))))[:22]
#print 'Rows: %d' % len(drm)
#print 'Max Len: %d' % max_len
#print_board(drm)
# 6 row instead of 7 now
while len(drm) < 6:
# 22 col insteaad of 23 now
drm.append('%-22s' % '\x00')
# digits column major
dcm = []
# 6 row instead of 7 now
tups = zip(drm[0], drm[1], drm[2], drm[3], drm[4], drm[5])
#tups = zip(drm[0])
for t in tups:
dcm.append(''.join(t))
#print('tups: %s') % tups
if real_hw:
for idx in range(len(all_columns)):
#print 'idx: %d' % idx
#print '>>>> [%d] %s' % (idx+1, dcm[idx][::-1])
##############################################################################################
send_packet(packet.set_targets(idx+1, dcm[idx][::-1], print_it))
read_and_print(ser, print_it)
send_packet(packet.arm(idx+1, print_it))
read_and_print(ser, print_it)
send_packet(packet.go(0x0001, print_it))
read_and_print(ser, print_it)
#print('skipping stuff...')
##############################################################################################
#else:
#print tups
def emc_blanks():
setup_digits(['`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7', '`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7', '`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7', '`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7', '`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7', '`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7`7'], left_to_right_swap=True)
def blanks():
#for c in all_columns:
# send_packet(packet.reg_write(c, packet.REG_FREQ_D, 8))
# read_and_print(ser)
# send_packet(packet.reg_write(c, packet.REG_FREQ_N, 2))
# read_and_print(ser)
setup_digits(['`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0'], left_to_right_swap=True)
#setup_digits(['', '', '', '', '', ''], left_to_right_swap=True)
def test_long_blanks():
#for c in all_columns:
# send_packet(packet.reg_write(c, packet.REG_FREQ_D, 8))
# read_and_print(ser)
# send_packet(packet.reg_write(c, packet.REG_FREQ_N, 2))
# read_and_print(ser)
setup_digits(['`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0TEST`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0LONG`0MESSAGE`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0'], left_to_right_swap=False)
#setup_digits(['', '', '', '', '', ''], left_to_right_swap=True)
def test_rapid_blanks():
#for c in all_columns:
# send_packet(packet.reg_write(c, packet.REG_FREQ_D, 8))
# read_and_print(ser)
# send_packet(packet.reg_write(c, packet.REG_FREQ_N, 2))
# read_and_print(ser)
setup_digits(['`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0TSET`0`0`0`0`0`0`0`0`0', '`0`0`0NOISSECCUS`0DIPAR`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0'], left_to_right_swap=True)
#setup_digits(['', '', '', '', '', ''], left_to_right_swap=True)
def test_check_blanks():
#for c in all_columns:
# send_packet(packet.reg_write(c, packet.REG_FREQ_D, 8))
# read_and_print(ser)
# send_packet(packet.reg_write(c, packet.REG_FREQ_N, 2))
# read_and_print(ser)
setup_digits(['`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0TSET`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0KCEHC`0PALF`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0'], left_to_right_swap=True)
#setup_digits(['', '', '', '', '', ''], left_to_right_swap=True)
def test_power_blanks():
setup_digits(['`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0TSET`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0WARD`0REWOP`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0', '`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0`0'], left_to_right_swap=True)
def board_init_uart():
global ser
#tty = '/dev/ttyUSB0'
tty = '/dev/ttyAMA0'
ser = serial.Serial(tty, 38400)
#def main(ser, args):
# init_all_columns()
#
# blanks()
# time.sleep(15)
# setup_digits(['vestaboard', 'welcome to', 't', 'e', 's', 't', '#'], left_to_right_swap=True)
# time.sleep(15)
# setup_digits(['colors `1`2`3', '`4`5`6 samples', '', '', '', '', ''], left_to_right_swap=True)
# time.sleep(15)
# setup_digits(['`0`1`2`3`4`5`6`5`4`3`2`1', '`6`5`4`3`2`1`0`1`2`3`4`5', '', '', '', '', ''], left_to_right_swap=True)
# time.sleep(15)
# blanks()
#
#if __name__ == '__main__':
# tty = '/dev/ttyUSB0'
# with serial.Serial(tty, 38400) as ser:
# main(ser, sys.argv[1:])