From 6a5cb8729af617937ea569512506d5a11258df95 Mon Sep 17 00:00:00 2001 From: David Thompson Date: Fri, 10 Nov 2017 12:12:07 -0500 Subject: Add SDL_GameControllerAddMappingsFromRW binding. * sdl2/bindings.scm (sdl-game-controller-add-mappings-from-file): New procedure. * sdl2/input/game-controller.scm (load-game-controller-mappings!): New procedure. --- sdl2/bindings.scm | 3 +++ sdl2/input/game-controller.scm | 20 +++++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) (limited to 'sdl2') diff --git a/sdl2/bindings.scm b/sdl2/bindings.scm index dd0a619..180f887 100644 --- a/sdl2/bindings.scm +++ b/sdl2/bindings.scm @@ -1071,6 +1071,9 @@ RETURN-TYPE and accept arguments of ARG-TYPES." (define-public SDL_CONTROLLER_BUTTON_DPAD_RIGHT 14) (define-public SDL_CONTROLLER_BUTTON_MAX 15) +(define-foreign sdl-game-controller-add-mappings-from-rw + int "SDL_GameControllerAddMappingsFromRW" (list '* int)) + (define-foreign sdl-game-controller-add-mapping int "SDL_GameControllerAddMapping" '(*)) diff --git a/sdl2/input/game-controller.scm b/sdl2/input/game-controller.scm index 66441a9..120cc53 100644 --- a/sdl2/input/game-controller.scm +++ b/sdl2/input/game-controller.scm @@ -30,7 +30,8 @@ #:use-module (system foreign) #:use-module ((sdl2 bindings) #:prefix ffi:) #:use-module (sdl2) - #:export (open-game-controller + #:export (load-game-controller-mappings! + open-game-controller close-game-controller game-controller? game-controller-attached? @@ -60,6 +61,23 @@ (define wrap-joystick (@@ (sdl2 input joystick) wrap-joystick)) +(define (load-game-controller-mappings! file) + "Load game controller mappings from FILE and return the number of +mappings added this way. + +See +https://raw.github.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt +for a community maintained controller mapping file." + (let ((count (ffi:sdl-game-controller-add-mappings-from-rw + (ffi:sdl-rw-from-file (string->pointer file) + (string->pointer "rb")) + 1))) + (if (= count -1) + (sdl-error "load-game-controller-mappings!" + (string-append "failed to load game controller mappings from file " + file)) + count))) + (define (open-game-controller joystick-index) "Return a game controller object for the physical joystick device associated with ." -- cgit v1.2.3