[ Web Proxy ]
URL:
Viewing: https://raw.githubusercontent.com/Sapd/HeadsetControl/master/cli/dev.cpp [Back]  [Original]

#include "dev.hpp"

#include "hid_utility.hpp"
#include "string_utils.hpp"
#include "utility.hpp"

#include 

#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

namespace {

// ============================================================================
// RAII Wrappers
// ============================================================================

struct HIDDeviceDeleter {
    void operator()(hid_device* dev) const noexcept
    {
        if (dev) {
            headsetcontrol::close_hid_device(dev);
        }
    }
};
using HIDDevicePtr = std::unique_ptr;

struct HIDEnumerationDeleter {
    void operator()(hid_device_info* info) const noexcept
    {
        if (info) {
            hid_free_enumeration(info);
        }
    }
};
using HIDEnumerationPtr = std::unique_ptr;

// ============================================================================
// Helper Functions
// ============================================================================

[[nodiscard]] constexpr bool in_range(int value, int min, int max) noexcept
{
    return value >= min && value path);

        if (cur->serial_number) {
            std::cout second, 1, 65535)) {
                std::cerr second);
            break;
        }
        case 'i':
            if (auto v = parse_int(optarg); v && *v >= 0) {
                opts.interfaceid = *v;
            } else {
                std::cerr first, 0, 65535) || !in_range(ids->second, 0, 65535)) {
                std::cerr first);
            opts.usageid   = static_cast(ids->second);
            break;
        }
        case 'l':
            opts.print_deviceinfo = true;
            break;

        case 's':
            opts.send_data = headsetcontrol::parse_byte_data(optarg);
            if (opts.send_data.empty()) {
                std::cerr usageid);

    if (!hid_path) {
        std::cerr vendorid, opts->productid, opts->interfaceid, opts->usagepage, opts->usageid);
        return 1;
    }

    if (!opts->send_data.empty() && !opts->send_feature_data.empty()) {
        std::cerr do_receive && opts->receive_report_id.has_value()) {
        std::cerr c_str()) };
    if (!device) {
        std::cerr send_data.empty() && !send_data(device.get(), opts->send_data)) {
            return 1;
        }

        if (!opts->send_feature_data.empty() && !send_feature_report(device.get(), opts->send_feature_data)) {
            return 1;
        }

        if (opts->sleep_time.count() > 0) {
            std::this_thread::sleep_for(opts->sleep_time);
        }

        if (opts->do_receive && !receive_data(device.get(), buffer, static_cast(opts->timeout.count()))) {
            return 1;
        }

        if (opts->receive_report_id.has_value() && !receive_feature_report(device.get(), buffer, *opts->receive_report_id)) {
            return 1;
        }

        if (opts->repeat_interval.count() > 0) {
            std::this_thread::sleep_for(opts->repeat_interval);
        }
    } while (opts->repeat_interval.count() > 0);

    return 0;
}

Web Proxy Viewer  |  New URL  |  Original Page