From 753fe3b037663dc38f51986ee5985d46c4f70b8f Mon Sep 17 00:00:00 2001 From: Jean-Laurent Girod Date: Sat, 26 Aug 2023 01:03:25 +0200 Subject: [PATCH 1/2] Create propState.js Calculate propulsion.*.state based on propulsion.*.revolutions --- calcs/propState.js | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 calcs/propState.js diff --git a/calcs/propState.js b/calcs/propState.js new file mode 100644 index 0000000..7467f79 --- /dev/null +++ b/calcs/propState.js @@ -0,0 +1,37 @@ +const _ = require('lodash') + +module.exports = function (app, plugin) { + var engines = plugin.engines + + app.debug('engines: %j', engines) + + return engines.map(instance => { + return { + group: 'propulsion', + optionKey: instance + 'state', + title: `${instance} propulsion state (based on revolutions)`, + derivedFrom: function () { + return [ + 'propulsion.' + instance + '.revolutions' + ] + }, + calculator: function (revol) { + if (revol > 0) { + return [ + { + path: 'propulsion.' + instance + '.state', + value: "started" + } + ] + } else { + return [ + { + path: 'propulsion.' + instance + '.state', + value: "stopped" + } + ] + } + } + } + }) +} From a7ed1a359e25951c763dd41eb505ac8fb2262ef3 Mon Sep 17 00:00:00 2001 From: Jean-Laurent Girod Date: Wed, 15 May 2024 17:47:10 +0200 Subject: [PATCH 2/2] Update propState.js Update value only when state changes --- calcs/propState.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/calcs/propState.js b/calcs/propState.js index 7467f79..5077688 100644 --- a/calcs/propState.js +++ b/calcs/propState.js @@ -16,14 +16,17 @@ module.exports = function (app, plugin) { ] }, calculator: function (revol) { - if (revol > 0) { + const currentState = + app.getSelfPath('propulsion.' + instance + '.state.value') || 'none' + + if ((revol > 0) && (currentState !== "started")) { return [ { path: 'propulsion.' + instance + '.state', value: "started" } ] - } else { + } else if ((revol == 0) && (currentState !== "stopped")) { return [ { path: 'propulsion.' + instance + '.state',