Comment a little bit the current situation
This commit is contained in:
parent
a3b089ebc0
commit
e7debb2e1d
|
@ -48,7 +48,6 @@ pub fn main() !void {
|
|||
return error.LeapSetAllocatorError;
|
||||
}
|
||||
|
||||
//var message: leapc.LEAP_CONNECTION_MESSAGE = std.mem.zeroes(leapc.LEAP_CONNECTION_MESSAGE);
|
||||
var message: leapc.LEAP_CONNECTION_MESSAGE = std.mem.zeroInit(leapc.LEAP_CONNECTION_MESSAGE, .{});
|
||||
|
||||
while (keep_running) {
|
||||
|
@ -69,11 +68,21 @@ pub fn main() !void {
|
|||
std.debug.print("Connected!\n", .{});
|
||||
},
|
||||
leapc.eLeapEventType_Tracking => {
|
||||
const frame: *const leapc.LEAP_TRACKING_EVENT = message.unnamed_0.tracking_event;
|
||||
std.debug.print("Frame id {d}, {d} hands found\n", .{ frame.tracking_frame_id, frame.nHands });
|
||||
|
||||
// Those are equivalent, you can grab the tracking event directly from the unnamed union,
|
||||
// or cast the pointer found in the union to whatever event you have
|
||||
// const frame: *const leapc.LEAP_TRACKING_EVENT = message.unnamed_0.tracking_event;
|
||||
const frame: *const leapc.LEAP_TRACKING_EVENT = @as(*const leapc.LEAP_TRACKING_EVENT, @ptrCast((@alignCast(message.unnamed_0.pointer))));
|
||||
|
||||
// Printing some of the data, all right, proves that we grabbed it properly
|
||||
// Interestingly, FPS shows 0 which lead to think that pHands and everything after pHands is wacked
|
||||
std.debug.print("Frame id {d}, {d} hands found. FPS: {d}\n", .{ frame.tracking_frame_id, frame.nHands, frame.framerate });
|
||||
|
||||
for (0..frame.nHands) |i| {
|
||||
// This SEGFAULT ! What is going on ?
|
||||
const hand: leapc.LEAP_HAND = frame.pHands[i];
|
||||
std.debug.print(hand_fmt, .{ hand.id, if (hand.type == leapc.eLeapHandType_Left) "Left" else "Right" });
|
||||
std.debug.print("{d}\n", .{hand.palm.position.unnamed_0.unnamed_0.x});
|
||||
}
|
||||
},
|
||||
else => {
|
||||
|
@ -83,11 +92,13 @@ pub fn main() !void {
|
|||
}
|
||||
}
|
||||
|
||||
/// Handler for SIGINT (sets `keep_running` to true to stop the main loop)
|
||||
fn sigintHandler(_: c_int) callconv(.C) void {
|
||||
std.debug.print("Received a sigint\n", .{});
|
||||
keep_running = false;
|
||||
}
|
||||
|
||||
/// Allocate memory for LeapC using a page allocator
|
||||
fn allocate(size: u32, typeHint: leapc.eLeapAllocatorType, _: ?*anyopaque) callconv(.C) ?*anyopaque {
|
||||
const allocator = std.heap.page_allocator;
|
||||
switch (typeHint) {
|
||||
|
@ -157,6 +168,8 @@ fn allocate(size: u32, typeHint: leapc.eLeapAllocatorType, _: ?*anyopaque) callc
|
|||
}
|
||||
}
|
||||
|
||||
/// Deallocate memory for LeapC
|
||||
fn deallocate(_: ?*anyopaque, _: ?*anyopaque) callconv(.C) void {
|
||||
//ptr.deallocate();
|
||||
// How to deallocate properly if we don't know what type we need to cast it in?
|
||||
// We could add the type to the state that is being sent to the allocator and deallocator?
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue