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,6 +1,7 @@
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)
@ -21,7 +22,8 @@ def setup():
# Bank4 Pin8 # Bank4 Pin8
gpio.setup(136, gpio.OUT) gpio.setup(136, gpio.OUT)
def keyread():
def gpioread():
keys = [] keys = []
for writeport in range(80, 87): for writeport in range(80, 87):
if writeport == 86: if writeport == 86:
@ -34,18 +36,12 @@ def keyread():
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
@ -175,6 +171,7 @@ def keyread():
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)