diff --git a/api_example.c b/api_example.c index 4a34479c..c55d98c4 100644 --- a/api_example.c +++ b/api_example.c @@ -49,9 +49,9 @@ int main(int argc, char **argv) { const struct SurviveSimplePoseUpdatedEvent *pose_event = survive_simple_get_pose_updated_event(&event); SurvivePose pose = pose_event->pose; FLT timecode = pose_event->time; - /*printf("%s %s (%7.3f): %f %f %f %f %f %f %f\n", survive_simple_object_name(pose_event->object), + printf("%s %s (%7.3f): %f %f %f %f %f %f %f\n", survive_simple_object_name(pose_event->object), survive_simple_serial_number(pose_event->object), timecode, pose.Pos[0], pose.Pos[1], pose.Pos[2], - pose.Rot[0], pose.Rot[1], pose.Rot[2], pose.Rot[3]);*/ + pose.Rot[0], pose.Rot[1], pose.Rot[2], pose.Rot[3]); break; } case SurviveSimpleEventType_ButtonEvent: { diff --git a/libs/cnmatrix/include/cnmatrix/cn_matrix.h b/libs/cnmatrix/include/cnmatrix/cn_matrix.h index 3e40b214..4fe697fc 100644 --- a/libs/cnmatrix/include/cnmatrix/cn_matrix.h +++ b/libs/cnmatrix/include/cnmatrix/cn_matrix.h @@ -21,7 +21,11 @@ #include +#ifdef __APPLE__ +#include +#else #include +#endif #include "cnmatrix/cn_flt.h" #include "math.h" #include "string.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c56c0538..28e1e395 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -56,6 +56,12 @@ if(USE_HIDAPI) add_definitions (-DHIDAPI) IF(WIN32) SET(SURVIVE_SRCS ${SURVIVE_SRCS} ../redist/hid-windows.c) + elseif(APPLE) + find_library(HIDAPI_LIBRARY hidapi PATHS /opt/homebrew/lib /usr/local/lib) + if(HIDAPI_LIBRARY) + list(APPEND ADDITIONAL_LIBRARIES ${HIDAPI_LIBRARY}) + include_directories(/opt/homebrew/include /usr/local/include) + endif() else() list(APPEND ADDITIONAL_LIBRARIES udev hidapi-libusb) endif() diff --git a/src/survive_kalman_lighthouses.c b/src/survive_kalman_lighthouses.c index f18daa49..91dbfc96 100644 --- a/src/survive_kalman_lighthouses.c +++ b/src/survive_kalman_lighthouses.c @@ -218,6 +218,7 @@ void error_fn(void *user, const struct CnMat *x0, const struct CnMat *x1, struct } } void survive_kalman_lighthouse_ootx(SurviveKalmanLighthouse *tracker) { + if (tracker == NULL) return; tracker->state.BSD0 = tracker->ctx->bsd[tracker->lh].fcal[0]; tracker->state.BSD1 = tracker->ctx->bsd[tracker->lh].fcal[1]; } diff --git a/src/survive_plugins.unix.h b/src/survive_plugins.unix.h index 2f09c721..6a76d9d6 100644 --- a/src/survive_plugins.unix.h +++ b/src/survive_plugins.unix.h @@ -9,12 +9,19 @@ #include #include #include +#ifdef __APPLE__ +#include +#endif #include "assert.h" #pragma GCC diagnostic ignored "-Wpedantic" +#ifdef __APPLE__ +static const char* plugin_ext() { return ".dylib"; } +#else static const char* plugin_ext() { return ".so"; } +#endif #ifndef PATH_MAX #define PATH_MAX 4096 @@ -37,8 +44,19 @@ static const char *get_so_filename() { static const char *get_exe_filename() { static char exe_path[PATH_MAX] = { 0 }; if (exe_path[0] == 0) { - size_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path)); - exe_path[len] = 0; +#ifdef __APPLE__ + uint32_t size = sizeof(exe_path); + if (_NSGetExecutablePath(exe_path, &size) != 0) { + exe_path[0] = 0; + } +#else + ssize_t len = readlink("/proc/self/exe", exe_path, sizeof(exe_path) - 1); + if (len > 0) { + exe_path[len] = 0; + } else { + exe_path[0] = 0; + } +#endif } return exe_path; }