Skip to content

Instantly share code, notes, and snippets.

@creationix
Last active January 13, 2020 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save creationix/1c9c15dcf654c6a00f570a5500c8a81a to your computer and use it in GitHub Desktop.
Save creationix/1c9c15dcf654c6a00f570a5500c8a81a to your computer and use it in GitHub Desktop.
Reading Asus bluetooth gamepad events in zig.
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