Added logging data on menu and distance

Added helper functionality to abort movements in state class and safeguards to NOT be able to abort in protected states.
some caps removal
This commit is contained in:
znetsixe
2025-10-02 17:29:31 +02:00
parent e72579e5d0
commit 44033da15d
4 changed files with 64 additions and 12 deletions

View File

@@ -180,33 +180,66 @@ getSaveInjectionCode(nodeName) {
return ` return `
// PhysicalPosition Save injection for ${nodeName} // PhysicalPosition Save injection for ${nodeName}
window.EVOLV.nodes.${nodeName}.positionMenu.saveEditor = function(node) { window.EVOLV.nodes.${nodeName}.positionMenu.saveEditor = function(node) {
console.log("=== PhysicalPosition Save Debug ===");
const sel = document.getElementById('node-input-positionVsParent'); const sel = document.getElementById('node-input-positionVsParent');
const hasDistanceCheck = document.getElementById('node-input-hasDistance'); const hasDistanceCheck = document.getElementById('node-input-hasDistance');
const distanceInput = document.getElementById('node-input-distance'); const distanceInput = document.getElementById('node-input-distance');
// Save existing position data console.log("→ sel element found:", !!sel);
node.positionVsParent = sel ? sel.value : 'atEquipment'; console.log("→ sel:", sel);
node.positionLabel = sel ? sel.options[sel.selectedIndex].textContent : 'At Equipment'; console.log("→ sel.value:", sel ? sel.value : "NO ELEMENT");
node.positionIcon = sel ? sel.options[sel.selectedIndex].getAttribute('data-icon') : 'fa fa-cog'; console.log("→ sel.selectedIndex:", sel ? sel.selectedIndex : "NO ELEMENT");
console.log("→ sel.options:", sel ? Array.from(sel.options).map(o => ({value: o.value, text: o.textContent})) : "NO OPTIONS");
if (!sel) {
console.error("→ positionMenu.saveEditor FAILED: select element not found!");
return false;
}
// Save existing position data
const positionValue = sel.value;
const selectedOption = sel.options[sel.selectedIndex];
console.log("→ positionValue:", positionValue);
console.log("→ selectedOption:", selectedOption);
console.log("→ selectedOption.textContent:", selectedOption ? selectedOption.textContent : "NO OPTION");
console.log("→ selectedOption data-icon:", selectedOption ? selectedOption.getAttribute('data-icon') : "NO ICON");
node.positionVsParent = positionValue || 'atEquipment';
node.positionLabel = selectedOption ? selectedOption.textContent : 'At Equipment';
node.positionIcon = selectedOption ? selectedOption.getAttribute('data-icon') : 'fa fa-cog';
console.log("→ node.positionVsParent set to:", node.positionVsParent);
console.log("→ node.positionLabel set to:", node.positionLabel);
// Save distance data
console.log("→ hasDistanceCheck found:", !!hasDistanceCheck);
console.log("→ hasDistanceCheck.checked:", hasDistanceCheck ? hasDistanceCheck.checked : "NO ELEMENT");
// Save distance data (NEW)
node.hasDistance = hasDistanceCheck ? hasDistanceCheck.checked : false; node.hasDistance = hasDistanceCheck ? hasDistanceCheck.checked : false;
if (node.hasDistance && distanceInput && distanceInput.value) { if (node.hasDistance && distanceInput && distanceInput.value) {
console.log("→ distanceInput.value:", distanceInput.value);
node.distance = parseFloat(distanceInput.value) || 0; node.distance = parseFloat(distanceInput.value) || 0;
node.distanceUnit = 'm'; // Fixed to meters for now node.distanceUnit = 'm'; // Fixed to meters for now
// Generate distance description based on position // Generate distance description based on position
const contexts = window.EVOLV.nodes.${nodeName}.menuData.position.distanceContexts; const contexts = window.EVOLV.nodes.${nodeName}.menuData.position.distanceContexts;
const context = contexts && contexts[node.positionVsParent]; const context = contexts && contexts[node.positionVsParent];
node.distanceDescription = context ? context.description : 'Distance from parent'; node.distanceDescription = context ? context.description : 'Distance from parent';
console.log("→ distance set to:", node.distance);
} else { } else {
// Clear distance data if not specified console.log("→ clearing distance data");
delete node.distance; delete node.distance;
delete node.distanceUnit; delete node.distanceUnit;
delete node.distanceDescription; delete node.distanceDescription;
} }
console.log("→ positionMenu.saveEditor result: SUCCESS");
console.log("→ final node.positionVsParent:", node.positionVsParent);
return true; return true;
}; };
`; `;

View File

@@ -1,7 +1,7 @@
{ {
"general": { "general": {
"name": { "name": {
"default": "Interpolation Configuration", "default": "interpolation configuration",
"rules": { "rules": {
"type": "string", "type": "string",
"description": "A human-readable name or label for this interpolation configuration." "description": "A human-readable name or label for this interpolation configuration."
@@ -70,7 +70,7 @@
} }
}, },
"role": { "role": {
"default": "Interpolator", "default": "interpolator",
"rules": { "rules": {
"type": "string", "type": "string",
"description": "Indicates the role of this configuration (e.g., 'Interpolator', 'DataCurve', etc.)." "description": "Indicates the role of this configuration (e.g., 'Interpolator', 'DataCurve', etc.)."

View File

@@ -52,6 +52,7 @@ class state{
return this.stateManager.getRunTimeHours(); return this.stateManager.getRunTimeHours();
} }
async moveTo(targetPosition) { async moveTo(targetPosition) {
// Check for invalid conditions and throw errors // Check for invalid conditions and throw errors
@@ -86,14 +87,33 @@ class state{
// -------- State Transition Methods -------- // // -------- State Transition Methods -------- //
abortCurrentMovement(reason = "group override") {
if (this.abortController && !this.abortController.signal.aborted) {
this.logger.warn(`Aborting movement: ${reason}`);
this.abortController.abort();
}
}
async transitionToState(targetState, signal) { async transitionToState(targetState, signal) {
const fromState = this.getCurrentState(); const fromState = this.getCurrentState();
const position = this.getCurrentPosition(); const position = this.getCurrentPosition();
// Define states that cannot be aborted for safety reasons
const protectedStates = ['warmingup', 'coolingdown'];
const isProtectedTransition = protectedStates.includes(fromState);
try { try {
this.logger.debug(`Starting transition from ${fromState} to ${targetState}.`); this.logger.debug(`Starting transition from ${fromState} to ${targetState}.`);
if( isProtectedTransition){
//overrule signal to prevent abortion
signal = null; // Disable abortion for protected states
//spit warning
this.logger.warn(`Transition from ${fromState} to ${targetState} is protected and cannot be aborted.`);
}
// Await the state transition and pass signal for abortion
const feedback = await this.stateManager.transitionTo(targetState,signal); const feedback = await this.stateManager.transitionTo(targetState,signal);
this.logger.info(`Statemanager: ${feedback}`); this.logger.info(`Statemanager: ${feedback}`);
@@ -108,7 +128,6 @@ class state{
//trigger move //trigger move
await this.moveTo(this.delayedMove,signal); await this.moveTo(this.delayedMove,signal);
this.delayedMove = null; this.delayedMove = null;
this.logger.info(`moveTo : ${feedback} `); this.logger.info(`moveTo : ${feedback} `);
} }

View File

@@ -1,7 +1,7 @@
{ {
"general": { "general": {
"name": { "name": {
"default": "State Configuration", "default": "state configuration",
"rules": { "rules": {
"type": "string", "type": "string",
"description": "A human-readable name for the state configuration." "description": "A human-readable name for the state configuration."
@@ -65,7 +65,7 @@
} }
}, },
"role": { "role": {
"default": "StateController", "default": "statecontroller",
"rules": { "rules": {
"type": "string", "type": "string",
"description": "Functional role within the system." "description": "Functional role within the system."