Skip to content

Commit

Permalink
#662 handle changing key img with dynamic config
Browse files Browse the repository at this point in the history
  • Loading branch information
oben01 committed Oct 23, 2020
1 parent 3ddc1d7 commit ccf9ac7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 3 deletions.
58 changes: 55 additions & 3 deletions sources/plugins/StreamDeck/StreamDeck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ void CStreamDeck::doWork(boost::shared_ptr<yApi::IYPluginApi> api)
{
auto keyIndex = api->getEventHandler().getEventData<int>();
api->historizeData(m_usbDeviceInformation->deviceName, m_keywords[keyIndex]);
handleKeyData(keyIndex);
break;
}
case yApi::IYPluginApi::kBindingQuery:
Expand Down Expand Up @@ -307,25 +308,30 @@ void CStreamDeck::doWork(boost::shared_ptr<yApi::IYPluginApi> api)
auto img = fileManager.getData();
fileManager.close();

setKeyData(img, customText, keyCounter);

m_deviceManager->setKeyImage(img, keyCounter, customText);

auto isSecondKeyChecked = config->get<bool>(
"mainSection.content.keyElement#" + std::to_string(keyCounter) + ".content.content.checkbox");
if (isSecondKeyChecked)
{
auto secondKeyIconNameIndex = config->get<int>(
"mainSection.content.keyElement#" + std::to_string(keyCounter) + ".content.content.content.iconWhenKeyIsPressed");
"mainSection.content.keyElement#" + std::to_string(keyCounter) +
".content.content.content.iconWhenKeyIsPressed");

auto secondKeyIconPath = CDefaultIconSelector::getIconPath(pluginPath, secondKeyIconNameIndex);
auto secondKeyCustomText = config->get<std::string>(
"mainSection.content.keyElement#" + std::to_string(keyCounter) + ".content.content.content.customTextWhenKeyIsPressed");
"mainSection.content.keyElement#" + std::to_string(keyCounter) +
".content.content.content.customTextWhenKeyIsPressed");

CFileManager secondKeyFileManager(secondKeyIconPath);
secondKeyFileManager.read();
auto secondKeyImg = secondKeyFileManager.getData();
secondKeyFileManager.close();
}

setKeyData(secondKeyImg, secondKeyCustomText, keyCounter, true);
}
}
keyCounter++;
}
Expand Down Expand Up @@ -374,3 +380,49 @@ void CStreamDeck::initDevice(boost::shared_ptr<yApi::IYPluginApi>& api)
throw;
}
}

void CStreamDeck::handleKeyData(int& keyIndex)
{
const auto firstKeyDataIterator = firstKeyData.find(keyIndex);
const auto secondKeyDataIterator = secondKeyData.find(keyIndex);

if (firstKeyDataIterator != firstKeyData.end())
{
//found value
if (!firstKeyDataIterator->second.isAlreadyPressed)
{
if (secondKeyDataIterator != secondKeyData.end())
{
// found second key data
if (!secondKeyDataIterator->second.isAlreadyPressed)
{
firstKeyDataIterator->second.isAlreadyPressed = true;
m_deviceManager->setKeyImage(secondKeyData.find(keyIndex)->second.img, keyIndex,
secondKeyData.find(keyIndex)->second.customText);
}
}
}
else
{
firstKeyDataIterator->second.isAlreadyPressed = false;
m_deviceManager->setKeyImage(firstKeyData.find(keyIndex)->second.img, keyIndex,
firstKeyData.find(keyIndex)->second.customText);
}
}
}

void CStreamDeck::setKeyData(std::string& img, std::string& customText, int& keyCounter, bool isSecondKey)
{
KeyData keyData;
keyData.img = img;
keyData.customText = customText;
keyData.isAlreadyPressed = false;
if (!isSecondKey)
{
firstKeyData.insert(std::pair<int, KeyData>(keyCounter, keyData));
}
else
{
secondKeyData.insert(std::pair<int, KeyData>(keyCounter, keyData));
}
}
5 changes: 5 additions & 0 deletions sources/plugins/StreamDeck/StreamDeck.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,9 @@ class CStreamDeck : public plugin_cpp_api::IPlugin

std::map<int, boost::shared_ptr<const shared::plugin::yPluginApi::historization::IHistorizable>> m_keywords;

std::map<int, KeyData> firstKeyData;
std::map<int, KeyData> secondKeyData;

void handleKeyData(int& keyIndex);
void setKeyData(std::string& img, std::string& customText, int& keyCounter, bool isSecondKey= false);
};
7 changes: 7 additions & 0 deletions sources/plugins/StreamDeck/windows/DeviceManagerHelper.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ struct UsbDeviceInformation
CStreamDeckFactory::EStreamDeckModel deviceModel;
};

struct KeyData
{
std::string img;
std::string customText;
bool isAlreadyPressed;
};

class CDeviceManagerHelper
{
public:
Expand Down

0 comments on commit ccf9ac7

Please sign in to comment.