/
index.html
135 lines (122 loc) · 6.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta content="
,-.
___,---.__ /'|`\ __,---,___
,-' \` `-.____,-' | `-.____,-' // `-.
,' | ~'\ /`~ | `.
/ ___// `. ,' , , \___ \
| ,-' `-.__ _ | , __,-' `-. |
| / /\_ ` . | , _/\ \ |
\ | \ \`-.___ \ | / ___,-'/ / | /
\ \ | `._ `\ | //' _,' | / /
`-.\ /' _ `---'' , . ``---' _ `\ /,-'
`` / \ ,='/ \`=. / \ ''
|__ /|\_,--.,-.--,--._/|\ __|
/ `./ \`\ | | | /,//' \,' \
/ / ||--+--|--+-/-| \ \
| | /'\_\_\ | /_/_/`\ | |
\ \__, \_ `~' _/ .__/ /
`-._,-' `-._______,-' `-._,-'
FILE: index.html
TITLE: Gcode_Corrector_for_Laserbot
AUTHOR: Taylor Lovell Shockey
AUTHOR WEBSITE: Strategic.International
AUTHOR EMAIL: Taylor.Shockey@Strategic.International
The Clear BSD License
Copyright (c) 2017, Taylor Lovell Shockey
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted (subject to the limitations in the disclaimer
below) provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
* Neither the name of the copyright holder nor the names of its contributors may be used
to endorse or promote products derived from this software without specific
prior written permission.
NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE GRANTED BY THIS
LICENSE. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
The Strategic_International_Logo is a trade mark of Taylor Lovell Shockey.">
</head>
<body>
<script src="./js/jquery-3.1.1.min.js"></script>
<script>
// DEFINE PERCENT CHANGE, IF ANY.
var percent_change = 1;
// var percent_change = 0.9904;
// var percent_change = 1.0096;
// var percent_change = 1.00969305331;
// var percent_change = 1.0090;
// var percent_change = 0.0096;
// var percent_change = 0.98;
// var percent_change = 0.99;
var gcode_array = [];
$.when(
jQuery.get('./gcode/grid_0005.gcode', function(data) {doc = data}, dataType="text") // Designate the gcode file to be corrected. Put it in the "gcode" folder.
).done(function () {
doc = doc.split("\n");
for (var i = doc.length - 1; i >= 0; i--) {
var replaced = doc[i].replace(/X([0-9\.]+) *Y([0-9\.]+)/g, function(match, p1, p2, offset, string) {
// console.log(match);
// console.log(p1 + " parseFloat=" + parseFloat(p1) + " parseFloat * percent_change=" + (parseFloat(p1) * percent_change));
// console.log((parseFloat(p1) * percent_change));
// $('body').append((parseFloat(p1) * percent_change) + "<br>");
// console.log(p2);
// console.log(string);
if (match != undefined) {
return "X" + (parseFloat(p1) * percent_change) + " Y" + (parseFloat(p2) * percent_change);
// return "X" + Math.round(parseFloat(p1) * percent_change) + " Y" + Math.round(parseFloat(p2) * percent_change);
}
else {
return string;
};
});
replaced = replaced.replace(/\(.*\)/g, "");
replaced = replaced.replace("G01 Z-0.000000 F100.0", "M4 P240\nG1 F400.0");
replaced = replaced.replace("G00 Z0.000000", "M4 P0\nG1 F400.0");
replaced = replaced.replace("G00 X0 Y0", "");
replaced = replaced.replace("M3", "");
replaced = replaced.replace("G21", "");
replaced = replaced.replace("%", "");
replaced = replaced.replace("G01", "G1");
replaced = replaced.replace("G00", "G0");
replaced = replaced.replace("M5", "");
replaced = replaced.replace("M2", "");
replaced = replaced.replace(/ Z.*/g, "");
gcode_array.push(replaced);
};
gcode_array.reverse();
gcode_array.push("M4 P0");
gcode_array.push("G0 X0 Y0");
doc = gcode_array.join("\n");
doc = doc.replace(/ \n/g, "");
doc = doc.replace(/(\n){2,}/g, "\n");
doc = doc.replace(/M4 P0\nG1 F400.0\nM4 P0\nG1 F400.0/g, "M4 P0");
doc = doc.replace(/G0/g, "G0 F2000.0\nG0")
doc = doc.replace(/^\s*\n/gm, "") // Removes blank lines from the beginning of file.
console.log(doc);
// DOWNLOAD EDITED GCODE FILE
var hiddenElement = document.createElement('a');
hiddenElement.href = 'data:attachment/text,' + encodeURI(doc);
hiddenElement.target = '_blank';
hiddenElement.download = 'edited_gcode.gcode';
hiddenElement.click();
});
</script>
</body>
</html>