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