ayvajs
Version:
A lightweight, behavior-based JavaScript API for controlling Open Source Multi Axis Stroker Robots.
85 lines (76 loc) • 2.17 kB
JavaScript
class MoveBuilder {
/**
* Construct a new move builder for the specified instance of Ayva.
* @ignore
*/
constructor (ayva) {
this.
Object.values(ayva.axes).forEach((axis) => {
this[axis.name] = this.
if (axis.alias) {
this[axis.alias] = this.
}
});
}
execute () {
return this.
}
return (...args) => {
if (args.length === 3 && typeof args[0] === 'number' && typeof args[1] === 'number' && typeof args[2] === 'function') {
// <to, duration, value>
this.
axis,
to: args[0],
duration: args[1],
value: args[2],
});
} else if (args.length === 2 && typeof args[0] === 'number' && typeof args[1] === 'number') {
// <to, duration>
this.
axis,
to: args[0],
duration: args[1],
});
} else if (args.length === 2 && typeof args[0] === 'number' && typeof args[1] === 'function') {
// <to, value>
this.
axis,
to: args[0],
value: args[1],
});
} else if (args.length === 1 && typeof args[0] === 'number') {
// <to>
this.
axis,
to: args[0],
});
} else if (args.length === 2 && typeof args[0] === 'function' && typeof args[1] === 'number') {
// <value, duration>
this.
axis,
value: args[0],
duration: args[1],
});
} else if (args.length === 1 && typeof args[0] === 'function') {
// <value>
this.
axis,
value: args[0],
});
} else if (args.length === 1 && typeof args[0] === 'object') {
// <object>
this.
...args[0],
axis,
});
} else {
throw new Error(`Invalid arguments: ${args}`);
}
return this;
};
}
}
export default MoveBuilder;