From a3d449757782be88d51da7374c91ea63869e2356 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 22 Feb 2021 19:37:16 +0100 Subject: [PATCH 01/10] hide color color col in temperatures panel if the chart is hidden Signed-off-by: Stefan Dej --- src/components/panels/ToolsPanel.vue | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/panels/ToolsPanel.vue b/src/components/panels/ToolsPanel.vue index 89282e59..bc72ea29 100644 --- a/src/components/panels/ToolsPanel.vue +++ b/src/components/panels/ToolsPanel.vue @@ -75,7 +75,7 @@ Name - Color + Color State Current Target @@ -87,7 +87,7 @@ mdi-{{ heater.icon }} {{ convertName(heater.name) }} - +
{{ heater.target > 0 ? (heater.power !== null ? (heater.power > 0 ? (heater.power * 100).toFixed(0)+'%' : "0%") : "active") : "off" }} @@ -107,7 +107,7 @@ mdi-fan
{{ convertName(fan.name) }} - +
{{ fan.target > 0 && fan.speed > 0 ? (fan.speed * 100).toFixed(0)+"%" : (fan.target > 0 ? "standby" : "off") }} @@ -129,7 +129,7 @@ {{ convertName(sensor.name) }} - +
  From 306d5107199c81efa3104b25410e79c24905f49f Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 22 Feb 2021 19:48:55 +0100 Subject: [PATCH 02/10] fix axis label in tempchart Signed-off-by: Stefan Dej --- src/components/charts/TempChart.vue | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/components/charts/TempChart.vue b/src/components/charts/TempChart.vue index e66517b5..245e3e85 100644 --- a/src/components/charts/TempChart.vue +++ b/src/components/charts/TempChart.vue @@ -118,7 +118,7 @@ export default { }, yAxis: [ { - name: '[°C] Temperature', + name: 'Temperature [°C]', type: 'value', min: 0, max: 300, From 1217927faeeb73839956604c9d05256512d853c7 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 22 Feb 2021 19:50:13 +0100 Subject: [PATCH 03/10] redesign color points in temperature panel Signed-off-by: Stefan Dej --- src/components/panels/ToolsPanel.vue | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/components/panels/ToolsPanel.vue b/src/components/panels/ToolsPanel.vue index bc72ea29..44972270 100644 --- a/src/components/panels/ToolsPanel.vue +++ b/src/components/panels/ToolsPanel.vue @@ -12,10 +12,12 @@ } .datasetColorSymbol { - width: 15px; - height: 15px; + width: 10px; + height: 10px; border-style: solid; border-width: 1px; + cursor: pointer; + border-radius: 50%; } @@ -88,7 +90,7 @@
{{ convertName(heater.name) }} -
+
{{ heater.target > 0 ? (heater.power !== null ? (heater.power > 0 ? (heater.power * 100).toFixed(0)+'%' : "0%") : "active") : "off" }} @@ -108,7 +110,7 @@ {{ convertName(fan.name) }} -
+
{{ fan.target > 0 && fan.speed > 0 ? (fan.speed * 100).toFixed(0)+"%" : (fan.target > 0 ? "standby" : "off") }} @@ -130,7 +132,7 @@ {{ convertName(sensor.name) }} -
+
  From 389c16287863044c8d4bdbe6b97da2b88a3fa8c8 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 22 Feb 2021 20:34:02 +0100 Subject: [PATCH 04/10] feature: save last setting of ExtruderPanel.vue in .mainsail.json Signed-off-by: Stefan Dej --- src/components/panels/ExtruderPanel.vue | 37 +++++++++++++++---------- src/store/gui/index.js | 2 ++ 2 files changed, 24 insertions(+), 15 deletions(-) diff --git a/src/components/panels/ExtruderPanel.vue b/src/components/panels/ExtruderPanel.vue index 640d7150..1fef72f4 100644 --- a/src/components/panels/ExtruderPanel.vue +++ b/src/components/panels/ExtruderPanel.vue @@ -9,13 +9,13 @@ Feed amount in mm: - {{ amount }} + {{ amount }} Feedrate in mm/s: - {{ rate }} + {{ rate }}
@@ -34,15 +34,6 @@ import Vue from "vue"; export default { - components: { - - }, - data: function() { - return { - feedAmount: 25, - feedrate: 5, - } - }, computed: { ...mapState({ loadings: state => state.socket.loadings, @@ -65,23 +56,39 @@ get() { return [...this.feedrates].sort((a,b) => { return b-a }) } + }, + currentFeedAmount: { + get() { + return parseFloat(this.$store.state.gui.dashboard.extruder.feedamount) + }, + set(newVal) { + return this.$store.dispatch('gui/setSettings', { dashboard: { extruder: { feedamount: newVal } } }) + } + }, + currentFeedRate: { + get() { + return parseFloat(this.$store.state.gui.dashboard.extruder.feedrate) + }, + set(newVal) { + return this.$store.dispatch('gui/setSettings', { dashboard: { extruder: { feedrate: newVal } } }) + } } }, methods: { setFeedAmount(value) { - this.feedAmount = value; + this.currentFeedAmount = value; }, setFeedrate(value) { - this.feedrate = value; + this.currentFeedRate = value; }, sendRetract() { - let gcode = "M83\nG1 E-"+this.feedAmount+" F"+(this.feedrate * 60); + let gcode = "M83\nG1 E-"+this.currentFeedAmount+" F"+(this.currentFeedRate * 60); this.$store.commit('server/addEvent', { message: gcode, type: 'command' }); this.$store.commit('socket/addLoading', { name: 'btnRetract' }); Vue.prototype.$socket.sendObj('printer.gcode.script', { script: gcode }, "socket/removeLoading", { name: 'btnRetract' }); }, sendDetract() { - let gcode = "M83\nG1 E"+this.feedAmount+" F"+(this.feedrate * 60); + let gcode = "M83\nG1 E"+this.currentFeedAmount+" F"+(this.currentFeedRate * 60); this.$store.commit('server/addEvent', { message: gcode, type: 'command' }); this.$store.commit('socket/addLoading', { name: 'btnDetract' }); Vue.prototype.$socket.sendObj('printer.gcode.script', { script: gcode }, "socket/removeLoading", { name: 'btnDetract' }); diff --git a/src/store/gui/index.js b/src/store/gui/index.js index 4e3bf7f4..08efea7f 100644 --- a/src/store/gui/index.js +++ b/src/store/gui/index.js @@ -20,7 +20,9 @@ export function getDefaultState() { stepsZ: [ 25, 1, 0.1 ], }, extruder: { + feedamount: 25, feedamounts: [ 50, 25, 10, 5, 1 ], + feedrate: 5, feedrates: [ 60, 30, 15, 5, 1 ], } }, From 14195daa5a7bfd1173de856812f30438f67e04da Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 22 Feb 2021 22:19:43 +0100 Subject: [PATCH 05/10] optimize dataset color and chart hover Signed-off-by: Stefan Dej --- src/components/charts/TempChart.vue | 12 ++++----- src/components/panels/ToolsPanel.vue | 12 ++++----- src/store/printer/tempHistory/actions.js | 29 ++++++++++++++++++++-- src/store/printer/tempHistory/mutations.js | 2 +- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/components/charts/TempChart.vue b/src/components/charts/TempChart.vue index 245e3e85..e9ae9a4e 100644 --- a/src/components/charts/TempChart.vue +++ b/src/components/charts/TempChart.vue @@ -57,11 +57,11 @@ export default { if (mainDataset) output += "" output += convertName(dataset.seriesName)+":" @@ -260,7 +260,7 @@ export default { methods: { createChart() { if (document.getElementById("tempchart") && this.chart === null) { - this.chart = echarts.init(document.getElementById("tempchart"), null, {renderer: 'svg'}) + this.chart = echarts.init(document.getElementById("tempchart"), null, {renderer: 'canvas'}) this.chart.setOption(this.chartOptions) } else setTimeout(() => { this.createChart() diff --git a/src/components/panels/ToolsPanel.vue b/src/components/panels/ToolsPanel.vue index 44972270..1afd75a8 100644 --- a/src/components/panels/ToolsPanel.vue +++ b/src/components/panels/ToolsPanel.vue @@ -12,10 +12,10 @@ } .datasetColorSymbol { - width: 10px; - height: 10px; + width: 8px; + height: 8px; border-style: solid; - border-width: 1px; + border-width: 0px; cursor: pointer; border-radius: 50%; } @@ -90,7 +90,7 @@ {{ convertName(heater.name) }} -
+
{{ heater.target > 0 ? (heater.power !== null ? (heater.power > 0 ? (heater.power * 100).toFixed(0)+'%' : "0%") : "active") : "off" }} @@ -110,7 +110,7 @@ {{ convertName(fan.name) }} -
+
{{ fan.target > 0 && fan.speed > 0 ? (fan.speed * 100).toFixed(0)+"%" : (fan.target > 0 ? "standby" : "off") }} @@ -132,7 +132,7 @@ {{ convertName(sensor.name) }} -
+
  diff --git a/src/store/printer/tempHistory/actions.js b/src/store/printer/tempHistory/actions.js index 990dfffb..ec58701e 100644 --- a/src/store/printer/tempHistory/actions.js +++ b/src/store/printer/tempHistory/actions.js @@ -43,9 +43,16 @@ export default { lineStyle: { color: rootGetters["gui/getDatasetValue"]({ name: name, type: 'color' }) || color, width: 2, - opacity: (rootGetters["gui/getDatasetValue"]({ name: name, type: 'temperature' })) ? 1 : 0 + opacity: (rootGetters["gui/getDatasetValue"]({ name: name, type: 'temperature' })) ? 0.9 : 0 }, symbol: 'none', + emphasis: { + lineStyle: { + color: rootGetters["gui/getDatasetValue"]({ name: name, type: 'color' }) || color, + width: 2, + opacity: (rootGetters["gui/getDatasetValue"]({ name: name, type: 'temperature' })) ? 0.9 : 0 + } + }, data: [], } @@ -74,6 +81,16 @@ export default { color: datasetTemperature.lineStyle.color, opacity: (rootGetters["gui/getDatasetValue"]({ name: name, type: 'target' })) ? 0.1 : 0 }, + emphasis: { + lineStyle: { + color: datasetTemperature.lineStyle.color, + width: 0, + }, + areaStyle: { + color: datasetTemperature.lineStyle.color, + opacity: (rootGetters["gui/getDatasetValue"]({ name: name, type: 'target' })) ? 0.1 : 0 + }, + }, symbol: 'none', data: [], } @@ -102,7 +119,15 @@ export default { color: datasetTemperature.lineStyle.color, width: 1, type: 'dotted', - opacity: (rootGetters["gui/getDatasetValue"]({ name: name, type: additionalType })) ? 1 : 0 + opacity: (rootGetters["gui/getDatasetValue"]({ name: name, type: additionalType })) ? 0.9 : 0 + }, + emphasis: { + lineStyle: { + color: datasetTemperature.lineStyle.color, + width: 1, + type: 'dotted', + opacity: (rootGetters["gui/getDatasetValue"]({ name: name, type: additionalType })) ? 0.9 : 0 + }, }, symbol: 'none', data: [], diff --git a/src/store/printer/tempHistory/mutations.js b/src/store/printer/tempHistory/mutations.js index 453958f9..d47cd021 100644 --- a/src/store/printer/tempHistory/mutations.js +++ b/src/store/printer/tempHistory/mutations.js @@ -59,7 +59,7 @@ export default { if (payload.type === "target" && 'areaStyle' in state.series[datasetIndex]) { Vue.set(state.series[datasetIndex].areaStyle, 'opacity', payload.value ? 0.1 : 0) } else if ('lineStyle' in state.series[datasetIndex]) { - Vue.set(state.series[datasetIndex].lineStyle, 'opacity', payload.value) + Vue.set(state.series[datasetIndex].lineStyle, 'opacity', payload.value ? 0.9 : 0) } } }, From 5b2dad6c32a367db3767e45140f42e74e48cee50 Mon Sep 17 00:00:00 2001 From: Rejdukien Date: Sun, 14 Feb 2021 17:41:26 +0100 Subject: [PATCH 06/10] PyImageStreamer websocket support --- .../panels/Settings/WebcamPanel.vue | 13 +++ src/components/panels/WebcamPanel.vue | 95 +++++++++++++++++-- 2 files changed, 98 insertions(+), 10 deletions(-) diff --git a/src/components/panels/Settings/WebcamPanel.vue b/src/components/panels/Settings/WebcamPanel.vue index 2fef7043..0d44a726 100644 --- a/src/components/panels/Settings/WebcamPanel.vue +++ b/src/components/panels/Settings/WebcamPanel.vue @@ -43,6 +43,11 @@ + + + + +
@@ -107,6 +112,14 @@ return this.$store.dispatch('gui/setSettings', { webcam: { bool: showNav } }); } }, + boolWebsocket: { + get() { + return this.$store.state.gui.webcam.boolWebsocket; + }, + set(useWebsocket) { + return this.$store.dispatch('gui/setSettings', { webcam: { boolWebsocket: useWebsocket } }); + } + }, }, methods: { diff --git a/src/components/panels/WebcamPanel.vue b/src/components/panels/WebcamPanel.vue index 43e0271d..45f85a33 100644 --- a/src/components/panels/WebcamPanel.vue +++ b/src/components/panels/WebcamPanel.vue @@ -8,7 +8,7 @@ - mdi-webcamWebcam + mdi-webcam{{subHeading}} @@ -23,12 +23,27 @@ export default { data: function() { return { - refresh: Math.ceil(Math.random() * Math.pow(10, 12)) - } + refresh: Math.ceil(Math.random() * Math.pow(10, 12)), + connection: "", + imageData: "", + + request_start_time: performance.now(), + start_time: performance.now(), + time: 1, + request_time: 0, + time_smoothing: 0.9, + request_time_smoothing: 0.2, + target_fps: 24 + }; }, created: function () { document.addEventListener("focus", () => this.handleRefreshChange(), false); document.addEventListener("visibilitychange", this.handleRefreshChange, false); + + if(this.webcamConfig.boolWebsocket) { + this.connect(); + } + }, components: { @@ -37,14 +52,28 @@ ...mapState({ 'webcamConfig': state => state.gui.webcam }), - url() { - let basicUrl = this.webcamConfig.url - if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?" - const params = new URLSearchParams(basicUrl) - params.set('bypassCache', ""+this.refresh) - return decodeURIComponent(params.toString()) + subHeading() { + return "Webcam" + (this.webcamConfig.boolWebsocket ? " - FPS: " + Math.round(1000 / this.time) : ""); }, + + url() { + if(!this.webcamConfig.boolWebsocket) { + let basicUrl = this.webcamConfig.url + if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?" + + const params = new URLSearchParams(basicUrl) + params.set('bypassCache', ""+this.refresh) + return decodeURIComponent(params.toString()) + } else { + return this.imageData; + /*return 'data:image/jpeg;base64,' + btoa( + new Uint8Array(this.blobData) + .reduce((data, byte) => data.String.fromCharCode(byte), '') + )*/ + } + }, + webcamStyle() { let transforms = ''; if (this.webcamConfig.flipX) { @@ -69,7 +98,53 @@ if (!document.hidden) { this.refresh = Math.ceil(Math.random() * Math.pow(10, 12)) } - } + }, + + connect() { + var wsProtocol = (location.protocol === "https:") ? "wss://" : "ws://"; + this.connection = new WebSocket(wsProtocol + this.webcamConfig.url) + this.connection.binaryType = 'arraybuffer'; + + console.log(wsProtocol + this.webcamConfig.url); + console.log(this.connection); + + this.connection.onmessage = (event) => { + var arrayBuffer = event.data; + /*this.blobUrl = 'data:image/jpeg;base64,' + btoa( + new Uint8Array(arrayBuffer) + .reduce((data, byte) => data.String.fromCharCode(byte), '') + );*/ + //this.imageData = 'data:image/jpeg;base64,' + arrayBuffer; + this.imageData = window.URL.createObjectURL(new Blob([new Uint8Array(arrayBuffer)], {type: "image/jpeg"})); + console.log(this.imageData); + + + var end_time = performance.now(); + var current_time = end_time - this.start_time; + // smooth with moving average + this.time = (this.time * this.time_smoothing) + (current_time * (1.0 - this.time_smoothing)); + this.start_time = end_time; + + var current_request_time = performance.now() - this.request_start_time; + // smooth with moving average + this.request_time = (this.request_time * this.request_time_smoothing) + (current_request_time * (1.0 - this.request_time_smoothing)); + var timeout = Math.max(0, this.target_time - this.request_time); + + setTimeout(this.requestImage(), timeout); + }; + + + this.connection.onopen = () => { + console.log("Connection to websocket was established"); + this.start_time = performance.now(); + this.requestImage(); + } + }, + + requestImage() { + this.request_start_time = performance.now(); + this.connection.send('more'); + }, } } \ No newline at end of file From b204373dd9778db3350cb776b701e090c0177bd9 Mon Sep 17 00:00:00 2001 From: Rejdukien Date: Sun, 14 Feb 2021 19:45:46 +0100 Subject: [PATCH 07/10] Change from websockets to regular pull-based approach --- package.json | 1 + .../panels/Settings/WebcamPanel.vue | 25 ++++-- src/components/panels/WebcamPanel.vue | 90 +++++++++---------- src/main.js | 2 + 4 files changed, 65 insertions(+), 53 deletions(-) diff --git a/package.json b/package.json index 7c3eaf6e..8880531c 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "vue-context": "^6.0.0", "vue-github-api": "^0.1.7", "vue-headful": "^2.1.0", + "vue-observe-visibility": "^1.0.0", "vue-plotly": "^1.1.0", "vue-prism-editor": "^1.2.2", "vue-resource": "^1.5.1", diff --git a/src/components/panels/Settings/WebcamPanel.vue b/src/components/panels/Settings/WebcamPanel.vue index 0d44a726..33a0f036 100644 --- a/src/components/panels/Settings/WebcamPanel.vue +++ b/src/components/panels/Settings/WebcamPanel.vue @@ -45,9 +45,14 @@ - + + + + + + @@ -69,6 +74,8 @@ return this.$store.state.gui.webcam.url; }, set(url) { + if(this.$store.state.gui.webcam.adaptiveFps) + url = url.replace("action=stream", "action=snapshot"); return this.$store.dispatch('gui/setSettings', { webcam: { url } }); } }, @@ -112,14 +119,22 @@ return this.$store.dispatch('gui/setSettings', { webcam: { bool: showNav } }); } }, - boolWebsocket: { + adaptiveFps: { get() { - return this.$store.state.gui.webcam.boolWebsocket; + return this.$store.state.gui.webcam.adaptiveFps; }, - set(useWebsocket) { - return this.$store.dispatch('gui/setSettings', { webcam: { boolWebsocket: useWebsocket } }); + set(useAdaptiveFps) { + return this.$store.dispatch('gui/setSettings', { webcam: { adaptiveFps: useAdaptiveFps } }); } }, + targetFps: { + get() { + return this.$store.state.gui.webcam.targetFps; + }, + set(fps) { + return this.$store.dispatch('gui/setSettings', { webcam: { targetFps: fps } }); + } + } }, methods: { diff --git a/src/components/panels/WebcamPanel.vue b/src/components/panels/WebcamPanel.vue index 45f85a33..25a8e4f7 100644 --- a/src/components/panels/WebcamPanel.vue +++ b/src/components/panels/WebcamPanel.vue @@ -5,14 +5,14 @@ @@ -29,19 +29,19 @@ request_start_time: performance.now(), start_time: performance.now(), - time: 1, + time: 0, request_time: 0, - time_smoothing: 0.9, - request_time_smoothing: 0.2, - target_fps: 24 + time_smoothing: 0.6, + request_time_smoothing: 0.1, + isVisible: true, }; }, created: function () { document.addEventListener("focus", () => this.handleRefreshChange(), false); document.addEventListener("visibilitychange", this.handleRefreshChange, false); - if(this.webcamConfig.boolWebsocket) { - this.connect(); + if(this.webcamConfig.adaptiveFps) { + this.requestMjpeg(); } }, @@ -54,11 +54,11 @@ }), subHeading() { - return "Webcam" + (this.webcamConfig.boolWebsocket ? " - FPS: " + Math.round(1000 / this.time) : ""); + return "Webcam" + (this.webcamConfig.adaptiveFps ? " - FPS: " + Math.round(1000 / this.time) : ""); }, url() { - if(!this.webcamConfig.boolWebsocket) { + if(!this.webcamConfig.adaptiveFps) { let basicUrl = this.webcamConfig.url if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?" @@ -100,51 +100,45 @@ } }, - connect() { - var wsProtocol = (location.protocol === "https:") ? "wss://" : "ws://"; - this.connection = new WebSocket(wsProtocol + this.webcamConfig.url) - this.connection.binaryType = 'arraybuffer'; + onLoad() { + var end_time = performance.now(); + var current_time = end_time - this.start_time; + this.time = (this.time * this.time_smoothing) + (current_time * (1.0 - this.time_smoothing)); + this.start_time = end_time; - console.log(wsProtocol + this.webcamConfig.url); - console.log(this.connection); - - this.connection.onmessage = (event) => { - var arrayBuffer = event.data; - /*this.blobUrl = 'data:image/jpeg;base64,' + btoa( - new Uint8Array(arrayBuffer) - .reduce((data, byte) => data.String.fromCharCode(byte), '') - );*/ - //this.imageData = 'data:image/jpeg;base64,' + arrayBuffer; - this.imageData = window.URL.createObjectURL(new Blob([new Uint8Array(arrayBuffer)], {type: "image/jpeg"})); - console.log(this.imageData); + var target_time = 1000/this.webcamConfig.targetFps + var current_request_time = performance.now() - this.request_start_time; + this.request_time = (this.request_time * this.request_time_smoothing) + (current_request_time * (1.0 - this.request_time_smoothing)); + var timeout = Math.max(0, target_time - this.request_time); - var end_time = performance.now(); - var current_time = end_time - this.start_time; - // smooth with moving average - this.time = (this.time * this.time_smoothing) + (current_time * (1.0 - this.time_smoothing)); - this.start_time = end_time; - - var current_request_time = performance.now() - this.request_start_time; - // smooth with moving average - this.request_time = (this.request_time * this.request_time_smoothing) + (current_request_time * (1.0 - this.request_time_smoothing)); - var timeout = Math.max(0, this.target_time - this.request_time); - - setTimeout(this.requestImage(), timeout); - }; - - - this.connection.onopen = () => { - console.log("Connection to websocket was established"); - this.start_time = performance.now(); - this.requestImage(); - } + this.$nextTick(() => { + console.log(end_time + " " + timeout); + setTimeout(this.requestMjpeg, timeout); + }) }, - requestImage() { + requestMjpeg() { + if(!this.isVisible) + return; this.request_start_time = performance.now(); - this.connection.send('more'); + let basicUrl = this.webcamConfig.url + if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?" + + const params = new URLSearchParams(basicUrl) + params.set('bypassCache', ""+ this.refresh + (Math.random() * 1000)) + + this.$nextTick(() => { + this.imageData = decodeURIComponent(params.toString()) + }) }, + + visibilityChanged(isVisible, entry) { + this.isVisible = isVisible; + console.log(entry); + if(isVisible) + this.requestMjpeg(); + } } } \ No newline at end of file diff --git a/src/main.js b/src/main.js index 1e72a08b..cc22b74a 100644 --- a/src/main.js +++ b/src/main.js @@ -7,10 +7,12 @@ import './components' import store from './store' import router from './plugins/router' import vueHeadful from 'vue-headful'; +import VueObserveVisibility from 'vue-observe-visibility'; Vue.config.productionTip = false; Vue.use(VueResource); +Vue.use(VueObserveVisibility); Vue.http.headers.common['Content-Type'] = 'application/json'; Vue.http.headers.common['Access-Control-Allow-Origin'] = '*'; Vue.http.headers.common['Accept'] = 'application/json, text/plain, */*'; From cbd9d6ea75d2a11fc1f411ce74de5ae552d7ba9d Mon Sep 17 00:00:00 2001 From: Rejdukien Date: Mon, 15 Feb 2021 16:19:44 +0100 Subject: [PATCH 08/10] Cleanup and change from switch to select element Signed-off-by: Rejdukien --- .../panels/Settings/WebcamPanel.vue | 20 ++++++++++--------- src/components/panels/WebcamPanel.vue | 14 +++++-------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/components/panels/Settings/WebcamPanel.vue b/src/components/panels/Settings/WebcamPanel.vue index 33a0f036..f64cf61d 100644 --- a/src/components/panels/Settings/WebcamPanel.vue +++ b/src/components/panels/Settings/WebcamPanel.vue @@ -45,10 +45,10 @@ - + - + @@ -65,7 +65,11 @@ }, data: function() { return { - rotationEnabled: false + rotationEnabled: false, + serviceMethodItems: [ + { value: 0, text: 'MJPEG-Streamer' }, + { value: 1, text: 'MJPEG-Streamer (Adaptive)' }, + ] } }, computed: { @@ -74,8 +78,6 @@ return this.$store.state.gui.webcam.url; }, set(url) { - if(this.$store.state.gui.webcam.adaptiveFps) - url = url.replace("action=stream", "action=snapshot"); return this.$store.dispatch('gui/setSettings', { webcam: { url } }); } }, @@ -119,12 +121,12 @@ return this.$store.dispatch('gui/setSettings', { webcam: { bool: showNav } }); } }, - adaptiveFps: { + serviceMethod: { get() { - return this.$store.state.gui.webcam.adaptiveFps; + return this.$store.state.gui.webcam.serviceMethod; }, - set(useAdaptiveFps) { - return this.$store.dispatch('gui/setSettings', { webcam: { adaptiveFps: useAdaptiveFps } }); + set(selectedMethod) { + return this.$store.dispatch('gui/setSettings', { webcam: { serviceMethod: selectedMethod } }); } }, targetFps: { diff --git a/src/components/panels/WebcamPanel.vue b/src/components/panels/WebcamPanel.vue index 25a8e4f7..85897d57 100644 --- a/src/components/panels/WebcamPanel.vue +++ b/src/components/panels/WebcamPanel.vue @@ -40,7 +40,7 @@ document.addEventListener("focus", () => this.handleRefreshChange(), false); document.addEventListener("visibilitychange", this.handleRefreshChange, false); - if(this.webcamConfig.adaptiveFps) { + if(this.webcamConfig.serviceMethod == 1) { this.requestMjpeg(); } @@ -54,11 +54,11 @@ }), subHeading() { - return "Webcam" + (this.webcamConfig.adaptiveFps ? " - FPS: " + Math.round(1000 / this.time) : ""); + return "Webcam" + (this.webcamConfig.serviceMethod == 1 ? " - FPS: " + Math.round(1000 / this.time) : ""); }, url() { - if(!this.webcamConfig.adaptiveFps) { + if(!this.webcamConfig.serviceMethod) { let basicUrl = this.webcamConfig.url if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?" @@ -67,10 +67,6 @@ return decodeURIComponent(params.toString()) } else { return this.imageData; - /*return 'data:image/jpeg;base64,' + btoa( - new Uint8Array(this.blobData) - .reduce((data, byte) => data.String.fromCharCode(byte), '') - )*/ } }, @@ -121,6 +117,7 @@ requestMjpeg() { if(!this.isVisible) return; + this.request_start_time = performance.now(); let basicUrl = this.webcamConfig.url if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?" @@ -133,9 +130,8 @@ }) }, - visibilityChanged(isVisible, entry) { + visibilityChanged(isVisible) { this.isVisible = isVisible; - console.log(entry); if(isVisible) this.requestMjpeg(); } From 2be28ab46327a1657b7601df3be423b3d90c51a7 Mon Sep 17 00:00:00 2001 From: Stefan Dej Date: Mon, 22 Feb 2021 23:26:00 +0100 Subject: [PATCH 09/10] cleanup adaptive mjpeg-streamer functions Signed-off-by: Stefan Dej --- package-lock.json | 15 +++++- .../panels/Settings/WebcamPanel.vue | 34 ++++++------ src/components/panels/WebcamPanel.vue | 53 ++++++++++--------- src/store/gui/index.js | 2 + 4 files changed, 59 insertions(+), 45 deletions(-) diff --git a/package-lock.json b/package-lock.json index 439f71c4..95845edf 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "mainsail", - "version": "1.2.0", + "version": "1.3.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "mainsail", - "version": "1.2.0", + "version": "1.3.0", "dependencies": { "axios": "^0.21.1", "core-js": "^3.8.2", @@ -19,6 +19,7 @@ "vue-context": "^6.0.0", "vue-github-api": "^0.1.7", "vue-headful": "^2.1.0", + "vue-observe-visibility": "^1.0.0", "vue-plotly": "^1.1.0", "vue-prism-editor": "^1.2.2", "vue-resource": "^1.5.1", @@ -17397,6 +17398,11 @@ "integrity": "sha1-M7QHd3VMZDJXPBIMw4CLvRDUfwQ=", "dev": true }, + "node_modules/vue-observe-visibility": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/vue-observe-visibility/-/vue-observe-visibility-1.0.0.tgz", + "integrity": "sha512-s5TFh3s3h3Mhd3jaz3zGzkVHKHnc/0C/gNr30olO99+yw2hl3WBhK3ng3/f9OF+qkW4+l7GkmwfAzDAcY3lCFg==" + }, "node_modules/vue-plotly": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/vue-plotly/-/vue-plotly-1.1.0.tgz", @@ -35152,6 +35158,11 @@ } } }, + "vue-observe-visibility": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/vue-observe-visibility/-/vue-observe-visibility-1.0.0.tgz", + "integrity": "sha512-s5TFh3s3h3Mhd3jaz3zGzkVHKHnc/0C/gNr30olO99+yw2hl3WBhK3ng3/f9OF+qkW4+l7GkmwfAzDAcY3lCFg==" + }, "vue-plotly": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/vue-plotly/-/vue-plotly-1.1.0.tgz", diff --git a/src/components/panels/Settings/WebcamPanel.vue b/src/components/panels/Settings/WebcamPanel.vue index f64cf61d..f33ce99f 100644 --- a/src/components/panels/Settings/WebcamPanel.vue +++ b/src/components/panels/Settings/WebcamPanel.vue @@ -12,7 +12,17 @@ - + + + + + + + + + + + - - - - - - - - - - @@ -66,9 +66,9 @@ data: function() { return { rotationEnabled: false, - serviceMethodItems: [ - { value: 0, text: 'MJPEG-Streamer' }, - { value: 1, text: 'MJPEG-Streamer (Adaptive)' }, + serviceItems: [ + { value: 'mjpegstreamer', text: 'MJPEG-Streamer' }, + { value: 'mjpegstreamer-adaptive', text: 'Adaptive MJPEG-Streamer (experimental)' }, ] } }, @@ -121,12 +121,12 @@ return this.$store.dispatch('gui/setSettings', { webcam: { bool: showNav } }); } }, - serviceMethod: { + service: { get() { - return this.$store.state.gui.webcam.serviceMethod; + return this.$store.state.gui.webcam.service; }, set(selectedMethod) { - return this.$store.dispatch('gui/setSettings', { webcam: { serviceMethod: selectedMethod } }); + return this.$store.dispatch('gui/setSettings', { webcam: { service: selectedMethod } }); } }, targetFps: { diff --git a/src/components/panels/WebcamPanel.vue b/src/components/panels/WebcamPanel.vue index 85897d57..f28fc6c7 100644 --- a/src/components/panels/WebcamPanel.vue +++ b/src/components/panels/WebcamPanel.vue @@ -8,7 +8,10 @@ - mdi-webcam{{subHeading}} + + mdi-webcam Webcam + (FPS: {{ currentFPS }}) + @@ -34,14 +37,15 @@ time_smoothing: 0.6, request_time_smoothing: 0.1, isVisible: true, + currentFPS: 0, }; }, created: function () { document.addEventListener("focus", () => this.handleRefreshChange(), false); document.addEventListener("visibilitychange", this.handleRefreshChange, false); - if(this.webcamConfig.serviceMethod == 1) { - this.requestMjpeg(); + if(this.webcamConfig.service === 'mjpegstreamer-adaptive') { + this.requestMjpeg() } }, @@ -53,20 +57,16 @@ 'webcamConfig': state => state.gui.webcam }), - subHeading() { - return "Webcam" + (this.webcamConfig.serviceMethod == 1 ? " - FPS: " + Math.round(1000 / this.time) : ""); - }, - url() { - if(!this.webcamConfig.serviceMethod) { + if(this.webcamConfig.service === 'mjpegstreamer-adaptive') { + return this.imageData; + } else { let basicUrl = this.webcamConfig.url if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?" const params = new URLSearchParams(basicUrl) params.set('bypassCache', ""+this.refresh) return decodeURIComponent(params.toString()) - } else { - return this.imageData; } }, @@ -97,43 +97,44 @@ }, onLoad() { - var end_time = performance.now(); - var current_time = end_time - this.start_time; - this.time = (this.time * this.time_smoothing) + (current_time * (1.0 - this.time_smoothing)); - this.start_time = end_time; + const end_time = performance.now() + const current_time = end_time - this.start_time + this.time = (this.time * this.time_smoothing) + (current_time * (1.0 - this.time_smoothing)) + this.start_time = end_time - var target_time = 1000/this.webcamConfig.targetFps + const target_time = 1000/this.webcamConfig.targetFps - var current_request_time = performance.now() - this.request_start_time; - this.request_time = (this.request_time * this.request_time_smoothing) + (current_request_time * (1.0 - this.request_time_smoothing)); - var timeout = Math.max(0, target_time - this.request_time); + const current_request_time = performance.now() - this.request_start_time + this.request_time = (this.request_time * this.request_time_smoothing) + (current_request_time * (1.0 - this.request_time_smoothing)) + const timeout = Math.max(0, target_time - this.request_time) this.$nextTick(() => { - console.log(end_time + " " + timeout); - setTimeout(this.requestMjpeg, timeout); + setTimeout(this.requestMjpeg, timeout) }) }, requestMjpeg() { - if(!this.isVisible) - return; + if(!this.isVisible) return - this.request_start_time = performance.now(); + this.request_start_time = performance.now() let basicUrl = this.webcamConfig.url + basicUrl = basicUrl.replace("action=stream", "action=snapshot") if (basicUrl && basicUrl.indexOf("?") === -1) basicUrl += "?" const params = new URLSearchParams(basicUrl) params.set('bypassCache', ""+ this.refresh + (Math.random() * 1000)) + + this.currentFPS = Math.round(1000 / this.time) + this.$nextTick(() => { this.imageData = decodeURIComponent(params.toString()) }) }, visibilityChanged(isVisible) { - this.isVisible = isVisible; - if(isVisible) - this.requestMjpeg(); + this.isVisible = isVisible + if(isVisible) this.requestMjpeg() } } } diff --git a/src/store/gui/index.js b/src/store/gui/index.js index 08efea7f..9ea8da63 100644 --- a/src/store/gui/index.js +++ b/src/store/gui/index.js @@ -27,6 +27,8 @@ export function getDefaultState() { } }, webcam: { + service: 'mjpegstreamer', + targetFps: 25, url: "", rotate: false, rotateDegrees: 90, From baa4d9b4166f035f4458dcf62ad6ece597257707 Mon Sep 17 00:00:00 2001 From: dewi-ny-je <2866139+dewi-ny-je@users.noreply.github.com> Date: Mon, 22 Feb 2021 23:34:28 +0100 Subject: [PATCH 10/10] Added infor about presets gcode Specified that gcode is executed after the temperatures are set. --- docs/quicktips/presets.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/quicktips/presets.md b/docs/quicktips/presets.md index 9ee2f55a..41f6a23d 100644 --- a/docs/quicktips/presets.md +++ b/docs/quicktips/presets.md @@ -16,7 +16,7 @@ In Mainsails interface settings you will find a section called "Preheat Presets" ### Preheat -Enter a name \(e.g. name, color and type of filament\) and the temperatures obtained. You can disable individual heaters and even specify a custom gcode for the preheat phase. +Enter a name \(e.g. name, color and type of filament\) and the temperatures obtained. You can disable individual heaters and even specify a custom gcode for the preheat phase. The gcode will be executed after the selected temperatures are set. ![](../assets/img/quicktips/presets/preheat.png)