Fumofumotris/rewrite/src/input.zig
2024-05-24 00:36:13 -05:00

43 lines
852 B
Zig

const std = @import("std");
const fumo = @import("fumostd.zig");
const IO_BUF_SIZE: usize = 16;
const STR_BUF_SIZE: usize = IO_BUF_SIZE * 4;
const Record = struct {
scancode: usize,
data: f64,
time: u64,
is_down: bool,
};
const Handle = struct {
record_buffer: fumo.RingBuffer(Record, IO_BUF_SIZE),
string_buffer: fumo.RingBuffer(u8, STR_BUF_SIZE),
thread: std.Thread,
mutex: std.Thread.Mutex = std.Thread.Mutex{},
pub fn init() !Handle {
const handle = Handle{
.thread = try std.Thread.spawn(.{}, handle.worker, .{}),
};
return handle;
}
fn worker(this: @This()) void {
while (true) {
// block platform read in
this.mutex.lock();
this.record_buffer.write(input);
this.mutex.unlock();
}
}
};