From 5636d9d84a70c1affdf0dcf194168b4d090808ba Mon Sep 17 00:00:00 2001 From: Gilbert Montague Date: Wed, 25 Jan 2017 11:12:51 -0800 Subject: [PATCH] Feature/feet display (#193) * Click on the units of depth will switch between imperial and metric units * Fixed depth/heading hold not responding --- src/plugins/diveprofile/index.js | 14 +- .../new-ui/public/webcomponents/depth.html | 118 +++++--- .../rovpilot-wire/public/js/rovpilot-wire.js | 269 ++++++++++-------- .../platforms/mock/boards/mock3000/bridge.js | 4 +- 4 files changed, 246 insertions(+), 159 deletions(-) diff --git a/src/plugins/diveprofile/index.js b/src/plugins/diveprofile/index.js index f13de397..7912548b 100644 --- a/src/plugins/diveprofile/index.js +++ b/src/plugins/diveprofile/index.js @@ -38,7 +38,7 @@ class DiveProfile this.depth = 0; // meters this.pressure = 0; // kPa this.temperature = 0; // celsius - this.waterType = "Freshwater"; + this.waterType = "Fresh"; this.SyncSettings = new Periodic( 100, "timeout", function() { @@ -107,11 +107,11 @@ class DiveProfile self.settings = settings.diveProfile; // Set target water type - if( self.settings.waterType == "Freshwater" ) + if( self.settings.waterType == "Fresh" ) { self.targetWaterType = 0; } - else if( self.settings.waterType == "Saltwater" ) + else if( self.settings.waterType == "Salt" ) { self.targetWaterType = 1; } @@ -153,11 +153,11 @@ class DiveProfile if( self.mcuWaterType == 0 ) { - this.waterType = "Freshwater"; + this.waterType = "Fresh"; } else { - this.waterType = "Saltwater"; + this.waterType = "Salt"; } self.cockpitBus.emit( "plugin.diveProfile.waterType", self.waterType ); @@ -239,8 +239,8 @@ class DiveProfile 'waterType': { 'type': 'string', 'enum': [ - 'Freshwater', - 'Saltwater' + 'Fresh', + 'Salt' ], 'title': 'Water Type', 'default': 'Freshwater' diff --git a/src/plugins/new-ui/public/webcomponents/depth.html b/src/plugins/new-ui/public/webcomponents/depth.html index 84e09524..51668d9e 100644 --- a/src/plugins/new-ui/public/webcomponents/depth.html +++ b/src/plugins/new-ui/public/webcomponents/depth.html @@ -16,7 +16,7 @@ margin-top: -0.6vw; } #depth { - font-size: 1.8vw; + font-size: 1.85vw; font-weight: bold; text-align: center; } @@ -30,27 +30,32 @@ 1px 1px 0 #fff; } #depthTarget { - font-size: 1vw; + font-size: 1.0vw; font-weight: bold; - /*padding-top: 2px;*/ } #depthTarget.hidden { opacity: 0; } #depth-footer { width: 100%; - margin-top: -20px; + margin-top: 0.75vw; + + font-size: 0.9vw; } #water-type { - width: 35%; - float: left; + font-weight: bold; } #depth-unit { - width: 35%; - text-align: right; float: right; + + font-weight: bold; + } + #depth-unit:hover { + cursor: pointer; + } + .depth-line-container { + margin-top: 0.5vw; } - .depth-line-container, #depth-change-container { position: relative; display:table; @@ -77,11 +82,12 @@ } #depthLock { text-align: right; + font-weight:bold; right: 10px; - margin-top: -29px; + margin-top: -0.2vw; } #numberContainer { - margin-top: 10px; + margin-top: -0.5vw; padding-bottom: 14px; } #depthLock.hidden { opacity: 0; } @@ -114,11 +120,12 @@ display: inline-block; max-width: 55px; margin: auto; - font-size: 1.0vw; + font-size: 1.25vw; vertical-align: middle; } #depth-change-unit { margin-top: -6px; + font-size: 0.85vw; } .depth-change-indicator { width: 15px; height: 15px } svg { width: 100%; } @@ -132,12 +139,17 @@
{{formatDepth(depth)}}
- + + +
@@ -160,7 +172,7 @@
-
{{__('m/s')}}
+
{{depthUnit}}{{__('/s')}}
@@ -178,7 +190,11 @@ }, depth: { type: Number, - value: 0 + value: function(){return 0;} + }, + depthUnit: { + type: String, + value: function(){return 'm';} }, options: { type: Object, @@ -191,11 +207,11 @@ }, target: { type: Number, - value: 0 + value: function(){return 0;} }, waterType: { type: String, - value: 'salt' + value: function(){return 'Salt';} } }, behaviors: [namespace('behaviors').oROVStandard], @@ -206,22 +222,34 @@ }); emitter.withHistory.on('plugin.rovpilot.depthHold.state', function (state) { - if(state.enabled){ - self.target = Number(state.targetDepth).toFixed(1); - $(self.$.depth).addClass('inverted'); - $(self.$.depthTarget).removeClass('hidden'); - $(self.$.depthLock).removeClass('hidden'); - } else{ - self.target = 0; - $(self.$.depth).removeClass('inverted'); - $(self.$.depthTarget).addClass('hidden'); - $(self.$.depthLock).addClass('hidden'); - } + if(state.enabled) + { + self.target = Number(state.targetDepth).toFixed(2); + //Format based on setting + if(self.depthUnit == "ft") + { + self.target = self.convertToFeet(state.targetDepth).toFixed(2); + } + $(self.$.depth).addClass('inverted'); + $(self.$.depthTarget).removeClass('hidden'); + $(self.$.depthLock).removeClass('hidden'); + + } + else + { + self.target = 0; + $(self.$.depth).removeClass('inverted'); + $(self.$.depthTarget).addClass('hidden'); + $(self.$.depthLock).addClass('hidden'); + } }); emitter.withHistory.on('plugin.diveProfile.waterType', function (waterType) { self.waterType = waterType; }); }, + listeners: { + 'depth-unit.tap': 'toggleDepthUnit', + }, attached: function(){ this._dataThrottleInterval=setInterval(function(){ if (newState == lastState){return;}; @@ -261,12 +289,15 @@ self.$.upPolygon.style.fill="black"; } - var changeText = ''; if (difference > 0) { changeText = '+'; } + if(self.depthUnit == "ft") + { + difference = self.convertToFeet(difference); + } changeText += difference.toFixed(2); self.change = changeText; oldDepth = currentDepth; @@ -286,7 +317,30 @@ clearInterval(this._updateInterval); }, formatDepth : function(depth){ - return depth.toFixed(1); + var self = this; + + //Format based on setting + if(self.depthUnit == "ft") + { + depth = self.convertToFeet(depth); + } + return depth.toFixed(2); + }, + convertToFeet(numberIn) { + return Number(numberIn * 3.28); + }, + toggleDepthUnit: function(e) { + var self = this; + + if(self.depthUnit == "m") + { + self.set("depthUnit", "ft"); + } + else + { + self.set("depthUnit", "m"); + } + } }); }()); diff --git a/src/plugins/rovpilot-wire/public/js/rovpilot-wire.js b/src/plugins/rovpilot-wire/public/js/rovpilot-wire.js index c7923c49..00c13cfa 100644 --- a/src/plugins/rovpilot-wire/public/js/rovpilot-wire.js +++ b/src/plugins/rovpilot-wire/public/js/rovpilot-wire.js @@ -1,134 +1,167 @@ -(function (window, $) { - 'use strict'; - var ROVpilotWire; - ROVpilotWire = function ROVpilotWire(cockpit) { - var self = this; - deps.logger.debug('Loading ROVpilot-Wire plugin in the browser.'); - // Instance variables - this.cockpit = cockpit; - this.rov = cockpit.rov; - this.priorSetPoints = {}; - this.sendToROVEnabled = true; - this.sendUpdateEnabled = true; - this.depthHold_state = {}; - this.headingHold_state = {}; - this.headingHold_desiredOn = false; - this.depthHold_desiredOn = false; - - //Defaults - this.settings = { - controlResetsSetPoint: false - }; +(function(window, document) +{ + 'use strict' + + //Necessary for debug utils + var log; + var trace; + var log_debug; + $.getScript('components/visionmedia-debug/dist/debug.js', function() { + log = debug('ROVPilotWire:log'); + trace = debug('ROVPilotWire:trace'); + log_debug = debug('ROVPilotWire:debug'); + }); + - this.actions = + + class ROVPilotWire + { + constructor(cockpit) { - 'rovPilot.toggleHeadingHold': + var self = this; + self.cockpit = cockpit; + self.rov = cockpit.rov; + + // Instance variables + self.priorSetPoints = {}; + self.sendToROVEnabled = true; + self.sendUpdateEnabled = true; + + self.depthHold_state = {}; + self.headingHold_state = {}; + + self.headingHold_desiredOn = false; + self.depthHold_desiredOn = false; + + //Defaults + this.settings = { + controlResetsSetPoint: false + }; + + this.actions = { - description: "Toggle Heading Hold", - controls: + 'rovPilot.toggleHeadingHold': { - button: + description: "Toggle Heading Hold", + controls: { - down: function() { - self.cockpit.emit('plugin.rovpilot.headingHold.set-enabled', !self.headingHold_state.enabled); - } + button: + { + down: function() { + self.cockpit.emit('plugin.rovpilot.headingHold.set-enabled', !self.headingHold_state.enabled); + } + } } - } - }, - 'rovPilot.toggleDepthHold': - { - description: "Toggle Depth Hold", - controls: + }, + 'rovPilot.toggleDepthHold': { - button: + description: "Toggle Depth Hold", + controls: { - down: function() { - self.cockpit.emit('plugin.rovpilot.depthHold.set-enabled', !self.depthHold_state.enabled); - } + button: + { + down: function() { + self.cockpit.emit('plugin.rovpilot.depthHold.set-enabled', !self.depthHold_state.enabled); + } + } } + } + }; + + this.inputDefaults = + { + keyboard: + { + "h": { type: "button", + action: 'rovPilot.toggleHeadingHold' }, + "g": { type: "button", + action: 'rovPilot.toggleDepthHold' } } - } + }; }; - - this.inputDefaults = + + altMenuDefaults() { - keyboard: + var self = this; + return [ + { + label: 'Toggle Depth hold', + callback: function () { + self.cockpit.emit('plugin.rovpilot.depthHold.set-enabled', !self.depthHold_state.enabled); + } + }, + { + label: 'Toggle Heading hold', + callback: function () { + self.cockpit.emit('plugin.rovpilot.headingHold.set-enabled', !self.headingHold_state.enabled); + } + } + ]; + }; + + listen() { - "h": { type: "button", - action: 'rovPilot.toggleHeadingHold' }, - "g": { type: "button", - action: 'rovPilot.toggleDepthHold' } - } + var self = this; + + this.cockpit.rov.withHistory.on('settings-change.pilotwire', function (settings) { + self.settings = settings.pilotwire; + }); + + this.rov.withHistory.on('plugin.rovpilot.depthHold.state', function (state) { + self.cockpit.emit('plugin.rovpilot.depthHold.state', state); + self.depthHold_state = state; + }); + + this.rov.withHistory.on('plugin.rovpilot.headingHold.state', function (state) { + self.cockpit.emit('plugin.rovpilot.headingHold.state', state); + self.headingHold_state = state; + }); + + this.cockpit.on('plugin.rovpilot.depthHold.set-enabled', function (value) { + self.depthHold_desiredOn = value; + self.rov.emit('plugin.rovpilot.depthHold.set', { enabled: value }); + }); + + this.cockpit.on('plugin.rovpilot.headingHold.set-enabled', function (value) { + self.headingHold_desiredOn = value; + self.rov.emit('plugin.rovpilot.headingHold.set', { enabled: value }); + }); + + //The code below will automatically disengadge the auto pilot in the axis that a flight control is + //is actively being changed in by the pilot, and then will re-engadge selecting the current position + //as the new set point when the control goes back to zero. + //TODO: This code requires message delivery and does not recover well if the enable hold message + // fails to get delivered. + var lastLiftCheck = false; + this.cockpit.on('plugin.rovpilot.setLift', function (targetRate) { + //short circuit if the condition is unchanged + if (lastLiftCheck == (targetRate == 0)) { + return; + } + lastLiftCheck = targetRate == 0; + if (self.depthHold_desiredOn && self.settings.controlResetsSetPoint) { + self.rov.emit('plugin.rovpilot.depthHold.set', { enabled: targetRate == 0 }); + } + }); + + var lastYawCheck = false; + this.cockpit.on('plugin.rovpilot.setYaw', function (targetRate) { + if (lastYawCheck == (targetRate == 0)) { + return; + } + lastYawCheck = targetRate == 0; + if (self.headingHold_desiredOn && self.settings.controlResetsSetPoint) { + self.rov.emit('plugin.rovpilot.headingHold.set', { enabled: targetRate == 0 }); + } + }); + }; + }; - }; - ROVpilotWire.prototype.altMenuDefaults = function altMenuDefaults() { - var self = this; - return [ - { - label: 'Toggle Depth hold', - callback: function () { - self.cockpit.emit('plugin.rovpilot.depthHold.set-enabled', !self.depthHold_state.enabled); - } - }, - { - label: 'Toggle Heading hold', - callback: function () { - self.cockpit.emit('plugin.rovpilot.headingHold.set-enabled', !self.headingHold_state.enabled); - } - } - ]; - }; - //This pattern will hook events in the cockpit and pull them all back - //so that the reference to this instance is available for further processing - ROVpilotWire.prototype.listen = function listen() { - var self = this; - this.cockpit.rov.withHistory.on('settings-change.pilotwire', function (settings) { - self.settings = settings.pilotwire; - }); - this.rov.withHistory.on('plugin.rovpilot.depthHold.state', function (state) { - self.cockpit.emit('plugin.rovpilot.depthHold.state', state); - self.depthHold_state = state; - }); - this.rov.withHistory.on('plugin.rovpilot.headingHold.state', function (state) { - self.cockpit.emit('plugin.rovpilot.headingHold.state', state); - self.headingHold_state = state; - }); - this.cockpit.on('plugin.rovpilot.depthHold.set-enabled', function (value) { - self.depthHold_desiredOn = value; - self.rov.emit('plugin.rovpilot.depthHold.set', { enabled: value }); - }); - this.cockpit.on('plugin.rovpilot.headingHold.set-enabled', function (value) { - self.headingHold_desiredOn = value; - self.rov.emit('plugin.rovpilot.headingHold.set', { enabled: value }); - }); - //The code below will automatically disengadge the auto pilot in the axis that a flight control is - //is actively being changed in by the pilot, and then will re-engadge selecting the current position - //as the new set point when the control goes back to zero. - //TODO: This code requires message delivery and does not recover well if the enable hold message - // fails to get delivered. - var lastLiftCheck = false; - this.cockpit.on('plugin.rovpilot.setLift', function (targetRate) { - //short circuit if the condition is unchanged - if (lastLiftCheck == (targetRate == 0)) { - return; - } - lastLiftCheck = targetRate == 0; - if (self.depthHold_desiredOn && self.settings.controlResetsSetPoint) { - self.rov.emit('plugin.rovpilot.depthHold.set', { enabled: targetRate == 0 }); - } - }); - var lastYawCheck = false; - this.cockpit.on('plugin.rovpilot.setYaw', function (targetRate) { - if (lastYawCheck == (targetRate == 0)) { - return; - } - lastYawCheck = targetRate == 0; - if (self.headingHold_desiredOn && self.settings.controlResetsSetPoint) { - self.rov.emit('plugin.rovpilot.headingHold.set', { enabled: targetRate == 0 }); - } - }); - }; - window.Cockpit.plugins.push(ROVpilotWire); -}(window, jQuery)); \ No newline at end of file + // Add plugin to the window object and add it to the plugins list + var plugins = namespace('plugins'); + plugins.ROVPilotWire = ROVPilotWire; + window.Cockpit.plugins.push( plugins.ROVPilotWire ); + +}(window, document)); diff --git a/src/system-plugins/platform-manager/platforms/mock/boards/mock3000/bridge.js b/src/system-plugins/platform-manager/platforms/mock/boards/mock3000/bridge.js index 24cecc4c..5bd72c63 100644 --- a/src/system-plugins/platform-manager/platforms/mock/boards/mock3000/bridge.js +++ b/src/system-plugins/platform-manager/platforms/mock/boards/mock3000/bridge.js @@ -277,7 +277,7 @@ function Bridge() if (!bridge.depthHoldEnabled) { - targetDepth = currentDepth; + targetDepth = depthSensor.depth; bridge.depthHoldEnabled = true; } @@ -298,7 +298,7 @@ function Bridge() case 'holdHeading_on': { var targetHeading = 0; - targetHeading = headingOut; + targetHeading = imu.yaw; bridge.targetHoldEnabled = true; bridge.emitStatus('targetHeading:' + (bridge.targetHoldEnabled ? targetHeading.toString() : DISABLED)); debug('Heading hold enabled');