Skip to content

Commit

Permalink
added a license fil e(MIT)
Browse files Browse the repository at this point in the history
move js to one file
missed json return from file upload, added this back
added serial init only for linux for easier windows coding
  • Loading branch information
jmuraca committed Feb 2, 2016
1 parent b3e8db9 commit ed8bde4
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 78 deletions.
8 changes: 8 additions & 0 deletions 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.
18 changes: 13 additions & 5 deletions cutter.py
@@ -1,4 +1,4 @@
import sys
import sys, platform
import serial
from SVG2PLT import SVG2PLT
from PLT import PLT
Expand Down Expand Up @@ -62,15 +62,17 @@ 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()

self.home()

def __del__(self):
self.serial.close()
if(platform.system() == 'Linux'):
self.serial.close()

# home the cutter location
def home(self):
Expand All @@ -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
Expand Down Expand Up @@ -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)


Expand Down
4 changes: 2 additions & 2 deletions 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
Expand Down
78 changes: 65 additions & 13 deletions 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)
{
Expand Down Expand Up @@ -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();
}

Expand Down
59 changes: 1 addition & 58 deletions templates/index.html
Expand Up @@ -223,67 +223,10 @@
</div>


</div>
</div>




<script type="text/javascript" language="javascript">
$('#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)
}

});

$('input[type=range]').change( function()
{
var name = $(this).attr("name");
var input = $('input[name='+name+']');
input.val(this.value);
})

$('.ui.accordion').accordion();

</script>


{% include 'footer.html' %}
</body>
</html>

0 comments on commit ed8bde4

Please sign in to comment.