Coder Social home page Coder Social logo

doodle3d-api's People

Contributors

casperlamboo avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

doodle3d-api's Issues

Sending large gcode files to DoodleBox

When sending large gcode files we have to take into account a couple of things

  1. Overflowing the doodle box with too many requests (see #10)
  2. Not exceeding the 4mb size limit of the doodle box

In order to keep under the 4mb size limit there are 2 options; reject files that exceed the size limit. Send part of the file up to 4mb and wait until buffer is cleared before sending te rest. The downside of this is that the browser must stay active during the print.

Add throttle mechanism?

To prevent crashing of the small webserver on the WiFi-Box it might be interesting to look into a throttle mechanism for all rest calls. This could queue requests that come in to quickly after a prev request.
Finding a way to give priority to some calls would also be important, to prioritize print calls for example.

Include the parameters as arguments

Currently a user has to specify the parameters in a data object, but this partly defeats the purpose of this library, in that it's easier to see what can be done with the API.
Especially with ES6's default arguments this could work really nice.

Simplification with ES6 and readablility improvements

            for (var i = 0; i < boxes.length; i ++) {
                var boxData = boxes[i];

                if (knownIPs.indexOf(boxData.localip) === -1) {
                    this.addBox(boxData);
                }
            }

With for ... of, using block scoped let and adding a variable.

for(let boxData of boxes) {
  // giving this a name makes it clearer what you're doing, without requiring comments. 
  let known = knownIPs.indexOf(boxData.localip) ===  -1; 
  if(known) this.addBox(boxData);
}

With the ES6 Array.include() method:

for(let boxData of boxes) {
  if(knownIPs.includes(boxData.localip)){
    this.addBox(boxData);
  }
}

Add basic package info

Add basic package info to package.json, this could be done with npm init.

Let's use mayor version 0, until the public api settles down. (NPM init defaults to 1.0.0) More info:

Major version zero (0.y.z) is for initial development. Anything may change at any time. The public API should not be considered stable.

From: http://semver.org/

Handle connection issues while sending prints

In the client that's used on the WiFi-Box we have a lot of checks to handle connection issues, this library should also perform these.
Relevant code: From: https://github.com/Doodle3D/doodle3d-client/blob/master/js/Printer.js

The logic in pseudo code:

Start checking printer status

Send print print
  if print to large:
    overrule state to idle
    start checking status
  enable warning about leaving when still sending.
  send first part (supply seq_number & seq_total)
    when receiving response
      if response.status success:
        if print sending completed
          remove leave warning
        else 
          if state is printing / buffering:
            send next part
          else if state is disconnected:
            retry sending same part after a delay
      else if response.status fail:
        if reason buffer full:
          wait for buffer space...
        else if reason seq_num_mismatch and sequence number is current sequence number:
          // we probably missed a response and the box is one chunk ahead
          send next part
        else:
          if status isn't stopping:
            display error
      start checking status
    when sending times out:
      retry sending same part after a delay

Wait for buffer space
  if WiFi-Box's buffer is above a certain ratio:
    call this function after a delay
  else
    if state is printing / buffering
      send same part

On stop
  clear all delays / timeouts
  remove leave warning
  on response
    start checking status
  on timeout
    retry stop after delay
    start checking status

Check printer status (/info/status)
  on response:
    if response.status succes
      state = data.state
    else
      status = unknown
    try checking status again after delay
  on timeout
    status = disconnected
    try checking status again after longer delay

When state is overridden
  store state
  stop checking status

Restructure?

If we include the connect API (#8) it might make sense to restructure the library slightly.

var d3d = new Doodle3DAPI();
d3d.refresh(); // or d3d.autoRefresh()
d3d.on("boxAppeared",(box) => {
  // includes box.id retrieved from connect.doodle3d.com
  console.log(`New Doodle3D WiFi-Box found: '${box.id}' with ip: '${box.ip} '`);
  box.printer.print("G1 X1 X2");
  box.info.autoRefresh();
  box.info.on("status",(status) => {
    console.log(`${box.id} status: `,status);
  });
})

Or skipping our connect api:

var d3d = new Doodle3DAPI();
var box = d3d.getBox("192.168.5.1"); // box.id not (yet) available. Maybe we can do a separate request to the box to fill this in? 
box.info.autoRefresh();
box.info.on("status",(status) => {
  var id = box.id? box.id : box.ip;
  console.log(`${id} status: `, status);
});

More inspiration:

Use ES6's array functions

            var knownIPs = [];
            for (var i = 0; i < this.boxes.length; i ++) {
                var boxData = this.boxes[i].boxData;
                knownIPs.push(boxData.localip);
            }

Can be also be done like:

var boxes = [
  { localIP:'10.0.0.1' },
  { localIP:'10.0.0.2' },
  { localIP:'10.0.0.3' }
  ];
var knownIPs = boxes.map((boxData) => boxData.localIP);
console.log(knownIPs)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.