diff --git a/menelaus.scm b/menelaus.scm index 19153b2..3415b3b 100644 --- a/menelaus.scm +++ b/menelaus.scm @@ -201,19 +201,18 @@ (call-c-func "usb_init") (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 "usb_send" - (vector-ref modifiers 0) (vector-ref modifiers 1) - (vector-ref modifiers 2) (vector-ref modifiers 3) - k0 k1 k2 k3 k4 k5)) + (let ((mods (+ (vector-ref m 0) (* (vector-ref m 1) 2)))) ; plus isn't variadic + (let ((mods (+ mods (+ (* (vector-ref m 2) 4) (* (vector-ref m 3) 8))))) + (call-c-func "usb_send" mods k0 k1 k2 k3 k4 k5)))) (define (loop) ;; scanning the matrix tells us only which physical keys were pressed and ;; how many; it doesn't tell us which keycodes to send yet. (free! (let ((keys-scanned (debounce-matrix))) (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)) (init) diff --git a/test.rkt b/test.rkt index c37525a..eb95943 100644 --- a/test.rkt +++ b/test.rkt @@ -18,12 +18,14 @@ (define last-usb-frame #f) ; save this off so we can test it -(define (usb-save ctrl shift alt supr . args) - (set! last-usb-frame (cons (filter symbol? (list (if (= 1 ctrl) 'ctrl 0) - (if (= 1 shift) 'shift 0) - (if (= 1 alt) 'alt 0) - (if (= 1 supr) 'super 0))) - args))) +(define (mods-list mods) + (filter symbol? (list (if (positive? (bitwise-and mods 1)) 'ctrl 0) + (if (positive? (bitwise-and mods 2)) 'shift 0) + (if (positive? (bitwise-and mods 4)) 'alt 0) + (if (positive? (bitwise-and mods 8)) 'super 0)))) + +(define (usb-save mods . args) + (set! last-usb-frame (cons (mods-list mods) args))) (define (call-c-func f-name . args) (when (equal? f-name "usb_send") diff --git a/usb_keyboard.c b/usb_keyboard.c index f531d78..7625ebf 100644 --- a/usb_keyboard.c +++ b/usb_keyboard.c @@ -337,10 +337,10 @@ int8_t usb_keyboard_send(void) } // 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 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[1] = (uint8_t)key1; keyboard_keys[2] = (uint8_t)key2;