Scan the whole matrix.

This commit is contained in:
Phil Hagelberg 2014-12-08 23:09:13 -08:00
parent 20df8134c1
commit 5f629927fb
3 changed files with 52 additions and 19 deletions

View file

@ -28,7 +28,26 @@
(define key-z 29)
(define key-semicolon 51)
(define mod-ctrl #x01)
(define mod-shift #x02)
(define mod-alt #x04)
(define mod-gui #x08)
(define key-comma 54)
(define key-period 55)
(define key-slash 56)
(define key-dash 45)
(define key-quote 52)
(define key-space 44)
(define key-backspace 42)
(define key-esc 41)
(define key-tab 43)
(define key-enter 40)
(define mod-ctrl 0)
(define mod-shift 0)
(define mod-alt 0)
(define mod-gui 0)
(define mod-fn 0)
;; (define mod-ctrl #x01)
;; (define mod-shift #x02)
;; (define mod-alt #x04)
;; (define mod-gui #x08)
;; (define mod-fn #x16)

9
layout.scm Normal file
View file

@ -0,0 +1,9 @@
(define layout
(list (list key-q key-w key-e key-r key-t 0
key-y key-u key-i key-o key-p)
(list key-a key-s key-d key-f key-g 0
key-h key-j key-k key-l key-semicolon)
(list key-z key-x key-c key-v key-b mod-alt
key-n key-m key-comma key-period key-slash)
(list key-esc key-tab mod-gui mod-shift key-backspace mod-ctrl
key-space mod-fn key-dash key-quote key-enter)))

View file

@ -1,22 +1,29 @@
;; -*- scheme -*-
(include "keycodes.scm")
(include "layout.scm")
(define column-pins (list 11 12 18 19 10 7 8 9 5 6))
(define layout (list key-a key-s key-d key-f key-g
key-h key-j key-k key-l key-semicolon))
(define row-pins (list 0 1 2 3))
(define column-pins (list 11 12 18 19 10 4 7 8 9 5 6))
(define (scan-column column-pins layout pressed)
(if (null? column-pins)
(define (scan-column columns row-layout pressed)
(if (null? columns)
pressed
(scan-column (cdr column-pins)
(cdr layout)
(if (low? (car column-pins))
(car layout)
(scan-column (cdr columns)
(cdr row-layout)
(if (low? (car columns))
(car row-layout)
pressed))))
(define (scan-rows rows layout-rows pressed)
(if (null? rows)
pressed
(begin
(for-each high row-pins)
(low (car rows)) ; activate row
(scan-rows (cdr rows) (cdr layout-rows)
(scan-column column-pins (car layout-rows) 0)))))
(define (loop)
(let ((pressed (scan-row column-pins layout 0)))
(let ((pressed (scan-rows row-pins layout 0)))
(call-c-func "usb_send" 0 pressed 0 0 0 0 0))
(loop))
@ -27,8 +34,7 @@
#x23 #x23 #x23 #x29 #x2D #x2D))
(set! arduino-pins (vector 4 8 2 1 16 64 128 64 16 32 64 128 64 128
8 2 4 32 65 128))
(output 1)
(low 1)
(for-each output row-pins)
(for-each input column-pins)
(for-each high column-pins) ; activate pullup resistors
(call-c-func "usb_init")
@ -36,4 +42,3 @@
(init)
(loop)