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

Multiple device support #382

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
f0e84da
Added support for multiple devices through -d or --device
nicola02nb Dec 4, 2024
148f449
clangd-formay fix
nicola02nb Dec 4, 2024
d11c4ba
Update output.c
nicola02nb Dec 4, 2024
0167b11
Fixed output of actions for multiple devices
nicola02nb Dec 5, 2024
c3f7cb0
Small fix
nicola02nb Dec 8, 2024
bae379c
Adding test_device to connected device list
nicola02nb Dec 8, 2024
63c8270
Improved --connected for test_device
nicola02nb Dec 8, 2024
7056ae1
Added support for -d [vendorId:productId]
nicola02nb Dec 8, 2024
e55daa3
Fixed for test
nicola02nb Dec 8, 2024
4139f14
Updated find_devices() to recognise devices only once
nicola02nb Dec 8, 2024
9681924
clangd-format-fix
nicola02nb Dec 8, 2024
54ba1c9
Moved get_two_ids() from dev.c to utility.c
nicola02nb Dec 10, 2024
855b7df
Added comment to find_devices(), moved DeviceListNode to device.h
nicola02nb Dec 10, 2024
6470bc0
Tidy up texts
Sapd Jan 14, 2025
312a42b
Improved help printing
nicola02nb Feb 2, 2025
7311574
Added showing info for all devices detected
nicola02nb Jan 22, 2025
b27acdd
Preventing get_two_ids to change values in case it gives errors
nicola02nb Jan 28, 2025
5461745
Added printing vendor and product id with OUTPUT_STANDARD
nicola02nb Jan 28, 2025
65d6751
Added terminate_device_hid function that does not clear static hid me…
nicola02nb Jan 28, 2025
512e16e
Removed -d INDEX support
nicola02nb Feb 3, 2025
819a9e6
Improved memory freeing
nicola02nb Feb 3, 2025
c92ea25
Clangd fix
nicola02nb Feb 3, 2025
cdad9e8
Update GitHub Actions to use upload-artifact@v4 (#394)
nicola02nb Feb 6, 2025
d18add1
Format
Sapd Feb 21, 2025
0722115
Fixed action running on test device when different device was selected
nicola02nb Feb 22, 2025
fc1aea5
Fixed spacing for clangd
nicola02nb Feb 22, 2025
7cbaf74
Original single device feature restored
nicola02nb Feb 22, 2025
46fc7b8
Improved main logic, added some device helper function and remove unn…
nicola02nb Feb 23, 2025
741527c
Merge branch 'Sapd:master' into multiple-device-support
nicola02nb Feb 23, 2025
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
39 changes: 0 additions & 39 deletions src/dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,45 +61,6 @@ int check_range(int number, int low, int high)
return 0;
}

/**
* @brief Accept an string input like 123:456 and splits them into two ids
*
* @param input input string
* @param id1 the first (left) id
* @param id2 the secound it
* @return int 0 if successfull, or 1 if not two ids provided
*/
static int get_two_ids(char* input, int* id1, int* id2)
{
const char* delim = " :.,";

size_t sz = strlen(input);
char* str = (char*)malloc(sz + 1);
strcpy(str, input);

char* token = strtok(input, delim);
int i = 0;
while (token) {
char* endptr;
long int val = strtol(token, &endptr, 0);

if (i == 0)
*id1 = val;
else if (i == 1)
*id2 = val;

i++;
token = strtok(NULL, delim);
}

free(str);

if (i != 2) // not exactly supplied two ids
return 1;

return 0;
}

static void print_help()
{
printf("HeadsetControl Developer menu. Take caution.\n\n");
Expand Down
12 changes: 12 additions & 0 deletions src/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,15 @@ const char capabilities_str_short[NUM_CAPABILITIES]
[CAP_BT_WHEN_POWERED_ON] = '\0',
[CAP_BT_CALL_VOLUME] = '\0'
};

bool device_check_ids(struct device* device, uint16_t vid, uint16_t pid)
{
return device->idVendor == vid && device->idProduct == pid;
}

bool device_has_capability(struct device* device, enum capabilities cap)
{
if (device == NULL)
return false;
return (device->capabilities & B(cap)) == B(cap);
}
20 changes: 15 additions & 5 deletions src/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ extern const char capabilities_str_short[NUM_CAPABILITIES];
/// Enum name of every capability
extern const char* const capabilities_str_enum[NUM_CAPABILITIES];

static inline bool has_capability(int device_capabilities, enum capabilities cap)
{
return (device_capabilities & B(cap)) == B(cap);
}

struct capability_detail {
// Usage page, only used when usageid is not 0; HID Protocol specific
uint16_t usagepage;
Expand Down Expand Up @@ -394,3 +389,18 @@ struct device {
*/
int (*send_bluetooth_call_volume)(hid_device* hid_device, uint8_t num);
};

/**
* @brief Node structure for a linked list of devices.
*
* This structure represents a node in a linked list where each node contains a pointer to a device
* and a pointer to the next node in the list.
*/
typedef struct DeviceListNode {
struct device* element;
struct DeviceListNode* next;
} DeviceListNode;

bool device_check_ids(struct device* device, uint16_t vid, uint16_t pid);

bool device_has_capability(struct device* device, enum capabilities cap);
16 changes: 13 additions & 3 deletions src/hid_utility.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,9 @@ char* get_hid_path(uint16_t vid, uint16_t pid, int iid, uint16_t usagepageid, ui
}

/**
* Helper freeing HID data and terminating HID usage.
* Helper freeing HID data.
*/
/* This function is explicitly called terminate_hid to avoid HIDAPI clashes. */
void terminate_hid(hid_device** handle, char** path)
void terminate_device_hid(hid_device** handle, char** path)
{
if (handle) {
if (*handle) {
Expand All @@ -112,7 +111,18 @@ void terminate_hid(hid_device** handle, char** path)

if (path) {
free(*path);

*path = NULL;
}
}

/**
* Helper freeing HID data and terminating HID usage.
*/
/* This function is explicitly called terminate_hid to avoid HIDAPI clashes. */
void terminate_hid(hid_device** handle, char** path)
{
terminate_device_hid(handle, path);

hid_exit();
}
5 changes: 5 additions & 0 deletions src/hid_utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@
*/
char* get_hid_path(uint16_t vid, uint16_t pid, int iid, uint16_t usagepageid, uint16_t usageid);

/**
* Helper freeing HID data.
*/
void terminate_device_hid(hid_device** handle, char** path);

/**
* Helper freeing HID data and terminating HID usage.
*/
Expand Down
Loading
Loading