Skip to content

Commit

Permalink
fix settings component
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed May 3, 2024
1 parent 1ede913 commit 2dc988a
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 16 deletions.
8 changes: 4 additions & 4 deletions Firmware/Bentuino/data/server/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -171,10 +171,10 @@
<h1>Bentuino Settings</h1>
<div id="controls">
<div class="control-block">
<input type="button" value="Save Settings" onclick="sendCommand('/root/saveSettings');restartDevice();" />
<input type="button" value="Shutdown" onclick="sendCommand('/root/shutdown')" />
<input type="button" value="Save Settings" onclick="sendCommand('/settings/save');restartDevice();" />
<input type="button" value="Shutdown" onclick="sendCommand('/shutdown')" />
<input type="button" value="Restart" onclick="restartDevice();" />
<input type="button" value="Test Mode" onclick="sendCommand('/root/test');" />
<input type="button" value="Test Mode" onclick="sendCommand('/settings/testMode');" />
Show Config<input id="showConfig" type="checkbox" value="Show Config" checked
onchange="updateShowConfig()" />
</div>
Expand Down Expand Up @@ -436,7 +436,7 @@ <h1>Bentuino Settings</h1>
}

function restartDevice() {
sendCommand('/root/restart');
sendCommand('/restart');
setTimeout(() => connectToServer(), 1000);
}

Expand Down
2 changes: 1 addition & 1 deletion Firmware/Bentuino/src/Common/StringHelpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ void StringHelpers::processStringMessage(const String &buffer, std::function<voi

int tcIndex = target.lastIndexOf('.');

String tc = target.substring(0, tcIndex); // component name
String tc = tcIndex == -1 ? "root" : target.substring(0, tcIndex); // component name
String cmd = target.substring(tcIndex + 1); // parameter name
String args = (splitIndex != -1 ? buffer.substring(splitIndex + 1) : ""); // value

Expand Down
4 changes: 3 additions & 1 deletion Firmware/Bentuino/src/Component/Component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ void Component::fillSettingsData(JsonObject o, bool showConfig)

void Component::fillChunkedOSCQueryData(OSCQueryChunk *chunk, bool showConfig)
{
const String fullPath = getFullPath(this == RootComponent::instance);
const String fullPath = getFullPath();//this == RootComponent::instance);

switch (chunk->nextType)
{
Expand Down Expand Up @@ -301,6 +301,8 @@ void Component::setupChunkAfterComponent(OSCQueryChunk *chunk, const Component *

String Component::getFullPath(bool includeRoot, bool scriptMode) const
{
if(this == RootComponent::instance && !includeRoot) return "";

Component *pc = parentComponent;
String s = name;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,16 @@ void CommunicationComponent::sendParamFeedback(Component *c, void *param, const
break;
}

String baseAddress = c->getFullPath();

#ifdef USE_SERIAL
if (serial.sendFeedback)
serial.sendMessage(c->name, pName, data, numData);
serial.sendMessage(baseAddress, pName, data, numData);
#endif

#ifdef USE_OSC
if (osc.sendFeedback)
osc.sendMessage("/" + c->name, pName, data, numData);
osc.sendMessage(baseAddress, pName, data, numData);
#endif

#ifdef USE_SERVER
Expand All @@ -95,25 +97,28 @@ void CommunicationComponent::sendParamFeedback(Component *c, void *param, const

void CommunicationComponent::sendEventFeedback(const ComponentEvent &e)
{
String baseAddress = e.component->getFullPath();
#ifdef USE_SERIAL
if (serial.sendFeedback)
serial.sendMessage(e.component->name, e.getName(), e.data, e.numData);
serial.sendMessage(baseAddress, e.getName(), e.data, e.numData);
#endif

#ifdef USE_OSC
if (osc.sendFeedback)
osc.sendMessage(e.component->name, e.getName(), e.data, e.numData);
osc.sendMessage(baseAddress, e.getName(), e.data, e.numData);
#endif
}

void CommunicationComponent::sendMessage(Component *c, const String &mName, const String &val)
{
String baseAddress = c->getFullPath();

var data[1]{val};
#ifdef USE_SERIAL
serial.sendMessage(c->name, mName, data, 1);
serial.sendMessage(baseAddress, mName, data, 1);
#endif

#ifdef USE_OSC
osc.sendMessage(c->name, mName, data, 1);
osc.sendMessage(baseAddress, mName, data, 1);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ void OSCComponent::processMessage(OSCMessage &msg)
String addrStr = String(addr).substring(1);
addrStr.replace('/', '.');
int tcIndex = addrStr.lastIndexOf('.');
String tc = addrStr.substring(0, tcIndex); // component name
String tc = tcIndex == -1 ? "root" : addrStr.substring(0, tcIndex); // component name
String cmd = addrStr.substring(tcIndex + 1);

const int numData = 10; // max 10-2 = 8 arguments
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ void SerialComponent::processMessage(String buffer)

void SerialComponent::sendMessage(String source, String command, var *data, int numData)
{

String msg = source + "." + command;
String msg = (source == "" ? "" : source + ".") + command;
for (int i = 0; i < numData; i++)
{
msg += " " + data[i].stringValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,10 @@ void SettingsComponent::saveSettings()
{
Settings::settings.clear();
JsonObject o = Settings::settings.to<JsonObject>();
fillSettingsData(o, true);
RootComponent::instance->fillSettingsData(o, true);
Settings::saveSettings();
NDBG("Settings saved");

}

void SettingsComponent::clearSettings()
Expand Down

0 comments on commit 2dc988a

Please sign in to comment.