Add check for devices with old firmware

This commit is contained in:
Matt Mets 2023-03-08 15:54:07 +01:00
parent 84e0851281
commit 644ffefc8e
1 changed files with 23 additions and 7 deletions

View File

@ -5,8 +5,8 @@
#include <sys/time.h> #include <sys/time.h>
#include <libusb-1.0/libusb.h> #include <libusb-1.0/libusb.h>
#define VENDOR_ID 0xCAFE #define VENDOR_ID 0x1209
#define PRODUCT_ID 0x4010 #define PRODUCT_ID 0x8886
//static hid_device * handle; //static hid_device * handle;
@ -286,15 +286,31 @@ const interface_t rpi_pico_interface = {
}; };
bool check_for_old_firmware() { bool check_for_old_firmware() {
const int vendor_id_old = 0xCAFE; // From: https://libusb.sourceforge.io/api-1.0/group__libusb__dev.html#details
const int product_id_old = 0x4004; libusb_device **list;
ssize_t cnt = libusb_get_device_list(NULL, &list);
if ( (devhaccess = libusb_open_device_with_vid_pid (ctx, vendor_id_old, product_id_old)) == 0) { if (cnt < 0) {
return false; return false;
} }
libusb_close (devhaccess); bool found = false;
return true; for (ssize_t i = 0; i < cnt; i++) {
libusb_device *device = list[i];
struct libusb_device_descriptor device_descriptor;
if(libusb_get_device_descriptor(device, &device_descriptor) != 0)
continue;
// Previous programmer firmware used 0xCAFE and either 0x4004 or 0x4010
if((device_descriptor.idVendor == 0xCAFE) &&
((device_descriptor.idProduct == 0x4004) || (device_descriptor.idProduct == 0x4010))) {
found = true;
}
}
libusb_free_device_list(list, 1);
return found;
} }
bool check_firmware_version() { bool check_firmware_version() {