| 156 | } |
| 157 | |
| 158 | int main(int argc, char* argv[]) |
| 159 | { |
| 160 | (void)argc; |
| 161 | (void)argv; |
| 162 | |
| 163 | #define MAX_STR 255 |
| 164 | |
| 165 | struct hid_device_info *devs, *cur_dev; |
| 166 | |
| 167 | printf("pp_data_dump tool. Compiled with hidapi version %s, runtime version %s.\n", HID_API_VERSION_STR, hid_version_str()); |
| 168 | if (hid_version()->major == HID_API_VERSION_MAJOR && hid_version()->minor == HID_API_VERSION_MINOR && hid_version()->patch == HID_API_VERSION_PATCH) { |
| 169 | printf("Compile-time version matches runtime version of hidapi.\n\n"); |
| 170 | } |
| 171 | else { |
| 172 | printf("Compile-time version is different than runtime version of hidapi.\n]n"); |
| 173 | } |
| 174 | |
| 175 | if (hid_init()) |
| 176 | return -1; |
| 177 | |
| 178 | devs = hid_enumerate(0x0, 0x0); |
| 179 | cur_dev = devs; |
| 180 | while (cur_dev) { |
| 181 | printf("Device Found\n type: %04hx %04hx\n path: %s\n serial_number: %ls", cur_dev->vendor_id, cur_dev->product_id, cur_dev->path, cur_dev->serial_number); |
| 182 | printf("\n"); |
| 183 | printf(" Manufacturer: %ls\n", cur_dev->manufacturer_string); |
| 184 | printf(" Product: %ls\n", cur_dev->product_string); |
| 185 | printf(" Release: %hX\n", cur_dev->release_number); |
| 186 | printf(" Interface: %d\n", cur_dev->interface_number); |
| 187 | printf(" Usage (page): %02X (%02X)\n", cur_dev->usage, cur_dev->usage_page); |
| 188 | |
| 189 | hid_device *device = hid_open_path(cur_dev->path); |
| 190 | if (device) { |
| 191 | char filename[MAX_STR]; |
| 192 | FILE* file; |
| 193 | |
| 194 | sprintf_s(filename, MAX_STR, "%04X_%04X_%04X_%04X.pp_data", cur_dev->vendor_id, cur_dev->product_id, cur_dev->usage, cur_dev->usage_page); |
| 195 | errno_t err = fopen_s(&file, filename, "w"); |
| 196 | if (err == 0) { |
| 197 | fprintf(file, "# HIDAPI device info struct:\n"); |
| 198 | fprintf(file, "dev->vendor_id = 0x%04hX\n", cur_dev->vendor_id); |
| 199 | fprintf(file, "dev->product_id = 0x%04hX\n", cur_dev->product_id); |
| 200 | fprintf(file, "dev->manufacturer_string = \"%ls\"\n", cur_dev->manufacturer_string); |
| 201 | fprintf(file, "dev->product_string = \"%ls\"\n", cur_dev->product_string); |
| 202 | fprintf(file, "dev->release_number = 0x%04hX\n", cur_dev->release_number); |
| 203 | fprintf(file, "dev->interface_number = %d\n", cur_dev->interface_number); |
| 204 | fprintf(file, "dev->usage = 0x%04hX\n", cur_dev->usage); |
| 205 | fprintf(file, "dev->usage_page = 0x%04hX\n", cur_dev->usage_page); |
| 206 | fprintf(file, "dev->path = \"%s\"\n", cur_dev->path); |
| 207 | fprintf(file, "\n# Preparsed Data struct:\n"); |
| 208 | int res = dump_pp_data(file, device); |
| 209 | |
| 210 | if (res == 0) { |
| 211 | printf("Dumped Preparsed Data to %s\n", filename); |
| 212 | } |
| 213 | else { |
| 214 | printf("ERROR: Dump Preparsed Data to %s failed!\n", filename); |
| 215 | } |
nothing calls this directly
no test coverage detected