Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add hid_version/hid_version_str API #192

Merged
merged 3 commits into from
Oct 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions HACKING.txt
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
This file is mostly for the maintainer.

1. Build hidapi.dll
2. Build hidtest.exe in DEBUG and RELEASE
3. Commit all

4. Run the Following
export VERSION=0.1.0
export TAG_NAME=hidapi-$VERSION
git tag $TAG_NAME
git archive --format zip --prefix $TAG_NAME/ $TAG_NAME >../$TAG_NAME.zip
5. Test the zip file.
6. Run the following:
git push origin $TAG_NAME
Updating a Version:
1. Update VERSION file.
2. HID_API_VERSION_MAJOR/HID_API_VERSION_MINOR/HID_API_VERSION_PATCH in hidapi.h.

Firing a new release:
1. Update the Version (if not yet updated).
2. Build hidapi.dll/.lib for x86/x64.
3. Upload Windows binaries to Github release page.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.9.0
9 changes: 1 addition & 8 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
AC_PREREQ(2.63)

# Version number. This is currently the only place.
m4_define([HIDAPI_MAJOR], 0)
m4_define([HIDAPI_MINOR], 9)
m4_define([HIDAPI_RELEASE], 0)
m4_define([HIDAPI_RC], )
m4_define([VERSION_STRING], HIDAPI_MAJOR[.]HIDAPI_MINOR[.]HIDAPI_RELEASE[]HIDAPI_RC)

