From 21d0b631c2ee5fd5f11f6cdcd79ae0358bb37df3 Mon Sep 17 00:00:00 2001 From: Phil Hagelberg Date: Sun, 4 Jan 2015 21:18:15 -0800 Subject: [PATCH] Step 3: all the keys (except modifiers) --- layout.scm | 16 ++++++++-------- menelaus.scm | 29 ++++++++++++++++------------- 2 files changed, 24 insertions(+), 21 deletions(-) diff --git a/layout.scm b/layout.scm index c80f9c5..a1e9b67 100644 --- a/layout.scm +++ b/layout.scm @@ -1,9 +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))) + (vector key-q key-w key-e key-r key-t 0 + key-y key-u key-i key-o key-p + key-a key-s key-d key-f key-g 0 + key-h key-j key-k key-l key-semicolon + key-z key-x key-c key-v key-b mod-alt + key-n key-m key-comma key-period key-slash + 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 81da1f2..ac5caf1 100644 --- a/menelaus.scm +++ b/menelaus.scm @@ -1,28 +1,31 @@ (include "keycodes.scm") +(include "layout.scm") -(define columns (list 0 1 2 3 4 5 6 7 8 9)) -(define column-pins (vector 11 12 18 19 - 10 7 8 9 5 6)) -(define layout (vector key-a key-s key-d key-f key-g - key-h key-j key-k key-l key-semicolon)) - -(for-each output (list 0 1 2 3)) -(for-each high (list 0 1 3)) -(low 2) +(define rows (list 0 1 2 3)) +(define row-pins (vector 3 2 1 0)) +(define columns (list 0 1 2 3 4 5 6 7 8 9 10)) +(define column-pins (vector 11 12 18 19 10 4 7 8 9 5 6)) +(for-each-vector output row-pins) +(for-each-vector high row-pins) (for-each-vector input column-pins) (for-each-vector high column-pins) ; activate pullup resistors (call-c-func "usb_init") (pause 200) -(define (scan-column last n) - (if (low? (vector-ref column-pins n)) - (vector-ref layout n) +(define (scan-column last offset) + (if (low? (vector-ref column-pins (mod offset 11))) + (vector-ref layout offset) last)) +(define (scan-row last row) + (for-each-vector high row-pins) + (low (vector-ref row-pins row)) + (fold scan-column last (map (lambda (col) (+ col (* row 11))) columns))) + (define (loop) - (let ((pressed (fold scan-column 0 columns))) + (let ((pressed (free! (fold scan-row 0 rows)))) (call-c-func "usb_send" 0 pressed 0 0 0 0 0)) (loop))