Skip to content

Commit

Permalink
Merge pull request #36 from guilhermealbm/master
Browse files Browse the repository at this point in the history
Add option to turn off NC and ambient sound
  • Loading branch information
Plutoberth authored Mar 14, 2021
2 parents 83029c9 + 53c41f2 commit 6355d26
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 18 deletions.
6 changes: 3 additions & 3 deletions Client/CommandSerializer.cpp
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit 6355d26

Please sign in to comment.