From a1a6a5cf18241da4cc5869d6b69ecbc89ffcec93 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Fri, 27 Jul 2018 15:18:55 +0200 Subject: [PATCH 1/2] Fix version check --- src/psmove.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/psmove.c b/src/psmove.c index 3285947d..8c7c990f 100644 --- a/src/psmove.c +++ b/src/psmove.c @@ -276,14 +276,13 @@ psmove_get_half_frame(PSMove *move, enum PSMove_Sensor sensor, enum PSMove_Bool psmove_init(enum PSMove_Version version) { - /** - * You could do initialization here. Be sure to always check - * if initialization has already been carried out, as this - * might be called multiple times, even after succeeding once. - **/ + // Compile-time version of the library is PSMOVE_CURRENT_VERSION + // Compile-time version of the user code is the value of "version" - /* For now, assume future versions will be backwards-compatible */ - if (version >= PSMOVE_CURRENT_VERSION) { + // The requested version must be equal or less than the version implemented, + // but it's okay if the requested version is less than the implemented version, + // as we (try to) be backwards compatible with older API users + if (version <= PSMOVE_CURRENT_VERSION) { return PSMove_True; } else { return PSMove_False; From 2bf06a637e90b73d56ddc1b9e29728639a1d1e00 Mon Sep 17 00:00:00 2001 From: Thomas Perl Date: Fri, 27 Jul 2018 15:19:16 +0200 Subject: [PATCH 2/2] Take PSMOVE_CURRENT_VERSION from CMake (Fixes #360) --- include/psmove.h | 11 +++-------- include/psmove_config.h.in | 5 +++++ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/include/psmove.h b/include/psmove.h index 03071181..2fffabce 100644 --- a/include/psmove.h +++ b/include/psmove.h @@ -231,14 +231,9 @@ typedef struct _PSMove_3AxisTransform PSMove_3AxisTransform; /*! Library version number */ enum PSMove_Version { - /** - * Version format: AA.BB.CC = 0xAABBCC - * - * Examples: - * 3.0.1 = 0x030001 - * 4.2.11 = 0x04020B - **/ - PSMOVE_CURRENT_VERSION = 0x030001, /*!< Current version, see psmove_init() */ + PSMOVE_CURRENT_VERSION = (PSMOVEAPI_VERSION_MAJOR << 16) | + (PSMOVEAPI_VERSION_MINOR << 8) | + (PSMOVEAPI_VERSION_PATCH << 0) }; /** diff --git a/include/psmove_config.h.in b/include/psmove_config.h.in index bfc16bcb..84e78586 100644 --- a/include/psmove_config.h.in +++ b/include/psmove_config.h.in @@ -33,3 +33,8 @@ #cmakedefine PSMOVE_BUILD_TRACKER #cmakedefine PSMOVE_USE_PSEYE + +/* Version information */ +#define PSMOVEAPI_VERSION_MAJOR @PSMOVEAPI_VERSION_MAJOR@ +#define PSMOVEAPI_VERSION_MINOR @PSMOVEAPI_VERSION_MINOR@ +#define PSMOVEAPI_VERSION_PATCH @PSMOVEAPI_VERSION_PATCH@