mirror of
https://github.com/raphnet/gc_n64_usb-v3
synced 2025-01-30 23:00:11 -05:00
Add openBy function
This commit is contained in:
parent
ae74a95c22
commit
41f2d359b8
45
tool/gcn64.c
45
tool/gcn64.c
@ -74,6 +74,7 @@ void gcn64_freeListCtx(struct gcn64_list_ctx *ctx)
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief List instances of our rgbleds device on the USB busses.
|
* \brief List instances of our rgbleds device on the USB busses.
|
||||||
|
* \param info Pointer to gcn64_info structure to store data
|
||||||
* \param dst Destination buffer for device serial number/id.
|
* \param dst Destination buffer for device serial number/id.
|
||||||
* \param dstbuf_size Destination buffer size.
|
* \param dstbuf_size Destination buffer size.
|
||||||
*/
|
*/
|
||||||
@ -140,6 +141,50 @@ gcn64_hdl_t gcn64_openDevice(struct gcn64_info *dev)
|
|||||||
return hdev;
|
return hdev;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gcn64_hdl_t gcn64_openBy(struct gcn64_info *dev, unsigned char flags)
|
||||||
|
{
|
||||||
|
struct gcn64_list_ctx *ctx;
|
||||||
|
struct gcn64_info inf;
|
||||||
|
gcn64_hdl_t h;
|
||||||
|
|
||||||
|
printf("gcn64_openBy, flags=0x%02x\n", flags);
|
||||||
|
|
||||||
|
ctx = gcn64_allocListCtx();
|
||||||
|
if (!ctx)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
while (gcn64_listDevices(&inf, ctx)) {
|
||||||
|
printf("Considering '%s'\n", inf.str_path);
|
||||||
|
if (flags & GCN64_FLG_OPEN_BY_SERIAL) {
|
||||||
|
if (wcscmp(inf.str_serial, dev->str_serial))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & GCN64_FLG_OPEN_BY_PATH) {
|
||||||
|
if (strcmp(inf.str_path, dev->str_path))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & GCN64_FLG_OPEN_BY_VID) {
|
||||||
|
if (inf.usb_vid != dev->usb_vid)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (flags & GCN64_FLG_OPEN_BY_PID) {
|
||||||
|
if (inf.usb_pid != dev->usb_pid)
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Found device. opening...\n");
|
||||||
|
h = gcn64_openDevice(&inf);
|
||||||
|
gcn64_freeListCtx(ctx);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
gcn64_freeListCtx(ctx);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
void gcn64_closeDevice(gcn64_hdl_t hdl)
|
void gcn64_closeDevice(gcn64_hdl_t hdl)
|
||||||
{
|
{
|
||||||
hid_device *hdev = (hid_device*)hdl;
|
hid_device *hdev = (hid_device*)hdl;
|
||||||
|
13
tool/gcn64.h
13
tool/gcn64.h
@ -29,6 +29,19 @@ void gcn64_freeListCtx(struct gcn64_list_ctx *ctx);
|
|||||||
struct gcn64_info *gcn64_listDevices(struct gcn64_info *info, struct gcn64_list_ctx *ctx);
|
struct gcn64_info *gcn64_listDevices(struct gcn64_info *info, struct gcn64_list_ctx *ctx);
|
||||||
|
|
||||||
gcn64_hdl_t gcn64_openDevice(struct gcn64_info *dev);
|
gcn64_hdl_t gcn64_openDevice(struct gcn64_info *dev);
|
||||||
|
|
||||||
|
#define GCN64_FLG_OPEN_BY_SERIAL 1 /** Serial must match */
|
||||||
|
#define GCN64_FLG_OPEN_BY_PATH 2 /** Path must match */
|
||||||
|
#define GCN64_FLG_OPEN_BY_VID 4 /** USB VID must match */
|
||||||
|
#define GCN64_FLG_OPEN_BY_PID 8 /** USB PID MUST match */
|
||||||
|
/**
|
||||||
|
* \brief Open a device matching a serial number
|
||||||
|
* \param dev The device structure
|
||||||
|
* \param flags Flags
|
||||||
|
* \return A handle to the opened device, or NULL if not found
|
||||||
|
**/
|
||||||
|
gcn64_hdl_t gcn64_openBy(struct gcn64_info *dev, unsigned char flags);
|
||||||
|
|
||||||
void gcn64_closeDevice(gcn64_hdl_t hdl);
|
void gcn64_closeDevice(gcn64_hdl_t hdl);
|
||||||
|
|
||||||
int gcn64_send_cmd(gcn64_hdl_t hdl, const unsigned char *cmd, int len);
|
int gcn64_send_cmd(gcn64_hdl_t hdl, const unsigned char *cmd, int len);
|
||||||
|
Loading…
Reference in New Issue
Block a user