updated new method

This commit is contained in:
znetsixe
2025-06-12 17:05:28 +02:00
parent a97326af08
commit c4f16fb36d
4 changed files with 29 additions and 14 deletions

View File

@@ -39,19 +39,18 @@
*/ */
const EventEmitter = require('events'); const EventEmitter = require('events');
const Logger = require('../../../generalFunctions/helper/logger'); const {logger,configUtils} = require('generalFunctions');
const defaultConfig = require('./measurementConfig.json'); const defaultConfig = require('./measurementConfig.json');
const ConfigUtils = require('../../../generalFunctions/helper/configUtils');
class Measurement { class Measurement {
constructor(config={}) { constructor(config={}) {
this.emitter = new EventEmitter(); // Own EventEmitter this.emitter = new EventEmitter(); // Own EventEmitter
this.configUtils = new ConfigUtils(defaultConfig); this.configUtils = new configUtils(defaultConfig);
this.config = this.configUtils.initConfig(config); this.config = this.configUtils.initConfig(config);
// Init after config is set // Init after config is set
this.logger = new Logger(this.config.general.logging.enabled,this.config.general.logging.logLevel, this.config.general.name); this.logger = new logger(this.config.general.logging.enabled,this.config.general.logging.logLevel, this.config.general.name);
// Smoothing // Smoothing
this.storedValues = []; this.storedValues = [];

BIN
measurement-1.0.0.tgz Normal file

Binary file not shown.

View File

@@ -1,6 +1,6 @@
<script type="module">
import * as menuUtils from "/generalFunctions/helper/menuUtils.js";
<script src="measurement/resources/menuUtils.js"></script>
<script>
RED.nodes.registerType("measurement", { RED.nodes.registerType("measurement", {
category: "digital twin", category: "digital twin",
@@ -48,6 +48,12 @@
const node = this; const node = this;
// Use the namespaced version instead of global
const menuUtils = window.EVOLV.nodes.measurement.utils.menuUtils;
const helpers = window.EVOLV.nodes.measurement.utils.helpers;
//this needs to live somewhere and for now we add it to every node file for simplicity
const projecSettingstURL = "http://localhost:1880/generalFunctions/settings/projectSettings.json";
// Define UI html elements // Define UI html elements
const elements = { const elements = {
// Basic fields // Basic fields
@@ -72,8 +78,7 @@
unit: document.getElementById("node-input-unit"), unit: document.getElementById("node-input-unit"),
}; };
//this needs to live somewhere and for now we add it to every node file for simplicity
const projecSettingstURL = "http://localhost:1880/generalFunctions/settings/projectSettings.json";
try{ try{

View File

@@ -1,3 +1,12 @@
console.log('Loading measurement.js module...');
// load helper modules from the generalFunctions folder
const { outputUtils } = require('generalFunctions');
//internal node-red node dependencies this is the class that will handle the measurement
const Measurement = require("./dependencies/measurement/measurement");
const { menuUtils } = require('generalFunctions');
console.log('All dependencies loaded successfully');
console.log(menuUtils);
module.exports = function (RED) { module.exports = function (RED) {
function measurement(config) { function measurement(config) {
//create node //create node
@@ -6,11 +15,6 @@ module.exports = function (RED) {
var node = this; var node = this;
try{ try{
//fetch measurement object from source.js
const Measurement = require("./dependencies/measurement/measurement");
const OutputUtils = require("../generalFunctions/helper/outputUtils");
//load user defined config in the node-red UI //load user defined config in the node-red UI
const mConfig={ const mConfig={
general: { general: {
@@ -52,7 +56,7 @@ module.exports = function (RED) {
node.source = m; node.source = m;
//load output utils //load output utils
const output = new OutputUtils(); const output = new outputUtils();
function updateNodeStatus(val) { function updateNodeStatus(val) {
//display status //display status
@@ -144,5 +148,12 @@ module.exports = function (RED) {
console.log(e); console.log(e);
} }
} }
RED.nodes.registerType("measurement", measurement); RED.nodes.registerType("measurement", measurement);
// Create a new instance of MenuUtils for use in the html browser
let menuUtil = new menuUtils();
// Create the endpoint with one line!
menuUtil.createMenuUtilsEndpoint(RED, 'measurement', menuUtils);
}; };