Cube 9 달 전
부모
커밋
139222b912
2개의 변경된 파일36개의 추가작업 그리고 3개의 파일을 삭제
  1. 28
    0
      CARDPUTER CircuitPython/full_display_test.py
  2. 8
    3
      CARDPUTER CircuitPython/keyboard.py

+ 28
- 0
CARDPUTER CircuitPython/full_display_test.py 파일 보기

@@ -0,0 +1,28 @@
1
+import board
2
+import terminalio
3
+from adafruit_display_text import label
4
+from keyboard import Keyboard
5
+
6
+# GUIDE
7
+# type freely! CTRL+D clears the text.
8
+# backspace, space, and return function as expected.
9
+# keys not recognised WILL print "UNKNOWN 0x??", but this is useful for extra key scans
10
+######
11
+
12
+keyb = Keyboard()
13
+
14
+text = ""
15
+text_area = label.Label(terminalio.FONT, text=text)
16
+text_area.x = 10
17
+text_area.y = 10
18
+board.DISPLAY.root_group = text_area
19
+
20
+while True:
21
+    key = keyb.scan()
22
+    if key == "BACKSP":
23
+        text = text[:-1]
24
+    elif key == "CTRLD":
25
+        text = ""
26
+    else:
27
+        text = text+key
28
+    text_area.text = text

+ 8
- 3
CARDPUTER CircuitPython/keyboard.py 파일 보기

@@ -4,7 +4,7 @@ class Keyboard:
4 4
     def __init__(self):
5 5
         # the number row starts with 3 and ends with the number, e.g. key number 5 is 0x35
6 6
         self.number_row=["0x30","0x31","0x32","0x33","0x34","0x35","0x36","0x37","0x38","0x39"]
7
-        self.shift_number_row={"0x21":"!","0x40":"@","0x23":"#","0x24":"$","0x25":"%","0x5e":"^","0x26":"&","0x2a":"*","0x28":"(","0x29":")"}
7
+        self.chars={"0x21":"!","0x40":"@","0x23":"#","0x24":"$","0x25":"%","0x5e":"^","0x26":"&","0x2a":"*","0x28":"(","0x29":")", "0x3f":"?"}
8 8
         self.lowercase={
9 9
             "0x71":"q", "0x77":"w", "0x65":"e", "0x72":"r", "0x74":"t", "0x79":"y", "0x75":"u", "0x69":"i", "0x6f":"o", "0x70":"p",
10 10
             "0x61":"a", "0x73":"s", "0x64":"d", "0x66":"f", "0x67":"g", "0x68":"h", "0x6a":"j", "0x6b":"k", "0x6c":"l",
@@ -15,6 +15,9 @@ class Keyboard:
15 15
             "0x41":"A", "0x53":"S", "0x44":"D", "0x46":"F", "0x47":"G", "0x48":"H", "0x4a":"J", "0x4b":"K", "0x4c":"L",
16 16
             "0x5a":"Z", "0x58":"X", "0x43":"C", "0x56":"V", "0x42":"B", "0x4e":"N", "0x4d":"M"
17 17
         }
18
+        self.special={
19
+            "0xa":"\n", "0x8":"BACKSP", "0x20":" ", "0x3b":"UP", "0x2e":"DOWN", "0x2c":"LEFT", "0x2f":"RIGHT", "0x10d":"OPTD", "0x4":"CTRLD", "0x13":"CTRLS"
20
+        }
18 21
 
19 22
     def scan(self):
20 23
         code=hex(ord(sys.stdin.read(1)))
@@ -23,12 +26,14 @@ class Keyboard:
23 26
         key = None
24 27
         if code in self.number_row:
25 28
             key = str(self.number_row.index(code))
26
-        elif code in self.shift_number_row:
27
-            key = self.shift_number_row[code]
29
+        elif code in self.chars:
30
+            key = self.chars[code]
28 31
         elif code in self.lowercase:
29 32
             key = self.lowercase[code]
30 33
         elif code in self.uppercase:
31 34
             key = self.uppercase[code]
35
+        elif code in self.special:
36
+            key = self.special[code]
32 37
             
33 38
         if key:
34 39
             return key