js::Value GCodeLibrary::speedCB(const js::Arguments &args) { // Return spindle info if no arguments were given if (!args.getCount()) { js::Value array = js::Value::createArray(3); spin_mode_t mode; double max; array.set(0, ctx.machine.getSpeed(&mode, &max)); array.set(1, mode); array.set(2, max); return array; } // Otherwise set spindle spin_mode_t mode = REVOLUTIONS_PER_MINUTE; double max = 0; if (args.has("surface")) { mode = CONSTANT_SURFACE_SPEED; if (args.has("max")) max = args["max"].toNumber(); } ctx.machine.setSpeed(args["rate"].toNumber(), mode, max); return ctx.machine.getSpeed(); }
js::Value GCodeLibrary::feedCB(const js::Arguments &args) { // Return feed info if no arguments were given if (!args.getCount()) { js::Value array = js::Value::createArray(2); feed_mode_t mode; array.set(0, ctx.machine.getFeed(&mode)); array.set(1, mode); return array; } // Otherwise set feed feed_mode_t mode = MM_PER_MINUTE; if (args.has("mode")) { mode = (feed_mode_t)args["mode"].toUint32(); switch (mode) { case INVERSE_TIME: case MM_PER_MINUTE: case MM_PER_REVOLUTION: break; default: THROW("Feed mode must be FEED_INVERSE_TIME, FEED_UNITS_PER_MIN or " "FEED_UNITS_PER_REV"); } } ctx.machine.setFeed(args["rate"].toNumber(), mode); return ctx.machine.getFeed(); }
js::Value GCodeLibrary::toolCB(const js::Arguments &args) { // Return tool number if no arguments were given if (!args.getCount()) return ctx.machine.getTool(); uint32_t number = args["number"].toUint32(); ctx.tools->get(number); // Make sure it exists ctx.machine.setTool(number); return ctx.machine.getTool(); }