-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathread_keys_SH3.py
178 lines (169 loc) · 5.27 KB
/
read_keys_SH3.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
import gpio # https://github.com/vitiral/gpio
import time
def setup():
# Bank2 Pin16~PIN21
gpio.setup(80, gpio.OUT)
gpio.setup(81, gpio.OUT)
gpio.setup(82, gpio.OUT)
gpio.setup(83, gpio.OUT)
gpio.setup(84, gpio.OUT)
gpio.setup(85, gpio.OUT)
# Bank4 Pin0~7
gpio.setup(128, gpio.IN)
gpio.setup(129, gpio.IN)
gpio.setup(130, gpio.IN)
gpio.setup(131, gpio.IN)
gpio.setup(132, gpio.IN)
gpio.setup(133, gpio.IN)
gpio.setup(134, gpio.IN)
gpio.setup(135, gpio.IN)
# Bank4 Pin8
gpio.setup(136, gpio.OUT)
def gpioread():
keys = []
for writeport in range(80, 87):
if writeport == 86:
writeport = 136
gpio.set(writeport, 1)
time.sleep(0.002)
key = 0
for readport in range(135, 127, -1):
key = (key << 1) + gpio.read(readport)
key = ~((key ^ (key >> 1)) & 0x1f ^ (key >> 1)) & 0x7f
keys.append(key)
gpio.set(writeport, 0)
return keys
def keyread():
keys = readgpio()
verify_keys = readgpio()
if not keys == verify_keys:
return
temp = 0
for key in keys:
temp = temp | key
if temp & 0x1:
for i, key in enumerate(keys):
if key & 0x1 == 0:
if i == 0:
print("英和和英", end=" ")
if i == 1:
print("調べる", end=" ")
if i == 2:
print("国語漢字", end=" ")
if i == 3:
print("My辞書", end=" ")
if i == 4:
print("履歴/しおり", end=" ")
if i == 5:
print("マーカーテスト", end=" ")
if i == 6:
print("HOME", end=" ")
if temp & 0x2:
for i, key in enumerate(keys):
if key & 0x2 == 0:
if i == 0:
print("Q", end=" ")
if i == 1:
print("W", end=" ")
if i == 2:
print("E", end=" ")
if i == 3:
print("T", end=" ")
if i == 4:
print("Y", end=" ")
if i == 5:
print("U", end=" ")
if i == 6:
print("I", end=" ")
if temp & 0x4:
for i, key in enumerate(keys):
if key & 0x4 == 0:
if i == 0:
print("A", end=" ")
if i == 1:
print("S", end=" ")
if i == 2:
print("D", end=" ")
if i == 3:
print("G", end=" ")
if i == 4:
print("H", end=" ")
if i == 5:
print("O", end=" ")
if i == 6:
print("P", end=" ")
if temp & 0x8:
for i, key in enumerate(keys):
if key & 0x8 == 0:
if i == 0:
print("Z", end=" ")
if i == 1:
print("X", end=" ")
if i == 2:
print("C", end=" ")
if i == 3:
print("B", end=" ")
if i == 4:
print("J", end=" ")
if i == 5:
print("K", end=" ")
if i == 6:
print("L", end=" ")
if temp & 0x10:
for i, key in enumerate(keys):
if key & 0x10 == 0:
if i == 0:
print("Shift", end=" ")
if i == 1:
print("R", end=" ")
if i == 2:
print("F", end=" ")
if i == 3:
print("記号", end=" ")
if i == 4:
print("N", end=" ")
if i == 5:
print("M", end=" ")
if i == 6:
print("-", end=" ")
if temp & 0x20:
for i, key in enumerate(keys):
if key & 0x20 == 0:
if i == 0:
print("V", end=" ")
if i == 1:
print("PageUp", end=" ")
if i == 2:
print("Space", end=" ")
if i == 3:
print("Left", end=" ")
if i == 4:
print("Up", end=" ")
if i == 5:
print("Down", end=" ")
if i == 6:
print("Right", end=" ")
if temp & 0x40:
for i, key in enumerate(keys):
if key & 0x40 == 0:
if i == 0:
print("文字切替", end=" ")
if i == 1:
print("PageDown", end=" ")
if i == 2:
print("ツール", end=" ")
if i == 3:
print("Esc", end=" ")
if i == 4:
print("Enter", end=" ")
if i == 5:
print("?", end=" ")
if i == 6:
print("BackSpace", end=" ")
keys = [f"{key:#04x}" for key in keys]
if not temp == 0:
print(f"\nKeys = {', '.join(keys)}")
setup()
while True:
time.sleep(0.001)
keyread()