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
@ -228,48 +228,48 @@ bool Configuration::importCurrentLayout(std::string folder, std::string file, bo
|
|||||||
// line empty
|
// line empty
|
||||||
if(line.empty() || (line.find_first_not_of(" \t\r") == std::string::npos))
|
if(line.empty() || (line.find_first_not_of(" \t\r") == std::string::npos))
|
||||||
{
|
{
|
||||||
retVal = false;
|
retVal = false;
|
||||||
}
|
}
|
||||||
// finding layout in existing list
|
// finding layout in existing list
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string seekedLayoutName = trimEnds(line);
|
std::string seekedLayoutName = trimEnds(line);
|
||||||
std::string layoutPathFound;
|
std::string layoutPathFound;
|
||||||
bool layoutFoundInList = false;
|
bool layoutFoundInList = false;
|
||||||
|
|
||||||
// check existing layout list */
|
// check existing layout list */
|
||||||
for(std::vector<std::string>::iterator it = layouts_.begin(); it != layouts_.end(); ++it){
|
for(std::vector<std::string>::iterator it = layouts_.begin(); it != layouts_.end(); ++it){
|
||||||
std::string curLayoutName = Utils::getFileName(*it);
|
std::string curLayoutName = Utils::getFileName(*it);
|
||||||
if(!curLayoutName.compare(seekedLayoutName)){
|
if(!curLayoutName.compare(seekedLayoutName)){
|
||||||
layoutPathFound = *it;
|
layoutPathFound = *it;
|
||||||
layoutFoundInList = true;
|
layoutFoundInList = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
index++;
|
index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (layoutFoundInList){
|
if (layoutFoundInList){
|
||||||
|
|
||||||
/* remove layout properties if they already exist */
|
/* remove layout properties if they already exist */
|
||||||
if(properties_.find("layout") != properties_.end())
|
if(properties_.find("layout") != properties_.end())
|
||||||
{
|
{
|
||||||
properties_.erase("layout");
|
properties_.erase("layout");
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Set new pair <key, value> for key = layout */
|
/* Set new pair <key, value> for key = layout */
|
||||||
properties_.insert(PropertiesPair("layout", seekedLayoutName));
|
properties_.insert(PropertiesPair("layout", seekedLayoutName));
|
||||||
|
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
//printf("Found layout: %s at idx %d\n", layoutPathFound.c_str(), index);
|
//printf("Found layout: %s at idx %d\n", layoutPathFound.c_str(), index);
|
||||||
ss << "Found layout: " << "\"" << layoutPathFound << "\" in layouts list at idx " << index;
|
ss << "Found layout: " << "\"" << layoutPathFound << "\" in layouts list at idx " << index;
|
||||||
Logger::write(Logger::ZONE_INFO, "Configuration", ss.str());
|
Logger::write(Logger::ZONE_INFO, "Configuration", ss.str());
|
||||||
retVal = true;
|
retVal = true;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -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());
|
||||||
|
|||||||
@ -54,10 +54,10 @@ void Sound::play()
|
|||||||
SDL_RemoveTimer(idTimer);
|
SDL_RemoveTimer(idTimer);
|
||||||
if(!ampliStarted){
|
if(!ampliStarted){
|
||||||
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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(chunk_)
|
if(chunk_)
|
||||||
@ -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