diff options
| author | Drew DeVault <sir@cmpwn.com> | 2022-02-05 09:41:17 +0100 |
|---|---|---|
| committer | Drew DeVault <sir@cmpwn.com> | 2022-02-05 09:41:17 +0100 |
| commit | 0fdfa823b404fff3d18d72bf2dccfe0ce444cfd5 (patch) | |
| tree | baea256e596312905159b8d860a07ebc553ef2fd | |
| parent | add gl.ha (diff) | |
| download | hare-chip8-0fdfa823b404fff3d18d72bf2dccfe0ce444cfd5.tar.gz | |
Add controller rumble support
Signed-off-by: Drew DeVault <sir@cmpwn.com>
| -rw-r--r-- | cmd/demo/main.ha | 1 | ||||
| -rw-r--r-- | sdl2/gamecontroller.ha | 26 |
2 files changed, 27 insertions, 0 deletions
diff --git a/cmd/demo/main.ha b/cmd/demo/main.ha index e97c433..3cac391 100644 --- a/cmd/demo/main.ha +++ b/cmd/demo/main.ha @@ -62,6 +62,7 @@ fn run() (void | fs::error | sdl2::error) = { match (sdl2::game_controller_open(i)) { case let c: *sdl2::gamecontroller => controller = c; + sdl2::game_controller_rumble(c, 0x4000, 0x4000, 1000): void; break; case sdl2::error => void; }; diff --git a/sdl2/gamecontroller.ha b/sdl2/gamecontroller.ha index 46b5f5c..4af8677 100644 --- a/sdl2/gamecontroller.ha +++ b/sdl2/gamecontroller.ha @@ -71,3 +71,29 @@ export fn game_controller_open( // Close a game controller previously opened with [[game_controller_open]]. export @symbol("SDL_GameControllerClose") fn game_controller_close( gamecontroller: *gamecontroller) void; + +@symbol("SDL_GameControllerRumble") fn _game_controller_rumble( + gamecontroller: *gamecontroller, + low_frequency_rumble: u16, + high_frequency_rumble: u16, + duration_ms: u32) int; + +// Start a rumble effect on a game controller. +// +// Each call to this function cancels any previous rumble effect, and calling +// it with 0 intensity stops any rumbling. +// +// The low-frequency motor is generally on the left, and the high-frequency +// motor is generally on the right. +export fn game_controller_rumble( + gamecontroller: *gamecontroller, + low_frequency_rumble: u16, + high_frequency_rumble: u16, + duration_ms: u32, +) (void | error) = { + return wrapvoid(_game_controller_rumble( + gamecontroller, + low_frequency_rumble, + high_frequency_rumble, + duration_ms)); +}; |
