Fixed mainaining state while deleting, removed time from config

This commit is contained in:
sanjayk03-dev
2024-01-23 14:18:26 +05:30
parent 4d311bd083
commit aa48701bcc
3 changed files with 525 additions and 528 deletions

View File

@@ -6,9 +6,9 @@ const cookie = require("./cookie")("bbctrl-");
module.exports = { module.exports = {
template: "#control-view-template", template: "#control-view-template",
props: [ "config", "template", "state" ], props: ["config", "template", "state"],
data: function() { data: function () {
return { return {
current_time: "", current_time: "",
mach_units: this.$root.state.metric ? "METRIC" : "IMPERIAL", mach_units: this.$root.state.metric ? "METRIC" : "IMPERIAL",
@@ -22,18 +22,18 @@ module.exports = {
speed_override: 1, speed_override: 1,
feed_override: 1, feed_override: 1,
jog_incr_amounts: { jog_incr_amounts: {
"METRIC": { METRIC: {
fine: 0.1, fine: 0.1,
small: 1.0, small: 1.0,
medium: 10, medium: 10,
large: 100, large: 100,
}, },
"IMPERIAL": { IMPERIAL: {
fine: 0.005, fine: 0.005,
small: 0.05, small: 0.05,
medium: 0.5, medium: 0.5,
large: 5, large: 5,
} },
}, },
jog_incr: localStorage.getItem("jog_incr") || "small", jog_incr: localStorage.getItem("jog_incr") || "small",
jog_step: cookie.get_bool("jog-step"), jog_step: cookie.get_bool("jog-step"),
@@ -48,60 +48,58 @@ module.exports = {
components: { components: {
"axis-control": require("./axis-control"), "axis-control": require("./axis-control"),
"path-viewer": require("./path-viewer"), "path-viewer": require("./path-viewer"),
"gcode-viewer": require("./gcode-viewer") "gcode-viewer": require("./gcode-viewer"),
}, },
watch: { watch: {
jog_incr: function(value) { jog_incr: function (value) {
localStorage.setItem("jog_incr", value); localStorage.setItem("jog_incr", value);
}, },
"state.metric": { "state.metric": {
handler: function(metric) { handler: function (metric) {
this.mach_units = metric this.mach_units = metric ? "METRIC" : "IMPERIAL";
? "METRIC"
: "IMPERIAL";
}, },
immediate: true immediate: true,
}, },
"state.line": function() { "state.line": function () {
if (this.mach_state != "HOMING") { if (this.mach_state != "HOMING") {
this.$broadcast("gcode-line", this.state.line); this.$broadcast("gcode-line", this.state.line);
} }
}, },
"state.selected_time": function() { "state.selected_time": function () {
this.loadGCode(); this.loadGCode();
}, },
jog_step: function() { jog_step: function () {
cookie.set_bool("jog-step", this.jog_step); cookie.set_bool("jog-step", this.jog_step);
}, },
jog_adjust: function() { jog_adjust: function () {
cookie.set("jog-adjust", this.jog_adjust); cookie.set("jog-adjust", this.jog_adjust);
} },
}, },
computed: { computed: {
display_units: { display_units: {
cache: false, cache: false,
get: function() { get: function () {
return this.$root.display_units; return this.$root.display_units;
}, },
set: function(value) { set: function (value) {
this.config.settings.units = value; this.config.settings.units = value;
this.$root.display_units = value; this.$root.display_units = value;
this.$dispatch("config-changed"); this.$dispatch("config-changed");
} },
}, },
metric: function() { metric: function () {
return this.display_units === "METRIC"; return this.display_units === "METRIC";
}, },
mach_state: function() { mach_state: function () {
const cycle = this.state.cycle; const cycle = this.state.cycle;
const state = this.state.xx; const state = this.state.xx;
@@ -112,46 +110,46 @@ module.exports = {
return state || ""; return state || "";
}, },
pause_reason: function() { pause_reason: function () {
return this.state.pr; return this.state.pr;
}, },
is_running: function() { is_running: function () {
return this.mach_state == "RUNNING" || this.mach_state == "HOMING"; return this.mach_state == "RUNNING" || this.mach_state == "HOMING";
}, },
is_stopping: function() { is_stopping: function () {
return this.mach_state == "STOPPING"; return this.mach_state == "STOPPING";
}, },
is_holding: function() { is_holding: function () {
return this.mach_state == "HOLDING"; return this.mach_state == "HOLDING";
}, },
is_ready: function() { is_ready: function () {
return this.mach_state == "READY"; return this.mach_state == "READY";
}, },
is_idle: function() { is_idle: function () {
return this.state.cycle == "idle"; return this.state.cycle == "idle";
}, },
is_paused: function() { is_paused: function () {
return this.is_holding && (this.pause_reason == "User pause" || this.pause_reason == "Program pause"); return this.is_holding && (this.pause_reason == "User pause" || this.pause_reason == "Program pause");
}, },
can_mdi: function() { can_mdi: function () {
return this.is_idle || this.state.cycle == "mdi"; return this.is_idle || this.state.cycle == "mdi";
}, },
can_set_axis: function() { can_set_axis: function () {
return this.is_idle; return this.is_idle;
// TODO allow setting axis position during pause // TODO allow setting axis position during pause
// return this.is_idle || this.is_paused; // return this.is_idle || this.is_paused;
}, },
message: function() { message: function () {
if (this.mach_state == "ESTOPPED") { if (this.mach_state == "ESTOPPED") {
return this.state.er; return this.state.er;
} }
@@ -167,15 +165,15 @@ module.exports = {
return ""; return "";
}, },
highlight_state: function() { highlight_state: function () {
return this.mach_state == "ESTOPPED" || this.mach_state == "HOLDING"; return this.mach_state == "ESTOPPED" || this.mach_state == "HOLDING";
}, },
plan_time: function() { plan_time: function () {
return this.state.plan_time; return this.state.plan_time;
}, },
plan_time_remaining: function() { plan_time_remaining: function () {
if (!(this.is_stopping || this.is_running || this.is_holding)) { if (!(this.is_stopping || this.is_running || this.is_holding)) {
return 0; return 0;
} }
@@ -183,7 +181,7 @@ module.exports = {
return this.toolpath.time - this.plan_time; return this.toolpath.time - this.plan_time;
}, },
eta: function() { eta: function () {
if (this.mach_state != "RUNNING") { if (this.mach_state != "RUNNING") {
return ""; return "";
} }
@@ -194,7 +192,7 @@ module.exports = {
return d.toLocaleString(); return d.toLocaleString();
}, },
progress: function() { progress: function () {
if (!this.toolpath.time || this.is_ready) { if (!this.toolpath.time || this.is_ready) {
return 0; return 0;
} }
@@ -203,28 +201,30 @@ module.exports = {
return Math.min(1, p); return Math.min(1, p);
}, },
gcodeFiles: function () { gcodeFiles: function () {
const filesWithNoMacros=this.state.files.filter(item => !this.config.macrosList.some(compareItem => compareItem.gcode_file_name == item)); const filesWithNoMacros = this.state.files.filter(
console.log('filesWithNoMacros: ',filesWithNoMacros); item => !this.config.macrosList.some(compareItem => compareItem.gcode_file_name == item),
console.log("this.state.GCodeList",this.state.GCodeList) );
console.log("filesWithNoMacros: ", filesWithNoMacros);
console.log("this.state.GCodeList", this.state.GCodeList);
const unionSet = new Set([...filesWithNoMacros, ...this.state.GCodeList]); const unionSet = new Set([...filesWithNoMacros, ...this.state.GCodeList]);
const files = [...unionSet]; const files = [...unionSet];
console.log("files: ",files); console.log("files: ", files);
return files; return files;
} },
}, },
events: { events: {
jog: function(axis, power) { jog: function (axis, power) {
const data = { ts: new Date().getTime() }; const data = { ts: new Date().getTime() };
data[axis] = power; data[axis] = power;
api.put("jog", data); api.put("jog", data);
}, },
back2zero: function(axis0, axis1) { back2zero: function (axis0, axis1) {
this.send(`G0 ${axis0}0 ${axis1}0`); this.send(`G0 ${axis0}0 ${axis1}0`);
}, },
step: function(axis, value) { step: function (axis, value) {
this.send(` this.send(`
M70 M70
G91 G91
@@ -234,7 +234,7 @@ module.exports = {
}, },
}, },
ready: function() { ready: function () {
this.loadGCode(); this.loadGCode();
setInterval(() => { setInterval(() => {
@@ -244,10 +244,10 @@ module.exports = {
SvelteComponents.registerControllerMethods({ SvelteComponents.registerControllerMethods({
stop: (...args) => this.stop(...args), stop: (...args) => this.stop(...args),
send: (...args) => this.send(...args), send: (...args) => this.send(...args),
isAxisHomed: (axis) => this[axis].homed, isAxisHomed: axis => this[axis].homed,
unhome: (...args) => this.unhome(...args), unhome: (...args) => this.unhome(...args),
set_position: (...args) => this.set_position(...args), set_position: (...args) => this.set_position(...args),
set_home: (...args) => this.set_home(...args) set_home: (...args) => this.set_home(...args),
}); });
}, },
@@ -256,10 +256,10 @@ module.exports = {
const weight = `font-weight:${this.jog_incr === value ? "bold" : "normal"}`; const weight = `font-weight:${this.jog_incr === value ? "bold" : "normal"}`;
const color = this.jog_incr === value ? "color:#0078e7" : ""; const color = this.jog_incr === value ? "color:#0078e7" : "";
return [ weight, color ].join(";"); return [weight, color].join(";");
}, },
jog_fn: function(x_jog, y_jog, z_jog, a_jog) { jog_fn: function (x_jog, y_jog, z_jog, a_jog) {
const amount = this.jog_incr_amounts[this.display_units][this.jog_incr]; const amount = this.jog_incr_amounts[this.display_units][this.jog_incr];
const xcmd = `X${x_jog * amount}`; const xcmd = `X${x_jog * amount}`;
@@ -274,18 +274,18 @@ module.exports = {
`); `);
}, },
send: function(msg) { send: function (msg) {
this.$dispatch("send", msg); this.$dispatch("send", msg);
}, },
loadGCode: function() { loadGCode: function () {
const file_time = this.state.selected_time; const file_time = this.state.selected_time;
const file = this.state.selected; const file = this.state.selected;
if (this.last_file == file && this.last_file_time == file_time) { if (this.last_file == file && this.last_file_time == file_time) {
return; return;
} }
console.log("file: ",file," time: ",file_time); console.log("file: ", file, " time: ", file_time);
this.last_file = file; this.last_file = file;
this.last_file_time = file_time; this.last_file_time = file_time;
@@ -296,7 +296,7 @@ module.exports = {
this.load_toolpath(file, file_time); this.load_toolpath(file, file_time);
}, },
load_toolpath: async function(file, file_time) { load_toolpath: async function (file, file_time) {
this.toolpath = {}; this.toolpath = {};
if (!file || this.last_file_time != file_time) { if (!file || this.last_file_time != file_time) {
@@ -327,7 +327,7 @@ module.exports = {
} }
}, },
submit_mdi: function() { submit_mdi: function () {
this.send(this.mdi); this.send(this.mdi);
if (!this.history.length || this.history[0] != this.mdi) { if (!this.history.length || this.history[0] != this.mdi) {
@@ -337,7 +337,7 @@ module.exports = {
this.mdi = ""; this.mdi = "";
}, },
mdi_start_pause: function() { mdi_start_pause: function () {
if (this.state.xx == "RUNNING") { if (this.state.xx == "RUNNING") {
this.pause(); this.pause();
} else if (this.state.xx == "STOPPING" || this.state.xx == "HOLDING") { } else if (this.state.xx == "STOPPING" || this.state.xx == "HOLDING") {
@@ -347,15 +347,15 @@ module.exports = {
} }
}, },
load_history: function(index) { load_history: function (index) {
this.mdi = this.history[index]; this.mdi = this.history[index];
}, },
open: function() { open: function () {
utils.clickFileInput("gcode-file-input"); utils.clickFileInput("gcode-file-input");
}, },
uploadGCode: async function(e) { uploadGCode: async function (e) {
const files = e.target.files || e.dataTransfer.files; const files = e.target.files || e.dataTransfer.files;
if (!files.length) { if (!files.length) {
return; return;
@@ -375,9 +375,9 @@ module.exports = {
return; return;
} }
const isAlreadyPresent = this.state.GCodeList.find((element) => element == file.name); const isAlreadyPresent = this.state.GCodeList.find(element => element == file.name);
if(isAlreadyPresent == undefined){ if (isAlreadyPresent == undefined) {
console.log('new gcode file'); console.log("new gcode file");
this.state.GCodeList.push(file.name); this.state.GCodeList.push(file.name);
try { try {
await api.put("config/save", this.config); await api.put("config/save", this.config);
@@ -386,12 +386,12 @@ module.exports = {
console.error("Restore Failed: ", error); console.error("Restore Failed: ", error);
alert("Restore failed"); alert("Restore failed");
} }
}else{ } else {
console.log('Already exists'); console.log("Already exists");
} }
if(this.config.macrosList.some(obj => obj.gcode_file_name == file.name)){ if (this.config.macrosList.some(obj => obj.gcode_file_name == file.name)) {
console.log("It is a macros, remove it from macrosList") console.log("It is a macros, remove it from macrosList");
// this.config.GCodeList.push(file.name); // this.config.GCodeList.push(file.name);
} }
@@ -400,35 +400,35 @@ module.exports = {
onComplete: () => { onComplete: () => {
this.last_file_time = undefined; // Force reload this.last_file_time = undefined; // Force reload
this.$broadcast("gcode-reload", file.name); this.$broadcast("gcode-reload", file.name);
} },
}); });
}, },
delete_current: function() { delete_current: function () {
if(this.config.macrosList.find(item=>item.gcode_file_name==this.state.selected)==undefined){ if (this.config.macrosList.find(item => item.gcode_file_name == this.state.selected) == undefined) {
if (this.state.selected) { if (this.state.selected) {
api.delete(`file/${this.state.selected}`); api.delete(`file/${this.state.selected}`);
} }
}else{ } else {
this.state.GCodeList.filter(item=>item!=this.state.selected); this.state.GCodeList = this.state.GCodeList.filter(item => item != this.state.selected);
} }
this.deleteGCode = false; this.deleteGCode = false;
}, },
delete_all: function() { delete_all: function () {
api.delete("file"); api.delete("file");
this.deleteGCode = false; this.deleteGCode = false;
}, },
delete_all_except_macros: function() { delete_all_except_macros: function () {
const macrosList=this.config.macrosList.map(item=>item.gcode_file_name).toString(); const macrosList = this.config.macrosList.map(item => item.gcode_file_name).toString();
api.delete(`file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${macrosList}`); api.delete(`file/EgZjaHJvbWUqCggBEAAYsQMYgAQyBggAEEUYOTIKCAE${macrosList}`);
this.state.GCodeList=[]; this.state.GCodeList = [];
this.deleteGCode = false; this.deleteGCode = false;
}, },
home: function(axis) { home: function (axis) {
this.ask_home = false; this.ask_home = false;
if (typeof axis == "undefined") { if (typeof axis == "undefined") {
@@ -440,31 +440,31 @@ module.exports = {
} }
}, },
set_home: function(axis, position) { set_home: function (axis, position) {
api.put(`home/${axis}/set`, { position: parseFloat(position) }); api.put(`home/${axis}/set`, { position: parseFloat(position) });
}, },
unhome: function(axis) { unhome: function (axis) {
api.put(`home/${axis}/clear`); api.put(`home/${axis}/clear`);
}, },
show_set_position: function(axis) { show_set_position: function (axis) {
SvelteComponents.showDialog("SetAxisPosition", { axis }); SvelteComponents.showDialog("SetAxisPosition", { axis });
}, },
showMoveToZeroDialog: function(axes) { showMoveToZeroDialog: function (axes) {
SvelteComponents.showDialog("MoveToZero", { axes }); SvelteComponents.showDialog("MoveToZero", { axes });
}, },
showToolpathMessageDialog: function(axis) { showToolpathMessageDialog: function (axis) {
SvelteComponents.showDialog("Message", { title: this[axis].toolmsg }); SvelteComponents.showDialog("Message", { title: this[axis].toolmsg });
}, },
set_position: function(axis, position) { set_position: function (axis, position) {
api.put(`position/${axis}`, { "position": parseFloat(position) }); api.put(`position/${axis}`, { position: parseFloat(position) });
}, },
zero_all: function() { zero_all: function () {
for (const axis of "xyzabc") { for (const axis of "xyzabc") {
if (this[axis].enabled) { if (this[axis].enabled) {
this.zero(axis); this.zero(axis);
@@ -472,7 +472,7 @@ module.exports = {
} }
}, },
zero: function(axis) { zero: function (axis) {
if (typeof axis == "undefined") { if (typeof axis == "undefined") {
this.zero_all(); this.zero_all();
} else { } else {
@@ -480,7 +480,7 @@ module.exports = {
} }
}, },
start_pause: function() { start_pause: function () {
if (this.state.xx == "RUNNING") { if (this.state.xx == "RUNNING") {
this.pause(); this.pause();
} else if (this.state.xx == "STOPPING" || this.state.xx == "HOLDING") { } else if (this.state.xx == "STOPPING" || this.state.xx == "HOLDING") {
@@ -490,39 +490,39 @@ module.exports = {
} }
}, },
start: function() { start: function () {
api.put("start"); api.put("start");
}, },
pause: function() { pause: function () {
api.put("pause"); api.put("pause");
}, },
unpause: function() { unpause: function () {
api.put("unpause"); api.put("unpause");
}, },
optional_pause: function() { optional_pause: function () {
api.put("pause/optional"); api.put("pause/optional");
}, },
stop: function() { stop: function () {
api.put("stop"); api.put("stop");
}, },
step: function() { step: function () {
api.put("step"); api.put("step");
}, },
override_feed: function() { override_feed: function () {
api.put(`override/feed/${this.feed_override}`); api.put(`override/feed/${this.feed_override}`);
}, },
override_speed: function() { override_speed: function () {
api.put(`override/speed/${this.speed_override}`); api.put(`override/speed/${this.speed_override}`);
}, },
current: function(axis, value) { current: function (axis, value) {
const x = value / 32.0; const x = value / 32.0;
if (this.state[`${axis}pl`] == x) { if (this.state[`${axis}pl`] == x) {
return; return;
@@ -533,22 +533,25 @@ module.exports = {
this.send(JSON.stringify(data)); this.send(JSON.stringify(data));
}, },
showProbeDialog: function(probeType) { showProbeDialog: function (probeType) {
SvelteComponents.showDialog("Probe", { probeType }); SvelteComponents.showDialog("Probe", { probeType });
}, },
runMacros : function(id){ runMacros: function (id) {
if( this.config.macros[id].gcode_file_name != this.state.selected || this.config.macros[id].gcode_file_time != this.state.selected_time ){ if (
this.state.selected=this.config.macros[id].gcode_file_name; this.config.macros[id].gcode_file_name != this.state.selected ||
this.state.selected_time=this.config.macros[id].gcode_file_time this.config.macros[id].gcode_file_time != this.state.selected_time
) {
this.state.selected = this.config.macros[id].gcode_file_name;
this.state.selected_time = this.config.macros[id].gcode_file_time;
} }
try{ try {
this.loadGCode(); this.loadGCode();
this.start_pause(); this.start_pause();
}catch(error){ } catch (error) {
console.warn("Error running program: ",error); console.warn("Error running program: ", error);
} }
}, },
}, },
mixins: [ require("./axis-vars") ] mixins: [require("./axis-vars")],
}; };

View File

@@ -145,9 +145,9 @@ module.exports = {
file, file,
onComplete: () => { onComplete: () => {
this.last_file_time = undefined; // Force reload this.last_file_time = undefined; // Force reload
this.loadMacrosGcode();
}, },
}); });
this.loadMacrosGcode();
}, },
uploadGCode: async function (filename, file) { uploadGCode: async function (filename, file) {
const xhr = new XMLHttpRequest(); const xhr = new XMLHttpRequest();

View File

@@ -681,13 +681,7 @@
"gcode_file_name": "TurnOffVac.ngc", "gcode_file_name": "TurnOffVac.ngc",
"gcode_file_time": 1705008395.476232 "gcode_file_time": 1705008395.476232
} }
], ]
"template": {
"gcode_file_time": {
"type": "int",
"default": 1705008395
}
}
}, },
"admin": { "admin": {