Skip to content

Commit

Permalink
hid: make the report protocol changeable during the lifetime of the a…
Browse files Browse the repository at this point in the history
…pplication
  • Loading branch information
benedekkupper committed Mar 10, 2024
1 parent 9c4c98e commit 020e5b7
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions c2usb/hid/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class application : public polymorphic
{
public:
constexpr explicit application(const report_protocol& rp)
: report_info_(rp)
: report_info_(&rp)
{}

constexpr const report_protocol& report_info() const { return report_info_; }
constexpr const report_protocol& report_info() const { return *report_info_; }

private: // internal behavior to override
/// @brief Initialize the application when the protocol has been (possibly implicitly) selected.
Expand Down Expand Up @@ -143,6 +143,14 @@ class application : public polymorphic
return receive_report(std::span<uint8_t>(report->data(), sizeof(*report)), report->type());
}

/// @brief Changes the report information on the fly. This is extremely rarely needed.
/// @param rp: the new report protocol to use
void set_report_info(const report_protocol& rp)
{
// assert(!has_transport());
report_info_ = &rp;
}

public:
// SPEC WTF: The IDLE parameter is meant to control how often the device should resend
// the same piece of information. This is introduced in the USB HID class spec,
Expand Down Expand Up @@ -189,7 +197,7 @@ class application : public polymorphic
}

private:
const report_protocol& report_info_;
const report_protocol* report_info_;
std::atomic<transport*> transport_{};
};

Expand Down

0 comments on commit 020e5b7

Please sign in to comment.