Limit use of C-style definitions

This commit is contained in:
pixl 2023-04-29 13:31:44 -04:00
parent c15419a234
commit 35b4dc03bf
No known key found for this signature in database
GPG Key ID: 1866C148CD593B6E
6 changed files with 26 additions and 29 deletions

View File

@ -302,12 +302,12 @@ void Device::sendReportNoACK(const Report& report) {
void Device::reportFixup(Report& report) const {
switch (report.type()) {
case Report::Type::Short:
if (!(supported_reports & HIDPP_REPORT_SHORT_SUPPORTED))
if (!(supported_reports & ShortReportSupported))
report.setType(Report::Type::Long);
break;
case Report::Type::Long:
/* Report can be truncated, but that isn't a good idea. */
assert(supported_reports & HIDPP_REPORT_LONG_SUPPORTED);
assert(supported_reports & LongReportSupported);
}
}

View File

@ -93,7 +93,7 @@ uint8_t hidpp::getSupportedReports(const std::vector<uint8_t>& report_desc) {
it = std::search(report_desc.begin(), report_desc.end(),
ShortReportDesc2.begin(), ShortReportDesc2.end());
if (it != report_desc.end())
ret |= HIDPP_REPORT_SHORT_SUPPORTED;
ret |= ShortReportSupported;
it = std::search(report_desc.begin(), report_desc.end(),
LongReportDesc.begin(), LongReportDesc.end());
@ -101,7 +101,7 @@ uint8_t hidpp::getSupportedReports(const std::vector<uint8_t>& report_desc) {
it = std::search(report_desc.begin(), report_desc.end(),
LongReportDesc2.begin(), LongReportDesc2.end());
if (it != report_desc.end())
ret |= HIDPP_REPORT_LONG_SUPPORTED;
ret |= LongReportSupported;
return ret;
}

View File

@ -23,14 +23,14 @@
#include <backend/hidpp/defs.h>
#include <cstdint>
/* Some devices only support a subset of these reports */
#define HIDPP_REPORT_SHORT_SUPPORTED 1U
#define HIDPP_REPORT_LONG_SUPPORTED 1U<<1U
/* Very long reports exist, however they have not been encountered so far */
namespace logid::backend::hidpp {
uint8_t getSupportedReports(const std::vector<uint8_t>& report_desc);
/* Some devices only support a subset of these reports */
static constexpr uint8_t ShortReportSupported = 1U;
static constexpr uint8_t LongReportSupported = (1U<<1);
/* Very long reports exist, however they have not been encountered so far */
namespace Offset {
static constexpr uint8_t Type = 0;
static constexpr uint8_t DeviceIndex = 1;

View File

@ -25,8 +25,13 @@ using namespace logid::features;
using namespace logid::backend;
using namespace logid::actions;
#define HIDPP20_REPROG_REBIND (hidpp20::ReprogControls::ChangeTemporaryDivert \
| hidpp20::ReprogControls::ChangeRawXYDivert)
#define REPROG_FLAG(x) (control.second.flags & hidpp20::ReprogControls::x ? "YES" : "")
#define REPROG_FLAG_ADDITIONAL(x) (control.second.additionalFlags & \
hidpp20::ReprogControls::x ? "YES" : "")
static constexpr auto hidpp20_reprog_rebind =
(hidpp20::ReprogControls::ChangeTemporaryDivert |
hidpp20::ReprogControls::ChangeRawXYDivert);
RemapButton::RemapButton(Device* dev) : DeviceFeature(dev),
_config(dev->activeProfile().buttons),
@ -49,7 +54,7 @@ RemapButton::RemapButton(Device* dev) : DeviceFeature(dev),
const std::shared_ptr<actions::Action>& action) {
hidpp20::ReprogControls::ControlInfo report{};
report.controlID = info.controlID;
report.flags = HIDPP20_REPROG_REBIND;
report.flags = hidpp20_reprog_rebind;
if (action) {
if ((action->reprogFlags() &
@ -72,11 +77,6 @@ RemapButton::RemapButton(Device* dev) : DeviceFeature(dev),
_ipc_interface = _device->ipcNode()->make_interface<IPC>(this);
if (global_loglevel <= DEBUG) {
#define FLAG(x) (control.second.flags & hidpp20::ReprogControls::x ? \
"YES" : "")
#define ADDITIONAL_FLAG(x) (control.second.additionalFlags & \
hidpp20::ReprogControls::x ? "YES" : "")
// Print CIDs, originally by zv0n
logPrintf(DEBUG, "%s:%d remappable buttons:",
dev->hidpp20().devicePath().c_str(),
@ -85,10 +85,8 @@ RemapButton::RemapButton(Device* dev) : DeviceFeature(dev),
"gesture support?");
for (const auto& control: _reprog_controls->getControls())
logPrintf(DEBUG, "0x%02x | %-7s | %-7s | %-10s | %s",
control.first, FLAG(TemporaryDivertable), FLAG(FKey),
FLAG(MouseButton), ADDITIONAL_FLAG(RawXY));
#undef ADDITIONAL_FLAG
#undef FLAG
control.first, REPROG_FLAG(TemporaryDivertable), REPROG_FLAG(FKey),
REPROG_FLAG(MouseButton), REPROG_FLAG_ADDITIONAL(RawXY));
}
}

View File

@ -25,8 +25,7 @@ using namespace logid::features;
using namespace logid::backend;
using namespace logid;
#define FLAG_STR(b) (_wheel_info.capabilities & _thumb_wheel->b ? "YES" : \
"NO")
#define FLAG_STR(b) (_wheel_info.capabilities & _thumb_wheel->b ? "YES" : "NO")
namespace {
std::shared_ptr<actions::Action> _genAction(

View File

@ -21,18 +21,18 @@
#include <util/log.h>
#include <algorithm>
#define LOGID_VIRTUAL_INPUT_NAME "LogiOps Virtual Input"
#define DEFAULT_CONFIG_FILE "/etc/logid.cfg"
#ifndef LOGIOPS_VERSION
#define LOGIOPS_VERSION "null"
#warning Version is undefined!
#endif
static constexpr auto virtual_input_name = "LogiOps Virtual Input";
static constexpr auto default_config = "/etc/logid.cfg";
using namespace logid;
struct CmdlineOptions {
std::string config_file = DEFAULT_CONFIG_FILE;
std::string config_file = default_config;
};
LogLevel logid::global_loglevel = INFO;
@ -115,7 +115,7 @@ Possible options are:
-V,--version Print version number
-c,--config [file path] Change config file from default at %s
-h,--help Print this message.
)", LOGIOPS_VERSION, argv[0], DEFAULT_CONFIG_FILE);
)", LOGIOPS_VERSION, argv[0], default_config);
exit(EXIT_SUCCESS);
case Option::Version:
printf("%s\n", LOGIOPS_VERSION);
@ -147,7 +147,7 @@ int main(int argc, char** argv) {
//Create a virtual input device
try {
virtual_input = std::make_unique<InputDevice>(LOGID_VIRTUAL_INPUT_NAME);
virtual_input = std::make_unique<InputDevice>(virtual_input_name);
} catch (std::system_error& e) {
logPrintf(ERROR, "Could not create input device: %s", e.what());
return EXIT_FAILURE;