Microscheme's apply is pretty janky.

This commit is contained in:
Phil Hagelberg 2019-07-06 16:49:29 -07:00
parent 397e659c37
commit a059395642
3 changed files with 15 additions and 14 deletions

View file

@ -201,19 +201,18 @@
(call-c-func "usb_init") (call-c-func "usb_init")
(pause 200)) (pause 200))
(define (usb-send modifiers k0 k1 k2 k3 k4 k5) (define (usb-send m k0 k1 k2 k3 k4 k5)
;; call-c-func is a special form and cannot be applied ;; call-c-func is a special form and cannot be applied
(call-c-func "usb_send" (let ((mods (+ (vector-ref m 0) (* (vector-ref m 1) 2)))) ; plus isn't variadic
(vector-ref modifiers 0) (vector-ref modifiers 1) (let ((mods (+ mods (+ (* (vector-ref m 2) 4) (* (vector-ref m 3) 8)))))
(vector-ref modifiers 2) (vector-ref modifiers 3) (call-c-func "usb_send" mods k0 k1 k2 k3 k4 k5))))
k0 k1 k2 k3 k4 k5))
(define (loop) (define (loop)
;; scanning the matrix tells us only which physical keys were pressed and ;; scanning the matrix tells us only which physical keys were pressed and
;; how many; it doesn't tell us which keycodes to send yet. ;; how many; it doesn't tell us which keycodes to send yet.
(free! (let ((keys-scanned (debounce-matrix))) (free! (let ((keys-scanned (debounce-matrix)))
(set-usb-frame (press/release-for keys-scanned)) (set-usb-frame (press/release-for keys-scanned))
(apply usb-send modifiers (vector->list keycodes-down)))) (apply usb-send (cons modifiers (vector->list keycodes-down)))))
(loop)) (loop))
(init) (init)

View file

@ -18,12 +18,14 @@
(define last-usb-frame #f) ; save this off so we can test it (define last-usb-frame #f) ; save this off so we can test it
(define (usb-save ctrl shift alt supr . args) (define (mods-list mods)
(set! last-usb-frame (cons (filter symbol? (list (if (= 1 ctrl) 'ctrl 0) (filter symbol? (list (if (positive? (bitwise-and mods 1)) 'ctrl 0)
(if (= 1 shift) 'shift 0) (if (positive? (bitwise-and mods 2)) 'shift 0)
(if (= 1 alt) 'alt 0) (if (positive? (bitwise-and mods 4)) 'alt 0)
(if (= 1 supr) 'super 0))) (if (positive? (bitwise-and mods 8)) 'super 0))))
args)))
(define (usb-save mods . args)
(set! last-usb-frame (cons (mods-list mods) args)))
(define (call-c-func f-name . args) (define (call-c-func f-name . args)
(when (equal? f-name "usb_send") (when (equal? f-name "usb_send")

View file

@ -337,10 +337,10 @@ int8_t usb_keyboard_send(void)
} }
// my own wrapper, mangled to work with the PoC microsheme FFI // my own wrapper, mangled to work with the PoC microsheme FFI
int16_t usb_send(int ctrl, int shift, int alt, int gui, int16_t usb_send(int modifiers,
int key0, int key1, int key2, int key0, int key1, int key2,
int key3, int key4, int key5) { int key3, int key4, int key5) {
keyboard_modifier_keys = (uint8_t) (ctrl) | (shift<<1) | (alt<<2) | (gui<<3); keyboard_modifier_keys = (uint8_t) modifiers;
keyboard_keys[0] = (uint8_t)key0; keyboard_keys[0] = (uint8_t)key0;
keyboard_keys[1] = (uint8_t)key1; keyboard_keys[1] = (uint8_t)key1;
keyboard_keys[2] = (uint8_t)key2; keyboard_keys[2] = (uint8_t)key2;