Skip to content

Commit 8ee54d0

Browse files
committed
Delay fast pressions on the movement buttons to at least a treshold duration
1 parent 2c8f8ef commit 8ee54d0

File tree

1 file changed

+23
-5
lines changed

1 file changed

+23
-5
lines changed

src/components/Control.vue

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ export default {
115115
this.$store.commit('toggleDrawer', !currentStatus)
116116
},
117117
move: function(direction) {
118+
this.$data.pressDuration = performance.now()
118119
console.log("move")
119120
let axios = this.$axios
120121
let CB = this.$data.CB
@@ -164,11 +165,27 @@ export default {
164165
console.log("stopping")
165166
let axios = this.$axios
166167
let CB = this.$data.CB
167-
axios.post(CB + '/stop').then(function(response) {
168-
console.log(response)
169-
}).catch(function(error) {
170-
console.log(error)
171-
})
168+
let pressDuration = this.$data.pressDuration
169+
pressDuration = performance.now() - this.$data.pressDuration
170+
let minTreshold = 500
171+
let delay = minTreshold - pressDuration
172+
console.log("Pressed for", pressDuration, "ms")
173+
if (pressDuration < 500){
174+
console.log("Too fast, postponing it by", delay ,"ms..")
175+
setTimeout(function () {
176+
axios.post(CB + '/stop').then(function(response) {
177+
console.log(response)
178+
}).catch(function(error) {
179+
console.log(error)
180+
})
181+
}, delay );
182+
} else {
183+
axios.post(CB + '/stop').then(function(response) {
184+
console.log(response)
185+
}).catch(function(error) {
186+
console.log(error)
187+
})
188+
}
172189
}
173190
},
174191
data() {
@@ -178,6 +195,7 @@ export default {
178195
webcamStream: process.env.CB_ENDPOINT + process.env.APIv1 + '/video/stream',
179196
CB: process.env.CB_ENDPOINT + process.env.APIv2,
180197
status: null,
198+
pressDuration: null,
181199
};
182200
},
183201
mounted() {

0 commit comments

Comments
 (0)