patlefort

ACL4080 set mode

Oct 22nd, 2025 (edited)
618
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | Source Code | 0 0
  1. #include <libusb-1.0/libusb.h>
  2. #include <iostream>
  3. #include <cstdint>
  4.  
  5. constexpr std::uint16_t vendor_id = 0x0db0;
  6. constexpr std::uint16_t product_id = 0xcd0e;
  7. //constexpr unsigned char mode = 0b00000100;
  8.  
  9. struct usb_exit
  10. {
  11.     ~usb_exit()
  12.     {
  13.         libusb_exit(nullptr);
  14.     }
  15. };
  16.  
  17. struct usb_device_guard
  18. {
  19.     libusb_device_handle *m_handle;
  20.  
  21.     ~usb_device_guard()
  22.     {
  23.         libusb_close(m_handle);
  24.     }
  25. };
  26.  
  27. int main()
  28. {
  29.     int result = libusb_init(nullptr);
  30.     if ( result < 0 )
  31.     {
  32.         std::cerr << "Error initializing libusb: " << libusb_error_name(result) << '\n';
  33.         return 1;
  34.     }
  35.     usb_exit usb_exit_guard;
  36.  
  37.     libusb_set_option(nullptr, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_WARNING);
  38.  
  39.     auto device_handle = libusb_open_device_with_vid_pid(nullptr, vendor_id, product_id);
  40.     if(!device_handle)
  41.     {
  42.         std::cerr << "Error opening usb device.\n";
  43.         return 1;
  44.     }
  45.     usb_device_guard dguard{device_handle};
  46.  
  47.     unsigned char data[1] = {0b00000010};
  48.     if ((result = libusb_control_transfer(device_handle, 0x40, 108, 0, 1, data, 1, 0)) < 0)
  49.     {
  50.         std::cerr << "libusb_control_transfer error: " << libusb_error_name(result) << '\n';
  51.         return 1;
  52.     }
  53.  
  54.     data[0] = 0b00000100;
  55.     if ((result = libusb_control_transfer(device_handle, 0x40, 108, 0, 1, data, 1, 0)) < 0)
  56.     {
  57.         std::cerr << "libusb_control_transfer error: " << libusb_error_name(result) << '\n';
  58.         return 1;
  59.     }
  60.  
  61.     return 0;
  62. }
  63.  
Tags: acl4080
Advertisement
Add Comment
Please, Sign In to add comment