Skip to content

Commit

Permalink
Merge pull request #364 from thp/fix-versioning
Browse files Browse the repository at this point in the history
 Take PSMOVE_CURRENT_VERSION from CMake (Fixes #360)
  • Loading branch information
thp authored Jul 30, 2018
2 parents 0805e26 + 2bf06a6 commit a9fb054
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 15 deletions.
11 changes: 3 additions & 8 deletions include/psmove.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,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)
};

/**
Expand Down
5 changes: 5 additions & 0 deletions include/psmove_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -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@
13 changes: 6 additions & 7 deletions src/psmove.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,14 +289,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;
Expand Down

0 comments on commit a9fb054

Please sign in to comment.