updated sync function
This commit is contained in:
@@ -216,65 +216,39 @@ module.exports = {
|
|||||||
// Force sync all state values to motor config
|
// Force sync all state values to motor config
|
||||||
// This ensures the UI reflects the current state even if changes happened while component was unmounted
|
// This ensures the UI reflects the current state even if changes happened while component was unmounted
|
||||||
|
|
||||||
const motor_axes = ["X", "Y", "Z", "A", "B", "C"];
|
if(this.state == undefined) {
|
||||||
|
console.log("State is undefined");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Define mapping between state properties and motor config properties
|
if (this.state[this.index + 'an'] != this.motor['axis']) {
|
||||||
const stateToMotorMapping = [
|
const motor_axes = ["X", "Y", "Z", "A", "B", "C"];
|
||||||
{
|
this.motor['axis'] = motor_axes[this.state[this.index + 'an']];
|
||||||
stateKey: 'current_axis',
|
}
|
||||||
motorKey: 'axis',
|
if (this.state[this.index + 'vm'] != this.motor['max-velocity']) {
|
||||||
transform: (value) => motor_axes[value]
|
this.motor['max-velocity'] = this.state[this.index + 'vm'];
|
||||||
},
|
}
|
||||||
{
|
if (this.state[this.index + 'tm'] != this.motor['max-soft-limit']) {
|
||||||
stateKey: 'current_max_velocity',
|
this.motor['max-soft-limit'] = this.state[this.index + 'tm'];
|
||||||
motorKey: 'max-velocity'
|
}
|
||||||
},
|
if (this.state[this.index + 'tn'] != this.motor['min-soft-limit']) {
|
||||||
{
|
this.motor['min-soft-limit'] = this.state[this.index + 'tn'];
|
||||||
stateKey: 'current_max_soft_limit',
|
}
|
||||||
motorKey: 'max-soft-limit'
|
if (this.state[this.index + 'am'] != this.motor['max-accel']) {
|
||||||
},
|
this.motor['max-accel'] = this.state[this.index + 'am'];
|
||||||
{
|
}
|
||||||
stateKey: 'current_min_soft_limit',
|
if (this.state[this.index + 'jm'] != this.motor['max-jerk']) {
|
||||||
motorKey: 'min-soft-limit'
|
this.motor['max-jerk'] = this.state[this.index + 'jm'];
|
||||||
},
|
}
|
||||||
{
|
if (this.state[this.index + 'sa'] != this.motor['step-angle']) {
|
||||||
stateKey: 'current_max_accel',
|
this.motor['step-angle'] = this.state[this.index + 'sa'];
|
||||||
motorKey: 'max-accel'
|
}
|
||||||
},
|
if (this.state[this.index + 'tr'] != this.motor['travel-per-rev']) {
|
||||||
{
|
this.motor['travel-per-rev'] = this.state[this.index + 'tr'];
|
||||||
stateKey: 'current_max_jerk',
|
}
|
||||||
motorKey: 'max-jerk'
|
if (this.state[this.index + 'mi'] != this.motor['microsteps']) {
|
||||||
},
|
this.motor['microsteps'] = this.state[this.index + 'mi'];
|
||||||
{
|
}
|
||||||
stateKey: 'current_step_angle',
|
|
||||||
motorKey: 'step-angle'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
stateKey: 'current_travel_per_rev',
|
|
||||||
motorKey: 'travel-per-rev'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
stateKey: 'current_microsteps',
|
|
||||||
motorKey: 'microsteps'
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
// Sync all properties using the mapping
|
|
||||||
stateToMotorMapping.forEach(({ stateKey, motorKey, transform }) => {
|
|
||||||
const stateValue = this[stateKey];
|
|
||||||
|
|
||||||
if (stateValue === undefined) {
|
|
||||||
console.log(`State value for ${stateKey} is undefined`);
|
|
||||||
return; // Skip if state value is not defined
|
|
||||||
}
|
|
||||||
|
|
||||||
const transformedValue = transform ? transform(stateValue) : stateValue;
|
|
||||||
const currentMotorValue = this.motor[motorKey];
|
|
||||||
|
|
||||||
if (transformedValue !== currentMotorValue) {
|
|
||||||
this.motor[motorKey] = transformedValue;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user