diff --git a/main/managementinterface.go b/main/managementinterface.go index 7807ce29..9344cb05 100644 --- a/main/managementinterface.go +++ b/main/managementinterface.go @@ -482,6 +482,21 @@ func handleCageAHRS(w http.ResponseWriter, r *http.Request) { } } +func handleResetGMeter(w http.ResponseWriter, r *http.Request) { + // define header in support of cross-domain AJAX + setNoCache(w) + w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Access-Control-Allow-Origin", "*") + w.Header().Set("Access-Control-Allow-Method", "GET, POST, OPTIONS") + w.Header().Set("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept") + + // For an OPTION method request, we return header without processing. + // This ensures we are recognized as supporting cross-domain AJAX REST calls. + if r.Method == "POST" { + ResetAHRSGLoad() + } +} + func doRestartApp() { time.Sleep(1) syscall.Sync() @@ -731,6 +746,7 @@ func managementInterface() { http.HandleFunc("/orientAHRS", handleOrientAHRS) http.HandleFunc("/cageAHRS", handleCageAHRS) + http.HandleFunc("/resetGMeter", handleResetGMeter) http.HandleFunc("/deletelogfile", handleDeleteLogFile) http.HandleFunc("/downloadlog", handleDownloadLogRequest) diff --git a/web/js/main.js b/web/js/main.js index 23eaa64d..26502120 100755 --- a/web/js/main.js +++ b/web/js/main.js @@ -17,6 +17,7 @@ var URL_RESTARTAPP = "http://" + URL_HOST_BASE + "/restart"; var URL_DEV_TOGGLE_GET = "http://" + URL_HOST_BASE + "/develmodetoggle"; var URL_AHRS_ORIENT = "http://" + URL_HOST_BASE + "/orientAHRS"; var URL_AHRS_CAGE = "http://" + URL_HOST_BASE + "/cageAHRS"; +var URL_GMETER_RESET = "http://" + URL_HOST_BASE + "/resetGMeter"; var URL_DELETELOGFILE = "http://" + URL_HOST_BASE + "/deletelogfile"; var URL_DOWNLOADLOGFILE = "http://" + URL_HOST_BASE + "/downloadlog"; var URL_DOWNLOADDB = "http://" + URL_HOST_BASE + "/downloaddb"; diff --git a/web/plates/js/ahrs.js b/web/plates/js/ahrs.js index 5fffd555..728e4544 100644 --- a/web/plates/js/ahrs.js +++ b/web/plates/js/ahrs.js @@ -143,7 +143,7 @@ AHRSRenderer.prototype = { } }; -function GMeterRenderer(locationId, plim, nlim) { +function GMeterRenderer(locationId, plim, nlim, resetCallback) { this.plim = plim; this.nlim = nlim; this.nticks = Math.floor(plim+1) - Math.floor(nlim) + 1; @@ -215,7 +215,7 @@ function GMeterRenderer(locationId, plim, nlim) { reset.text('RESET').cx(0).cy(0).addClass('text'); reset.on('click', function() { reset.animate(200).rotate(20, 0, 0); - this.reset(); + resetCallback(); reset.animate(200).rotate(0, 0, 0); }, this); } @@ -235,19 +235,13 @@ GMeterRenderer.prototype = { } }, - update: function (g) { + update: function (g, gmin, gmax) { this.g = g; - this.max = g > this.max ? g : this.max; - this.min = g < this.min ? g : this.min; + this.min = gmin; + this.max = gmax; this.pointer_el.animate(50).rotate((g-1)/this.nticks*360, 0, 0); this.max_el.animate(50).rotate((this.max-1)/this.nticks*360, 0, 0); this.min_el.animate(50).rotate((this.min-1)/this.nticks*360, 0, 0); - }, - - reset: function() { - this.g = 1; - this.max = 1; - this.min = 1; } }; diff --git a/web/plates/js/gps.js b/web/plates/js/gps.js index 9e760060..d68e811f 100644 --- a/web/plates/js/gps.js +++ b/web/plates/js/gps.js @@ -175,7 +175,7 @@ function GPSCtrl($rootScope, $scope, $state, $http, $interval) { if ($scope.ahrs_gload > 360) { $scope.ahrs_gload = "--"; } else { - gMeter.update(situation.AHRSGLoad); + gMeter.update(situation.AHRSGLoad, situation.AHRSGLoadMin, situation.AHRSGLoadMax); } if (situation.AHRSTurnRate > 360) { @@ -204,7 +204,7 @@ function GPSCtrl($rootScope, $scope, $state, $http, $interval) { } if (situation.AHRSStatus & 0x02) { if (statusIMU.classList.contains("off")) { - setTimeout(gMeter.reset(), 1000); + setTimeout($scope.GMeterReset, 1000); } statusIMU.classList.remove("off"); statusIMU.classList.add("on"); @@ -357,7 +357,15 @@ function GPSCtrl($rootScope, $scope, $state, $http, $interval) { return caging; }; - var gMeter = new GMeterRenderer("gMeter_display", 4.4, -1.76); + $scope.GMeterReset = function() { + $http.post(URL_GMETER_RESET).then(function (response) { + // do nothing + }, function (response) { + // do nothing + }); + }; + + var gMeter = new GMeterRenderer("gMeter_display", 4.4, -1.76, $scope.GMeterReset); // GPS Controller tasks connect($scope); // connect - opens a socket and listens for messages