diff --git a/assets/js/jogtouch.js b/assets/js/jogtouch.js index 4cbd6b9..2852a79 100644 --- a/assets/js/jogtouch.js +++ b/assets/js/jogtouch.js @@ -407,10 +407,6 @@ /*$document.on(EVENT_MOUSE_MOVE, (this._move = proxy(this.move, this))).*/ - /*if ($.isFunction(options.touch)) { - $this.on(EVENT_TOUCH, options.touch); - }*/ - $window.on(EVENT_RESIZE, (this._resize = proxy(this.resize, this))); }, diff --git a/assets/js/jquery.WebSocket.js b/assets/js/jquery.WebSocket.js index 0cb0b25..1f26a9a 100644 --- a/assets/js/jquery.WebSocket.js +++ b/assets/js/jquery.WebSocket.js @@ -575,7 +575,7 @@ // send data via jQuery ajax() $.ajax({ - async: false, + async: true, // changed from false to true because it blocked the UI, success will always be returned as true type: ajax_method, url: ajax_url, data:ajax_data, @@ -746,8 +746,8 @@ var ws, isNative = true; // websocket support built in? - if (window.WebSocket) { - //if (false) { + //if (window.WebSocket) { + if (false) { // in firefox we use MozWebSocket (but it seems that from now (FF 17) MozWebsocket is removed) if (typeof(MozWebSocket) == 'function') { ws = new MozWebSocket(url); diff --git a/controller.php b/controller.php index be39ccd..178045c 100644 --- a/controller.php +++ b/controller.php @@ -528,12 +528,51 @@ public function startTask() public function ws_fallback() { - $response['type'] = 'debug'; - $response['data'] = array( - 'message' => 'this is websocket fallback', - 'method' => $this->input->method(true), - 'data-get' => $this->input->get(), - 'data-post' => $this->input->post() ); + $method = $this->input->method(true); + + $response = array("type" => "unknown", "data" => ""); + + if($method == "GET") + { + /*$request = $this->input->get(); + $requestData = json_decode($request, true);*/ + + } + else if($method == "POST") + { + $request = $this->input->post("data"); + $requestData = json_decode($request, true); + + if(isset($requestData['function'])){ + $function = $requestData['function']; + $functionParams = isset($requestData['params']) ? $requestData['params'] : ''; + + switch($function) + { + case "serial": { + $this->load->library('JogFactory', '', 'jogFactory'); + $jogFactory = $this->jogFactory; + + $method = $functionParams['method']; + $methodParam = $functionParams['value']; + $methodStamp = $functionParams['stamp']; + + /*unset($data['method']); + unset($data['value']); + unset($data['stamp']);*/ + + if(method_exists($jogFactory, $method)){ //if method exists than do it + $response['data'] = $jogFactory = $this->jogFactory->$method($methodParam, $methodStamp); + $response['type'] = 'jog'; + } + } + break; + + + } + } + + } $this->output->set_content_type('application/json')->set_output(json_encode($response)); } diff --git a/views/make/js.php b/views/make/js.php index 116175c..bcc80b9 100644 --- a/views/make/js.php +++ b/views/make/js.php @@ -16,7 +16,7 @@ wsApp = (function(app) { app.mytemp = 0; - app.ws = null; + app.socket = null; app.ws_callbacks = {} app.setMytest = function(value) { @@ -51,14 +51,14 @@ 'params' : data }; - ws.send( JSON.stringify(messageToSend) ); - if($.isFunction(callback)) { app.ws_callbacks[stamp] = callback; - console.log('adding callback for', stamp, app.ws_callbacks); + //~ console.log('=== adding callback for', stamp, app.ws_callbacks); } + app.socket.send( JSON.stringify(messageToSend) ); + return stamp; }; @@ -94,7 +94,7 @@ //~ arguments: {arg1:"test1", arg2:"test2"} }; - app.ws = ws = $.WebSocket ('ws://'+socket_host+':'+socket_port, null, options); + app.socket = ws = $.WebSocket ('ws://'+socket_host+':'+socket_port, null, options); // WebSocket onerror event triggered also in fallback ws.onerror = function (e) { @@ -105,11 +105,10 @@ // if connection is opened => start opening a pipe (multiplexing) ws.onopen = function () { console.log("ws: opened as ", ws.fallback?"fallback":"websocket"); - //ws.send( JSON.stringify({data:'my data'}) ); }; ws.onmessage = function (e) { - //console.log(e.data); + //console.log('>> ws.onmessage', e); try { var obj = jQuery.parseJSON(e.data); diff --git a/views/std/jog_setup_js.php b/views/std/jog_setup_js.php index be48134..51d3698 100644 --- a/views/std/jog_setup_js.php +++ b/views/std/jog_setup_js.php @@ -107,6 +107,7 @@ function rotation(value) function jogAction(e) { + console.log("== jog_busy", jog_busy); if(jog_busy) return false; @@ -174,9 +175,11 @@ function jogAction(e) //fabApp.jogMdi(cmd); jog_busy = true; + console.log("== jog_busy set to BUSY", jog_busy); wsApp.jogMdi(cmd, function(e) { console.log("wsApp, COMMAND COMPLETED", e); jog_busy = false; + console.log("== jog_busy set to READY", jog_busy); }); /*fabApp.jogMdi(cmd, function(e) {