Skip to content

Commit

Permalink
host info (needs per-id listen mechanism)
Browse files Browse the repository at this point in the history
  • Loading branch information
benkuper committed Oct 7, 2023
1 parent 26074a4 commit 59c4ed3
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 26 deletions.
60 changes: 41 additions & 19 deletions Firmware/Bentuino/server/edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -107,16 +107,17 @@ <h1>Bentuino Settings</h1>

function initWebSocket() {
oscWS = new osc.WebSocketPort({
url: "ws://" + ip + "/ws",
url: "ws://" + ip + "",
metadata: true
});

oscWS.on('message', function (oscMsg) {
var p = document.getElementById(oscMsg.address);

var pid = oscMsg.address.substring(1).replace(/\//g, "-");
var p = document.getElementById(pid);
// console.log("here", oscMsg, p);
var val = oscMsg.args[0].value;
if(p != undefined)
{
if (p != undefined) {
processParameterFeedback(p, val);
}
});
Expand Down Expand Up @@ -170,29 +171,51 @@ <h1>Bentuino Settings</h1>

function createParameterEditor(item, level) {

item.id = item.FULL_PATH.substring(1).replace(/\//g, "-");

var paramDiv;
//generate the parameter editor depending on its type
switch (item.TYPE) {
case "i":
return createIntParameterEditor(item, level);
paramDiv = createIntParameterEditor(item, level);
break;

case "f":
return createFloatParameterEditor(item, level);
paramDiv = createFloatParameterEditor(item, level);
break;

case "s":
return createStringParameterEditor(item, level);
paramDiv = createStringParameterEditor(item, level);
break;

case "b":
case "T":
case "F":
return createBoolParameterEditor(item, level);
paramDiv = createBoolParameterEditor(item, level);
break;


default:
return createDefaultParameterEditor(item, level);
paramDiv = createDefaultParameterEditor(item, level);
break;


}

if(item.ACCESS == 1)
{
paramDiv.querySelector(`#${item.id}`).disabled = true;
var pVal = paramDiv.querySelector(`#${item.id}-value`);
if(pVal) pVal.disabled = true;
}
return paramDiv;
}

function createIntParameterEditor(item, level) {
var paramDiv = document.createElement('div');
paramDiv.classList.add("parameter");
var range = item.RANGE != undefined ? `min="${item.RANGE[0].MIN}" max="${item.RANGE[0].MAX}` : "";
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="number" ${range} id="${item.FULL_PATH}" value="${item.VALUE[0]}" oninput='sendParameterValue("${item.FULL_PATH}", "i", this.value)'/>`;
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="number" ${range} id="${item.id}" value="${item.VALUE[0]}" oninput='sendParameterValue("${item.FULL_PATH}", "i", this.value)'/>`;
return paramDiv;
}

Expand All @@ -201,30 +224,30 @@ <h1>Bentuino Settings</h1>
paramDiv.classList.add("parameter");
var range = item.RANGE != null ? `min="${item.RANGE[0].MIN}" max="${item.RANGE[0].MAX}"` : "";
var inputType = item.RANGE != null ? "range" : "number";
var rangeText = item.RANGE != null? `<input type="text" class="sliderText" id="${item.FULL_PATH}-value" value="${item.VALUE[0]}">`:'';
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="${inputType}" ${range} step="any" id="${item.FULL_PATH}" value="${item.VALUE[0]}" oninput='this.nextElementSibling.value = parseFloat(this.value).toFixed(3);sendParameterValue("${item.FULL_PATH}", "f", this.value)'/>${rangeText}`;
var rangeText = item.RANGE != null ? `<input type="text" class="sliderText" id="${item.id}-value" value="${item.VALUE[0]}">` : '';
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="${inputType}" ${range} step="any" id="${item.id}" value="${item.VALUE[0]}" oninput='this.nextElementSibling.value = parseFloat(this.value).toFixed(3);sendParameterValue("${item.FULL_PATH}", "f", this.value)'/>${rangeText}`;
return paramDiv;
}

function createStringParameterEditor(item, level) {
var paramDiv = document.createElement('div');
paramDiv.classList.add("parameter");
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="text" id="${item.FULL_PATH}" value="${item.VALUE[0]}" oninput='sendParameterValue("${item.FULL_PATH}", "s", this.value)'/>`;
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="text" id="${item.id}" value="${item.VALUE[0]}" oninput='sendParameterValue("${item.FULL_PATH}", "s", this.value)'/>`;
return paramDiv;
}

function createBoolParameterEditor(item, level) {
var paramDiv = document.createElement('div');
paramDiv.classList.add("parameter");
var checked = item.VALUE[0] ? "checked" : "";
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="checkbox" id="${item.FULL_PATH}" ${checked} oninput='sendParameterValue("${item.FULL_PATH}", "i", this.checked)'/>`;
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="checkbox" id="${item.id}" ${checked} oninput='sendParameterValue("${item.FULL_PATH}", "i", this.checked)'/>`;
return paramDiv;
}

function createDefaultParameterEditor(item, level) {
var paramDiv = document.createElement('div');
paramDiv.classList.add("parameter");
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="text" id="${item.FULL_PATH}" value="${item.VALUE[0]}" oninput='sendParameterValue("${item.FULL_PATH}", "f", this.value)'/>`;
paramDiv.innerHTML = `<label>${lowerCamelCaseToTitleCase(item.DESCRIPTION)}:</label><input type="text" id="${item.id}" value="${item.VALUE[0]}" oninput='sendParameterValue("${item.FULL_PATH}", "f", this.value)'/>`;
return paramDiv;
}

Expand All @@ -237,11 +260,10 @@ <h1>Bentuino Settings</h1>
oscWS.send({ address: command });
}

function processParameterFeedback(p, val)
{
if(p.type == "checkbox") p.checked = val;
function processParameterFeedback(p, val) {
if (p.type == "checkbox") p.checked = val;
else p.value = val;
if(p.type == "range") p.nextElementSibling.value = parseFloat(p.value).toFixed(3)
if (p.type == "range") p.nextElementSibling.value = parseFloat(p.value).toFixed(3)
}

//Helpers
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,40 @@ ImplementSingleton(WebServerComponent)
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Methods", "GET, POST, PUT");
DefaultHeaders::Instance().addHeader("Access-Control-Allow-Headers", "Content-Type");

server.on("/", HTTP_GET, [](AsyncWebServerRequest *request)
server.addHandler(&ws);
server.on("/", HTTP_GET, [&](AsyncWebServerRequest *request)
{
DynamicJsonDocument doc(32000);
JsonObject o = doc.to<JsonObject>();
RootComponent::instance->fillOSCQueryData(o);
oscQueryDoc.clear();
JsonObject o = oscQueryDoc.to<JsonObject>();

if (request->hasArg("HOST_INFO"))
{
JsonObject eo = o.createNestedObject("EXTENSIONS");
eo["ACCESS"] = true;
eo["CLIPMODE"] = false;
eo["CRITICAL"] = false;
eo["RANGE"] = true;
eo["TAGS"] = false;
eo["TYPE"] = true;
eo["UNIT"] = false;
eo["VALUE"] = true;
eo["LISTEN"] = true;
eo["PATH_ADDED"] = true;
eo["PATH_REMOVED"] = true;
eo["PATH_RENAMED"] = true;
eo["PATH_CHANGED"] = false;

o["NAME"] = RootComponent::instance->deviceName.stringValue();
o["OSC_PORT"] = OSC_LOCAL_PORT;
o["OSC_TRANSPORT"] = "UDP";

}else
{
RootComponent::instance->fillOSCQueryData(o);
}

String jStr;
serializeJson(doc, jStr);
serializeJson(oscQueryDoc, jStr);
request->send(200, "application/json", jStr); });

// server.onNotFound(std::bind(&WebServerComponent::handleNotFound, this));
Expand All @@ -37,7 +63,7 @@ ImplementSingleton(WebServerComponent)
ws.onEvent(std::bind(&WebServerComponent::onWSEvent,
this, std::placeholders::_1, std::placeholders::_2, std::placeholders::_3, std::placeholders::_4, std::placeholders::_5, std::placeholders::_6));

server.addHandler(&ws);


return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
DeclareComponentSingleton(WebServer, "server",)

AsyncWebServer server = AsyncWebServer(80);
AsyncWebSocket ws = AsyncWebSocket("/ws");
AsyncWebSocket ws = AsyncWebSocket("/");

class WSPrint : public Print
{
Expand All @@ -23,6 +23,8 @@ bool isUploading;
int uploadedBytes;
File uploadingFile;

StaticJsonDocument<32000> oscQueryDoc;

String tmpExcludeParam = "";//to change with client exclude when AsyncWebServer implements it

bool initInternal(JsonObject o) override;
Expand Down

0 comments on commit 59c4ed3

Please sign in to comment.