gcanvas
gcanvas copied to clipboard
Option to specify the amount of decimal digits
Hi everyone.
I suggest the addition of an option to limit the maximum amount of decimal digits that are output, additionally with the option to choose between truncation and rounding.
If I understood correctly, as it stands, I have to parse the output of the GcodeDriver
to extract the values, treat them and reformat the output.
Thanks in advance.
EDIT: finally managed to do it with regex. Using the example from the readme.md
and considering no more than 3 decimal digits:
var Gcanvas = require('gcanvas');
var driver = new Gcanvas.GcodeDriver({
write: function(cmd) {
// matches a period plus 4 or mode digits; works globally
console.log(cmd.replace(/[.]\d{4,}/g, match => match.substring(0, 4)));
}
});
var ctx = new Gcanvas(driver);
Note that this will probably fail if gcanvas
outputs commands like G5.1
and you want to remove all decimal digits... Also, I completely disregarded commands that are not movement commands.
I don't have a CNC machine anymore. I added you as a collaborator if you want to work on the project.
Thanks, I'm honored but I don't have conditions right now to help, I'm sorry.