├── M100Keyboard.py ├── README.md └── model100KeyboardGPIO.png /M100Keyboard.py: -------------------------------------------------------------------------------- 1 | """ 2 | Test code to read TRS-80 Model 100 Keyboard and send chars to uinput . 3 | written by Codeman 4 | 5 | """ 6 | import uinput 7 | import RPi.GPIO as GPIO 8 | import time 9 | import threading 10 | GPIO.setmode(GPIO.BCM) 11 | GPIO.setwarnings(False) 12 | pin=0 13 | debounce = .01 14 | delay = .1 15 | control = 0 16 | shift = 0 17 | alt=0 18 | code = 0 19 | c0 = 4 20 | c1 = 17 21 | c2 = 18 22 | c3 = 27 23 | c4 = 22 24 | c5 = 23 25 | c6 = 24 26 | c7 = 25 27 | c8 = 5 28 | 29 | r0 = 6 30 | r1 = 12 31 | r2 = 13 32 | r3 = 19 33 | r4 = 16 34 | r5 = 26 35 | r6 = 20 36 | r7 = 21 37 | 38 | lookup = [ 39 | uinput.KEY_Z, uinput.KEY_A, uinput.KEY_Q, uinput.KEY_O, uinput.KEY_1, uinput.KEY_9, uinput.KEY_SPACE, uinput.KEY_F1, uinput.KEY_LEFTSHIFT, 40 | uinput.KEY_X, uinput.KEY_S, uinput.KEY_W, uinput.KEY_P, uinput.KEY_2, uinput.KEY_0, uinput.KEY_BACKSPACE, uinput.KEY_F2, uinput.KEY_LEFTCTRL, 41 | uinput.KEY_C, uinput.KEY_D, uinput.KEY_E, uinput.KEY_RIGHTBRACE, uinput.KEY_3, uinput.KEY_MINUS, uinput.KEY_TAB, uinput.KEY_F3, uinput.KEY_LEFTALT, 42 | uinput.KEY_V, uinput.KEY_F, uinput.KEY_R, uinput.KEY_SEMICOLON, uinput.KEY_4, uinput.KEY_EQUAL, uinput.KEY_ESC, uinput.KEY_F4, uinput.KEY_LEFTSHIFT, 43 | uinput.KEY_B, uinput.KEY_G, uinput.KEY_T, uinput.KEY_APOSTROPHE, uinput.KEY_5, uinput.KEY_LEFT, uinput.KEY_F9, uinput.KEY_F5, uinput.KEY_LEFTSHIFT, 44 | uinput.KEY_N, uinput.KEY_H, uinput.KEY_Y, uinput.KEY_COMMA, uinput.KEY_6, uinput.KEY_RIGHT, uinput.KEY_F10, uinput.KEY_F6, uinput.KEY_LEFTSHIFT, 45 | uinput.KEY_M, uinput.KEY_J, uinput.KEY_U, uinput.KEY_DOT, uinput.KEY_7, uinput.KEY_UP, uinput.KEY_F11, uinput.KEY_F7, uinput.KEY_LEFTSHIFT, 46 | uinput.KEY_L, uinput.KEY_K, uinput.KEY_I, uinput.KEY_SLASH, uinput.KEY_8, uinput.KEY_DOWN, uinput.KEY_ENTER, uinput.KEY_F8, uinput.KEY_F12, 47 | uinput.KEY_PAGEUP, uinput.KEY_PAGEDOWN, 48 | ] 49 | device = uinput.Device([ 50 | uinput.KEY_Z, uinput.KEY_A, uinput.KEY_Q, uinput.KEY_O, uinput.KEY_1, uinput.KEY_9, uinput.KEY_SPACE, uinput.KEY_F1, uinput.KEY_LEFTSHIFT, 51 | uinput.KEY_X, uinput.KEY_S, uinput.KEY_W, uinput.KEY_P, uinput.KEY_2, uinput.KEY_0, uinput.KEY_BACKSPACE, uinput.KEY_F2, uinput.KEY_LEFTCTRL, 52 | uinput.KEY_C, uinput.KEY_D, uinput.KEY_E, uinput.KEY_RIGHTBRACE, uinput.KEY_3, uinput.KEY_MINUS, uinput.KEY_TAB, uinput.KEY_F3, uinput.KEY_LEFTALT, 53 | uinput.KEY_V, uinput.KEY_F, uinput.KEY_R, uinput.KEY_SEMICOLON, uinput.KEY_4, uinput.KEY_EQUAL, uinput.KEY_ESC, uinput.KEY_F4, uinput.KEY_LEFTSHIFT, 54 | uinput.KEY_B, uinput.KEY_G, uinput.KEY_T, uinput.KEY_APOSTROPHE, uinput.KEY_5, uinput.KEY_LEFT, uinput.KEY_F9, uinput.KEY_F5, uinput.KEY_LEFTSHIFT, 55 | uinput.KEY_N, uinput.KEY_H, uinput.KEY_Y, uinput.KEY_COMMA, uinput.KEY_6, uinput.KEY_RIGHT, uinput.KEY_F10, uinput.KEY_F6, uinput.KEY_LEFTSHIFT, 56 | uinput.KEY_M, uinput.KEY_J, uinput.KEY_U, uinput.KEY_DOT, uinput.KEY_7, uinput.KEY_UP, uinput.KEY_F11, uinput.KEY_F7, uinput.KEY_LEFTSHIFT, 57 | uinput.KEY_L, uinput.KEY_K, uinput.KEY_I, uinput.KEY_SLASH, uinput.KEY_8, uinput.KEY_DOWN, uinput.KEY_ENTER, uinput.KEY_F8, uinput.KEY_F12, 58 | ]) 59 | 60 | def checkKB(row): 61 | global control, shift, alt, code 62 | col=-1 63 | 64 | if GPIO.input(c8) == True: #col 8 65 | time.sleep(debounce) 66 | if GPIO.input(c8) == True: 67 | if row==0: 68 | shift=1 69 | elif row==1: 70 | control=1 71 | elif row==5: 72 | shift=1 73 | elif row==2: 74 | alt =1 75 | elif row == 3: 76 | code = 1 77 | 78 | else: 79 | col = 8 80 | else : 81 | shift =0 82 | control =0 83 | alt =0 84 | 85 | if GPIO.input(c0) == True: 86 | time.sleep(debounce) 87 | if GPIO.input(c0) == True: 88 | col = 0 89 | if GPIO.input(c1) == True: 90 | time.sleep(debounce) 91 | if GPIO.input(c1) == True: 92 | col = 1 93 | if GPIO.input(c2) == True: 94 | time.sleep(debounce) 95 | if GPIO.input(c2) == True: 96 | col = 2 97 | if GPIO.input(c3) == True: 98 | time.sleep(debounce) 99 | if GPIO.input(c3) == True: 100 | col = 3 101 | if GPIO.input(c4) == True: 102 | time.sleep(debounce) 103 | if GPIO.input(c4) == True: 104 | col = 4 105 | if GPIO.input(c5) == True: 106 | time.sleep(debounce) 107 | if GPIO.input(c5) == True: 108 | col = 5 109 | if GPIO.input(c6) == True: 110 | time.sleep(debounce) 111 | if GPIO.input(c6) == True: 112 | col = 6 113 | if GPIO.input(c7) == True: 114 | time.sleep(debounce) 115 | if GPIO.input(c7) == True: 116 | col = 7 117 | if col!=-1: 118 | 119 | key=lookup[row*9+col] 120 | 121 | if control==1 : 122 | 123 | device.emit_combo([uinput.KEY_LEFTCTRL, key]) 124 | control=0 125 | elif shift==1: 126 | 127 | device.emit_combo([uinput.KEY_LEFTSHIFT, key]) 128 | shift=0 129 | elif alt==1: 130 | 131 | device.emit_combo([uinput.KEY_LEFTALT, key]) 132 | alt=0 133 | elif code==1: 134 | 135 | if row==6 and col ==5: 136 | device.emit_click(uinput.KEY_PAGEUP) 137 | 138 | if row==7 and col ==5: 139 | device.emit_click(uinput.KEY_PAGEDOWN) 140 | 141 | if row==3 and col ==3: 142 | device.emit_click((0x01,124)) 143 | 144 | code=0 145 | else: 146 | 147 | device.emit_click(key) 148 | 149 | time.sleep(delay) 150 | col=-1 151 | def scanKB(): 152 | 153 | GPIO.output(r0, GPIO.HIGH) 154 | checkKB(0) 155 | GPIO.output(r0, GPIO.LOW) 156 | 157 | GPIO.output(r1, GPIO.HIGH) 158 | checkKB(1) 159 | GPIO.output(r1, GPIO.LOW) 160 | 161 | GPIO.output(r2, GPIO.HIGH) 162 | checkKB(2) 163 | GPIO.output(r2, GPIO.LOW) 164 | 165 | GPIO.output(r3, GPIO.HIGH) 166 | checkKB(3) 167 | GPIO.output(r3, GPIO.LOW) 168 | 169 | GPIO.output(r4, GPIO.HIGH) 170 | checkKB(4) 171 | GPIO.output(r4, GPIO.LOW) 172 | 173 | GPIO.output(r5, GPIO.HIGH) 174 | checkKB(5) 175 | GPIO.output(r5, GPIO.LOW) 176 | 177 | GPIO.output(r6, GPIO.HIGH) 178 | checkKB(6) 179 | GPIO.output(r6, GPIO.LOW) 180 | 181 | 182 | GPIO.output(r7, GPIO.HIGH) 183 | checkKB(7) 184 | GPIO.output(r7, GPIO.LOW) 185 | 186 | 187 | 188 | GPIO.setup(c0, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 189 | GPIO.setup(c1, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 190 | GPIO.setup(c2, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 191 | GPIO.setup(c3, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 192 | GPIO.setup(c4, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 193 | GPIO.setup(c5, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 194 | GPIO.setup(c6, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 195 | GPIO.setup(c7, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 196 | GPIO.setup(c8, GPIO.IN, pull_up_down=GPIO.PUD_DOWN) 197 | 198 | GPIO.setup(r0, GPIO.OUT) 199 | GPIO.setup(r1, GPIO.OUT) 200 | GPIO.setup(r2, GPIO.OUT) 201 | GPIO.setup(r3, GPIO.OUT) 202 | GPIO.setup(r4, GPIO.OUT) 203 | GPIO.setup(r5, GPIO.OUT) 204 | GPIO.setup(r6, GPIO.OUT) 205 | GPIO.setup(r7, GPIO.OUT) 206 | 207 | 208 | GPIO.output(r0, GPIO.LOW) 209 | GPIO.output(r1, GPIO.LOW) 210 | GPIO.output(r2, GPIO.LOW) 211 | GPIO.output(r3, GPIO.LOW) 212 | GPIO.output(r4, GPIO.LOW) 213 | GPIO.output(r5, GPIO.LOW) 214 | GPIO.output(r6, GPIO.LOW) 215 | GPIO.output(r7, GPIO.LOW) 216 | 217 | while True: 218 | scanKB() 219 | time.sleep(.005) 220 | GPIO.cleanup() 221 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TRS-80-Model-100-Raspberry-Pi-Keyboard 2 | Quick Python to scan Model 100 keyboard and send chars to uinput 3 | -------------------------------------------------------------------------------- /model100KeyboardGPIO.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TheCodeman/TRS-80-Model-100-Raspberry-Pi-Keyboard/c94f2df9b7499478daa11d61d7fe3ffaaa20baa4/model100KeyboardGPIO.png --------------------------------------------------------------------------------