Last active
January 13, 2020 17:03
-
-
Save creationix/1c9c15dcf654c6a00f570a5500c8a81a to your computer and use it in GitHub Desktop.
Reading Asus bluetooth gamepad events in zig.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const std = @import("std"); | |
const File = std.fs.File; | |
const InputEvent = packed struct { | |
sec: u64, | |
usec: u64, | |
type: u16, | |
code: u16, | |
value: i32, | |
}; | |
pub fn main() !void { | |
const file = try File.openRead("/dev/input/event17"); | |
defer file.close(); | |
var array: [@sizeOf(InputEvent)]u8 = undefined; | |
while ((try file.read(&array)) > 0) { | |
std.debug.warn("{}\n", @bitCast(InputEvent, array)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment