├── 90-micro-3d-local.rules
├── Changelog
├── LICENSE
├── Makefile
├── README.md
├── gcode.cpp
├── gcode.h
├── main.cpp
├── printer.cpp
├── printer.h
├── vector.cpp
└── vector.h
/90-micro-3d-local.rules:
--------------------------------------------------------------------------------
1 | # Micro 3D Printer rules file
2 | # Run the following to install this rule
3 | # cp ./90-micro-3d-local.rules /etc/udev/rules.d/
4 | # sudo /etc/init.d/udev restart
5 |
6 | ACTION=="add", SUBSYSTEMS=="usb", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2404", GROUP="users", MODE="0666", SYMLINK="micro_3d", ENV{ID_MM_DEVICE_IGNORE}="1"
7 |
--------------------------------------------------------------------------------
/Changelog:
--------------------------------------------------------------------------------
1 | Changelog:
2 |
3 | V0.16 October 8, 2015
4 |
5 | * Added center model pre-processor
6 | * Updated all pre-processors to match those in the official software
7 | * Added ability to flash unencrypted firmware ROMs
8 |
9 | V0.15 July 21, 2015
10 |
11 | * Changed translator mode to require the third part software to handle confirmation, skips, and resends
12 |
13 | V0.14 July 20, 2015
14 |
15 | * Printer values that are used by the pre-processor stages can be provided as parameters
16 | * Automatically creates /usr/share/m33-linux after collecting printer information if it doesn't exist
17 |
18 | V0.13 July 15, 2015
19 |
20 | * Saves printer settings to /usr/share/m33-linux/settings whenever printer is connected. This allows the settings to be used for the pre-processor without the printer having to be connected
21 |
22 | V0.12 July 14, 2015
23 |
24 | * Added firmware version requirement
25 | * Virtual serial port manages all the resends and confirmations itself, so all of the issues with line numbers are fixed
26 | * Added a way to force the firmware ROM to flash instead of only flashing when corrupt or outdated
27 |
28 | V0.11 July 10, 2015
29 |
30 | * Improved G-code parser so that it works with commands that don't have whitespace, like how Cura sends N0M110
31 | * Only forces elevated priveledges when using translate mode
32 |
33 | V0.10 July 9, 2015
34 |
35 | * Added ability to process an input file with the desired pre-processor stages then outputting it to a file
36 |
37 | V0.9 July 9, 2015
38 |
39 | * Creates a symbolic link for the virtual serial port now to allow other software to more easily recognize that it is a serial port
40 |
41 | V0.8 July 9, 2015
42 |
43 | * Add initial code for setting backlash speed. Wont be used until I figure out which address in EEPROM stores the value.
44 | * Added a translator mode where the software acts as a middle man between other software and the printer. So now other software can send it standard G-code, which allows it to work with Octoprint.
45 |
46 | V0.7 July 8, 2015
47 |
48 | * Fixed jerky movements by using the printers line number communication system for buffering
49 | * Fixed percent (Thanks jsc69)
50 | * If the system variables are set, the temporary files are created in TEMP, TMP, or TMPDIR (Thanks TonyH)
51 | * Fixed bug in Z calibration that would hang forever
52 |
53 | V0.6 July 7, 2015
54 |
55 | * Moved all the pre-processor code to the printer library
56 | * Added a CLI
57 | * Added a validation pre-processor stage that removed M82, M82, and T commands (Thanks MrBeta)
58 |
59 | V0.5 July 7, 2015
60 |
61 | * Finished all the G-code pre-processor stages. So now it has preparation, wave bonding, thermal bonding, bed compensation, backlash, and feed rate stages that can be preformed on a provided G-code file. Right not it just defaults to applying all of them except the wave bonding stage, but I'll make a CLI soon to allow better configurations at run time.
62 | * It obtains more information about the print before preforming the pre-processor stages now. So it determines the maximums and minimums of the model dimensions and extruder movements. The extruder movements are used to check if the model will go out of bounds.
63 |
64 | V0.4 July 5, 2015
65 |
66 | * Changed how firmware files work. So no they need to be named with their version number, Ex: 2015062401.rom, and they don't need to be modified at all so ignore the whole formatting for the header introduced in V0.3. Right now it looks for a file named 2015062401.rom, but it'll later be changed so you can provide a file name as a parameter.
67 | * Implemented decrypting and encrypting firmware rom, it it'll decrypt the provided rom and generate a CRC32 from that which is used to verify that updating was successful
68 | * Got preparation, thermal bonding, and feed rate conversion G-code pre-processors all done
69 | * Added boundary checking for when the model is analyzed to prevent printing outside of what the printer is capable of
70 |
71 | V0.3 July 3, 2015
72 |
73 | * Moved printer to its own class
74 | * Added firmware verification
75 | * Added fan type and extruder current EEPROM updating
76 | * Added firmware updating. Firmware files need to be in the following format:
77 | Bytes 1 - 3: M3D
78 | Byte 4: 0x1A
79 | Bytes 5 - 8: Firmware version in big endian. Ex: 2015062401 would be 0x78 0x1B 0x69 0x81
80 | Bytes 9 - 12: Firmware CRC in big endian. Ex: 459338129 would be 0x1B 0x60 0xF1 0x91
81 | Bytes 13 - EOF: The firmware data
82 | * Currently the rom has to be named test.rom and be in the same directory as the program for it to be used
83 |
84 | V0.2 July 1, 2015
85 |
86 | * Implemented udev rule to map printer to /dev/micro_3d, to change permission of printer to not require root, and avoid problems with Modem Manager
87 | * Simplified connecting to the printer
88 | * Moved G-code parser to its own class
89 | * Started implementing G-code pre-processor
90 |
91 | V0.1 June 26, 2015
92 |
93 | * Initial release
94 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 | {one line to give the program's name and a brief idea of what it does.}
635 | Copyright (C) {year} {name of author}
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | {project} Copyright (C) {year} {fullname}
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
676 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | PROG = m33-linux
2 | CC = g++
3 | SRCS = main.cpp gcode.cpp printer.cpp vector.cpp
4 | CFLAGS = -Wall -std=c++14 -O3
5 |
6 | all: $(PROG)
7 |
8 | $(PROG): $(SRCS)
9 | $(CC) $(CFLAGS) -o $(PROG) $(SRCS) $(LIBS)
10 |
11 | clean:
12 | rm -f $(PROG)
13 |
14 | run:
15 | ./$(PROG)
16 |
17 | install:
18 | install $(PROG) /usr/sbin/$(PROG)
19 |
20 | package:
21 | cp $(PROG) $(PROG)-0.16
22 | cd $(PROG)-0.16 && fakeroot dpkg-buildpackage -b
23 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # M33 Linux
2 | © 2015 Exploit Kings. All rights reserved.
3 |
4 | A Linux program that can communicate with the Micro 3D printer
5 |
6 |
7 | M33 Linux was succeeded by M33 Fio on October 15, 2015.
8 |
9 |
10 | The parameters that can be provided when running this program are as follows:
11 |
12 | Usage: m33-linux -v -c -p -w -t -b -l -f -x -r firmware.rom -a -i input.gcode -s -o output.gcode -e -d
13 |
14 | -v | --validation: Use validation pre-processor
15 |
16 | -p | --preparation: Use preparation pre-processor
17 |
18 | -w | --wavebonding: Use wave bonding pre-processor
19 |
20 | -t | --thermalbonding: Use thermal bonding pre-processor
21 |
22 | -b | --bedcompensation: Use bed compensation pre-processor
23 |
24 | -l | --backlashcompensation: Use backlash compensation pre-processor
25 |
26 | -f | --feedrateconversion: Use feed rate conversion pre-processor
27 |
28 | -c | --centermodel: Use center model pre-processor
29 |
30 | -r | --firmwarerom: Use the following parameter as the firmware ROM in case firmware is corrupt or outdated
31 |
32 | -x | --exit: Switches printer into firmware mode and exits if firmware is updated
33 |
34 | -a | --forceflash: Forces the firmware to update to the provided ROM
35 |
36 | -i | --inputfile: Use the following parameter as the G-code file to processes and send to the printer. G-code commands can be manually entered if no G-code file is not provided.
37 |
38 | -s | --translate: Uses the program as a middle man to communicate between the printer and other software
39 |
40 | -o | --outputfile: Use the following parameter as the G-code file to output after the input file has been processed by all the desired pre-processor stages.
41 |
42 | -e | --settings: Uses values from settings file instead of obtaining them from the printer
43 |
44 | -d | --provided: Uses provided values instead of obtaining them from the printer
45 |
46 | --backlashX: Provide backlash X
47 |
48 | --backlashY: Provide backlash Y
49 |
50 | --backlashSpeed: Provide backlash speed
51 |
52 | --filamentTemperature: Provide filament temperature
53 |
54 | --filamentType: Provide filament type
55 |
56 | --bedHeightOffset: Provide bed height offset
57 |
58 | --backRightOffset: Provide back right offset
59 |
60 | --backLeftOffset: Provide back left offset
61 |
62 | --frontLeftOffset: Provide front left offset
63 |
64 | --frontRightOffset: Provide front right offset
65 |
66 |
67 |
68 | If the printer's firmware is corrupt or the provided firmware rom is newer, it will update the firmware if a rom is provided. Firmware roms must be named after their version number, ex: 2015062401.rom. If the Z calibration of the printer is invalid, it will calibrate it automatically. If a G-code file is provided and it contains a line that indicated the ideal temperature, ex: ;ideal temp:195, then that temperature will be used for printing. Otherwise the temperature stored in the printer's EEPROM will be used.
69 |
70 |
71 | The 90-micro-3d-local.rules needs to applied in order to avoid issues. You can apply it like this:
72 |
73 | cp ./90-micro-3d-local.rules /etc/udev/rules.d/
74 |
75 | sudo /etc/init.d/udev restart
76 |
--------------------------------------------------------------------------------
/gcode.cpp:
--------------------------------------------------------------------------------
1 | // Header files
2 | #include
3 | #include
4 | #include "gcode.h"
5 |
6 |
7 | // Definitions
8 | #define ORDER "NMGXYZE FTSP IJRD"
9 |
10 |
11 | // Supporting function implementation
12 | Gcode::Gcode() {
13 |
14 | // Set parameter value size
15 | parameterValue.resize(strlen(ORDER));
16 |
17 | // Set inital data type
18 | dataType = 0x1080;
19 | }
20 |
21 | Gcode::Gcode(Gcode &value) {
22 |
23 | // Copy data type
24 | value.dataType = this->dataType;
25 |
26 | // Copy host command
27 | value.hostCommand = this->hostCommand;
28 |
29 | // Copy parameter values
30 | value.parameterValue = this->parameterValue;
31 |
32 | // Copy original command
33 | value.originalCommand = this->originalCommand;
34 | }
35 |
36 | bool Gcode::parseLine(const char *line) {
37 |
38 | // Initialize variables
39 | string command = line, currentValue;
40 | size_t characterOffset;
41 | char parameterIdentifier = 0;
42 | const char *parameterOffset;
43 |
44 | // Reset data type
45 | dataType = 0x1080;
46 |
47 | // Reset parameter values
48 | parameterValue.clear();
49 | parameterValue.resize(strlen(ORDER));
50 |
51 | // Clear host command
52 | hostCommand.clear();
53 |
54 | // Check if command contains a checksum
55 | if((characterOffset = command.find('*')) != string::npos)
56 |
57 | // Remove checksum
58 | command = command.substr(0, characterOffset);
59 |
60 | // Remove leading and trailing whitespace
61 | if((characterOffset = command.find_first_not_of(" \t\n\r")) != string::npos)
62 | command = command.substr(characterOffset);
63 | if((characterOffset = command.find_last_not_of(" \t\n\r")) != string::npos)
64 | command = command.substr(0, characterOffset + 1);
65 |
66 | // Set original command
67 | originalCommand = command;
68 |
69 | // Check if command contains a comment
70 | if((characterOffset = command.find(';')) != string::npos)
71 |
72 | // Remove comment
73 | command = command.substr(0, characterOffset);
74 |
75 | // Check if command is empty
76 | if(!command.length())
77 |
78 | // Return false
79 | return false;
80 |
81 | // Check if command is a host command
82 | if(command[0] == '@') {
83 |
84 | // Set host command
85 | hostCommand = command;
86 |
87 | // Return true
88 | return true;
89 | }
90 |
91 | // Go through data
92 | for(uint8_t i = 0; i <= command.length(); i++) {
93 |
94 | // Check if a parameter is detected
95 | if(i == 0 || isupper(command[i]) || command[i] == ' ' || !command[i]) {
96 |
97 | // Check if valid value has been obtained for the parameter
98 | if(i && parameterIdentifier != ' ' && (parameterOffset = strchr(ORDER, parameterIdentifier))) {
99 |
100 | // Set data type
101 | dataType |= (1 << (parameterOffset - ORDER));
102 |
103 | // Store parameter value
104 | parameterValue[parameterOffset - ORDER] = currentValue;
105 | }
106 |
107 | // Reset current value
108 | currentValue.clear();
109 |
110 | // Check if a string is required
111 | if(parameterIdentifier == 'M' && (parameterValue[1] == "23" || parameterValue[1] == "28" || parameterValue[1] == "29" || parameterValue[1] == "30" || parameterValue[1] == "32" || parameterValue[1] == "117")) {
112 |
113 | // Get string data
114 | for(; i < command.length(); i++)
115 | currentValue.push_back(command[i]);
116 |
117 | // Remove leading and trailing whitespace
118 | if((characterOffset = currentValue.find_first_not_of(" \t\n\r")) != string::npos)
119 | currentValue = currentValue.substr(characterOffset);
120 | if((characterOffset = currentValue.find_last_not_of(" \t\n\r")) != string::npos)
121 | currentValue = currentValue.substr(0, characterOffset + 1);
122 |
123 | // Set string parameter
124 | parameterValue[15] = currentValue;
125 |
126 | // Check if string exists
127 | if(!parameterValue[15].empty())
128 |
129 | // Set data type
130 | dataType |= (1 << 15);
131 |
132 | // Stop parsing line
133 | break;
134 | }
135 |
136 | // Set parameter identifier
137 | parameterIdentifier = command[i];
138 | }
139 |
140 | // Otherwise check if value isn't whitespace
141 | else if(!isspace(command[i]))
142 |
143 | // Get current value
144 | currentValue.push_back(command[i]);
145 | }
146 |
147 | // Return if data wasn't empty
148 | return dataType != 0x1080;
149 | }
150 |
151 | bool Gcode::parseLine(const string &line) {
152 |
153 | // Return parse line
154 | return parseLine(line.c_str());
155 | }
156 |
157 | bool Gcode::parseBinary(const char *line) {
158 |
159 | // Initialize variables
160 | uint8_t index = 4;
161 | int32_t *tempPointer;
162 | float tempFloat;
163 |
164 | // Set data type
165 | dataType = (line[0] & 0xF0) + (line[0] & 0x0F) + (((line[1] & 0xF0) + (line[1] & 0x0F)) << 8) + (((line[2] & 0xF0) + (line[2] & 0x0F)) << 16) + (((line[3] & 0xF0) + (line[3] & 0x0F)) << 24);
166 |
167 | // Check if command contains no data
168 | if(!dataType || dataType == 0x1080)
169 |
170 | // Return false
171 | return false;
172 |
173 | // Reset parameter values
174 | parameterValue.clear();
175 | parameterValue.resize(strlen(ORDER));
176 |
177 | // Clear host command
178 | hostCommand.clear();
179 |
180 | // Check if command contains a string parameter
181 | if(dataType & (1 << 15))
182 |
183 | // Increment parameter location index
184 | index++;
185 |
186 | // Check if command contains an N value
187 | if(dataType & 1) {
188 |
189 | // Set parameter value
190 | parameterValue[0] = to_string((line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8));
191 |
192 | // Increment parameter location index
193 | index += 2;
194 | }
195 |
196 | // Check if command contains an M value
197 | if(dataType & (1 << 1)) {
198 |
199 | // Set parameter value
200 | parameterValue[1] = to_string((line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8));
201 |
202 | // Increment parameter location index
203 | index += 2;
204 | }
205 |
206 | // Check if command contains an G value
207 | if(dataType & (1 << 2)) {
208 |
209 | // Set parameter value
210 | parameterValue[2] = to_string((line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8));
211 |
212 | // Increment parameter location index
213 | index += 2;
214 | }
215 |
216 | // Check if command contains an X value
217 | if(dataType & (1 << 3)) {
218 |
219 | // Set parameter value
220 | tempPointer = reinterpret_cast(&tempFloat);
221 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
222 | parameterValue[3] = to_string(tempFloat);
223 |
224 | // Increment parameter location index
225 | index += 4;
226 | }
227 |
228 | // Check if command contains a Y value
229 | if(dataType & (1 << 4)) {
230 |
231 | // Set parameter value
232 | tempPointer = reinterpret_cast(&tempFloat);
233 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
234 | parameterValue[4] = to_string(tempFloat);
235 |
236 | // Increment parameter location index
237 | index += 4;
238 | }
239 |
240 | // Check if command contains a Z value
241 | if(dataType & (1 << 5)) {
242 |
243 | // Set parameter value
244 | tempPointer = reinterpret_cast(&tempFloat);
245 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
246 | parameterValue[5] = to_string(tempFloat);
247 |
248 | // Increment parameter location index
249 | index += 4;
250 | }
251 |
252 | // Check if command contains an E value
253 | if(dataType & (1 << 6)) {
254 |
255 | // Set parameter value
256 | tempPointer = reinterpret_cast(&tempFloat);
257 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
258 | parameterValue[6] = to_string(tempFloat);
259 |
260 | // Increment parameter location index
261 | index += 4;
262 | }
263 |
264 | // Check if command contains an F value
265 | if(dataType & (1 << 8)) {
266 |
267 | // Set parameter value
268 | tempPointer = reinterpret_cast(&tempFloat);
269 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
270 | parameterValue[8] = to_string(tempFloat);
271 |
272 | // Increment parameter location index
273 | index += 4;
274 | }
275 |
276 | // Check if command contains a T value
277 | if(dataType & (1 << 9)) {
278 |
279 | // Set parameter value
280 | parameterValue[9] = to_string((line[index] & 0xF0) + (line[index] & 0x0F));
281 |
282 | // Increment parameter location index
283 | index++;
284 | }
285 |
286 | // Check if command contains an S value
287 | if(dataType & (1 << 10)) {
288 |
289 | // Set parameter value
290 | parameterValue[10] = to_string((line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24));
291 |
292 | // Increment parameter location index
293 | index += 4;
294 | }
295 |
296 | // Check if command contains a P value
297 | if(dataType & (1 << 11)) {
298 |
299 | // Set parameter value
300 | parameterValue[11] = to_string((line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24));
301 |
302 | // Increment parameter location index
303 | index += 4;
304 | }
305 |
306 | // Check if command contains an I value
307 | if(dataType & (1 << 16)) {
308 |
309 | // Set parameter value
310 | tempPointer = reinterpret_cast(&tempFloat);
311 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
312 | parameterValue[16] = to_string(tempFloat);
313 |
314 | // Increment parameter location index
315 | index += 4;
316 | }
317 |
318 | // Check if command contains a J value
319 | if(dataType & (1 << 17)) {
320 |
321 | // Set parameter value
322 | tempPointer = reinterpret_cast(&tempFloat);
323 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
324 | parameterValue[17] = to_string(tempFloat);
325 |
326 | // Increment parameter location index
327 | index += 4;
328 | }
329 |
330 | // Check if command contains an R value
331 | if(dataType & (1 << 18)) {
332 |
333 | // Set parameter value
334 | tempPointer = reinterpret_cast(&tempFloat);
335 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
336 | parameterValue[18] = to_string(tempFloat);
337 |
338 | // Increment parameter location index
339 | index += 4;
340 | }
341 |
342 | // Check if command contains a D value
343 | if(dataType & (1 << 19)) {
344 |
345 | // Set parameter value
346 | tempPointer = reinterpret_cast(&tempFloat);
347 | *tempPointer = (line[index] & 0xF0) + (line[index] & 0x0F) + (((line[index + 1] & 0xF0) + (line[index + 1] & 0x0F)) << 8) + (((line[index + 2] & 0xF0) + (line[index + 2] & 0x0F)) << 16) + (((line[index + 3] & 0xF0) + (line[index + 3] & 0x0F)) << 24);
348 | parameterValue[19] = to_string(tempFloat);
349 |
350 | // Increment parameter location index
351 | index += 4;
352 | }
353 |
354 | // Check if command contains a string parameter
355 | if(dataType & (1 << 15))
356 |
357 | // Set string parameter value
358 | for(uint8_t i = 0; i < (line[4] & 0xF0) + (line[4] & 0x0F); i++)
359 | parameterValue[15].push_back(line[index + i]);
360 |
361 | // Set original command
362 | originalCommand = getAscii();
363 |
364 | // Return true
365 | return true;
366 | }
367 |
368 | string Gcode::getOriginalCommand() const {
369 |
370 | // Return original command
371 | return originalCommand;
372 | }
373 |
374 | vector Gcode::getBinary() const {
375 |
376 | // Initialize request
377 | vector request;
378 |
379 | // Check if host command
380 | if(!hostCommand.empty())
381 |
382 | // Set request to host command
383 | for(uint8_t i = 0; i < hostCommand.length(); i++)
384 | request.push_back(hostCommand[i]);
385 |
386 | // Otherwise
387 | else {
388 |
389 | // Initialize variables
390 | uint16_t sum1 = 0, sum2 = 0;
391 | int32_t tempNumber, *tempPointer;
392 | float tempFloat;
393 |
394 | // Fill first four bytes of request to data type
395 | request.push_back(dataType);
396 | request.push_back(dataType >> 8);
397 | request.push_back(dataType >> 16);
398 | request.push_back(dataType >> 24);
399 |
400 | // Check if command contains a string parameter
401 | if(!parameterValue[15].empty())
402 |
403 | // Set fifth byte of request to string length
404 | request.push_back(parameterValue[15].length());
405 |
406 | // Check if command contains an N value
407 | if(!parameterValue[0].empty()) {
408 |
409 | // Set 2 byte integer parameter value
410 | tempNumber = stoi(parameterValue[0]);
411 | request.push_back(tempNumber & 0xFF);
412 | request.push_back((tempNumber >> 8) & 0xFF);
413 | }
414 |
415 | // Check if command contains an M value
416 | if(!parameterValue[1].empty()) {
417 |
418 | // Set 2 byte integer parameter value
419 | tempNumber = stoi(parameterValue[1]);
420 | request.push_back(tempNumber & 0xFF);
421 | request.push_back((tempNumber >> 8) & 0xFF);
422 | }
423 |
424 | // CCheck if command contains a G value
425 | if(!parameterValue[2].empty()) {
426 |
427 | // Set 2 byte integer parameter value
428 | tempNumber = stoi(parameterValue[2]);
429 | request.push_back(tempNumber & 0xFF);
430 | request.push_back((tempNumber >> 8) & 0xFF);
431 | }
432 |
433 | // Check if command contains an X value
434 | if(!parameterValue[3].empty()) {
435 |
436 | // Set 4 byte float parameter value
437 | tempFloat = stof(parameterValue[3]);
438 | tempPointer = reinterpret_cast(&tempFloat);
439 | request.push_back(*tempPointer & 0xFF);
440 | request.push_back((*tempPointer >> 8) & 0xFF);
441 | request.push_back((*tempPointer >> 16) & 0xFF);
442 | request.push_back((*tempPointer >> 24) & 0xFF);
443 | }
444 |
445 | // Check if command contains a Y value
446 | if(!parameterValue[4].empty()) {
447 |
448 | // Set 4 byte float parameter value
449 | tempFloat = stof(parameterValue[4]);
450 | tempPointer = reinterpret_cast(&tempFloat);
451 | request.push_back(*tempPointer & 0xFF);
452 | request.push_back((*tempPointer >> 8) & 0xFF);
453 | request.push_back((*tempPointer >> 16) & 0xFF);
454 | request.push_back((*tempPointer >> 24) & 0xFF);
455 | }
456 |
457 | // Check if command contains a Z value
458 | if(!parameterValue[5].empty()) {
459 |
460 | // Set 4 byte float parameter value
461 | tempFloat = stof(parameterValue[5]);
462 | tempPointer = reinterpret_cast(&tempFloat);
463 | request.push_back(*tempPointer & 0xFF);
464 | request.push_back((*tempPointer >> 8) & 0xFF);
465 | request.push_back((*tempPointer >> 16) & 0xFF);
466 | request.push_back((*tempPointer >> 24) & 0xFF);
467 | }
468 |
469 | // Check if command contains an E value
470 | if(!parameterValue[6].empty()) {
471 |
472 | // Set 4 byte float parameter value
473 | tempFloat = stof(parameterValue[6]);
474 | tempPointer = reinterpret_cast(&tempFloat);
475 | request.push_back(*tempPointer & 0xFF);
476 | request.push_back((*tempPointer >> 8) & 0xFF);
477 | request.push_back((*tempPointer >> 16) & 0xFF);
478 | request.push_back((*tempPointer >> 24) & 0xFF);
479 | }
480 |
481 | // Check if command contains an F value
482 | if(!parameterValue[8].empty()) {
483 |
484 | // Set 4 byte float parameter value
485 | tempFloat = stof(parameterValue[8]);
486 | tempPointer = reinterpret_cast(&tempFloat);
487 | request.push_back(*tempPointer & 0xFF);
488 | request.push_back((*tempPointer >> 8) & 0xFF);
489 | request.push_back((*tempPointer >> 16) & 0xFF);
490 | request.push_back((*tempPointer >> 24) & 0xFF);
491 | }
492 |
493 | // Check if command contains a T value
494 | if(!parameterValue[9].empty()) {
495 |
496 | // Set 1 byte integer parameter value
497 | tempNumber = stoi(parameterValue[9]);
498 | request.push_back(tempNumber & 0xFF);
499 | }
500 |
501 | // Check if command contains an S value
502 | if(!parameterValue[10].empty()) {
503 |
504 | // Set 4 byte integer parameter value
505 | tempNumber = static_cast(round(stod(parameterValue[10])));
506 | request.push_back(tempNumber & 0xFF);
507 | request.push_back((tempNumber >> 8) & 0xFF);
508 | request.push_back((tempNumber >> 16) & 0xFF);
509 | request.push_back((tempNumber >> 24) & 0xFF);
510 | }
511 |
512 | // Check if command contains a P value
513 | if(!parameterValue[11].empty()) {
514 |
515 | // Set 4 byte integer parameter value
516 | tempNumber = static_cast(round(stod(parameterValue[11])));
517 | request.push_back(tempNumber & 0xFF);
518 | request.push_back((tempNumber >> 8) & 0xFF);
519 | request.push_back((tempNumber >> 16) & 0xFF);
520 | request.push_back((tempNumber >> 24) & 0xFF);
521 | }
522 |
523 | // Check if command contains an I value
524 | if(!parameterValue[16].empty()) {
525 |
526 | // Set 4 byte float parameter value
527 | tempFloat = stof(parameterValue[16]);
528 | tempPointer = reinterpret_cast(&tempFloat);
529 | request.push_back(*tempPointer & 0xFF);
530 | request.push_back((*tempPointer >> 8) & 0xFF);
531 | request.push_back((*tempPointer >> 16) & 0xFF);
532 | request.push_back((*tempPointer >> 24) & 0xFF);
533 | }
534 |
535 | // Check if command contains a J value
536 | if(!parameterValue[17].empty()) {
537 |
538 | // Set 4 byte float parameter value
539 | tempFloat = stof(parameterValue[17]);
540 | tempPointer = reinterpret_cast(&tempFloat);
541 | request.push_back(*tempPointer & 0xFF);
542 | request.push_back((*tempPointer >> 8) & 0xFF);
543 | request.push_back((*tempPointer >> 16) & 0xFF);
544 | request.push_back((*tempPointer >> 24) & 0xFF);
545 | }
546 |
547 | // Check if command contains an R value
548 | if(!parameterValue[18].empty()) {
549 |
550 | // Set 4 byte float parameter value
551 | tempFloat = stof(parameterValue[18]);
552 | tempPointer = reinterpret_cast(&tempFloat);
553 | request.push_back(*tempPointer & 0xFF);
554 | request.push_back((*tempPointer >> 8) & 0xFF);
555 | request.push_back((*tempPointer >> 16) & 0xFF);
556 | request.push_back((*tempPointer >> 24) & 0xFF);
557 | }
558 |
559 | // Check if command contains a D value
560 | if(!parameterValue[19].empty()) {
561 |
562 | // Set 4 byte float parameter value
563 | tempFloat = stof(parameterValue[19]);
564 | tempPointer = reinterpret_cast(&tempFloat);
565 | request.push_back(*tempPointer & 0xFF);
566 | request.push_back((*tempPointer >> 8) & 0xFF);
567 | request.push_back((*tempPointer >> 16) & 0xFF);
568 | request.push_back((*tempPointer >> 24) & 0xFF);
569 | }
570 |
571 | // Check if command contains a string
572 | if(!parameterValue[15].empty())
573 |
574 | // Set string parameter value
575 | for(uint8_t i = 0; i < parameterValue[15].length(); i++)
576 | request.push_back(parameterValue[15][i]);
577 |
578 | // Go through all values
579 | for(uint8_t index = 0; index < request.size(); index++) {
580 |
581 | // Set sums
582 | sum1 = (sum1 + request[index]) % 0xFF;
583 | sum2 = (sum1 + sum2) % 0xFF;
584 | }
585 |
586 | // Append Fletcher 16 checksum checksum to request
587 | request.push_back(sum1);
588 | request.push_back(sum2);
589 | }
590 |
591 | // Return request
592 | return request;
593 | }
594 |
595 | string Gcode::getAscii() const {
596 |
597 | // Check if host command
598 | if(!hostCommand.empty())
599 |
600 | // Return host command
601 | return hostCommand;
602 |
603 | // Initialize request
604 | string request;
605 |
606 | // Go through all values
607 | for(uint8_t i = 0; i < strlen(ORDER); i++)
608 |
609 | // Check if command contains value and value is valid
610 | if(dataType & (1 << i) && 0xF0F7F & (1 << i)) {
611 |
612 | // Append parameter identifier and value
613 | request += ORDER[i] + parameterValue[i] + ' ';
614 |
615 | // Check if M command contains a string
616 | if(i == 1 && dataType & (1 << 15))
617 |
618 | // Append string to request
619 | request += parameterValue[15] + ' ';
620 | }
621 |
622 | // Remove last space from request
623 | if(!request.empty())
624 | request.pop_back();
625 |
626 | // Return request
627 | return request;
628 | }
629 |
630 | uint32_t Gcode::getDataType() const {
631 |
632 | // Return data type
633 | return dataType;
634 | }
635 |
636 | bool Gcode::hasParameter(char parameter) const {
637 |
638 | // Check if parameter isn't a space
639 | if(parameter != ' ') {
640 |
641 | // Check if parameter is valid
642 | const char *parameterOffset = strchr(ORDER, parameter);
643 | if(parameterOffset)
644 |
645 | // Return if value is set
646 | return dataType & (1 << (parameterOffset - ORDER));
647 | }
648 |
649 | // Return false
650 | return false;
651 | }
652 |
653 | void Gcode::removeParameter(char parameter) {
654 |
655 | // Check if parameter isn't a space
656 | if(parameter != ' ') {
657 |
658 | // Check if parameter is valid
659 | const char *parameterOffset = strchr(ORDER, parameter);
660 | if(parameterOffset) {
661 |
662 | // Clear data type
663 | dataType &= ~(1 << (parameterOffset - ORDER));
664 |
665 | // Clear parameter value
666 | parameterValue[parameterOffset - ORDER].clear();
667 |
668 | // Check if command is now empty
669 | if(dataType == 0x1080)
670 |
671 | // Clear original command
672 | originalCommand = "";
673 | }
674 | }
675 | }
676 |
677 | bool Gcode::hasValue(char parameter) const {
678 |
679 | // Check if parameter isn't a space
680 | if(parameter != ' ') {
681 |
682 | // Check if parameter is valid
683 | const char *parameterOffset = strchr(ORDER, parameter);
684 | if(parameterOffset)
685 |
686 | // Return if parameter's value isn't empty
687 | return !parameterValue[parameterOffset - ORDER].empty();
688 | }
689 |
690 | // Return false
691 | return false;
692 | }
693 |
694 | string Gcode::getValue(char parameter) const {
695 |
696 | // Check if parameter isn't a space
697 | if(parameter != ' ') {
698 |
699 | // Check if parameter is valid
700 | const char *parameterOffset = strchr(ORDER, parameter);
701 | if(parameterOffset)
702 |
703 | // Return parameter's value
704 | return parameterValue[parameterOffset - ORDER];
705 | }
706 |
707 | // Return empty
708 | return "";
709 | }
710 |
711 | void Gcode::setValue(char parameter, const string &value) {
712 |
713 | // Check if parameter isn't a space
714 | if(parameter != ' ') {
715 |
716 | // Check if parameter is valid
717 | const char *parameterOffset = strchr(ORDER, parameter);
718 | if(parameterOffset) {
719 |
720 | // Set data type
721 | dataType |= (1 << (parameterOffset - ORDER));
722 |
723 | // Set parameter value
724 | parameterValue[parameterOffset - ORDER] = value;
725 | }
726 | }
727 | }
728 |
729 | bool Gcode::hasString() const {
730 |
731 | // Return if string is set
732 | return dataType & (1 << 15);
733 | }
734 |
735 | string Gcode::getString() const {
736 |
737 | // Return string
738 | return parameterValue[15];
739 | }
740 |
741 | void Gcode::setString(const string &value) {
742 |
743 | // Set data type
744 | dataType |= (1 << 15);
745 |
746 | // Set string value
747 | parameterValue[15] = value;
748 | }
749 |
750 | void Gcode::clear() {
751 |
752 | // Set inital data type
753 | dataType = 0x1080;
754 |
755 | // Set parameter value size
756 | parameterValue.clear();
757 | parameterValue.resize(strlen(ORDER));
758 |
759 | // Clear host command
760 | hostCommand.clear();
761 |
762 | // Clear original command
763 | originalCommand.clear();
764 | }
765 |
766 | bool Gcode::isHostCommand() const {
767 |
768 | // Return if host command is set
769 | return !hostCommand.empty();
770 | }
771 |
772 | bool Gcode::isEmpty() const {
773 |
774 | // Return if doesn't contain any values
775 | return dataType == 0x1080;
776 | }
777 |
778 | Gcode &Gcode::operator=(const Gcode &value) {
779 |
780 | // Return self if calling on self
781 | if(this == &value)
782 | return *this;
783 |
784 | // Copy data type
785 | dataType = value.dataType;
786 |
787 | // Copy host command
788 | hostCommand = value.hostCommand;
789 |
790 | // Copy parameter values
791 | parameterValue = value.parameterValue;
792 |
793 | // Copy original command
794 | originalCommand = value.originalCommand;
795 |
796 | // Return self
797 | return *this;
798 | }
799 |
800 | ostream &operator<<(ostream &output, const Gcode &gcode) {
801 |
802 | // Return command sent to output
803 | return output << (gcode.isEmpty() ? gcode.getOriginalCommand() : gcode.getAscii());
804 | }
805 |
--------------------------------------------------------------------------------
/gcode.h:
--------------------------------------------------------------------------------
1 | // Header gaurd
2 | #ifndef GCODE_H
3 | #define GCODE_H
4 |
5 |
6 | // Header files
7 | #include
8 | #include
9 |
10 | using namespace std;
11 |
12 |
13 | // Gcode class
14 | class Gcode {
15 |
16 | // Public
17 | public:
18 |
19 | /*
20 | Name: Constructor
21 | Purpose: Initializes the variable
22 | */
23 | Gcode();
24 |
25 | /*
26 | Name: Copy constructor
27 | Purpose: Initializes the variable if copied
28 | */
29 | Gcode(Gcode &value);
30 |
31 | /*
32 | Name: Parse line
33 | Purpose: Extracts G-code from the parameter
34 | */
35 | bool parseLine(const char *line);
36 | bool parseLine(const string &line);
37 |
38 | /*
39 | Name: Parse binary
40 | Purpose: Extracts G-code from the binary parameter
41 | */
42 | bool parseBinary(const char *line);
43 |
44 | /*
45 | Name: Get original command
46 | Purpose: Returns the orignal G-code command
47 | */
48 | string getOriginalCommand() const;
49 |
50 | /*
51 | Name: Get binary
52 | Purpose: Returns binary representation of the G-code
53 | */
54 | vector getBinary() const;
55 |
56 | /*
57 | Name: Get ascii
58 | Purpose: Returns Ascii representation of the G-code
59 | */
60 | string getAscii() const;
61 |
62 | /*
63 | Name: Get data type
64 | Purpose: Returns the data type of the G-code
65 | */
66 | uint32_t getDataType() const;
67 |
68 | /*
69 | Name: Has parameter
70 | Purpose: Checks if the G-code has a specific parameter, but does not check if it has a value associated with it
71 | */
72 | bool hasParameter(char parameter) const;
73 |
74 | /*
75 | Name: Remove parameter
76 | Purpose: Removes a specified parameter from the G-cocdde
77 | */
78 | void removeParameter(char parameter);
79 |
80 | /*
81 | Name: Has value
82 | Purpose: Checks if the G-code has a value associated with a specific parameter, so it can't detect flags
83 | */
84 | bool hasValue(char parameter) const;
85 |
86 | /*
87 | Name: Get value
88 | Purpose: Retuns the value associated with a specific parameter
89 | */
90 | string getValue(char parameter) const;
91 |
92 | /*
93 | Name: Set value
94 | Purpose: Sets the value associated with a specific parameter
95 | */
96 | void setValue(char parameter, const string &value);
97 |
98 | /*
99 | Name: Has string
100 | Purpose: Returns if the G-code contained a string as a value for a parameter
101 | */
102 | bool hasString() const;
103 |
104 | /*
105 | Name: Get string
106 | Purpose: Returns the string value associated with a parameter
107 | */
108 | string getString() const;
109 |
110 | /*
111 | Name: Set string
112 | Purpose: Sets the string value associated with a parameter
113 | */
114 | void setString(const string &value);
115 |
116 | /*
117 | Name: Clear
118 | Purpose: Resets G-code to initial state
119 | */
120 | void clear();
121 |
122 | /*
123 | Name: Is host command
124 | Purpose: Returns if the G-code is a host command
125 | */
126 | bool isHostCommand() const;
127 |
128 | /*
129 | Name: Is empty
130 | Purpose: Returns if no G-code has attempted to be parsed yet
131 | */
132 | bool isEmpty() const;
133 |
134 | /*
135 | Name: Assignment operator
136 | Purpose: Allows using the assignment operator
137 | */
138 | Gcode &operator=(const Gcode &value);
139 |
140 | /*
141 | Name: Output stream operator
142 | Purpose: Allows using the output stream operator
143 | */
144 | friend ostream &operator<<(ostream &output, const Gcode &value);
145 |
146 | // Private
147 | private:
148 |
149 | // Original command
150 | string originalCommand;
151 |
152 | // Parameter values
153 | vector parameterValue;
154 |
155 | // Data type
156 | uint32_t dataType;
157 |
158 | // Host command
159 | string hostCommand;
160 | };
161 |
162 |
163 | #endif
164 |
--------------------------------------------------------------------------------
/main.cpp:
--------------------------------------------------------------------------------
1 | // Header files
2 | #include
3 | #include
4 | #include
5 | #include
6 | #include
7 | #include "printer.h"
8 |
9 | using namespace std;
10 |
11 |
12 | // Global variables
13 | Printer printer;
14 |
15 |
16 | // Function prototypes
17 | void breakHandler(int signal);
18 |
19 |
20 | // Main function
21 | int main(int argc, char *argv[]) {
22 |
23 | // Initialize variables
24 | string response, line, firmwareRom, inputFile, outputFile;
25 | ifstream file;
26 | bool translate = false, forceFlash = false, settings = false, provided = false, exit = false;
27 |
28 | // Attach break handler
29 | signal(SIGINT, breakHandler);
30 |
31 | // Display version
32 | cout << "M33 Linux V0.16" << endl << endl;
33 |
34 | // Go through all commands
35 | for(uint8_t i = 0; i < argc; i++) {
36 |
37 | // Check if help is requested
38 | if(!strcmp(argv[i], "-h") || !strcmp(argv[i], "--help")) {
39 |
40 | // Display help
41 | cout << "Usage: m33-linux -v -c -p -w -t -b -l -f -x -r firmware.rom -a -i input.gcode -s -o output.gcode -e -d" << endl;
42 | cout << "-v | --validation: Use validation pre-processor" << endl;
43 | cout << "-p | --preparation: Use preparation pre-processor" << endl;
44 | cout << "-w | --wavebonding: Use wave bonding pre-processor" << endl;
45 | cout << "-t | --thermalbonding: Use thermal bonding pre-processor" << endl;
46 | cout << "-b | --bedcompensation: Use bed compensation pre-processor" << endl;
47 | cout << "-l | --backlashcompensation: Use backlash compensation pre-processor" << endl;
48 | cout << "-f | --feedrateconversion: Use feed rate conversion pre-processor" << endl;
49 | cout << "-c | --centermodel: Use center model pre-processor" << endl;
50 | cout << "-r | --firmwarerom: Use the following parameter as the firmware ROM in case firmware is corrupt or outdated" << endl;
51 | cout << "-x | --exit: Switches printer into firmware mode and exits if firmware is updated" << endl;
52 | cout << "-a | --forceflash: Forces the firmware to update to the provided ROM" << endl;
53 | cout << "-i | --inputfile: Use the following parameter as the G-code file to processes and send to the printer. G-code commands can be manually entered if no G-code file is not provided." << endl;
54 | cout << "-s | --translate: Uses the program as a middle man to communicate between the printer and other software" << endl;
55 | cout << "-o | --outputfile: Use the following parameter as the G-code file to output after the input file has been processed by all the desired pre-processor stages." << endl;
56 | cout << "-e | --settings: Uses values from settings file instead of obtaining them from the printer" << endl;
57 | cout << "-d | --provided: Uses provided values instead of obtaining them from the printer" << endl;
58 | cout << "--backlashX: Provide backlash X" << endl;
59 | cout << "--backlashY: Provide backlash Y" << endl;
60 | cout << "--backlashSpeed: Provide backlash speed" << endl;
61 | cout << "--filamentTemperature: Provide filament temperature" << endl;
62 | cout << "--filamentType: Provide filament type" << endl;
63 | cout << "--bedHeightOffset: Provide bed height offset" << endl;
64 | cout << "--backRightOffset: Provide back right offset" << endl;
65 | cout << "--backLeftOffset: Provide back left offset" << endl;
66 | cout << "--frontLeftOffset: Provide front left offset" << endl;
67 | cout << "--frontRightOffset: Provide front right offset" << endl << endl;
68 | return 0;
69 | }
70 |
71 | // Otherwise check if using validation pre-processor
72 | else if(!strcmp(argv[i], "-v") || !strcmp(argv[i], "--validation"))
73 |
74 | // Set validation preprocessor
75 | printer.setValidationPreprocessor();
76 |
77 | // Otherwise check if using preparation pre-processor
78 | else if(!strcmp(argv[i], "-p") || !strcmp(argv[i], "--preparation"))
79 |
80 | // Set preparation preprocessor
81 | printer.setPreparationPreprocessor();
82 |
83 | // Otherwise check if using wave bonding pre-processor
84 | else if(!strcmp(argv[i], "-w") || !strcmp(argv[i], "--wavebonding"))
85 |
86 | // Set wave bonding preprocessor
87 | printer.setWaveBondingPreprocessor();
88 |
89 | // Otherwise check if using thermal bonding pre-processor
90 | else if(!strcmp(argv[i], "-t") || !strcmp(argv[i], "--thermalbonding"))
91 |
92 | // Set thermal bonding preprocessor
93 | printer.setThermalBondingPreprocessor();
94 |
95 | // Otherwise check if using bed compensation pre-processor
96 | else if(!strcmp(argv[i], "-b") || !strcmp(argv[i], "--bedcompensation"))
97 |
98 | // Set bed compensation preprocessor
99 | printer.setBedCompensationPreprocessor();
100 |
101 | // Otherwise check if using backlash compensation pre-processor
102 | else if(!strcmp(argv[i], "-l") || !strcmp(argv[i], "--backlashcompensation"))
103 |
104 | // Set backlash compensation preprocessor
105 | printer.setBacklashCompensationPreprocessor();
106 |
107 | // Otherwise check if using feed rate conversion pre-processor
108 | else if(!strcmp(argv[i], "-f") || !strcmp(argv[i], "--feedrateconversion"))
109 |
110 | // Set feed rate conversion preprocessor
111 | printer.setFeedRateConversionPreprocessor();
112 |
113 | // Otherwise check if using center model pre-processor
114 | else if(!strcmp(argv[i], "-c") || !strcmp(argv[i], "--centermodel"))
115 |
116 | // Set center model preprocessor
117 | printer.setCenterModelPreprocessor();
118 |
119 | // Otherwise check if a firmware rom is provided
120 | else if(!strcmp(argv[i], "-r") || !strcmp(argv[i], "--firmwarerom")) {
121 |
122 | // Check if firmware rom parameter exists
123 | if(i < argc - 1)
124 |
125 | // Set firmware rom
126 | firmwareRom = argv[++i];
127 |
128 | // Otherwise
129 | else {
130 |
131 | // Display error
132 | cout << "No firmware ROM provided" << endl;
133 | return 0;
134 | }
135 | }
136 |
137 | // Otherwise check if using force flash
138 | else if(!strcmp(argv[i], "-a") || !strcmp(argv[i], "--forceflash"))
139 |
140 | // Set force flash
141 | forceFlash = true;
142 |
143 | // Otherwise check if using exiting after flash
144 | else if(!strcmp(argv[i], "-x") || !strcmp(argv[i], "--exit"))
145 |
146 | // Set exit
147 | exit = true;
148 |
149 | // Otherwise check if an input file is provided
150 | else if(!strcmp(argv[i], "-i") || !strcmp(argv[i], "--inputfile")) {
151 |
152 | // Check if input file parameter exists
153 | if(i < argc - 1)
154 |
155 | // Set input file
156 | inputFile = argv[++i];
157 |
158 | // Otherwise
159 | else {
160 |
161 | // Display error
162 | cout << "No input file provided" << endl;
163 | return 0;
164 | }
165 | }
166 |
167 | // Otherwise check if an output file is provided
168 | else if(!strcmp(argv[i], "-o") || !strcmp(argv[i], "--outputfile")) {
169 |
170 | // Check if output file parameter exists
171 | if(i < argc - 1)
172 |
173 | // Set output file
174 | outputFile = argv[++i];
175 |
176 | // Otherwise
177 | else {
178 |
179 | // Display error
180 | cout << "No output file provided" << endl;
181 | return 0;
182 | }
183 | }
184 |
185 | // Otherwise check if using with translate
186 | else if(!strcmp(argv[i], "-s") || !strcmp(argv[i], "--translate"))
187 |
188 | // Set translate
189 | translate = true;
190 |
191 | // Otherwise check if using settings
192 | else if(!strcmp(argv[i], "-e") || !strcmp(argv[i], "--settings"))
193 |
194 | // Set settings
195 | settings = true;
196 |
197 | // Otherwise check if using provided
198 | else if(!strcmp(argv[i], "-d") || !strcmp(argv[i], "--provided"))
199 |
200 | // Set provided
201 | provided = true;
202 |
203 | // Otherwise check if a backlash X is provided
204 | else if(!strcmp(argv[i], "--backlashX")) {
205 |
206 | // Check if backlash X parameter exists
207 | if(i < argc - 1)
208 |
209 | // Set backlash X
210 | printer.setBacklashX(argv[++i]);
211 |
212 | // Otherwise
213 | else {
214 |
215 | // Display error
216 | cout << "No backlash X provided" << endl;
217 | return 0;
218 | }
219 | }
220 |
221 | // Otherwise check if a backlash Y is provided
222 | else if(!strcmp(argv[i], "--backlashY")) {
223 |
224 | // Check if backlash Y parameter exists
225 | if(i < argc - 1)
226 |
227 | // Set backlash Y
228 | printer.setBacklashY(argv[++i]);
229 |
230 | // Otherwise
231 | else {
232 |
233 | // Display error
234 | cout << "No backlash Y provided" << endl;
235 | return 0;
236 | }
237 | }
238 |
239 | // Otherwise check if a backlash speed is provided
240 | else if(!strcmp(argv[i], "--backlashSpeed")) {
241 |
242 | // Check if backlash speed parameter exists
243 | if(i < argc - 1)
244 |
245 | // Set backlash speed
246 | printer.setBacklashSpeed(argv[++i]);
247 |
248 | // Otherwise
249 | else {
250 |
251 | // Display error
252 | cout << "No backlash speed provided" << endl;
253 | return 0;
254 | }
255 | }
256 |
257 | // Otherwise check if a filament type is provided
258 | else if(!strcmp(argv[i], "--filamentType")) {
259 |
260 | // Check if filament type parameter exists
261 | if(i < argc - 1)
262 |
263 | // Set filament type
264 | printer.setFilamentType(argv[++i]);
265 |
266 | // Otherwise
267 | else {
268 |
269 | // Display error
270 | cout << "No filament type provided" << endl;
271 | return 0;
272 | }
273 | }
274 |
275 | // Otherwise check if a filament temperature is provided
276 | else if(!strcmp(argv[i], "--filamentTemperature")) {
277 |
278 | // Check if filament temperature parameter exists
279 | if(i < argc - 1)
280 |
281 | // Set filament temperature
282 | printer.setFilamentTemperature(argv[++i]);
283 |
284 | // Otherwise
285 | else {
286 |
287 | // Display error
288 | cout << "No filament temperature provided" << endl;
289 | return 0;
290 | }
291 | }
292 |
293 | // Otherwise check if a bed height offset is provided
294 | else if(!strcmp(argv[i], "--bedHeightOffset")) {
295 |
296 | // Check if bed height offset parameter exists
297 | if(i < argc - 1)
298 |
299 | // Set bed height offset
300 | printer.setBedHeightOffset(argv[++i]);
301 |
302 | // Otherwise
303 | else {
304 |
305 | // Display error
306 | cout << "No bed height offset provided" << endl;
307 | return 0;
308 | }
309 | }
310 |
311 | // Otherwise check if a back right offset is provided
312 | else if(!strcmp(argv[i], "--backRightOffset")) {
313 |
314 | // Check if back right offset parameter exists
315 | if(i < argc - 1)
316 |
317 | // Set back right offset
318 | printer.setBackRightOffset(argv[++i]);
319 |
320 | // Otherwise
321 | else {
322 |
323 | // Display error
324 | cout << "No back right offset provided" << endl;
325 | return 0;
326 | }
327 | }
328 |
329 | // Otherwise check if a back left offset is provided
330 | else if(!strcmp(argv[i], "--backLeftOffset")) {
331 |
332 | // Check if back left offset parameter exists
333 | if(i < argc - 1)
334 |
335 | // Set back left offset
336 | printer.setBackLeftOffset(argv[++i]);
337 |
338 | // Otherwise
339 | else {
340 |
341 | // Display error
342 | cout << "No back left offset provided" << endl;
343 | return 0;
344 | }
345 | }
346 |
347 | // Otherwise check if a front left offset is provided
348 | else if(!strcmp(argv[i], "--frontLeftOffset")) {
349 |
350 | // Check if front left offset parameter exists
351 | if(i < argc - 1)
352 |
353 | // Set front left offset
354 | printer.setFrontLeftOffset(argv[++i]);
355 |
356 | // Otherwise
357 | else {
358 |
359 | // Display error
360 | cout << "No front left offset provided" << endl;
361 | return 0;
362 | }
363 | }
364 |
365 | // Otherwise check if a front right offset is provided
366 | else if(!strcmp(argv[i], "--frontRightOffset")) {
367 |
368 | // Check if front right offset parameter exists
369 | if(i < argc - 1)
370 |
371 | // Set front right offset
372 | printer.setFrontRightOffset(argv[++i]);
373 |
374 | // Otherwise
375 | else {
376 |
377 | // Display error
378 | cout << "No front right offset provided" << endl;
379 | return 0;
380 | }
381 | }
382 | }
383 |
384 | // Check if a firmware rom is provided
385 | if(!firmwareRom.empty()) {
386 |
387 | // Check if firmware rom doesn't exists
388 | file.open(firmwareRom);
389 | if(!file.good()) {
390 |
391 | // Display error
392 | cout << "Firmware ROM doesn't exist" << endl;
393 | return 0;
394 | }
395 |
396 | // Go through the file name
397 | uint8_t i = 0;
398 | if(firmwareRom.find(' ') != string::npos)
399 | i = firmwareRom.find(' ') + 1;
400 | for(; i < firmwareRom.size(); i++) {
401 |
402 | // Check if extension is occuring
403 | if(firmwareRom[i] == '.') {
404 |
405 | // Break if file name beings with 10 numbers
406 | if(firmwareRom.find(' ') != string::npos && i - firmwareRom.find(' ') - 1 == 10)
407 | break;
408 |
409 | if(i == 10)
410 | break;
411 |
412 | // Display error
413 | cout << "Invalid firmware ROM name" << endl;
414 | return 0;
415 | }
416 |
417 | // Check if current character isn't a digit or length is invalid
418 | if(firmwareRom[i] < '0' || firmwareRom[i] > '9' || (i == firmwareRom.size() - 1 && i < 9)) {
419 |
420 | // Display error
421 | cout << "Invalid firmware ROM name" << endl;
422 | return 0;
423 | }
424 | }
425 |
426 | // Close file
427 | file.close();
428 | }
429 |
430 | // Check if an input file is provided
431 | if(!inputFile.empty()) {
432 |
433 | // Check if the input file doesn't exists
434 | file.open(inputFile);
435 | if(!file.good()) {
436 |
437 | // Display error
438 | cout << "Input file doesn't exist" << endl;
439 | return 0;
440 | }
441 |
442 | // Close file
443 | file.close();
444 | }
445 |
446 | // Check if an output file is provided without an input file
447 | if(!outputFile.empty() && inputFile.empty()) {
448 |
449 | // Display error
450 | cout << "An output file cannot be generated without an input file" << endl;
451 | return 0;
452 | }
453 |
454 | // Check if force flash without a rom
455 | if(forceFlash && firmwareRom.empty()) {
456 |
457 | // Display error
458 | cout << "Cannot force flash when no ROM is provided" << endl;
459 | return 0;
460 | }
461 |
462 | // Check if using output file with settings file
463 | if(!outputFile.empty() && settings) {
464 |
465 | // Display message
466 | cout << "Using printer values from settings file" << endl;
467 |
468 | // Check if gettings settings from file failed
469 | if(!printer.useSettingsFile()) {
470 |
471 | // Display error
472 | cout << "Failed to get settings from file" << endl;
473 | return 0;
474 | }
475 | }
476 |
477 | // Otherwise check if using output file with provided values
478 | else if(!outputFile.empty() && provided)
479 |
480 | // Display message
481 | cout << "Using printer values that were provided" << endl;
482 |
483 | // Otherwise
484 | else {
485 |
486 | // Check if not root and not just updating firmware
487 | if(getuid() && (firmwareRom.empty() || !forceFlash || !exit)) {
488 |
489 | // Display error
490 | cout << "Elevated privileges required" << endl;
491 | return 0;
492 | }
493 |
494 | // Wait for device to be connected
495 | cout << "Attempting to connect to the printer" << endl;
496 | while(!printer.connect())
497 | cout << "Printer not detected" << endl;
498 |
499 | // Display message
500 | cout << "Connected to printer" << endl;
501 |
502 | // Check if a rom is provided and printer isn't in bootloader mode
503 | if(!firmwareRom.empty() && !printer.isBootloaderMode())
504 |
505 | // Enter bootloader mode
506 | printer.sendRequest("M115 S628");
507 |
508 | // Check if printer's firmware isn't valid
509 | if(!printer.isFirmwareValid() || forceFlash) {
510 |
511 | // Display error
512 | if(!forceFlash)
513 | cout << "Printer's firmware is corrupt" << endl;
514 |
515 | // Check if a firmware rom is provided
516 | if(!firmwareRom.empty()) {
517 |
518 | // Display message
519 | cout << "Updating firmware" << endl;
520 |
521 | // Check if updating printer's firmware failed
522 | if(!printer.updateFirmware(firmwareRom.c_str())) {
523 |
524 | // Display error
525 | cout << "Failed to update firmware" << endl;
526 | return 0;
527 | }
528 |
529 | // Display message
530 | cout << "Done updating firmware" << endl;
531 |
532 | // Put printer into firmware mode and exit if set
533 | if(exit) {
534 | printer.sendRequest("Q");
535 | return 0;
536 | }
537 | }
538 |
539 | // Otherwise
540 | else
541 |
542 | // Return 0
543 | return 0;
544 | }
545 |
546 | // Check if printer's firmware is outdated
547 | if(!firmwareRom.empty() && !printer.getFirmwareVersion().empty() && stoi(printer.getFirmwareVersion()) < stoi(firmwareRom)) {
548 |
549 | // Display error
550 | cout << "Printer's firmware is outdated" << endl << "Updating firmware" << endl;
551 |
552 | // Check if updating printer's firmware failed
553 | if(!printer.updateFirmware(firmwareRom.c_str())) {
554 |
555 | // Display error
556 | cout << "Failed to update firmware" << endl;
557 | return 0;
558 | }
559 |
560 | // Display message
561 | cout << "Done updating firmware" << endl;
562 |
563 | // Put printer into firmware mode and exit if set
564 | if(exit) {
565 | printer.sendRequest("Q");
566 | return 0;
567 | }
568 | }
569 |
570 | // Check if printer'a firmware is incompatible
571 | if(!printer.getFirmwareVersion().empty() && stoi(printer.getFirmwareVersion()) < 2015080602) {
572 |
573 | // Display error
574 | cout << "Printer's firmware is incompatible" << endl;
575 | return 0;
576 | }
577 |
578 | // Check if collect printer information failed
579 | if(!printer.collectInformation()) {
580 |
581 | // Display error
582 | cout << "Failed to collect printer information" << endl;
583 | return 0;
584 | }
585 |
586 | // Check if printer Z isn't valid
587 | if(!printer.isZValid()) {
588 |
589 | // Display error
590 | cout << "Printer's Z is invalid" << endl << "Calibrating Z" << endl;
591 |
592 | // Calibrate Z
593 | printer.calibrateZ();
594 | }
595 |
596 | // Check if printer bed orientation isn't valid
597 | if(!printer.isBedOrientationValid()) {
598 |
599 | // Display error
600 | cout << "Printer's bed orientation is invalid" << endl << "Calibrating bed orientation" << endl;
601 |
602 | // Calibrate bed orientation
603 | printer.calibrateBedOrientation();
604 | }
605 | }
606 |
607 | // Check if an output file was provided
608 | if(!outputFile.empty())
609 |
610 | // Process file
611 | printer.processFile(inputFile.c_str(), outputFile.c_str());
612 |
613 | // Otherwise check if an input file was provided
614 | else if(!inputFile.empty())
615 |
616 | // Print file
617 | printer.printFile(inputFile.c_str());
618 |
619 | // Otherwise check if translating
620 | else if(translate)
621 |
622 | // Enter translator mode
623 | printer.translatorMode();
624 |
625 | // Otherwise
626 | else {
627 |
628 | // Display message
629 | cout << "Entering manual G-code mode" << endl << "Enter 'quit' to exit" << endl;
630 |
631 | // Loop forever
632 | while(1) {
633 |
634 | // Get g-code from user
635 | cout << "Enter command: ";
636 | getline(cin, line);
637 |
638 | // End if requested
639 | if(line == "quit")
640 | break;
641 |
642 | // Send g-code to device
643 | do {
644 |
645 | // Get next command if line didn't contain valid g-code
646 | if(!printer.sendRequest(line)) {
647 |
648 | cout << "Failed to parse command" << endl << endl;
649 | break;
650 | }
651 |
652 | // Display command
653 | cout << "Send: " << line << endl;
654 |
655 | // Get valid response
656 | do {
657 | response = printer.receiveResponse();
658 | while(response == "Info:Too small" || response.substr(0, 2) == "T:")
659 | response = printer.receiveResponse();
660 | } while(response.empty());
661 |
662 | // Display response
663 | cout << "Receive: " << response << endl << endl;
664 | } while(response.substr(0, 2) != "ok");
665 | }
666 | }
667 |
668 | // Return 0
669 | return 0;
670 | }
671 |
672 | // Supporting function implementation
673 | void breakHandler(int signal) {
674 |
675 | // Exit so that destructor is called on printer
676 | exit(0);
677 | }
678 |
--------------------------------------------------------------------------------
/printer.h:
--------------------------------------------------------------------------------
1 | // Header gaurd
2 | #ifndef PRINTER_H
3 | #define PRINTER_H
4 |
5 |
6 | // Header files
7 | #include
8 | #include "gcode.h"
9 | #include "vector.h"
10 |
11 | using namespace std;
12 |
13 |
14 | // Definitions
15 |
16 | // Printer bed size limits
17 | #define BED_LOW_MAX_X 113.0
18 | #define BED_LOW_MIN_X 0.0
19 | #define BED_LOW_MAX_Y 107.0
20 | #define BED_LOW_MIN_Y 0.0
21 | #define BED_LOW_MAX_Z 5.0
22 | #define BED_LOW_MIN_Z 0.0
23 | #define BED_MEDIUM_MAX_X 110.2
24 | #define BED_MEDIUM_MIN_X 2.8
25 | #define BED_MEDIUM_MAX_Y 107.0
26 | #define BED_MEDIUM_MIN_Y -6.6
27 | #define BED_MEDIUM_MAX_Z 73.5
28 | #define BED_MEDIUM_MIN_Z BED_LOW_MAX_Z
29 | #define BED_HIGH_MAX_X 82.0
30 | #define BED_HIGH_MIN_X 2.35
31 | #define BED_HIGH_MAX_Y 92.95
32 | #define BED_HIGH_MIN_Y 20.05
33 | #define BED_HIGH_MAX_Z 112.0
34 | #define BED_HIGH_MIN_Z BED_MEDIUM_MAX_Z
35 |
36 | // Filament details
37 | enum filamentTypes {NO_TYPE, ABS, PLA, HIPS, OTHER};
38 |
39 | enum filamentLocations {NO_LOCATION, INTERNAL, EXTERNAL};
40 |
41 | enum filamentColors {BLACK, BLUE, BROWN, GOLD, PINK, GREEN, LIGHT_BLUE, LIGHT_GREEN, MAGENTA, NATURAL, NEON_BLUE, NEON_ORANGE, NEON_YELLOW, ORANGE, PURPLE, RED, SILVER, WHITE, YELLOW = 0x13, OTHER_COLOR, PHANTOM_WHITE, HONEY_CLEAR, FUCHSIA_RED, CHRIMSON_RED, FIRE_ORANGE, MANGO_YELLOW, SHAMROCK_GREEN, COBALT_BLUE, CARRIBEAN_BLUE, MULBERRY_PURPLE = 0x1E, TITANIUM_SILVER, CHARCOAL_BLACK, WHITE_PEARL, CRYSTAL_CLEAR, LIGHT_FUCHSIA, DEEP_CRIMSON, DEEP_SHAMROCK, DEEP_COLBALT, LIGHT_CARRIBEAN = 0x27, DEEP_MULBERRY, SATELLITE_SILVER, DEEP_LEMON, SUNSET_ORANGE, ONYX_BLACK, DRANGON_RED_TOUCH, DRAGON_RED_HOT, ROSE_RED_TOUCH, CORAL_ORANGE_TOUCH, CORAL_ORANGE_WARM, DESPICABLE_YELLOW_TOUCH, MONSTER_GREEN_TOUCH = 0x33, GENIT_BLUE_TOUCH, GENIE_BLUE_ICE, GARGOYLE_BLACK_TOUCH, TRICHROME_NEBULA, TRICHROME_TIGER, FUTURE_ABS = 0x4000, FUTURE_FILAMENT = 0x8000};
42 |
43 |
44 | // Class
45 | class Printer {
46 |
47 | // Public
48 | public:
49 |
50 | /*
51 | Name: Constructor
52 | Purpose: Initializes the variables
53 | */
54 | Printer();
55 |
56 | /*
57 | Name: Destructor
58 | Purpose: Uninitializes the variables
59 | */
60 | ~Printer();
61 |
62 | /*
63 | Name: Connect
64 | Purpose: Connects or reconnects to the printer
65 | */
66 | bool connect();
67 |
68 | /*
69 | Name: Is Bootloader Mode
70 | Purpose: Return is the printer is in bootloader mode
71 | */
72 | bool isBootloaderMode();
73 |
74 | /*
75 | Name: Get Firnware Version
76 | Purpose: Returns the printer's firmware version
77 | */
78 | string getFirmwareVersion();
79 |
80 | /*
81 | Name: Is Firmware Valid
82 | Purpose: Checks if the printer's firmware is valid
83 | */
84 | bool isFirmwareValid();
85 |
86 | /*
87 | Name: Update Firmware
88 | Purpose: Updates the printer's firmware to the provided file
89 | */
90 | bool updateFirmware(const char *file);
91 |
92 | /*
93 | Name: Is Z Valid
94 | Purpose: Checks if the printer's Z is valid
95 | */
96 | bool isZValid();
97 |
98 | /*
99 | Name: Calibrate Z
100 | Purpose: Calibraters the printer's Z
101 | */
102 | void calibrateZ();
103 |
104 | /*
105 | Name: Is Bed Orientation Valid
106 | Purpose: Checks if the printer's bed orientation is valid
107 | */
108 | bool isBedOrientationValid();
109 |
110 | /*
111 | Name: Calibrate orientation
112 | Purpose: Calibraters the printer's bed orientation
113 | */
114 | void calibrateBedOrientation();
115 |
116 | /*
117 | Name: Collect information
118 | Purpose: Collects information from the printer
119 | */
120 | bool collectInformation();
121 |
122 | /*
123 | Name: Send Request
124 | Purpose: Sends data to the printer
125 | */
126 | bool sendRequest(const char *data);
127 | bool sendRequest(const string &data);
128 | bool sendRequest(const Gcode &data);
129 |
130 | /*
131 | Name: Receive Response
132 | Purpose: Receives data to the printer
133 | */
134 | string receiveResponse();
135 |
136 | /*
137 | Name: Process File
138 | Purpose: Processes a g-code file with the set pre-processor parameters
139 | */
140 | bool processFile(const char *inputFile, const char *outputFile = NULL);
141 |
142 | /*
143 | Name: Print File
144 | Purpose: Pre-processed and send a file to the printer
145 | */
146 | bool printFile(const char *file);
147 |
148 | /*
149 | Name: Set Pre-processors
150 | Purpose: Sets which pre-processor stages to use
151 | */
152 | void setValidationPreprocessor();
153 | void setPreparationPreprocessor();
154 | void setWaveBondingPreprocessor();
155 | void setThermalBondingPreprocessor();
156 | void setBedCompensationPreprocessor();
157 | void setBacklashCompensationPreprocessor();
158 | void setFeedRateConversionPreprocessor();
159 | void setCenterModelPreprocessor();
160 |
161 |
162 | /*
163 | Name: Set printer values
164 | Purpose: Sets the printer settings for use in the pre-processor stages
165 | */
166 | void setBacklashX(const string &value);
167 | void setBacklashY(const string &value);
168 | void setBacklashSpeed(const string &value);
169 | void setBedHeightOffset(const string &value);
170 | void setBackRightOffset(const string &value);
171 | void setBackLeftOffset(const string &value);
172 | void setFrontLeftOffset(const string &value);
173 | void setFrontRightOffset(const string &value);
174 | void setFilamentTemperature(const string &value);
175 | void setFilamentType(const string &value);
176 |
177 | /*
178 | Name: Translator Mode
179 | Purpose: Acts as a translator for other software to communicate with the printer
180 | */
181 | void translatorMode();
182 |
183 | /*
184 | Name: Use settings file
185 | Purpose: Reads in printer values from settings file
186 | */
187 | bool useSettingsFile();
188 |
189 | // Private
190 | private:
191 |
192 | // Write to eeprom
193 | bool writeToEeprom(uint16_t address, const uint8_t *data, uint16_t length);
194 | bool writeToEeprom(uint16_t address, uint8_t data);
195 |
196 | // Send data to the printer
197 | bool sendRequestAscii(char data);
198 | bool sendRequestAscii(const char *data);
199 | bool sendRequestAscii(const Gcode &data);
200 | bool sendRequestBinary(const char *data);
201 | bool sendRequestBinary(const Gcode &data);
202 |
203 | // Receive data from the printer
204 | string receiveResponseAscii();
205 | string receiveResponseBinary();
206 |
207 | // CRC32
208 | uint32_t crc32(int32_t offset, const uint8_t *data, int32_t count);
209 |
210 | // Create settings file
211 | bool createSettingsFile();
212 |
213 | // Checks if file to print doesn't go past the printer's boundaries
214 | bool checkPrintDimensions(const char *file, bool overrideCenterModelPreprocessor);
215 |
216 | // Get max
217 | double max(double first, double second);
218 |
219 | // Get bounded temperature
220 | uint16_t getBoundedTemperature(uint16_t temperature);
221 |
222 | // Get distance
223 | double getDistance(const Gcode &firstPoint, const Gcode &secondPoint);
224 |
225 | // Create tack point
226 | Gcode createTackPoint(const Gcode &point, const Gcode &refrence);
227 |
228 | // Is sharp corner
229 | bool isSharpCorner(const Gcode &point, const Gcode &refrence);
230 |
231 | // get current adjustment Z
232 | double getCurrentAdjustmentZ();
233 |
234 | // Calculate plane normal vector
235 | Vector calculatePlaneNormalVector(const Vector &v1, const Vector &v2, const Vector &v3);
236 |
237 | // Generate plane equation
238 | Vector generatePlaneEquation(const Vector &v1, const Vector &v2, const Vector &v3);
239 |
240 | // Get height adjustment required
241 | double getHeightAdjustmentRequired(double x, double y);
242 |
243 | // Get Z from XY plane
244 | double getZFromXYAndPlane(const Vector &point, const Vector &planeABC);
245 |
246 | // Is point in triangle
247 | bool isPointInTriangle(const Vector &pt, const Vector &v1, const Vector &v2, const Vector &v3);
248 |
249 | // Sign
250 | double sign(const Vector &p1, const Vector &p2, const Vector &p3);
251 |
252 | // Pre-processor stages
253 | bool validationPreprocessor(const char *file);
254 | bool preparationPreprocessor(const char *file, bool overrideCornerExcess);
255 | bool waveBondingPreprocessor(const char *file);
256 | bool thermalBondingPreprocessor(const char *file, bool overrideWaveBondingPreprocessor);
257 | bool bedCompensationPreprocessor(const char *file);
258 | bool backlashCompensationPreprocessor(const char *file);
259 | bool feedRateConversionPreprocessor(const char *file);
260 | bool centerModelPreprocessor(const char *file);
261 |
262 | // Use pre-processor stages
263 | bool useValidation;
264 | bool usePreparation;
265 | bool useWaveBonding;
266 | bool useThermalBonding;
267 | bool useBedCompensation;
268 | bool useBacklashCompensation;
269 | bool useFeedRateConversion;
270 | bool useCenterModel;
271 | bool ignorePrintDimensionLimitations;
272 |
273 | // Print values
274 | double maxXExtruderLow;
275 | double maxXExtruderMedium;
276 | double maxXExtruderHigh;
277 | double maxYExtruderLow;
278 | double maxYExtruderMedium;
279 | double maxYExtruderHigh;
280 | double maxZExtruder;
281 | double minXExtruderLow;
282 | double minXExtruderMedium;
283 | double minXExtruderHigh;
284 | double minYExtruderLow;
285 | double minYExtruderMedium;
286 | double minYExtruderHigh;
287 | double minZExtruder;
288 |
289 | // Working folder location
290 | string workingFolderLocation;
291 |
292 | // Bootloader mode
293 | bool bootloaderMode;
294 |
295 | // Valid Z
296 | bool validZ;
297 |
298 | // Valid bed orientation
299 | bool validBedOrientation;
300 |
301 | // Valid firmware
302 | bool validFirmware;
303 |
304 | // Firmware version
305 | string firmwareVersion;
306 |
307 | // Serial number
308 | string serialNumber;
309 |
310 | // Filament information
311 | filamentTypes filamentType;
312 | filamentLocations filamentLocation;
313 | filamentColors filamentColor;
314 | uint16_t filamentTemperature;
315 |
316 | // Bed offsets
317 | double backRightOffset;
318 | double backLeftOffset;
319 | double frontRightOffset;
320 | double frontLeftOffset;
321 | double bedHeightOffset;
322 |
323 | // Backlash settings
324 | double backlashX;
325 | double backlashY;
326 | uint16_t backlashSpeed;
327 |
328 | // Bed orientations
329 | double backRightOrientation;
330 | double backLeftOrientation;
331 | double frontRightOrientation;
332 | double frontLeftOrientation;
333 |
334 | // Status
335 | uint8_t status;
336 |
337 | // File descriptor
338 | int fd;
339 |
340 | // Virtual port descriptor
341 | int vd;
342 |
343 | // Virtual serial port location
344 | string virtualSerialPortLocation;
345 | };
346 |
347 |
348 | #endif
349 |
--------------------------------------------------------------------------------
/vector.cpp:
--------------------------------------------------------------------------------
1 | // Header files
2 | #include
3 | #include "vector.h"
4 |
5 |
6 | // Supporting function implementation
7 | Vector::Vector(double x, double y, double z, double e) {
8 |
9 | // Initialize vector components
10 | this->x = x;
11 | this->y = y;
12 | this->z = z;
13 | this->e = e;
14 | }
15 |
16 | Vector::Vector(Vector &value) {
17 |
18 | // Copy vector components
19 | x = value.x;
20 | y = value.y;
21 | z = value.z;
22 | e = value.e;
23 | }
24 |
25 | double Vector::getLength() const {
26 |
27 | // Return length
28 | return sqrt(x * x + y * y + z * z + e * e);
29 | }
30 |
31 | void Vector::normalize() {
32 |
33 | // Get length
34 | double length = getLength();
35 |
36 | // Normalize components
37 | x /= length;
38 | y /= length;
39 | z /= length;
40 | e /= length;
41 | }
42 |
43 | Vector Vector::operator+(const Vector &addend) const {
44 |
45 | // Initialize variables
46 | Vector vector;
47 |
48 | // Set vector components
49 | vector.x = x + addend.x;
50 | vector.y = y + addend.y;
51 | vector.z = z + addend.z;
52 | vector.e = e + addend.e;
53 |
54 | // Return vector
55 | return vector;
56 | }
57 |
58 | Vector &Vector::operator+=(const Vector &addend) {
59 |
60 | // Set vector components
61 | x += addend.x;
62 | y += addend.y;
63 | z += addend.z;
64 | e += addend.e;
65 |
66 | // Return self
67 | return *this;
68 | }
69 |
70 | Vector Vector::operator-(const Vector &subtrahend) const {
71 |
72 | // Initialize variables
73 | Vector vector;
74 |
75 | // Set vector components
76 | vector.x = x - subtrahend.x;
77 | vector.y = y - subtrahend.y;
78 | vector.z = z - subtrahend.z;
79 | vector.e = e - subtrahend.e;
80 |
81 | // Return vector
82 | return vector;
83 | }
84 |
85 | Vector &Vector::operator-=(const Vector &subtrahend) {
86 |
87 | // Set vector components
88 | x -= subtrahend.x;
89 | y -= subtrahend.y;
90 | z -= subtrahend.z;
91 | e -= subtrahend.e;
92 |
93 | // Return self
94 | return *this;
95 | }
96 |
97 | Vector Vector::operator*(double multiplier) const {
98 |
99 | // Initialize variables
100 | Vector vector;
101 |
102 | // Set vector components
103 | vector.x = x * multiplier;
104 | vector.y = y * multiplier;
105 | vector.z = z * multiplier;
106 | vector.e = e * multiplier;
107 |
108 | // Return vector
109 | return vector;
110 | }
111 |
112 | Vector &Vector::operator*=(double multiplier) {
113 |
114 | // Set vector components
115 | x *= multiplier;
116 | y *= multiplier;
117 | z *= multiplier;
118 | e *= multiplier;
119 |
120 | // Return self
121 | return *this;
122 | }
123 |
124 | Vector Vector::operator/(double divisor) const {
125 |
126 | // Initialize variables
127 | Vector vector;
128 |
129 | // Set vector components
130 | vector.x = x / divisor;
131 | vector.y = y / divisor;
132 | vector.z = z / divisor;
133 | vector.e = e / divisor;
134 |
135 | // Return vector
136 | return vector;
137 | }
138 |
139 | Vector &Vector::operator/=(double divisor) {
140 |
141 | // Set vector components
142 | x /= divisor;
143 | y /= divisor;
144 | z /= divisor;
145 | e /= divisor;
146 |
147 | // Return self
148 | return *this;
149 | }
150 |
151 | const double& Vector::operator[](int index) const {
152 |
153 | // Return indexed value
154 | switch(index) {
155 |
156 | case 0:
157 | return x;
158 | break;
159 |
160 | case 1:
161 | return y;
162 | break;
163 |
164 | case 2:
165 | return z;
166 | break;
167 |
168 | default:
169 | return e;
170 | }
171 | }
172 |
173 | double &Vector::operator[](int index) {
174 |
175 | // Return indexed value
176 | switch(index) {
177 |
178 | case 0:
179 | return x;
180 | break;
181 |
182 | case 1:
183 | return y;
184 | break;
185 |
186 | case 2:
187 | return z;
188 | break;
189 |
190 | default:
191 | return e;
192 | }
193 | }
194 |
195 | Vector &Vector::operator=(const Vector &vector) {
196 |
197 | // Return self if calling on self
198 | if(this == &vector)
199 | return *this;
200 |
201 | // Copy vector components
202 | x = vector.x;
203 | y = vector.y;
204 | z = vector.z;
205 | e = vector.e;
206 |
207 | // Return self
208 | return *this;
209 | }
210 |
--------------------------------------------------------------------------------
/vector.h:
--------------------------------------------------------------------------------
1 | // Header gaurd
2 | #ifndef VECTOR_H
3 | #define VECTOR_H
4 |
5 |
6 | // Vector class
7 | class Vector {
8 |
9 | // Public
10 | public:
11 |
12 | /*
13 | Name: Constructor
14 | Purpose: Allows setting vector components upon creation
15 | */
16 | Vector(double x = 0, double y = 0, double z = 0, double e = 0);
17 |
18 | /*
19 | Name: Copy Constructor
20 | Purpose: Initializes a copy of a vector
21 | */
22 | Vector(Vector &value);
23 |
24 | /*
25 | Name: Get Length
26 | Purpose: Returns length of vector
27 | */
28 | double getLength() const;
29 |
30 | /*
31 | Name: Normalize
32 | Purpose: Normalizes vector components
33 | */
34 | void normalize();
35 |
36 | /*
37 | Name: Addition operator
38 | Purpose: Allows adding vectors
39 | */
40 | Vector operator+(const Vector &addend) const;
41 | Vector &operator+=(const Vector &addend);
42 |
43 | /*
44 | Name: Subtraction operator
45 | Purpose: Allows subtracting vectors
46 | */
47 | Vector operator-(const Vector &subtrahend) const;
48 | Vector &operator-=(const Vector &addend);
49 |
50 | /*
51 | Name: Multiplication operator
52 | Purpose: Allows scaling a vector
53 | */
54 | Vector operator*(double multiplier) const;
55 | Vector &operator*=(double multiplier);
56 |
57 | /*
58 | Name: Division operator
59 | Purpose: Allows shrinking a vector
60 | */
61 | Vector operator/(double divisor) const;
62 | Vector &operator/=(double divisor);
63 |
64 | /*
65 | Name: Subscript operator
66 | Purpose: Allows addressing vector components
67 | */
68 | const double& operator[](int index) const;
69 | double& operator[](int index);
70 |
71 | /*
72 | Name: Assignment operator
73 | Purpose: Allows copying a vector
74 | */
75 | Vector &operator=(const Vector &vector);
76 |
77 | // Vector components
78 | double x;
79 | double y;
80 | double z;
81 | double e;
82 | };
83 |
84 |
85 | #endif
86 |
--------------------------------------------------------------------------------