Skip to content

Commit

Permalink
big changes for async API; still resend problems; better gcode parsin…
Browse files Browse the repository at this point in the history
…g and serial handling on back end
  • Loading branch information
Evan Raskob committed Sep 14, 2019
1 parent ee907b0 commit dddbda3
Show file tree
Hide file tree
Showing 6 changed files with 2,056 additions and 1,827 deletions.
60 changes: 49 additions & 11 deletions liveprinter/static/examples/hilbert.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,62 @@
// hilbert curve
// https://github.com/nylki/lindenmayer
// L-systems test
// Uses a modified verion of the Lindenmayer library for JavaScript that uses ES6 Generators
// https://github.com/pixelpusher/lindenmayer


await lp.start(195);

attachScript("http://localhost:8888/static/lib/linden/linden.js");

// Now initialize the L-System to generate the tree
var tree = new LSystem({
await lp.moveto({ x: 40, y: 80, z: 80, speed: 80 });

await lp.retract();

await lp.ext({ e: 10, speed: 8 })

// Now initialize the L-System to generate the Hilbert curve
global hilbert = new LSystem({
axiom: 'L',
ignoredSymbols: "",
productions: {
'L': "+RF-LFL-FR+",
'R': "-LF+RFR+FL-",
},
finals: {
'F': () => { lp.dist(20).go(1); },
'+': () => { lp.turn(90); },
'-': () => { lp.turn(-90); }
'F': async () => { await lp.dist(4).go(1, false); },
'+': async () => { lp.turn(-90); return true; },
'-': async () => { lp.turn(90); return true; }
}
});

// Run the 5 iterations of the L-System
tree.iterate(4);
console.log(tree);
tree.final();
// Run the 1 iterations of the L-System
hilbert.iterate(1);

console.log(window.hilbert.getFuncs())
console.log(window.hilbert.axiom)

loginfo(hilbert.getString())
loginfo(totalsteps)


// draw each layer of the Hilbert curve (as a block, or manually)
{
lp.lh = 0.25; // make it thick
let layer = 1; // current index of layer we're printing
await lp.moveto({ x: 120, y: 100, z: 0.2 + 0.2 * layer, speed: 80 }); // set this to where you want to print and how high

lp.speed(10); // set speed conservatively
await lp.unretract(); // unretract material for printing
lp.turnto(0); // turn to initial angle (facing right)
//await hilbert.run();

for await (let f of hilbert.getFuncs()) {
const func = f[0];
const index = f[1];
const part = f[2];
await func({ index, part });
}

await lp.retract(); // unretract material for printing
await lp.up(90).go();
}

23 changes: 10 additions & 13 deletions liveprinter/static/lib/linden/linden.js
Original file line number Diff line number Diff line change
Expand Up @@ -478,19 +478,16 @@
}

// get iterable list of functions -- runs the function and returns index / total
*run(args) {
const funcsList = this.getFuncs(); // array
const totalFuncs = funcsList.length - 1;

yield* function* () {
for (let f of funcsList) {
const func = f[0];
const index = f[1];
const part = f[2];
func({ index, part }, args); // see above function:
yield { 'index': index, 'part': part, 'total': totalFuncs };
}
}();
async run(args) {
let funcsList = this.getFuncs(); // array

for await (let f of funcsList) {
const func = f[0];
const index = f[1];
const part = f[2];
await func({ index, part }, args); // see above function: ))
}
return true;
}


Expand Down
Loading

1 comment on commit dddbda3

@pixelpusher
Copy link
Owner

@pixelpusher pixelpusher commented on dddbda3 Sep 15, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an almost-finished re-implementation of async tornado for #29
It needs https://www.npmjs.com/package/bottleneck implemented in the front-end for queuing. Also, it fixes #45

Please sign in to comment.