Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to turn off NC and ambient sound #36

Merged
merged 5 commits into from Mar 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions Client/CommandSerializer.cpp
Expand Up @@ -4,7 +4,7 @@ constexpr unsigned char ESCAPED_BYTE_SENTRY = 61;
constexpr unsigned char ESCAPED_60 = 44;
constexpr unsigned char ESCAPED_61 = 45;
constexpr unsigned char ESCAPED_62 = 46;
constexpr unsigned int MAX_STEPS_WH_1000_XM3 = 19;
constexpr int MAX_STEPS_WH_1000_XM3 = 19;

namespace CommandSerializer
{
Expand Down Expand Up @@ -153,7 +153,7 @@ namespace CommandSerializer
return ret;
}

NC_DUAL_SINGLE_VALUE getDualSingleForAsmLevel(unsigned char asmLevel)
NC_DUAL_SINGLE_VALUE getDualSingleForAsmLevel(char asmLevel)
{
NC_DUAL_SINGLE_VALUE val = NC_DUAL_SINGLE_VALUE::OFF;
if (asmLevel > MAX_STEPS_WH_1000_XM3)
Expand All @@ -171,7 +171,7 @@ namespace CommandSerializer
return val;
}

Buffer serializeNcAndAsmSetting(NC_ASM_EFFECT ncAsmEffect, NC_ASM_SETTING_TYPE ncAsmSettingType, ASM_SETTING_TYPE asmSettingType, ASM_ID asmId, unsigned char asmLevel)
Buffer serializeNcAndAsmSetting(NC_ASM_EFFECT ncAsmEffect, NC_ASM_SETTING_TYPE ncAsmSettingType, ASM_SETTING_TYPE asmSettingType, ASM_ID asmId, char asmLevel)
{
Buffer ret;
ret.push_back(static_cast<unsigned char>(COMMAND_TYPE::NCASM_SET_PARAM));
Expand Down
6 changes: 3 additions & 3 deletions Client/CommandSerializer.h
Expand Up @@ -6,7 +6,7 @@
#include <stdexcept>
#include "Exceptions.h"

constexpr unsigned int MINIMUM_VOICE_FOCUS_STEP = 2;
constexpr int MINIMUM_VOICE_FOCUS_STEP = 2;

namespace CommandSerializer
{
Expand Down Expand Up @@ -37,7 +37,7 @@ namespace CommandSerializer

Message unpackBtMessage(const Buffer& src);

NC_DUAL_SINGLE_VALUE getDualSingleForAsmLevel(unsigned char asmLevel);
Buffer serializeNcAndAsmSetting(NC_ASM_EFFECT ncAsmEffect, NC_ASM_SETTING_TYPE ncAsmSettingType, ASM_SETTING_TYPE asmSettingType, ASM_ID asmId, unsigned char asmLevel);
NC_DUAL_SINGLE_VALUE getDualSingleForAsmLevel(char asmLevel);
Buffer serializeNcAndAsmSetting(NC_ASM_EFFECT ncAsmEffect, NC_ASM_SETTING_TYPE ncAsmSettingType, ASM_SETTING_TYPE asmSettingType, ASM_ID asmId, char asmLevel);
}

35 changes: 23 additions & 12 deletions Client/GUI_Impls/CrossPlatformGUI.cpp
Expand Up @@ -152,30 +152,38 @@ void CrossPlatformGUI::_drawDeviceDiscovery()

void CrossPlatformGUI::_drawASMControls()
{
static bool ambientSoundControl = true;
static bool sentAmbientSoundControl = ambientSoundControl;
static bool focusOnVoice = false;
static bool sentFocusOnVoice = focusOnVoice;
static int asmLevel = 0;
static int lastAsmLevel = asmLevel;
static int sentAsmLevel = asmLevel;
//Don't show if the command only takes a few frames to send
static int commandLinger = 0;

if (ImGui::CollapsingHeader("Ambient Sound Mode ", ImGuiTreeNodeFlags_DefaultOpen))
{
ImGui::Text("Control ambient sound for your %ss", this->_connectedDevice.name.c_str());
ImGui::Checkbox("Ambient Sound Control", &ambientSoundControl);

ImGui::SliderInt("Ambient Sound Level", &asmLevel, 0, 19);
if (ambientSoundControl)
{
ImGui::Text("Control ambient sound for your %ss", this->_connectedDevice.name.c_str());

bool sliderActive = ImGui::IsItemActive();
ImGui::SliderInt("Ambient Sound Level", &asmLevel, 0, 19);

if (asmLevel >= MINIMUM_VOICE_FOCUS_STEP)
{
ImGui::Checkbox("Focus on Voice", &focusOnVoice);
}
else
{
ImGui::Text("Focus on Voice isn't enabled on this level.");
if (asmLevel >= MINIMUM_VOICE_FOCUS_STEP)
{
ImGui::Checkbox("Focus on Voice", &focusOnVoice);
}
else
{
ImGui::Text("Focus on Voice isn't enabled on this level.");
}
}

bool sliderActive = ImGui::IsItemActive();

if (this->_sendCommandFuture.ready())
{
commandLinger = 0;
Expand Down Expand Up @@ -205,10 +213,12 @@ void CrossPlatformGUI::_drawASMControls()
}
}
//We're not waiting, and there's no command in the air, so we can evaluate sending a new command
else if (sentAsmLevel != asmLevel || sentFocusOnVoice != focusOnVoice)
else if (sentAsmLevel != asmLevel || sentFocusOnVoice != focusOnVoice || sentAmbientSoundControl != ambientSoundControl)
{
auto ncAsmEffect = sliderActive ? NC_ASM_EFFECT::ADJUSTMENT_IN_PROGRESS : NC_ASM_EFFECT::ADJUSTMENT_COMPLETION;
auto ncAsmEffect = sliderActive ? NC_ASM_EFFECT::ADJUSTMENT_IN_PROGRESS : ambientSoundControl ? NC_ASM_EFFECT::ADJUSTMENT_COMPLETION : NC_ASM_EFFECT::OFF;
auto asmId = focusOnVoice ? ASM_ID::VOICE : ASM_ID::NORMAL;
lastAsmLevel = asmLevel == -1 ? lastAsmLevel : asmLevel;
asmLevel = ambientSoundControl ? lastAsmLevel : -1;

this->_sendCommandFuture.setFromAsync([=]() {
return this->_bt.sendCommand(CommandSerializer::serializeNcAndAsmSetting(
Expand All @@ -221,6 +231,7 @@ void CrossPlatformGUI::_drawASMControls()
});
sentAsmLevel = asmLevel;
sentFocusOnVoice = focusOnVoice;
sentAmbientSoundControl = ambientSoundControl;
}
}
}
Expand Down