AC_INIT([hidapi],[VERSION_STRING],[alan@signal11.us])
AC_INIT([hidapi],[m4_normalize(m4_builtin([include], VERSION))],[https://github.com/libusb/hidapi/issues])

# Library soname version
# Follow the following rules (particularly the ones in the second link):
Expand Down
2 changes: 1 addition & 1 deletion dist/hidapi.podspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
Pod::Spec.new do |spec|

spec.name = "hidapi"
spec.version = "0.9.0"
spec.version = "<fill me up from VERSION file, before submit>"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it's possible to read version from VERSION file
spec.version = File.read('../VERSION')
I'm going to try this during publishing 0.10.0, and if it will work, I create a PR

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds great

spec.summary = "A Simple library for communicating with USB and Bluetooth HID devices on Linux, Mac and Windows."

spec.description = <<-DESC
Expand Down
52 changes: 52 additions & 0 deletions hidapi/hidapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,42 @@

#define HID_API_EXPORT_CALL HID_API_EXPORT HID_API_CALL /**< API export and call macro*/

/** @brief Static/compile-time major version of the library.

@ingroup API
*/
#define HID_API_VERSION_MAJOR 0
/** @brief Static/compile-time minor version of the library.

@ingroup API
*/
#define HID_API_VERSION_MINOR 9
/** @brief Static/compile-time patch version of the library.

@ingroup API
*/
#define HID_API_VERSION_PATCH 0

/* Helper macros */
#define HID_API_AS_STR_IMPL(x) #x
#define HID_API_AS_STR(x) HID_API_AS_STR_IMPL(x)
#define HID_API_TO_VERSION_STR(v1, v2, v3) HID_API_AS_STR(v1.v2.v3)

/** @brief Static/compile-time string version of the library.

@ingroup API
*/
#define HID_API_VERSION_STR HID_API_TO_VERSION_STR(HID_API_VERSION_MAJOR, HID_API_VERSION_MINOR, HID_API_VERSION_PATCH)

#ifdef __cplusplus
extern "C" {
#endif
struct hid_api_version {
int major;
int minor;
int patch;
};

struct hid_device_;
typedef struct hid_device_ hid_device; /**< opaque hidapi structure */

Expand Down Expand Up @@ -438,6 +471,25 @@ extern "C" {
*/
HID_API_EXPORT const wchar_t* HID_API_CALL hid_error(hid_device *dev);

/** @brief Get a runtime version of the library.

@ingroup API

@returns
Pointer to statically allocated struct, that contains version.
*/
HID_API_EXPORT const struct hid_api_version* HID_API_CALL hid_version();


/** @brief Get a runtime version string of the library.

@ingroup API

@returns
Pointer to statically allocated string, that contains version string.
*/
HID_API_EXPORT const char* HID_API_CALL hid_version_str();

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 9 additions & 1 deletion hidtest/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,15 @@ int main(int argc, char* argv[])
#endif

struct hid_device_info *devs, *cur_dev;


printf("hidapi test/example tool. Compiled with hidapi version %s, runtime version %s.\n", HID_API_VERSION_STR, hid_version_str());
if (hid_version()->major == HID_API_VERSION_MAJOR && hid_version()->minor == HID_API_VERSION_MINOR && hid_version()->patch == HID_API_VERSION_PATCH) {
printf("Compile-time version matches runtime version of hidapi.\n\n");
}
else {
printf("Compile-time version is different than runtime version of hidapi.\n]n");
}

if (hid_init())
return -1;

Expand Down
15 changes: 15 additions & 0 deletions libusb/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@ struct hid_device_ {
#endif
};

static struct hid_api_version api_version = {
.major = HID_API_VERSION_MAJOR,
.minor = HID_API_VERSION_MINOR,
.patch = HID_API_VERSION_PATCH
};

static libusb_context *usb_context = NULL;

uint16_t get_usb_code_for_current_locale(void);
Expand Down Expand Up @@ -490,6 +496,15 @@ static char *make_path(libusb_device *dev, int interface_number)
return strdup(str);
}

HID_API_EXPORT const struct hid_api_version* HID_API_CALL hid_version()
{
return &api_version;
}

HID_API_EXPORT const char* HID_API_CALL hid_version_str()
{
return HID_API_VERSION_STR;
}

int HID_API_EXPORT hid_init(void)
{
Expand Down
16 changes: 16 additions & 0 deletions linux/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ struct hid_device_ {
wchar_t *last_error_str;
};

static struct hid_api_version api_version = {
.major = HID_API_VERSION_MAJOR,
.minor = HID_API_VERSION_MINOR,
.patch = HID_API_VERSION_PATCH
};

/* Global error message that is not specific to a device, e.g. for
hid_open(). It is thread-local like errno. */
__thread wchar_t *last_global_error_str = NULL;
Expand Down Expand Up @@ -374,6 +380,16 @@ static int get_device_string(hid_device *dev, enum device_string_id key, wchar_t
return ret;
}

HID_API_EXPORT const struct hid_api_version* HID_API_CALL hid_version()
{
return &api_version;
}

HID_API_EXPORT const char* HID_API_CALL hid_version_str()
{
return HID_API_VERSION_STR;
}

int HID_API_EXPORT hid_init(void)
{
const char *locale;
Expand Down
16 changes: 16 additions & 0 deletions mac/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,12 @@ static void free_hid_device(hid_device *dev)
free(dev);
}

static struct hid_api_version api_version = {
.major = HID_API_VERSION_MAJOR,
.minor = HID_API_VERSION_MINOR,
.patch = HID_API_VERSION_PATCH
};

static IOHIDManagerRef hid_mgr = 0x0;


Expand Down Expand Up @@ -374,6 +380,16 @@ static int init_hid_manager(void)
return -1;
}

HID_API_EXPORT const struct hid_api_version* HID_API_CALL hid_version()
{
return &api_version;
}

HID_API_EXPORT const char* HID_API_CALL hid_version_str()
{
return HID_API_VERSION_STR;
}

/* Initialize the IOHIDManager if necessary. This is the public function, and
it is safe to call this function repeatedly. Return 0 for success and -1
for failure. */
Expand Down
16 changes: 16 additions & 0 deletions windows/hid.c
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ extern "C" {
extern "C" {
#endif

static struct hid_api_version api_version = {
.major = HID_API_VERSION_MAJOR,
.minor = HID_API_VERSION_MINOR,
.patch = HID_API_VERSION_PATCH
};

#ifndef HIDAPI_USE_DDK
/* Since we're not building with the DDK, and the HID header
files aren't part of the SDK, we have to define all this
Expand Down Expand Up @@ -257,6 +263,16 @@ static HANDLE open_device(const char *path, BOOL open_rw)
return handle;
}

HID_API_EXPORT const struct hid_api_version* HID_API_CALL hid_version()
{
return &api_version;
}

HID_API_EXPORT const char* HID_API_CALL hid_version_str()
{
return HID_API_VERSION_STR;
}

int HID_API_EXPORT hid_init(void)
{
#ifndef HIDAPI_USE_DDK
Expand Down