3 Commits

Author SHA1 Message Date
57b7dc8412 feat: add default config fallback
All checks were successful
CI / build (amd64, usbmakroboard-amd64, linux_amd64) (pull_request) Successful in 1m9s
CI / build (arm64, usbmakroboard-arm64, linux_arm64) (pull_request) Successful in 4m5s
2025-12-27 13:17:00 +01:00
3052bb199f Revert "feat: add default config path"
This reverts commit 6021ec89f5.
2025-12-27 13:12:02 +01:00
e8891983d9 Revert "change default config file name"
This reverts commit eebd03bb4e.
2025-12-27 13:11:59 +01:00
2 changed files with 21 additions and 4 deletions

View File

@@ -12,7 +12,7 @@ For info that with "EVIOCGRAB" the keyboard events can be consumed exclusively b
## Configuration ## Configuration
The configuration can be provided by either specifying a config file path via the `-c` parameter. If no parameter is provided, the default config path under `$HOME/.config/usbMakroBoard.yaml` is used. The configuration can be provided by either specifying a config file path via the `-c` parameter. If no parameter is provided, the default config path under `$HOME/.config/UsbMakroBoard.yaml` is used.
Find the config schema in [schemas/config.schema.json](./schemas/config.schema.json) as well as a default config in [config.yaml](./config.yaml). Find the config schema in [schemas/config.schema.json](./schemas/config.schema.json) as well as a default config in [config.yaml](./config.yaml).

View File

@@ -7,6 +7,7 @@
#include <fcntl.h> #include <fcntl.h>
#include <linux/input.h> #include <linux/input.h>
#include <iostream> #include <iostream>
#include <cstdlib>
#include <spdlog/spdlog.h> #include <spdlog/spdlog.h>
#include <spdlog/sinks/stdout_sinks.h> #include <spdlog/sinks/stdout_sinks.h>
#include <yaml-cpp/yaml.h> #include <yaml-cpp/yaml.h>
@@ -57,7 +58,7 @@ std::pair<int, int> mapKeyEventToRowColumn(int keyEventNumber, const std::unorde
std::string getConfigPathFromCliArguments(int argc, char *argv[]) std::string getConfigPathFromCliArguments(int argc, char *argv[])
{ {
std::string configPath = ""; std::string configPath;
int opt; int opt;
while ((opt = getopt(argc, argv, "c:")) != -1) while ((opt = getopt(argc, argv, "c:")) != -1)
{ {
@@ -67,14 +68,30 @@ std::string getConfigPathFromCliArguments(int argc, char *argv[])
configPath = optarg; configPath = optarg;
break; break;
default: default:
std::cout << "No config path provided. Using default config path: $HOME/.config/usbMakroBoard.yaml\n"; std::cerr << "Usage: " << argv[0] << " [-c config_file_path]\n";
configPath = "$HOME/.config/usbMakroBoard.yaml"; exit(EXIT_FAILURE);
}
}
if (configPath.empty()) {
const char *home = std::getenv("HOME");
if (home != nullptr) {
configPath = std::string(home) + "/.config/usbMakroBoard.yaml";
}
else {
std::cerr << "HOME environment variable is not set. Exiting.\n";
exit(EXIT_FAILURE);
} }
} }
return configPath; return configPath;
} }
YAML::Node loadConfig(const std::string &configPath)
{
return YAML::LoadFile(configPath);
}
int openDevice(const std::string &devicePath) int openDevice(const std::string &devicePath)
{ {
int fdKeyboard = open(devicePath.c_str(), O_RDONLY); int fdKeyboard = open(devicePath.c_str(), O_RDONLY);