mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-12 17:58:53 +01:00
applying keymap files if found. Fixed sound regression due to pclose
This commit is contained in:
parent
152bae7693
commit
4e9b31baff
@ -120,6 +120,44 @@ bool Launcher::run(std::string collection, Item *collectionItem)
|
|||||||
selectedItemsDirectory,
|
selectedItemsDirectory,
|
||||||
collection);
|
collection);
|
||||||
|
|
||||||
|
/* Apply key mapping for selected item's directory if found */
|
||||||
|
std::string selectedItemDirnameKeyfile = Utils::getDirectory(selectedItemsPath) + "/default_config.key";
|
||||||
|
if (!access(selectedItemDirnameKeyfile.c_str(), R_OK)) {
|
||||||
|
|
||||||
|
/* Create shell cmd */
|
||||||
|
std::string cmd = SHELL_CMD_MAPPING_SET;
|
||||||
|
cmd += " " + selectedItemDirnameKeyfile;
|
||||||
|
|
||||||
|
/* Log shell cmd */
|
||||||
|
Logger::write(Logger::ZONE_INFO, "Launcher", "Applying keymap file: " + selectedItemDirnameKeyfile);
|
||||||
|
printf("Applying keymap file cmd: \"%s\"\n", cmd.c_str());
|
||||||
|
|
||||||
|
/* Launch shell cmd */
|
||||||
|
fp = popen(cmd.c_str(), "r");
|
||||||
|
if (fp != NULL) {
|
||||||
|
pclose(fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Apply specific key mapping for selected item if found */
|
||||||
|
std::string selectedItemBasenameKeyfile = Utils::removeExtension(selectedItemsPath) + ".key";
|
||||||
|
if (!access(selectedItemBasenameKeyfile.c_str(), R_OK)) {
|
||||||
|
|
||||||
|
/* Create shell cmd */
|
||||||
|
std::string cmd = SHELL_CMD_MAPPING_SET;
|
||||||
|
cmd += " " + selectedItemBasenameKeyfile;
|
||||||
|
|
||||||
|
/* Log shell cmd */
|
||||||
|
Logger::write(Logger::ZONE_INFO, "Launcher", "Applying keymap file: " + selectedItemBasenameKeyfile);
|
||||||
|
printf("Applying keymap file cmd: \"%s\"\n", cmd.c_str());
|
||||||
|
|
||||||
|
/* Launch shell cmd */
|
||||||
|
fp = popen(cmd.c_str(), "r");
|
||||||
|
if (fp != NULL) {
|
||||||
|
pclose(fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Restart audio amp */
|
/* Restart audio amp */
|
||||||
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
|
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
@ -139,6 +177,12 @@ bool Launcher::run(std::string collection, Item *collectionItem)
|
|||||||
pclose(fp);
|
pclose(fp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Reset default key mapping */
|
||||||
|
fp = popen(SHELL_CMD_MAPPING_RESET, "r");
|
||||||
|
if (fp != NULL) {
|
||||||
|
pclose(fp);
|
||||||
|
}
|
||||||
|
|
||||||
/* Restore stored PID */
|
/* Restore stored PID */
|
||||||
char shellCmd[20];
|
char shellCmd[20];
|
||||||
sprintf(shellCmd, "%s %d", SHELL_CMD_RECORD_PID, getpid());
|
sprintf(shellCmd, "%s %d", SHELL_CMD_RECORD_PID, getpid());
|
||||||
|
|||||||
@ -56,7 +56,7 @@ void Sound::play()
|
|||||||
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
|
fp = popen(SHELL_CMD_TURN_AMPLI_ON, "r");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
ampliStarted = 1;
|
ampliStarted = 1;
|
||||||
pclose(fp);
|
//pclose(fp); // --> regression, to investigate
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -75,7 +75,7 @@ uint32_t Sound::turnOffAmpli(uint32_t interval, void *param)
|
|||||||
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
|
fp = popen(SHELL_CMD_TURN_AMPLI_OFF, "r");
|
||||||
if (fp != NULL) {
|
if (fp != NULL) {
|
||||||
ampliStarted = 0;
|
ampliStarted = 0;
|
||||||
pclose(fp);
|
//pclose(fp); // --> regression, to investigate
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -255,6 +255,23 @@ std::string Utils::getFileName(std::string filePath)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string Utils::removeExtension(std::string filePath)
|
||||||
|
{
|
||||||
|
|
||||||
|
/** Declared static to be kept in memory even after this function's scope */
|
||||||
|
static std::string filename;
|
||||||
|
filename = filePath;
|
||||||
|
|
||||||
|
const size_t lastPoint = filename.find_last_of(".");
|
||||||
|
if (std::string::npos != lastPoint)
|
||||||
|
{
|
||||||
|
filename = filePath.substr(0, lastPoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
return filename;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::string Utils::trimEnds(std::string str)
|
std::string Utils::trimEnds(std::string str)
|
||||||
{
|
{
|
||||||
// strip off any initial tabs or spaces
|
// strip off any initial tabs or spaces
|
||||||
|
|||||||
@ -25,6 +25,8 @@
|
|||||||
#define SHELL_CMD_RECORD_PID "record_pid"
|
#define SHELL_CMD_RECORD_PID "record_pid"
|
||||||
#define SHELL_CMD_TURN_AMPLI_ON "start_audio_amp 1"
|
#define SHELL_CMD_TURN_AMPLI_ON "start_audio_amp 1"
|
||||||
#define SHELL_CMD_TURN_AMPLI_OFF "start_audio_amp 0"
|
#define SHELL_CMD_TURN_AMPLI_OFF "start_audio_amp 0"
|
||||||
|
#define SHELL_CMD_MAPPING_SET "keymap"
|
||||||
|
#define SHELL_CMD_MAPPING_RESET "keymap reset"
|
||||||
|
|
||||||
class Utils
|
class Utils
|
||||||
{
|
{
|
||||||
@ -38,6 +40,7 @@ public:
|
|||||||
static std::string getDirectory(std::string filePath);
|
static std::string getDirectory(std::string filePath);
|
||||||
static std::string getParentDirectory(std::string filePath);
|
static std::string getParentDirectory(std::string filePath);
|
||||||
static std::string getFileName(std::string filePath);
|
static std::string getFileName(std::string filePath);
|
||||||
|
static std::string removeExtension(std::string filePath);
|
||||||
static bool findMatchingFile(std::string prefix, std::vector<std::string> &extensions, std::string &file);
|
static bool findMatchingFile(std::string prefix, std::vector<std::string> &extensions, std::string &file);
|
||||||
static std::string toLower(std::string str);
|
static std::string toLower(std::string str);
|
||||||
static std::string uppercaseFirst(std::string str);
|
static std::string uppercaseFirst(std::string str);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user