Fix bug were fast clicks could cause jog commands to arrive out of order
authorJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 27 Jun 2019 22:13:11 +0000 (15:13 -0700)
committerJoseph Coffland <joseph@cauldrondevelopment.com>
Thu, 27 Jun 2019 22:13:11 +0000 (15:13 -0700)
src/js/control-view.js
src/py/bbctrl/Web.py

index 7244eeaf35ba98a42d26885a8a74cc82fb8f0d8a..6ba4fcf989814b341f34bcd73a95b939433f1e5c 100644 (file)
@@ -182,7 +182,7 @@ module.exports = {
 
   events: {
     jog: function (axis, power) {
-      var data = {};
+      var data = {ts: new Date().getTime()};
       data[axis] = power;
       api.put('jog', data);
     }
index a0dd6c89a988dcb73e45b6358d24f7c09b9169ab..891bdce9eea2491cb0e67a90fa87b564675dafb6 100644 (file)
@@ -390,7 +390,21 @@ class ModbusWriteHandler(bbctrl.APIHandler):
 
 
 class JogHandler(bbctrl.APIHandler):
-    def put_ok(self): self.get_ctrl().mach.jog(self.json)
+    def put_ok(self):
+        # Handle possible out of order jog command processing
+        if 'ts' in self.json:
+            ts = self.json['ts']
+            id = self.get_cookie('client-id')
+
+            if not hasattr(self.app, 'last_jog'):
+                self.app.last_jog = {}
+
+            last = self.app.last_jog.get(id, 0)
+            self.app.last_jog[id] = ts
+
+            if ts < last: return # Out of order
+
+        self.get_ctrl().mach.jog(self.json)
 
 
 # Base class for Web Socket connections