format and some fix

This commit is contained in:
Chiharu Shirasaka 2021-01-04 20:33:08 +09:00
parent e7d67d4e8d
commit 1f60e07b12

View File

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