Skip to content

Commit

Permalink
Implement ptpusb_get_status for libusb and libwpd
Browse files Browse the repository at this point in the history
Based on latest changes from libwpd
  • Loading branch information
petabyt committed Nov 17, 2024
1 parent d3903fe commit 36cbd4b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/cl_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,7 @@ int ptpip_close(struct PtpRuntime *r);

void ptpusb_free_device_list_entry(void *);

/// @brief Get status of connected device
int ptpusb_get_status(struct PtpRuntime *r);

#endif
9 changes: 9 additions & 0 deletions src/libusb.c
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,15 @@ int ptp_read_int(struct PtpRuntime *r, void *to, int length) {
return transferred;
}

int ptpusb_get_status(struct PtpRuntime *r) {
struct LibUSBBackend *backend = (struct LibUSBBackend *)r->comm_backend;
if (backend == NULL || r->io_kill_switch) return -1;
char buffer[2];
int rc = libusb_control_transfer(backend->handle, 0x80, 0, 0, 0, buffer, 2, 1000);
if (rc) return -1;
return 0;
}

int reset_int(struct PtpRuntime *r) {
return -1;
}
6 changes: 6 additions & 0 deletions src/libwpd.c
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,12 @@ int ptp_device_close(struct PtpRuntime *r) {
return 0;
}

int ptpusb_get_status(struct PtpRuntime *r) {
struct WpdStruct *wpd = (struct WpdStruct *)(r->comm_backend);
if (wpd == NULL) return PTP_IO_ERR;
return wpd_check_connected(wpd);
}

int ptp_device_reset(struct PtpRuntime *r) {
return 0;
}

0 comments on commit 36cbd4b

Please sign in to comment.