|
|
|
@ -316,44 +316,44 @@ function createInputForPin(pin) { |
|
|
|
|
input.type = "radio"; |
|
|
|
|
input.name = "pins"; |
|
|
|
|
input.data = pin.name; |
|
|
|
|
input.className = "pin-input"; |
|
|
|
|
input.className = "pin-input"; |
|
|
|
|
input.value= pin.value; |
|
|
|
|
input.id = "opt-" + pin.value; |
|
|
|
|
if (currPin == pin.name) input.checked = "1"; |
|
|
|
|
|
|
|
|
|
var descr = m('<label for="opt-'+pin.value+'"><b>'+pin.name+":</b>"+pin.descr+"</label>"); |
|
|
|
|
var div = document.createElement("div"); |
|
|
|
|
div.appendChild(input); |
|
|
|
|
div.appendChild(descr); |
|
|
|
|
return div; |
|
|
|
|
var descr = m('<label for="opt-'+pin.value+'"><b>'+pin.name+":</b>"+pin.descr+"</label>"); |
|
|
|
|
var div = document.createElement("div"); |
|
|
|
|
div.appendChild(input); |
|
|
|
|
div.appendChild(descr); |
|
|
|
|
return div; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function displayPins(resp) { |
|
|
|
|
var po = $("#pin-mux"); |
|
|
|
|
po.innerHTML = ""; |
|
|
|
|
currPin = resp.curr; |
|
|
|
|
resp.map.forEach(function(v) { |
|
|
|
|
po.appendChild(createInputForPin(v)); |
|
|
|
|
}); |
|
|
|
|
var i, inputs = $(".pin-input"); |
|
|
|
|
for (i=0; i<inputs.length; i++) { |
|
|
|
|
inputs[i].onclick = function() { setPins(this.value, this.data) }; |
|
|
|
|
}; |
|
|
|
|
var po = $("#pin-mux"); |
|
|
|
|
po.innerHTML = ""; |
|
|
|
|
currPin = resp.curr; |
|
|
|
|
resp.map.forEach(function(v) { |
|
|
|
|
po.appendChild(createInputForPin(v)); |
|
|
|
|
}); |
|
|
|
|
var i, inputs = $(".pin-input"); |
|
|
|
|
for (i=0; i<inputs.length; i++) { |
|
|
|
|
inputs[i].onclick = function() { setPins(this.value, this.data) }; |
|
|
|
|
}; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function fetchPins() { |
|
|
|
|
ajaxJson("GET", "/pins", displayPins, function() { |
|
|
|
|
window.setTimeout(fetchPins, 1000); |
|
|
|
|
}); |
|
|
|
|
window.setTimeout(fetchPins, 1000); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function setPins(v, name) { |
|
|
|
|
ajaxSpin("POST", "/pins?map="+v, function() { |
|
|
|
|
showNotification("Pin assignment changed to " + name); |
|
|
|
|
}, function() { |
|
|
|
|
showNotification("Pin assignment change failed"); |
|
|
|
|
window.setTimeout(fetchPins, 100); |
|
|
|
|
}); |
|
|
|
|
showNotification("Pin assignment changed to " + name); |
|
|
|
|
}, function() { |
|
|
|
|
showNotification("Pin assignment change failed"); |
|
|
|
|
window.setTimeout(fetchPins, 100); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//===== TCP client card
|
|
|
|
@ -390,8 +390,8 @@ function displayTcpClient(resp) { |
|
|
|
|
|
|
|
|
|
function fetchTcpClient() { |
|
|
|
|
ajaxJson("GET", "/tcpclient", displayTcpClient, function() { |
|
|
|
|
window.setTimeout(fetchTcpClient, 1000); |
|
|
|
|
}); |
|
|
|
|
window.setTimeout(fetchTcpClient, 1000); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//===== MQTT cards
|
|
|
|
@ -399,7 +399,7 @@ function fetchTcpClient() { |
|
|
|
|
function changeMqtt(e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
var url = "mqtt?1=1"; |
|
|
|
|
var i, inputs = $("input"); |
|
|
|
|
var i, inputs = document.querySelectorAll('#mqtt-form input'); |
|
|
|
|
for (i=0; i<inputs.length; i++) { |
|
|
|
|
if (inputs[i].type != "checkbox") |
|
|
|
|
url += "&" + inputs[i].name + "=" + inputs[i].value; |
|
|
|
@ -409,12 +409,12 @@ function changeMqtt(e) { |
|
|
|
|
var cb = $("#mqtt-button"); |
|
|
|
|
addClass(cb, 'pure-button-disabled'); |
|
|
|
|
ajaxSpin("POST", url, function(resp) { |
|
|
|
|
showNotification("MQTT updated"); |
|
|
|
|
removeClass(cb, 'pure-button-disabled'); |
|
|
|
|
fetchMqtt(); |
|
|
|
|
}, function(s, st) { |
|
|
|
|
showWarning("Error: "+st); |
|
|
|
|
removeClass(cb, 'pure-button-disabled'); |
|
|
|
|
fetchMqtt(); |
|
|
|
|
window.setTimeout(fetchMqtt, 100); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -446,17 +446,28 @@ function displayMqtt(data) { |
|
|
|
|
|
|
|
|
|
function fetchMqtt() { |
|
|
|
|
ajaxJson("GET", "/mqtt", displayMqtt, function() { |
|
|
|
|
window.setTimeout(fetchMqtt, 1000); |
|
|
|
|
}); |
|
|
|
|
window.setTimeout(fetchMqtt, 1000); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function changeMqttStatus(e) { |
|
|
|
|
e.preventDefault(); |
|
|
|
|
var v = document.querySelector('input[name="mqtt-status-topic"]').value; |
|
|
|
|
ajaxSpin("POST", "/mqtt?mqtt-status-topic=" + v, function() { |
|
|
|
|
showNotification("MQTT status settings updated"); |
|
|
|
|
}, function(s, st) { |
|
|
|
|
showWarning("Error: "+st); |
|
|
|
|
window.setTimeout(fetchMqtt, 100); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
function setMqtt(name, v) { |
|
|
|
|
ajaxSpin("POST", "/mqtt?" + name + "=" + (v ? 1 : 0), function() { |
|
|
|
|
showNotification(name + " is now " + (v ? "enabled" : "disabled")); |
|
|
|
|
}, function() { |
|
|
|
|
showNotification("Enable/disable failed"); |
|
|
|
|
window.setTimeout(fetchMqtt, 100); |
|
|
|
|
}); |
|
|
|
|
var n = name.replace("-enable", ""); |
|
|
|
|
showNotification(n + " is now " + (v ? "enabled" : "disabled")); |
|
|
|
|
}, function() { |
|
|
|
|
showWarning("Enable/disable failed"); |
|
|
|
|
window.setTimeout(fetchMqtt, 100); |
|
|
|
|
}); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|