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 time
def setup():
# Bank2 Pin16~PIN21
gpio.setup(80, gpio.OUT)
@ -21,7 +22,8 @@ def setup():
# Bank4 Pin8
gpio.setup(136, gpio.OUT)
def keyread():
def gpioread():
keys = []
for writeport in range(80, 87):
if writeport == 86:
@ -34,18 +36,12 @@ def keyread():
key = ~((key ^ (key >> 1)) & 0x1f ^ (key >> 1)) & 0x7f
keys.append(key)
gpio.set(writeport, 0)
verify_keys = []
for writeport in range(80,87):
if writeport == 86:
writeport=136
gpio.set(writeport,1)
time.sleep(0.001)
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)
return keys
def keyread():
keys = readgpio()
verify_keys = readgpio()
if not keys == verify_keys:
return
temp = 0
@ -175,6 +171,7 @@ def keyread():
if not temp == 0:
print(f"\nKeys = {', '.join(keys)}")
setup()
while True:
time.sleep(0.001)