From 5f629927fbc1c2b601cf36d41eaad3b89bd73c55 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Mon, 8 Dec 2014 23:09:13 -0800 Subject: [PATCH] Scan the whole matrix. --- keycodes.scm | 27 +++++++++++++++++++++++---- layout.scm | 9 +++++++++ menelaus.scm | 35 ++++++++++++++++++++--------------- 3 files changed, 52 insertions(+), 19 deletions(-) create mode 100644 layout.scm diff --git a/keycodes.scm b/keycodes.scm index 495163b..c461fa2 100644 --- a/keycodes.scm +++ b/keycodes.scm @@ -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) diff --git a/layout.scm b/layout.scm new file mode 100644 index 0000000..c80f9c5 --- /dev/null +++ b/layout.scm @@ -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))) diff --git a/menelaus.scm b/menelaus.scm index 8415eab..9110258 100644 --- a/menelaus.scm +++ b/menelaus.scm @@ -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) -