-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathps2serialwriter.py
executable file
·122 lines (109 loc) · 3.41 KB
/
ps2serialwriter.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
#!/usr/bin/env python3
import serial
import sys
import time
""" otvara .txt file na read mode """
file = open(sys.argv[1], 'r')
""" sve u fajlu pretvara u velika slova """
file = file.read().upper()
""" svaku komandu iz BASIC koju mogu skracujem na tacka verziju nje """
#file = file.replace("PRINT", "P.")
""" pretvaram fajl u charove """
file = list(file)
""" svi char u PS2 """
char_list = ['A','B','C','D','E','F','G','H','I','J',
'K','L','M','N','O','P','Q','R','S','T',
'U','V','W','X','Y','Z','1','2','3','4',
'5','6','7','8','9','0',';',':',',','=',
'.','/',' ','\n','!','\"','#','$','%','&','\'','(',
')','*','+','-','>','<','?','Č','Ć','Ž','Š']
ps2_list = [
(0x1c, 0xf0, 0x1c), # A
(0x32, 0xf0, 0x32), # B
(0x21, 0xf0, 0x21), # C
(0x23, 0xf0, 0x23), # D
(0x24, 0xf0, 0x24), # E
(0x2b, 0xf0, 0x2b), # F
(0x34, 0xf0, 0x34), # G
(0x33, 0xf0, 0x33), # H
(0x43, 0xf0, 0x43), # I
(0x3b, 0xf0, 0x3b), # J
(0x42, 0xf0, 0x42), # K
(0x4b, 0xf0, 0x4b), # L
(0x3a, 0xf0, 0x3a), # M
(0x31, 0xf0, 0x31), # N
(0x44, 0xf0, 0x44), # O
(0x4d, 0xf0, 0x4d), # P
(0x15, 0xf0, 0x15), # Q
(0x2d, 0xf0, 0x2d), # R
(0x1b, 0xf0, 0x1b), # S
(0x2c, 0xf0, 0x2c), # T
(0x3c, 0xf0, 0x3c), # U
(0x2a, 0xf0, 0x2a), # V
(0x1d, 0xf0, 0x1d), # W
(0x22, 0xf0, 0x22), # X
(0x35, 0xf0, 0x35), # Y
(0x1a, 0xf0, 0x1a), # Z
(0x16, 0xf0, 0x16), # 1
(0x1e, 0xf0, 0x1e), # 2
(0x26, 0xf0, 0x26), # 3
(0x25, 0xf0, 0x25), # 4
(0x2e, 0xf0, 0x2e), # 5
(0x36, 0xf0, 0x36), # 6
(0x3d, 0xf0, 0x3d), # 7
(0x3e, 0xf0, 0x3e), # 8
(0x46, 0xf0, 0x46), # 9
(0x45, 0xf0, 0x45), # 0
(0x4c, 0xf0, 0x4c), # ;
(0x52, 0xf0, 0x52), # :
(0x41, 0xf0, 0x41), # ,
(0x55, 0xf0, 0x55), # =
(0x49, 0xf0, 0x49), # .
(0x4a, 0xf0, 0x4a), # /
(0x29, 0xf0, 0x29), # Space
(0x5a, 0xf0, 0x5a), # Return
(0x59, 0x16, 0xf0, 0x16, 0xf0, 0x59), # !
(0x59, 0x1e, 0xf0, 0x1e, 0xf0, 0x59), # "
(0x59, 0x26, 0xf0, 0x26, 0xf0, 0x59), # #
(0x59, 0x25, 0xf0, 0x25, 0xf0, 0x59), # $
(0x59, 0x2e, 0xf0, 0x2e, 0xf0, 0x59), # %
(0x59, 0x36, 0xf0, 0x36, 0xf0, 0x59), # &
(0x59, 0x3d, 0xf0, 0x3d, 0xf0, 0x59), # '
(0x59, 0x3e, 0xf0, 0x3e, 0xf0, 0x59), # (
(0x59, 0x46, 0xf0, 0x46, 0xf0, 0x59), # )
(0x59, 0x52, 0xf0, 0x52, 0xf0, 0x59), # *
(0x59, 0x4c, 0xf0, 0x4c, 0xf0, 0x59), # +
(0x59, 0x55, 0xf0, 0x55, 0xf0, 0x59), # -
(0x59, 0x49, 0xf0, 0x49, 0xf0, 0x59), # >
(0x59, 0x41, 0xf0, 0x41, 0xf0, 0x59), # <
(0x59, 0x4a, 0xf0, 0x4a, 0xf0, 0x59), # ?
(0x59, 0x22, 0xf0, 0x22, 0xf0, 0x59), # Č
(0x59, 0x21, 0xf0, 0x21, 0xf0, 0x59), # Ć
(0x59, 0x1a, 0xf0, 0x1a, 0xf0, 0x59), # Ž
(0x59, 0x1b, 0xf0, 0x1b, 0xf0, 0x59) # Š
]
""" pisanje fajla kao ps2 """
for i in range(0,len(file)):
file[i] = ps2_list[char_list.index(file[i])]
""" prebacivanje na serijski port """
ser = serial.Serial(sys.argv[2], int(sys.argv[3])) # prvi arg promeni
time.sleep(2)
values = []
for i in range(0, len(file)):
for j in range(0, len(file[i])):
values.append(file[i][j])
print(values)
# ser.write(bytearray(values))
for value in values:
# print("napisano: {}".format(ser.write(bytes([value]))))
ser.write(bytes([value]))
time.sleep(0.05)
# print("napisano: {}".format(ser.write(bytearray(values))))
# for i in range(65, 90):
# print(bytes([i]))
# ser.write(bytes([i]))
# print("read: {}".format(ser.read(1)))
# for i in range(14):
# print("in waiting: {}".format(ser.in_waiting))
# print("read: {}".format(ord(ser.read(1))))
ser.close()