nneves / 3DPrinterInterface

3D Printer Interface
15 stars 3 forks source link

Add a REST endpoint to list ./bin/gcode/*.gcode and ./bin/stl/*.stl files #8

Closed nneves closed 11 years ago

nneves commented 11 years ago

Need to list the cache GCODE and STL files. This will be required by the UI/front-end webapp to be able to select a specific file to be converter / printed.

nneves commented 11 years ago

GCODE file list

http://127.0.0.1:8080/api/getfilelistgcode/

request response: {"response":true}

Data fetch process will be asynchronous and will trigger a UI callback with data:

{"filelistgcode":[{"filename":"3D_Knot.gcode","extension":"gcode","filesize":1670110},{"filename":"calibrate.gcode","extension":"gcode","filesize":369},{"filename":"demo.gcode","extension":"gcode","filesize":1758},{"filename":"test.gcode","extension":"gcode","filesize":2642}]}

STL file list

http://127.0.0.1:8080/api/getfileliststl/

request response: {"response":true}

Data fetch process will be asynchronous and will trigger a UI callback with data:

{"fileliststl":[{"filename":"SteeringArm_l.stl","extension":"stl","filesize":172626}]}

More technical explanation on the requests workflow

After the async rest request gets called from [rest.js] it will then run [mainapp.js] mainapp.getFileList("GCODE"); that will do an async system file list. When file list is completed, [mainapp.js] will then emit events on the printer output stream channel (printercore.oStreamPrinter) and will then follow the normal workflow (mainapp.printercore.oStreamPrinter -> rest.jsonStream -> Socket.IO channel -> Client).

From client side, printer.js as now a possibility to map callbacks to Socket.IO events:

    // index.html
    var cbPrinterMessages = function (data) {
      var datastring = JSON.stringify(data);
      alert(datastring);
    } 

    var printer = PRINTER.WebInterface();
    printer.cblist.response = cbPrinterMessages;
    printer.cblist.printer = cbPrinterMessages;
    printer.cblist.error = cbPrinterMessages;
    printer.cblist.filelistgcode = cbPrinterMessages;
    printer.cblist.fileliststl = cbPrinterMessages;

Note: Each event can have its own callback.