Scan all the things. 6kro but no modifiers.
This commit is contained in:
parent
c6be0893d4
commit
58b9c37bf4
3 changed files with 66 additions and 30 deletions
|
@ -12,6 +12,6 @@ for Teensy models will be added later.
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
Copyright © 2014 Phil Hagelberg and contributors
|
Copyright © 2014-2019 Phil Hagelberg and contributors
|
||||||
|
|
||||||
Released under the [GNU GPL version 3](https://www.gnu.org/licenses/gpl.html).
|
Released under the [GNU GPL version 3](https://www.gnu.org/licenses/gpl.html).
|
||||||
|
|
16
keycodes.scm
16
keycodes.scm
|
@ -40,14 +40,8 @@
|
||||||
(define key-tab 43)
|
(define key-tab 43)
|
||||||
(define key-enter 40)
|
(define key-enter 40)
|
||||||
|
|
||||||
(define mod-ctrl 0)
|
(define mod-ctrl #x01)
|
||||||
(define mod-shift 0)
|
(define mod-shift #x02)
|
||||||
(define mod-alt 0)
|
(define mod-alt #x04)
|
||||||
(define mod-gui 0)
|
(define mod-gui #x08)
|
||||||
(define mod-fn 0)
|
(define mod-fn #x16)
|
||||||
|
|
||||||
;; (define mod-ctrl #x01)
|
|
||||||
;; (define mod-shift #x02)
|
|
||||||
;; (define mod-alt #x04)
|
|
||||||
;; (define mod-gui #x08)
|
|
||||||
;; (define mod-fn #x16)
|
|
||||||
|
|
78
menelaus.scm
78
menelaus.scm
|
@ -4,29 +4,71 @@
|
||||||
(define rows (list 0 1 2 3))
|
(define rows (list 0 1 2 3))
|
||||||
(define row-pins (vector 3 2 1 0))
|
(define row-pins (vector 3 2 1 0))
|
||||||
(define columns (list 0 1 2 3 4 5 6 7 8 9 10))
|
(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))
|
(define column-pins (vector 6 5 9 8 7 4 10 19 18 12 11))
|
||||||
|
|
||||||
(for-each-vector output row-pins)
|
(define max-keys 6)
|
||||||
(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")
|
(define (init)
|
||||||
(pause 200)
|
(for-each-vector output row-pins)
|
||||||
|
|
||||||
(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)
|
(for-each-vector high row-pins)
|
||||||
(low (vector-ref row-pins row))
|
(for-each-vector input column-pins)
|
||||||
(fold scan-column last (map (lambda (col) (+ col (* row 11))) columns)))
|
(for-each-vector high column-pins) ; activate pullup resistors
|
||||||
|
|
||||||
|
(call-c-func "usb_init")
|
||||||
|
(pause 200))
|
||||||
|
|
||||||
|
(define (offset-for row col)
|
||||||
|
(+ col (* row (length columns))))
|
||||||
|
|
||||||
|
(define (usb-send modifiers key1 key2 key3 key4 key5 key6)
|
||||||
|
(call-c-func "usb_send" modifiers key1 key2 key3 key4 key5 key6))
|
||||||
|
|
||||||
|
(define (scan-key keys-pressed key-count row col)
|
||||||
|
;; pullup resistors mean a closed circuit is low rather than high
|
||||||
|
(if (low? (vector-ref column-pins col))
|
||||||
|
(begin
|
||||||
|
(if (<= key-count max-keys)
|
||||||
|
(vector-set! keys-pressed key-count (offset-for row col))
|
||||||
|
#f)
|
||||||
|
(+ key-count 1))
|
||||||
|
key-count))
|
||||||
|
|
||||||
|
(define (scan-column keys-pressed key-count row columns-left)
|
||||||
|
(if (= (length columns-left) 0)
|
||||||
|
key-count
|
||||||
|
(let ((key-count (scan-key keys-pressed key-count row (car columns-left))))
|
||||||
|
(scan-column keys-pressed key-count row (cdr columns-left)))))
|
||||||
|
|
||||||
|
(define (activate-row row)
|
||||||
|
(for-each-vector high row-pins)
|
||||||
|
(low (vector-ref row-pins row)))
|
||||||
|
|
||||||
|
(define (scan-matrix keys-pressed key-count rows-left)
|
||||||
|
(if (= (length rows-left) 0)
|
||||||
|
key-count
|
||||||
|
(let ((_ (activate-row (car rows-left)))
|
||||||
|
(key-count (scan-column keys-pressed key-count
|
||||||
|
(car rows-left) columns)))
|
||||||
|
(scan-matrix keys-pressed key-count (cdr rows-left)))))
|
||||||
|
|
||||||
|
(define (layout-lookup key-position)
|
||||||
|
(vector-ref layout key-position))
|
||||||
|
|
||||||
|
(define (keycodes-for keys-pressed key-count keycodes)
|
||||||
|
(if (= 0 key-count)
|
||||||
|
(vector->list keycodes)
|
||||||
|
(let ((keycode (vector-ref layout (vector-ref keys-pressed key-count))))
|
||||||
|
;; (printf "keycode ~s ~s~n" keycode key-count)
|
||||||
|
(vector-set! keycodes key-count keycode)
|
||||||
|
(keycodes-for keys-pressed (- key-count 1) keycodes))))
|
||||||
|
|
||||||
(define (loop)
|
(define (loop)
|
||||||
(let ((pressed (free! (fold scan-row 0 rows))))
|
(free! (let ((keys-pressed (vector 0 0 0 0 0 0 0)))
|
||||||
(call-c-func "usb_send" 0 pressed 0 0 0 0 0))
|
(let ((key-count (scan-matrix keys-pressed 1 rows)))
|
||||||
|
(apply usb-send (keycodes-for keys-pressed (- key-count 1)
|
||||||
|
(vector 0 0 0 0 0 0 0))))))
|
||||||
(loop))
|
(loop))
|
||||||
|
|
||||||
|
;;; showtime!
|
||||||
|
(init)
|
||||||
(loop)
|
(loop)
|
||||||
|
|
Loading…
Reference in a new issue