OpenBuilds-CONTROL/app/js/websocket.js

743 wiersze
25 KiB
JavaScript
Czysty Zwykły widok Historia

2018-06-19 08:07:03 +00:00
var socket, laststatus;;
var server = ''; //192.168.14.100';
var programBoard = {};
var grblParams = {}
var smoothieParams = {}
var nostatusyet = true;
2018-06-19 20:25:40 +00:00
var safeToUpdateSliders = false;
var laststatus
var simstopped = false;
2018-06-21 21:04:41 +00:00
var bellstate = false;
var toast = Metro.toast.create;
2019-05-10 18:36:51 +00:00
var unit = "mm"
2018-06-19 20:25:40 +00:00
$(document).ready(function() {
initSocket();
2018-06-21 20:02:40 +00:00
$("#command").inputHistory({
enter: function() {
2018-06-21 20:02:40 +00:00
$("#sendCommand").click();
}
});
$("form").submit(function() {
return false;
});
2019-09-03 18:36:09 +00:00
});
2019-09-13 18:39:59 +00:00
function showGrbl(bool) {
if (bool) {
sendGcode('$$')
sendGcode('$I')
$("#grblButtons").show()
$("#firmwarename").html('Grbl')
} else {
$("#grblButtons").hide()
$("#firmwarename").html('')
}
}
2018-06-19 20:25:40 +00:00
function printLog(string) {
2019-10-18 18:55:41 +00:00
if (!disableSerialLog) {
if (document.getElementById("console") !== null) {
if (string.isString) {
// split(/\r\n|\n|\r/);
string = string.replace(/\r\n|\n|\r/, "<br />");
}
if ($('#console p').length > 100) {
// remove oldest if already at 300 lines
$('#console p').first().remove();
}
var template = '<p class="pf">';
var time = new Date();
2018-06-19 20:25:40 +00:00
2019-10-18 18:55:41 +00:00
template += '<span class="fg-brandColor1">[' + (time.getHours() < 10 ? '0' : '') + time.getHours() + ":" + (time.getMinutes() < 10 ? '0' : '') + time.getMinutes() + ":" + (time.getSeconds() < 10 ? '0' : '') + time.getSeconds() + ']</span> ';
template += string;
$('#console').append(template);
$('#console').scrollTop(($("#console")[0].scrollHeight - $("#console").height()) + 20);
}
2018-08-24 19:00:03 +00:00
}
2019-10-18 18:55:41 +00:00
};
2018-06-19 20:25:40 +00:00
2018-06-19 08:07:03 +00:00
function initSocket() {
2018-06-19 20:25:40 +00:00
socket = io.connect(server); // socket.io init
2018-09-18 19:26:29 +00:00
printLog("<span class='fg-red'>[ Websocket ] </span><span class='fg-green'>Bidirectional Websocket Interface Started</span>")
2018-06-19 20:25:40 +00:00
setTimeout(function() {
populatePortsMenu();
}, 2000);
2018-06-20 13:16:46 +00:00
socket.on('disconnect', function() {
console.log("WEBSOCKET DISCONNECTED")
printLog("<span class='fg-red'>[ Websocket ] </span><span class='fg-brown'> Disconnected. OpenBuilds CONTROL probably quit or crashed</span>")
$("#websocketstatus").html("Disconnected")
2018-06-20 13:16:46 +00:00
});
socket.on('connect', function() {
$("#websocketstatus").html("Connected")
});
2018-06-29 19:48:34 +00:00
socket.on('gcodeupload', function(data) {
printLog("Received new GCODE from API")
2020-03-30 15:26:11 +00:00
editor.session.setValue(data.gcode);
loadedFileName = data.filename;
setWindowTitle()
parseGcodeInWebWorker(data.gcode)
$('#controlTab').click()
2019-10-18 18:55:41 +00:00
if (webgl) {
2018-08-29 08:11:14 +00:00
$('#gcodeviewertab').click();
} else {
$('#gcodeeditortab').click()
}
2018-06-29 19:48:34 +00:00
});
2018-08-09 12:20:42 +00:00
socket.on('gcodeupload', function(data) {
printLog("Activated window");
});
socket.on('integrationpopup', function(data) {
printLog("Integration called from " + data)
// editor.session.setValue(data);
$('#controlTab').click()
$('#consoletab').click()
// gcodeeditortab
});
2018-06-29 19:48:34 +00:00
2018-07-12 13:06:53 +00:00
socket.on('updatedata', function(data) {
// console.log(data.length, data)
var toPrint = data.response;
2018-08-10 19:42:30 +00:00
printLog("<span class='fg-red'>[ " + data.command + " ]</span> <span class='fg-green'>" + toPrint + "</span>")
2018-07-12 13:06:53 +00:00
});
socket.on('updateready', function(data) {
2019-07-17 15:14:18 +00:00
// 0 = not connected
// 1 = Connected, but not Playing yet
// 2 = Connected, but not Playing yet
// 3 = Busy Streaming GCODE
// 4 = Paused
// 5 = Alarm State
// 6 = Firmware Upgrade State
2020-01-08 13:39:24 +00:00
if (laststatus.comms.connectionStatus < 3 && !continuousJogRunning) {
2019-07-17 15:14:18 +00:00
$('#availVersion').html(data)
2020-03-06 15:59:58 +00:00
getChangelog();
2019-07-17 15:14:18 +00:00
Metro.dialog.open('#downloadUpdate')
}
2018-07-12 13:06:53 +00:00
});
socket.on('updateprogress', function(data) {
$('#downloadprogress').html(data + "%");
});
2018-06-29 19:48:34 +00:00
2018-06-19 20:25:40 +00:00
socket.on('data', function(data) {
2018-12-21 13:56:11 +00:00
// console.log(data)
2018-09-27 15:00:49 +00:00
var toPrint = escapeHTML(data.response);
2018-06-19 08:07:03 +00:00
2018-06-20 13:00:05 +00:00
// Parse Grbl Settings Feedback
2018-06-27 20:53:07 +00:00
if (data.response.indexOf('$') === 0) {
2018-08-24 19:00:03 +00:00
if (typeof grblSettings !== 'undefined') {
grblSettings(data.response)
var key = data.response.split('=')[0].substr(1);
var descr = grblSettingCodes[key];
toPrint = data.response + " ;" + descr
printLog("<span class='fg-red'>[ " + data.command + " ]</span> <span class='fg-green'>" + toPrint + "</span>")
}
2018-09-27 15:00:49 +00:00
} else {
printLog("<span class='fg-red'>[ " + data.command + " ]</span> <span class='fg-green'>" + toPrint + "</span>")
2018-06-19 20:25:40 +00:00
};
2018-06-20 13:00:05 +00:00
2018-06-19 20:25:40 +00:00
});
2018-06-21 20:02:40 +00:00
socket.on("grbl", function(data) {
showGrbl(true)
});
2020-06-22 21:04:23 +00:00
// socket.on("prbResult", function(data) {
// console.log("Probe Data: ", data)
// });
2018-12-28 21:28:44 +00:00
2019-09-13 18:39:59 +00:00
socket.on("jobComplete", function(data) {
2020-03-06 15:59:58 +00:00
2020-04-16 13:32:26 +00:00
// console.log("jobComplete", data)
2020-03-06 15:59:58 +00:00
if (data.completed) {
2020-04-16 13:32:26 +00:00
// console.log("Job Complete", data)
2020-03-06 15:59:58 +00:00
}
if (data.jobCompletedMsg && data.jobCompletedMsg.length > 0) {
$("#completeMsgDiv").html(data.jobCompletedMsg);
Metro.dialog.open("#completeMsgModal");
}
2020-06-22 21:04:23 +00:00
$('#jobCompleteBtnOk').focus();
2020-03-06 15:59:58 +00:00
2019-09-13 18:39:59 +00:00
});
2019-01-23 19:07:58 +00:00
socket.on("machinename", function(data) {
2019-04-22 19:17:09 +00:00
if (typeof setMachineButton !== 'undefined') {
2019-04-22 14:52:10 +00:00
setMachineButton(data)
}
2019-01-23 19:07:58 +00:00
});
2019-09-13 18:39:59 +00:00
2018-06-19 20:25:40 +00:00
socket.on("queueCount", function(data) {
2018-08-01 20:20:17 +00:00
// calc percentage
2020-04-17 21:07:39 +00:00
var left = data[0]
var total = data[1]
2018-08-01 20:20:17 +00:00
var done = total - left;
2020-04-17 21:07:39 +00:00
var donepercent = done / total * 100
2018-08-01 20:20:17 +00:00
var progressbar = $("#progressbar").data("progress");
2018-08-24 19:00:03 +00:00
if (progressbar) {
progressbar.val(donepercent);
}
2019-04-18 14:23:51 +00:00
if (laststatus) {
if (laststatus.comms.connectionStatus == 3) {
2020-04-17 21:07:39 +00:00
editor.gotoLine(data[1] - data[0]);
2019-04-18 14:23:51 +00:00
}
2019-04-22 14:52:10 +00:00
if (typeof object !== 'undefined' && done > 0) {
2019-09-13 18:39:59 +00:00
if (object.userData !== 'undefined' && object.userData && object.userData.lines.length > 2) {
2019-05-10 18:36:51 +00:00
var timeremain = object.userData.lines[object.userData.lines.length - 1].p2.timeMinsSum - object.userData.lines[done].p2.timeMinsSum;
}
2019-04-18 14:23:51 +00:00
if (!isNaN(timeremain)) {
var mins_num = parseFloat(timeremain, 10); // don't forget the second param
var hours = Math.floor(mins_num / 60);
var minutes = Math.floor((mins_num - ((hours * 3600)) / 60));
var seconds = Math.floor((mins_num * 60) - (hours * 3600) - (minutes * 60));
// Appends 0 when unit is less than 10
if (hours < 10) {
hours = "0" + hours;
}
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
var formattedTime = hours + ':' + minutes + ':' + seconds;
2020-04-16 13:32:26 +00:00
// console.log('Remaining time: ', formattedTime)
2019-04-18 14:23:51 +00:00
// output formattedTime to UI here
$('#timeRemaining').html(" / " + formattedTime);
}
} else {
$('#timeRemaining').empty();
}
}
2020-04-17 21:07:39 +00:00
$('#gcodesent').html("Job Queue: " + data[0]);
2018-06-19 20:25:40 +00:00
})
2019-03-06 19:26:09 +00:00
socket.on('toastErrorAlarm', function(data) {
2020-04-17 21:07:39 +00:00
console.log(data)
printLog("<span class='fg-red'>[ ALARM ]</span> <span class='fg-red'>" + data + "</span>")
2019-03-06 19:26:09 +00:00
Metro.dialog.create({
2019-06-03 17:07:46 +00:00
clsDialog: 'dark',
title: "<i class='fas fa-exclamation-triangle'></i> Grbl Alarm:",
2019-03-06 19:26:09 +00:00
content: "<i class='fas fa-exclamation-triangle fg-red'></i> " + data,
actions: [{
caption: "Clear Alarm",
2019-04-22 14:52:10 +00:00
cls: "js-dialog-close alert closeAlarmBtn",
2019-03-06 19:26:09 +00:00
onclick: function() {
socket.emit('clearAlarm', 2)
}
},
{
caption: "Cancel",
cls: "js-dialog-close",
onclick: function() {
//
}
}
]
});
2020-03-06 15:59:58 +00:00
setTimeout(function() {
$(".closeAlarmBtn").focus();
}, 200, )
2019-03-06 19:26:09 +00:00
//
});
socket.on('toastError', function(data) {
2020-04-17 21:07:39 +00:00
console.log(data)
printLog("<span class='fg-red'>[ ERROR ]</span> <span class='fg-red'>" + data + "</span>")
2018-10-25 19:25:57 +00:00
Metro.dialog.create({
2019-06-03 17:07:46 +00:00
title: "<i class='fas fa-exclamation-triangle'></i> Grbl Error:",
content: "<i class='fas fa-exclamation-triangle fg-red'></i> " + data,
2020-03-06 15:59:58 +00:00
clsDialog: 'dark',
actions: [{
caption: "OK",
cls: "js-dialog-close alert closeErrorBtn",
onclick: function() {
socket.emit('clearAlarm', 2)
}
}]
2018-10-25 19:25:57 +00:00
});
2020-03-06 15:59:58 +00:00
setTimeout(function() {
$(".closeErrorBtn").focus();
}, 200, )
//
});
2018-10-25 19:25:57 +00:00
2019-12-30 19:56:20 +00:00
2018-12-20 19:22:02 +00:00
socket.on('progStatus', function(data) {
$('#controlTab').click();
$('#consoletab').click();
console.log(data.port, data.string)
var string = data.string
if (string) {
if (string.indexOf('flash complete') != -1) {
setTimeout(function() {
populatePortsMenu();
}, 400)
}
string = string.replace('flash complete.', "<span class='fg-red'><i class='fas fa-times fa-fw fg-red fa-fw'> </i> FLASH FAILED!</span> ");
string = string.replace('', "<span class='fg-green'><i class='fas fa-check fa-fw fg-green fa-fw'></i> ");
string = string.replace('', "</span>");
printLog("<span class='fg-red'>[ Firmware Upgrade ] </span>" + string)
// $('#sendCommand').click();
}
});
2018-06-19 20:25:40 +00:00
socket.on('status', function(status) {
2018-06-26 10:33:13 +00:00
if (nostatusyet) {
2020-03-30 15:26:11 +00:00
// $('#windowtitle').html("OpenBuilds CONTROL v" + status.driver.version)
setWindowTitle(status)
2020-09-01 13:23:10 +00:00
if (status.driver.operatingsystem == "rpi") {
2019-06-06 19:11:48 +00:00
$('#windowtitlebar').hide();
}
2018-06-26 10:33:13 +00:00
}
2018-06-19 20:25:40 +00:00
nostatusyet = false;
2018-06-26 10:33:13 +00:00
2018-06-19 20:25:40 +00:00
// if (!_.isEqual(status, laststatus)) {
if (laststatus !== undefined) {
if (!_.isEqual(status.comms.interfaces.ports, laststatus.comms.interfaces.ports)) {
var string = "Detected a change in available ports: ";
for (i = 0; i < status.comms.interfaces.ports.length; i++) {
2020-03-19 15:13:52 +00:00
string += "[" + status.comms.interfaces.ports[i].path + "]"
2018-06-19 20:25:40 +00:00
}
2019-04-16 13:17:42 +00:00
if (!status.comms.interfaces.ports.length) {
string += "[ No devices connected ]"
}
2018-06-19 20:25:40 +00:00
printLog(string)
laststatus.comms.interfaces.ports = status.comms.interfaces.ports;
populatePortsMenu();
2018-06-19 08:07:03 +00:00
}
2018-06-19 20:25:40 +00:00
}
2018-06-27 19:23:34 +00:00
2018-06-19 20:25:40 +00:00
$('#runStatus').html("Controller: " + status.comms.runStatus);
2019-10-18 18:55:41 +00:00
if (!disableDROupdates) {
if (unit == "mm") {
var xpos = status.machine.position.work.x + unit;
var ypos = status.machine.position.work.y + unit;
var zpos = status.machine.position.work.z + unit;
} else if (unit == "in") {
var xpos = (status.machine.position.work.x / 25.4).toFixed(2) + unit;
var ypos = (status.machine.position.work.y / 25.4).toFixed(2) + unit;
var zpos = (status.machine.position.work.z / 25.4).toFixed(2) + unit;
}
2019-10-18 18:55:41 +00:00
if ($('#xPos').html() != xpos) {
$('#xPos').html(xpos);
}
if ($('#yPos').html() != ypos) {
$('#yPos').html(ypos);
}
if ($('#zPos').html() != zpos) {
$('#zPos').html(zpos);
}
} else {
$('#xPos').html('disabled');
$('#yPos').html('disabled');
$('#zPos').html('disabled');
}
2018-06-19 20:25:40 +00:00
2018-08-28 15:16:17 +00:00
if (webgl) {
2019-10-18 18:55:41 +00:00
if (!disable3Drealtimepos) {
if (!isJogWidget) {
if (!simRunning) {
if (object) {
cone.position.x = status.machine.position.work.x
cone.position.y = status.machine.position.work.y
2020-04-17 21:07:39 +00:00
cone.position.z = status.machine.position.work.z + 20
2019-10-18 18:55:41 +00:00
// }
}
2019-10-18 18:55:41 +00:00
}
2018-08-28 15:16:17 +00:00
}
2018-08-28 15:09:20 +00:00
}
}
2018-06-19 20:25:40 +00:00
if (safeToUpdateSliders) {
2018-08-24 19:00:03 +00:00
if ($('#fro').data('slider') && $('#tro').data('slider')) {
$('#fro').data('slider').val(status.machine.overrides.feedOverride)
$('#tro').data('slider').val(status.machine.overrides.spindleOverride)
}
2018-06-19 20:25:40 +00:00
}
2020-04-20 20:58:03 +00:00
// Windows Power Management
if (status.driver.operatingsystem == "windows") {
$("#powerSettingsCard").show();
if (status.driver.powersettings.usbselectiveAC == false) {
$('#selectivesuspendAC').removeClass('alert').addClass('success').html('DISABLED')
} else if (status.driver.powersettings.usbselectiveAC == null) {
$('#selectivesuspendAC').removeClass('success').addClass('alert').html('UNKNOWN')
} else if (status.driver.powersettings.usbselectiveAC == true) {
$('#selectivesuspendAC').removeClass('success').addClass('alert').html('ENABLED')
}
if (status.driver.powersettings.usbselectiveDC == false) {
$('#selectivesuspendDC').removeClass('alert').addClass('success').html('DISABLED')
} else if (status.driver.powersettings.usbselectiveDC == null) {
$('#selectivesuspendDC').removeClass('success').addClass('alert').html('UNKNOWN')
} else if (status.driver.powersettings.usbselectiveDC == true) {
$('#selectivesuspendDC').removeClass('success').addClass('alert').html('ENABLED')
}
} else {
$("#powerSettingsCard").hide();
}
// Grbl Pins Input Status
$('.pinstatus').removeClass('alert').addClass('success').html('OFF')
2020-04-17 21:07:39 +00:00
$('#holdpin').html('HOLD/DOOR:OFF')
2019-01-23 19:07:58 +00:00
$('#resetpin').html('RST:OFF')
$('#startpin').html('START:OFF')
if (status.machine.inputs.length > 0) {
for (i = 0; i < status.machine.inputs.length; i++) {
switch (status.machine.inputs[i]) {
case 'X':
// console.log('PIN: X-LIMIT');
$('#xpin').removeClass('success').addClass('alert').html('ON')
break;
case 'Y':
// console.log('PIN: Y-LIMIT');
$('#ypin').removeClass('success').addClass('alert').html('ON')
break;
case 'Z':
// console.log('PIN: Z-LIMIT');
$('#zpin').removeClass('success').addClass('alert').html('ON')
break;
case 'P':
// console.log('PIN: PROBE');
$('#prbpin').removeClass('success').addClass('alert').html('ON')
break;
2019-01-23 19:07:58 +00:00
case 'D':
// console.log('PIN: DOOR');
$('#doorpin').removeClass('success').addClass('alert').html('ON')
2020-06-23 17:55:56 +00:00
2019-01-23 19:07:58 +00:00
break;
case 'H':
// console.log('PIN: HOLD');
$('#holdpin').removeClass('success').addClass('alert').html('HOLD:ON')
break;
case 'R':
// console.log('PIN: SOFTRESET');
$('#resetpin').removeClass('success').addClass('alert').html('RST:ON')
break;
case 'S':
// console.log('PIN: CYCLESTART');
$('#startpin').removeClass('success').addClass('alert').html('START:ON')
break;
}
}
}
$('#driverver').html("v" + status.driver.version);
if (!status.machine.firmware.type) {
$('#firmwarever').html("NOCOMM");
} else {
$('#firmwarever').html(status.machine.firmware.type + " v" + status.machine.firmware.version);
}
$('#commblocked').html(status.comms.blocked ? "BLOCKED" : "Ready");
var string = '';
switch (status.comms.connectionStatus) {
case 0:
string += "Not Connected"
break;
case 2:
string += "Connected"
break;
case 3:
string += "Streaming"
break;
case 4:
string += "Paused"
break;
case 5:
string += "Alarmed"
break;
}
$('#commstatus').html(string);
$('#drvqueue').html(status.comms.queue);
2019-05-07 17:26:26 +00:00
2018-12-21 13:56:11 +00:00
if (status.comms.interfaces.activePort) {
$('#activeportstatus').html(status.comms.interfaces.activePort)
} else {
$('#activeportstatus').html("none")
}
2018-08-25 16:54:28 +00:00
// Set the Connection Toolbar option
setConnectBar(status.comms.connectionStatus, status);
setControlBar(status.comms.connectionStatus, status)
setJogPanel(status.comms.connectionStatus, status)
setConsole(status.comms.connectionStatus, status)
if (status.comms.connectionStatus != 5) {
bellstate = false
};
if (status.comms.connectionStatus == 0) {
showGrbl(false)
}
2018-06-19 20:25:40 +00:00
laststatus = status;
});
2019-07-23 19:04:50 +00:00
socket.on('features', function(data) {
2020-04-16 13:32:26 +00:00
// console.log('FEATURES', data)
2019-09-03 18:36:09 +00:00
for (i = 0; i < data.length; i++) {
switch (data[i]) {
2019-07-23 19:04:50 +00:00
case 'Q':
2020-04-16 13:32:26 +00:00
// console.log('SPINDLE_IS_SERVO Enabled')
2019-07-23 19:04:50 +00:00
$('#enServo').removeClass('alert').addClass('success').html('ON')
2019-09-03 18:36:09 +00:00
$(".servo-active").show()
2019-07-23 19:04:50 +00:00
break;
case 'V': // Variable spindle enabled
2020-04-16 13:32:26 +00:00
// console.log('Variable spindle enabled')
2019-07-23 19:04:50 +00:00
$('#enVariableSpindle').removeClass('alert').addClass('success').html('ON')
break;
case 'N': // Line numbers enabled
2020-04-16 13:32:26 +00:00
// console.log('Line numbers enabled')
2019-07-23 19:04:50 +00:00
$('#enLineNumbers').removeClass('alert').addClass('success').html('ON')
break;
case 'M': // Mist coolant enabled
2020-04-16 13:32:26 +00:00
// console.log('Mist coolant enabled')
2019-07-23 19:04:50 +00:00
$('#menuMisting').show();
$('#enMisting').removeClass('alert').addClass('success').html('ON')
break;
case 'C': // CoreXY enabled
2020-04-16 13:32:26 +00:00
// console.log('CoreXY enabled')
2019-07-23 19:04:50 +00:00
$('#enCoreXY').removeClass('alert').addClass('success').html('ON')
break;
case 'P': // Parking motion enabled
2020-04-16 13:32:26 +00:00
// console.log('Parking motion enabled')
2019-07-23 19:04:50 +00:00
$('#enParking').removeClass('alert').addClass('success').html('ON')
break;
case 'Z': // Homing force origin enabled
2020-04-16 13:32:26 +00:00
// console.log('Homing force origin enabled')
2019-07-23 19:04:50 +00:00
$('#enHomingOrigin').removeClass('alert').addClass('success').html('ON')
break;
case 'H': // Homing single axis enabled
2020-04-16 13:32:26 +00:00
// console.log('Homing single axis enabled')
2019-07-23 19:04:50 +00:00
$('#enSingleAxisHome').removeClass('alert').addClass('success').html('ON')
break;
case 'T': // Two limit switches on axis enabled
2020-04-16 13:32:26 +00:00
// console.log('Two limit switches on axis enabled')
2019-07-23 19:04:50 +00:00
$('#enTwoLimits').removeClass('alert').addClass('success').html('ON')
break;
case 'A': // Allow feed rate overrides in probe cycles
2020-04-16 13:32:26 +00:00
// console.log('Allow feed rate overrides in probe cycles')
2019-07-23 19:04:50 +00:00
$('#enFeedOVProbe').removeClass('alert').addClass('success').html('ON')
break;
case '$': // Restore EEPROM $ settings disabled
2020-04-16 13:32:26 +00:00
// console.log('Restore EEPROM $ settings disabled')
2019-07-23 19:04:50 +00:00
$('#enEepromSettingsDisable').removeClass('alert').addClass('success').html('ON')
break;
case '#': // Restore EEPROM parameter data disabled
2020-04-16 13:32:26 +00:00
// console.log('Restore EEPROM parameter data disabled')
2019-07-23 19:04:50 +00:00
$('#enEepromParamsDisable').removeClass('alert').addClass('success').html('ON')
break;
case 'I': // Build info write user string disabled
2020-04-16 13:32:26 +00:00
// console.log('Build info write user string disabled')
2019-07-23 19:04:50 +00:00
$('#enBuildInfoDisabled').removeClass('alert').addClass('success').html('ON')
break;
case 'E': // Force sync upon EEPROM write disabled
2020-04-16 13:32:26 +00:00
// console.log('Force sync upon EEPROM write disabled')
2019-07-23 19:04:50 +00:00
$('#enForceSyncEeprom').removeClass('alert').addClass('success').html('ON')
break;
case 'W': // Force sync upon work coordinate offset change disabled
2020-04-16 13:32:26 +00:00
// console.log('Force sync upon work coordinate offset change disabled')
2019-07-23 19:04:50 +00:00
$('#enForceSyncWco').removeClass('alert').addClass('success').html('ON')
break;
case 'L': // Homing init lock sets Grbl into an alarm state upon power up
2020-04-16 13:32:26 +00:00
// console.log('Homing init lock sets Grbl into an alarm state upon power up')
2019-07-23 19:04:50 +00:00
$('#enHomingInitLock').removeClass('alert').addClass('success').html('ON')
break;
}
}
})
2018-06-19 20:25:40 +00:00
$('#sendCommand').on('click', function() {
var commandValue = $('#command').val();
sendGcode(commandValue);
// $('#command').val('');
2018-06-19 20:25:40 +00:00
});
$('#command').on('keypress', function(e) {
if (e.which === 13) {
$(this).attr("disabled", "disabled");
var commandValue = $('#command').val();
sendGcode(commandValue);
$('#command').val('');
$(this).removeAttr("disabled");
}
});
var bellflash = setInterval(function() {
if (!nostatusyet) {
if (laststatus) {
if (laststatus.comms.connectionStatus == 5) {
if (bellstate == false) {
$('#navbell').hide();
2018-06-25 20:13:58 +00:00
$('#navbellBtn1').hide();
$('#navbellBtn2').hide();
$('#navbellBtn3').hide();
bellstate = true
} else {
$('#navbell').show();
2018-06-25 20:13:58 +00:00
$('#navbellBtn1').show();
$('#navbellBtn2').show();
$('#navbellBtn3').show();
bellstate = false
}
2018-06-19 20:25:40 +00:00
} else {
$('#navbell').hide();
2018-06-25 20:13:58 +00:00
$('#navbellBtn1').hide();
$('#navbellBtn2').hide();
$('#navbellBtn3').hide();
2018-06-19 08:07:03 +00:00
}
}
2018-06-19 20:25:40 +00:00
}
}, 200);
2018-06-19 08:07:03 +00:00
};
function selectPort() {
2019-03-25 19:10:26 +00:00
$('#consoletab').click();
2018-06-19 20:25:40 +00:00
socket.emit('connectTo', 'usb,' + $("#portUSB").val() + ',' + '115200');
2018-06-19 08:07:03 +00:00
};
function closePort() {
socket.emit('closePort', 1);
populatePortsMenu();
$('.mdata').val('');
}
function populatePortsMenu() {
2018-06-20 13:00:05 +00:00
var response = `<select id="select1" data-role="select" class="mt-4"><optgroup label="USB Ports">`
2018-06-19 20:25:40 +00:00
for (i = 0; i < laststatus.comms.interfaces.ports.length; i++) {
var port = friendlyPort(i)
2020-03-19 15:13:52 +00:00
response += `<option value="` + laststatus.comms.interfaces.ports[i].path + `">` + port.note + " " + laststatus.comms.interfaces.ports[i].path.replace("/dev/tty.", "") + `</option>`;
2018-06-19 20:25:40 +00:00
};
2019-04-16 13:17:42 +00:00
if (!laststatus.comms.interfaces.ports.length) {
2020-03-06 15:59:58 +00:00
response += `<option value="">Waiting for USB</option>`
$("#driverBtn").show();
} else {
$("#driverBtn").hide();
2019-04-16 13:17:42 +00:00
}
2018-06-20 13:00:05 +00:00
response += `</optgroup></select>`
var select = $("#portUSB").data("select");
select.data(response);
2018-12-21 13:56:11 +00:00
var select2 = $("#portUSB2").data("select");
2019-04-22 14:52:10 +00:00
if (select2) {
select2.data(response);
}
2018-06-21 20:02:40 +00:00
$('#portUSB').parent(".select").removeClass('disabled')
2018-12-21 13:56:11 +00:00
$('#portUSB2').parent(".select").removeClass('disabled')
2018-06-27 19:23:34 +00:00
$("#connectBtn").attr('disabled', false);
2018-06-19 08:07:03 +00:00
}
function sendGcode(gcode) {
2018-06-19 20:25:40 +00:00
if (gcode) {
socket.emit('runCommand', gcode);
}
2018-06-19 08:07:03 +00:00
}
function feedOverride(step) {
if (socket) {
socket.emit('feedOverride', step);
2019-04-12 13:32:56 +00:00
$('#fro').data('slider').buff(((step - 10) * 100) / (200 - 10))
}
2018-06-19 08:07:03 +00:00
}
function spindleOverride(step) {
if (socket) {
socket.emit('spindleOverride', step);
2019-04-12 13:32:56 +00:00
$('#tro').data('slider').buff(((step - 10) * 100) / (200 - 10))
}
2018-06-19 08:07:03 +00:00
}
function friendlyPort(i) {
2018-06-19 20:25:40 +00:00
// var likely = false;
var img = 'usb.png';
var note = '';
var manufacturer = laststatus.comms.interfaces.ports[i].manufacturer
if (manufacturer == `(Standard port types)`) {
img = 'serial.png'
note = 'Motherboard Serial Port';
} else if (laststatus.comms.interfaces.ports[i].productId && laststatus.comms.interfaces.ports[i].vendorId) {
if (laststatus.comms.interfaces.ports[i].productId == '6015' && laststatus.comms.interfaces.ports[i].vendorId == '1D50') {
// found Smoothieboard
img = 'smoothieboard.png';
note = 'Smoothieware USB Port';
}
if (laststatus.comms.interfaces.ports[i].productId == '6001' && laststatus.comms.interfaces.ports[i].vendorId == '0403') {
// found FTDI FT232
img = 'usb.png';
note = 'FTDI USB to Serial';
}
if (laststatus.comms.interfaces.ports[i].productId == '6015' && laststatus.comms.interfaces.ports[i].vendorId == '0403') {
// found FTDI FT230x
img = 'usb.png';
note = 'FTDI USD to Serial';
}
if (laststatus.comms.interfaces.ports[i].productId == '606D' && laststatus.comms.interfaces.ports[i].vendorId == '1D50') {
// found TinyG G2
img = 'usb.png';
note = 'Tiny G2';
}
if (laststatus.comms.interfaces.ports[i].productId == '003D' && laststatus.comms.interfaces.ports[i].vendorId == '2341') {
// found Arduino Due Prog Port
img = 'due.png';
note = 'Arduino Due Prog';
2018-06-19 08:07:03 +00:00
}
2018-06-19 20:25:40 +00:00
if (laststatus.comms.interfaces.ports[i].productId == '0043' && laststatus.comms.interfaces.ports[i].vendorId == '2341' || laststatus.comms.interfaces.ports[i].productId == '0001' && laststatus.comms.interfaces.ports[i].vendorId == '2341' || laststatus.comms.interfaces.ports[i].productId == '0043' && laststatus.comms.interfaces.ports[i].vendorId == '2A03') {
// found Arduino Uno
img = 'uno.png';
note = 'Arduino Uno';
}
if (laststatus.comms.interfaces.ports[i].productId == '2341' && laststatus.comms.interfaces.ports[i].vendorId == '0042') {
// found Arduino Mega
img = 'mega.png';
note = 'Arduino Mega';
}
if (laststatus.comms.interfaces.ports[i].productId == '7523' && laststatus.comms.interfaces.ports[i].vendorId == '1A86') {
// found CH340
img = 'uno.png';
note = 'CH340 Arduino Fake';
}
if (laststatus.comms.interfaces.ports[i].productId == 'EA60' && laststatus.comms.interfaces.ports[i].vendorId == '10C4') {
// found CP2102
img = 'nodemcu.png';
note = 'NodeMCU';
}
if (laststatus.comms.interfaces.ports[i].productId == '2303' && laststatus.comms.interfaces.ports[i].vendorId == '067B') {
// found CP2102
// img = 'nodemcu.png';
note = 'Prolific USB to Serial';
}
} else {
img = "usb.png";
}
2018-06-19 08:07:03 +00:00
2018-06-19 20:25:40 +00:00
return {
img: img,
note: note
};
2018-09-27 15:00:49 +00:00
}
function escapeHTML(html) {
return document.createElement('div').appendChild(document.createTextNode(html)).parentNode.innerHTML;
2019-09-03 18:36:09 +00:00
}