diff --git a/LICENSE.md b/LICENSE.md new file mode 100644 index 0000000..5bdee43 --- /dev/null +++ b/LICENSE.md @@ -0,0 +1,8 @@ +The MIT License (MIT) +Copyright (c) 2016 James Muraca + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/cutter.py b/cutter.py index 6e0e2d0..c2cdb6c 100644 --- a/cutter.py +++ b/cutter.py @@ -1,4 +1,4 @@ -import sys +import sys, platform import serial from SVG2PLT import SVG2PLT from PLT import PLT @@ -62,7 +62,8 @@ class Cutter: # CONSTRUCTOR def __init__(self): - self.serial = serial.Serial ("/dev/ttyAMA0", self.BAUDRATE, timeout=1) # open the serial "/dev/ttyAMA0" + if(platform.system() == 'Linux'): + self.serial = serial.Serial ("/dev/ttyAMA0", self.BAUDRATE, timeout=1) # open the serial "/dev/ttyAMA0" self.svg2plt = SVG2PLT() self.plt = PLT() @@ -70,7 +71,8 @@ def __init__(self): self.home() def __del__(self): - self.serial.close() + if(platform.system() == 'Linux'): + self.serial.close() # home the cutter location def home(self): @@ -84,13 +86,16 @@ def change_setting(self, setting, value): print(setting+":"+value) # load a file - def load_file(self, filename): + def load_file(self, filename='./static/svg/pattern.svg'): self.svg2plt.load_file(filename) self.svg2plt.parse() self.plt = self.svg2plt.plt # TODO: i'm not completely happy with this idea self.plt.reset_settings() + output = {"width":self.svg2plt.display_width,"height":self.svg2plt.display_height,"units":self.svg2plt.display_units} + return(json.dumps(output)) + # send the PLT to the cutter def cut(self): self.plt.scale = self.scale @@ -135,7 +140,10 @@ def move(self, x, y): # send a string to the serial port and read the response def send(self, command): - response = self.serial.write(command.encode('utf-8')) + if(platform.system() == 'Linux'): + response = self.serial.write(command.encode('utf-8')) + else: + response = 1 return(response) diff --git a/server.py b/server.py index c268c8a..2afebd5 100644 --- a/server.py +++ b/server.py @@ -1,13 +1,13 @@ import os from flask import Flask, request, render_template from werkzeug import secure_filename -from cutter import Cutter +from Cutter import Cutter UPLOAD_FOLDER = './static/svg/' ALLOWED_EXTENSIONS = set(['svg']) knk = Cutter() -knk.load_file(UPLOAD_FOLDER+'pattern.svg') +knk.load_file() app = Flask(__name__, static_url_path='') app.config['UPLOAD_FOLDER'] = UPLOAD_FOLDER diff --git a/static/js/cutter.js b/static/js/cutter.js index 5a817f8..9f90bd1 100644 --- a/static/js/cutter.js +++ b/static/js/cutter.js @@ -1,5 +1,48 @@ window.onload = function() { + $('#button_cut').click(function() { + $('.ui.modal') + .modal({ + onApprove : function() { + $.post( "/cut" ); + return false; + } + }) + .modal('show'); + }); + + $(document).keydown(function(e) + { + if($('.ui.modal').hasClass('active')) + { + switch(e.which) { + case 32: // cut + $.post( "/cut" ); + break; + + case 37: // left + $.post( "/move", { direction: "W" } ); + break; + + case 38: // up + $.post( "/move", { direction: "N" } ); + break; + + case 39: // right + $.post( "/move", { direction: "E" } ); + break; + + case 40: // down + $.post( "/move", { direction: "S" } ); + break; + + default: return; // exit this handler for other keys + } + e.preventDefault(); // prevent the default action (scroll / move caret) + } + + }); + var file_input = document.getElementById('file_input'); file_input.addEventListener('change', function(e) { @@ -48,28 +91,37 @@ window.onload = function() return false; // prevent default }); + $('input[type=range]').bind("propertychange change", function(event) + { + var name = $(this).attr("name"); + var input = $('input[name='+name+']'); + input.val(this.value); + }) $('.setting').bind("propertychange change input", function(event) { var name = $(this).attr("name") var value = $(this).val() - var slider = $('input[type=range][name='+name+']'); - slider.val(this.value); - - $.ajax({ - type: "POST", - url: "/setting", - data: { setting:name, value:value }, - success: function(msg) - { - console.log("ok"); - } - }); + if($.isNumeric(value)) + { + var slider = $('input[type=range][name='+name+']'); + slider.val(this.value); + + $.ajax({ + type: "POST", + url: "/setting", + data: { setting:name, value:value }, + success: function(msg) + { + console.log("ok"); + } + }); + } return false; // prevent default }); - + $('.ui.accordion').accordion(); scale_svg(); } diff --git a/templates/index.html b/templates/index.html index 5ca59be..8cb75dc 100644 --- a/templates/index.html +++ b/templates/index.html @@ -223,67 +223,10 @@ - + - - - - {% include 'footer.html' %} \ No newline at end of file