├── .github └── ISSUE_TEMPLATE │ └── bug_report.md ├── LICENSE ├── README.md ├── bed_mesh_fast.cfg ├── bed_surface.cfg ├── beep.cfg ├── draw.cfg ├── fans.cfg ├── filament.cfg ├── globals.cfg ├── heaters.cfg ├── idle.cfg ├── kinematics.cfg ├── layers.cfg ├── optional ├── bed_mesh.cfg └── lcd_menus.cfg ├── park.cfg ├── pause_resume_cancel.cfg ├── start_end.cfg ├── state.cfg ├── status_events.cfg └── velocity.cfg /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | title: "[BUG]" 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | Before making a report please ensure you've followed the troubleshooting steps at: 10 | https://github.com/jschuh/klipper-macros#troubleshooting 11 | 12 | You can also get general troubleshooting assistance in the Q&A Discussion tab: 13 | https://github.com/jschuh/klipper-macros/discussions/categories/q-a 14 | 15 | **Describe the bug** 16 | Please provide a clear and concise description of the issue. 17 | 18 | **Klipper errors** 19 | Paste the full text of any commands that trigger the error, along with any Klipper error messages and relevant portions of the Klipper logs. 20 | 21 | **Klipper config** 22 | Paste any relevant sections from your Klipper config, or attach the full config if you prefer. Please also note any other macros you are including as part of your config. **Bug reports without attached configs will most likely be closed.** 23 | -------------------------------------------------------------------------------- /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 | 635 | Copyright (C) 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 | Copyright (C) 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 | -------------------------------------------------------------------------------- /bed_mesh_fast.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | # 5 | # Credit to original inspiration: 6 | # https://gist.github.com/ChipCE/95fdbd3c2f3a064397f9610f915f7d02 7 | 8 | [gcode_macro bed_mesh_calibrate_fast] 9 | description: Wraps BED_MESH_CALIBRATE, scaling probe count to specified area. 10 | Usage: See Klipper documentation. 11 | gcode: 12 | # Abort on a bad config. 13 | BED_MESH_CHECK ABORT=1 14 | 15 | # Find the real bed_mesh_calibrate command. 16 | {% set calibrate_cmd = 17 | (printer["gcode_macro list_macros"].macros.bed_mesh_calibrate| 18 | default(["bed_mesh_calibrate"],True))[-1] %} 19 | 20 | {% set km = printer["gcode_macro _km_globals"] %} 21 | {% set probe_mesh_padding = km.probe_mesh_padding %} 22 | {% set probe_min_count = km.probe_min_count %} 23 | {% set probe_count_scale = km.probe_count_scale %} 24 | {% set bed_mesh = printer.configfile.settings.bed_mesh %} 25 | 26 | # TODO: Handle the math for a delta bed. 27 | {%if "mesh_radius" not in bed_mesh and 28 | "MESH_RADIUS" not in params %} 29 | {% set safe_min_x = bed_mesh.mesh_min[0] %} 30 | {% set safe_min_y = bed_mesh.mesh_min[1] %} 31 | {% set safe_max_x = bed_mesh.mesh_max[0] %} 32 | {% set safe_max_y = bed_mesh.mesh_max[1] %} 33 | 34 | # Always bound MESH_MIN and MESH_MAX. 35 | {% if "MESH_MIN" in params %} 36 | {% set mesh_min_x = (params.MESH_MIN.split(",")[0]|float - 37 | probe_mesh_padding, safe_min_x)|max %} 38 | {% set mesh_min_y = (params.MESH_MIN.split(",")[1]|float - 39 | probe_mesh_padding, safe_min_y)|max %} 40 | {% else %} 41 | {% set mesh_min_x = safe_min_x %} 42 | {% set mesh_min_y = safe_min_y %} 43 | {% endif %} 44 | {% if "MESH_MAX" in params %} 45 | {% set mesh_max_x = (params.MESH_MAX.split(",")[0]|float + 46 | probe_mesh_padding, safe_max_x)|min %} 47 | {% set mesh_max_y = (params.MESH_MAX.split(",")[1]|float + 48 | probe_mesh_padding, safe_max_y)|min %} 49 | {% else %} 50 | {% set mesh_max_x = safe_max_x %} 51 | {% set mesh_max_y = safe_max_y %} 52 | {% endif %} 53 | 54 | {% set probe_count = bed_mesh.probe_count if not params.PROBE_COUNT else 55 | params.PROBE_COUNT.split(",")|map('int')|list %} 56 | # Don't scale the probe count if one was explicitly provided. 57 | {% if "PROBE_COUNT" not in params %} 58 | {% set max_x_probes = probe_count[0] %} 59 | {% set max_y_probes = probe_count[-1] %} 60 | 61 | {% set x_probes = (max_x_probes * (mesh_max_x - mesh_min_x) / 62 | (safe_max_x - safe_min_x) * probe_count_scale) 63 | | round(0) | int %} 64 | {% set x_probes = ((x_probes, probe_min_count)|max, max_x_probes)|min %} 65 | 66 | {% set y_probes = (max_y_probes * (mesh_max_y - mesh_min_y ) / 67 | (safe_max_y - safe_min_y) * probe_count_scale ) 68 | | round(0) | int %} 69 | {% set y_probes = ((y_probes, probe_min_count)|max, max_y_probes)|min %} 70 | # Add probes for bicubic if one axis has too many probes for lagrange. 71 | {% if x_probes > 6 and y_probes < 4 %} 72 | {% set y_probes = 4 %} 73 | {% elif y_probes > 6 and x_probes < 4 %} 74 | {% set x_probes = 4 %} 75 | {% endif %} 76 | {% set probe_count = [x_probes,y_probes] %} 77 | {% elif probe_count|length == 1 %} 78 | {% set dummy = probe_count.append(probe_count[0]) %} 79 | {% endif %} 80 | 81 | # If the config includes a relative_reference_index then we need to find the 82 | # point in the new mesh that's closest to the index point in the mesh that 83 | # the config would have generated. 84 | # TODO: Could also adjust the mesh parameters in here to ensure it includes 85 | # the original index point, but that would be extra work and would cause 86 | # slower probes if the mesh needs to be expanded to include the point. 87 | {% if "relative_reference_index" in bed_mesh %} 88 | {% set row = (bed_mesh.relative_reference_index / bed_mesh.probe_count[0] 89 | )|int%} 90 | {% set rrf_x = (((safe_max_x - safe_min_x) / 91 | (bed_mesh.probe_count[0] - 1))|round(2, 'floor')) * 92 | (bed_mesh.relative_reference_index % 93 | bed_mesh.probe_count[-1]) %} 94 | {% if row % 2 %} 95 | {% set rrf_x = safe_max_x - rrf_x %} 96 | {% else %} 97 | {% set rrf_x = safe_min_x + rrf_x %} 98 | {% endif %} 99 | {% set rrf_y = (((safe_max_y - safe_min_y) / 100 | (bed_mesh.probe_count[-1] - 1))|round(2, 'floor')) * 101 | row + safe_min_x %} 102 | {% set x_dist = (mesh_max_x - mesh_min_x) / (probe_count[0] - 1) %} 103 | {% set y_dist = (mesh_max_y - mesh_min_y) / (probe_count[1] - 1) %} 104 | {% set rrf = {'x':0, 'y':0, 'dist':safe_max_x**2+safe_max_y**2,'pos':0} %} 105 | {% for row in range(probe_count[1])%} 106 | {% for col in range(probe_count[0])%} 107 | {% if row % 2 %} 108 | {% set x = mesh_max_x - col * x_dist %} 109 | {% else %} 110 | {% set x = mesh_min_x + col * x_dist %} 111 | {% endif %} 112 | {% set y = mesh_min_y + row * y_dist %} 113 | {% set dist = ((x - rrf_x)**2 + (y - rrf_y)**2)**0.5 %} 114 | {% if dist < rrf.dist %} 115 | {% set dummy = rrf.__setitem__("dist", dist) %} 116 | {% set dummy = rrf.__setitem__("x", x) %} 117 | {% set dummy = rrf.__setitem__("y", y) %} 118 | {% set dummy = rrf.__setitem__("pos", row * probe_count[1] + col) %} 119 | {% endif %} 120 | {% endfor %} 121 | {% endfor %} 122 | {% if rrf.x != rrf_x or rrf.y != rrf_y %} 123 | {action_respond_info("relative_reference_index remapped to" 124 | " %d (%.2f,%.2f) from %d (%.2f,%.2f)" % 125 | (rrf.pos, rrf.x, rrf.y, 126 | bed_mesh.relative_reference_index, rrf_x, rrf_y))} 127 | {% endif %} 128 | {% set dummy = params.__setitem__("RELATIVE_REFERENCE_INDEX", rrf.pos) %} 129 | {% endif %} 130 | 131 | {% set dummy = params.__setitem__("MESH_MIN", mesh_min_x~","~mesh_min_y) %} 132 | {% set dummy = params.__setitem__("MESH_MAX", mesh_max_x~","~mesh_max_y) %} 133 | {% set dummy = params.__setitem__("PROBE_COUNT", probe_count|join(',')) %} 134 | # Force bicubic if we've exceeded the max for lagrange. 135 | {% if probe_count[0] > 6 or probe_count[1]|default(0) > 6 %} 136 | {% set dummy = params.__setitem__("ALGORITHM", "bicubic") %} 137 | {% endif %} 138 | # Warn on bad parameters that were fixed. 139 | {% if "MESH_MIN" in params or "MESH_MAX" in params %} 140 | BED_MESH_CHECK {rawparams} 141 | {% endif %} 142 | {% else %} 143 | # Mesh limits may be out of bounds, so strip them from the fallback path. 144 | {% set dummy = params.__delitem__("MESH_MIN") %} 145 | {% set dummy = params.__delitem__("MESH_MAX") %} 146 | {% endif %} 147 | # Abort on bad parameters. 148 | {% if "MESH_MIN" in params or "MESH_MAX" in params %} 149 | BED_MESH_CHECK ABORT=1{%for k in params%}{' '~k~'="'~params[k]~'"'}{% 150 | endfor%} 151 | {% endif %} 152 | _KM_PRINT_STATUS ACTION=PUSH_STATUS 153 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=meshing 154 | {calibrate_cmd}{%for k in params%}{' '~k~'="'~params[k]~'"'}{%endfor%} 155 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=pop_status 156 | 157 | [gcode_macro bed_mesh_check] 158 | description: Warns if bed_mesh config may generate an invalid mesh. 159 | Usage: BED_MESH_CHECK [MESH_MIN=] [MESH_MAX=] [ABORT=<0|1>] 160 | gcode: 161 | {% if printer.bed_mesh is defined %} 162 | {% set action = action_respond_info if params.ABORT|default(0)|int == 0 else 163 | action_raise_error %} 164 | {% set settings = printer.configfile.settings %} 165 | {% set x_min = settings.stepper_x.position_min %} 166 | {% set y_min = settings.stepper_y.position_min %} 167 | {% set x_max = settings.stepper_x.position_max %} 168 | {% set y_max = settings.stepper_y.position_max %} 169 | 170 | {% set label = "[bed_mesh] config" %} 171 | {% if "MESH_MIN" in params %} 172 | {% set label = "BED_MESH_CALIBRATE params" %} 173 | {% set mesh_min_x = params.MESH_MIN.split(",")[0]|float %} 174 | {% set mesh_min_y = params.MESH_MIN.split(",")[1]|float %} 175 | {% else %} 176 | {% set mesh_min_x = settings.bed_mesh.mesh_min[0] %} 177 | {% set mesh_min_y = settings.bed_mesh.mesh_min[1] %} 178 | {% endif %} 179 | {% if "MESH_MAX" in params %} 180 | {% set label = "BED_MESH_CALIBRATE params" %} 181 | {% set mesh_max_x = params.MESH_MAX.split(",")[0]|float %} 182 | {% set mesh_max_y = params.MESH_MAX.split(",")[1]|float %} 183 | {% else %} 184 | {% set mesh_max_x = settings.bed_mesh.mesh_max[0] %} 185 | {% set mesh_max_y = settings.bed_mesh.mesh_max[1] %} 186 | {% endif %} 187 | 188 | {% if "bltouch" in settings %} 189 | {% set x_offset = settings.bltouch.x_offset %} 190 | {% set y_offset = settings.bltouch.y_offset %} 191 | {% set probe = "bltouch" %} 192 | {% elif "probe" in settings %} 193 | {% set x_offset = settings.probe.x_offset %} 194 | {% set y_offset = settings.probe.y_offset %} 195 | {% set probe = "probe" %} 196 | {% else %} 197 | {% set x_offset = 0.0 %} 198 | {% set y_offset = 0.0 %} 199 | {% endif %} 200 | 201 | {% set output = [] %} 202 | {% set warn = 203 | "* mesh_%s (%f, %f) adjusted by " ~ probe ~ 204 | ".%s_offset (%f) can move out of range for " 205 | "stepper_%s.position_%s (%f)." %} 206 | {% if x_offset > 0 and (mesh_min_x - x_offset) < x_min %} 207 | {% set dummy = output.append(warn % ('min', mesh_min_x, mesh_min_y, 208 | 'x', x_offset, 'x', 'min', x_min)) %} 209 | {% elif x_offset < 0 and (mesh_max_x - x_offset) > x_max %} 210 | {% set dummy = output.append(warn % ('max', mesh_max_x, mesh_max_y, 211 | 'x', x_offset, 'x', 'max', x_max)) %} 212 | {% endif %} 213 | {% if y_offset > 0 and (mesh_min_y - y_offset) < y_min %} 214 | {% set dummy = output.append(warn % ('min', mesh_min_x, mesh_min_y, 215 | 'y', y_offset, 'y', 'min', y_min)) %} 216 | {% elif y_offset < 0 and (mesh_max_y - y_offset) > y_max %} 217 | {% set dummy = output.append(warn % ('max', mesh_max_x, mesh_max_y, 218 | 'y', y_offset, 'y', 'max', y_max)) %} 219 | {% endif %} 220 | 221 | {% if output %} 222 | { action( 223 | "Warning: The following issue(s) were detected in your " ~ label ~ 224 | ":\n" ~ output|join("\n")) } 225 | {% endif %} 226 | {% endif %} 227 | -------------------------------------------------------------------------------- /bed_surface.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | # 5 | # Credit to original inspiration: 6 | # https://klipper.discourse.group/t/saving-and-adjusting-per-build-surface-z-offsets/696 7 | 8 | [gcode_macro _apply_bed_surface_offset] 9 | gcode: 10 | {% set surfaces = printer.save_variables.variables.bed_surfaces %} 11 | {% if surfaces.active %} 12 | SET_SURFACE_ACTIVE SURFACE={surfaces.active} 13 | {% endif %} 14 | 15 | [gcode_macro _init_surfaces] 16 | gcode: 17 | {% set km = printer["gcode_macro _km_globals"] %} 18 | {% if "bed_surfaces" in printer.save_variables.variables %} 19 | {% set old_surfaces = printer.save_variables.variables.bed_surfaces %} 20 | {% else %} 21 | {% set old_surfaces = { 'active' : '', 'available' : {} } %} 22 | {% endif %} 23 | {% set settings = printer.configfile.settings %} 24 | {% set new_probe_z = (settings.probe | default(settings.bltouch) | 25 | default(settings.smart_effector) | default({}) 26 | ).z_offset|default(0.0)|float %} 27 | {% set new_endstop_z = (settings.stepper_z | default({})).position_endstop | 28 | default(0.0)|float %} 29 | {% if 'endstop_z' not in old_surfaces %} 30 | {% set dummy = old_surfaces.__setitem__('endstop_z', new_endstop_z) %} 31 | {% endif %} 32 | {% if 'probe_z' not in old_surfaces %} 33 | {% set dummy = old_surfaces.__setitem__('probe_z', new_probe_z) %} 34 | {% endif %} 35 | {% set surfaces = { 'active' : '', 'available' : {}, 36 | 'endstop_z' : old_surfaces.endstop_z, 37 | 'probe_z' : old_surfaces.probe_z } %} 38 | {% for s in km.bed_surfaces %} 39 | {% set s = s.split()|join(' ')|lower %} 40 | {% if s|length > km.bed_surface_max_name_length or 41 | s|list|select("in", " \r\n\"\'")|list %} 42 | {action_raise_error('Invalid surface name "%s". Name must be %d or fewer ' 43 | 'characters and must not include space or quotation characters' 44 | | format(s, km.bed_surface_max_name_length))} 45 | {% endif %} 46 | {% if s in old_surfaces.available %} 47 | {% set dummy = surfaces.available.__setitem__(s, 48 | old_surfaces.available[s]) %} 49 | {% else %} 50 | {% set dummy = surfaces.available.__setitem__(s, {'offset' : 0.0}) %} 51 | {% endif %} 52 | {% endfor %} 53 | {% if old_surfaces.active in surfaces.available %} 54 | {% set dummy = surfaces.__setitem__('active', old_surfaces.active) %} 55 | {% elif km.bed_surfaces %} 56 | {% set dummy = surfaces.__setitem__('active', km.bed_surfaces[0]|lower) %} 57 | {% endif %} 58 | SAVE_VARIABLE VARIABLE=bed_surfaces VALUE="{surfaces}" 59 | _APPLY_BED_SURFACE_OFFSET 60 | {% if new_probe_z != surfaces.probe_z or 61 | new_endstop_z != surfaces.endstop_z %} 62 | { action_respond_info( 63 | 'Z probe offset or endstop position changed. Run ADJUST_SURFACE_OFFSETS ' 64 | 'to adjust the offset for all saved surfaces by the change differential, ' 65 | 'or run ADJUST_SURFACE_OFFSETS IGNORE=1 to hide this message without ' 66 | 'making changes.') } 67 | {% endif %} 68 | 69 | [gcode_macro adjust_surface_offsets] 70 | description: Adjusts surface offsets to account for changes in the Z endstop 71 | position or probe Z offset. 72 | Usage: ADJUST_SURFACE_OFFSETS [IGNORE] 73 | gcode: 74 | {% set surfaces = printer.save_variables.variables.bed_surfaces %} 75 | {% set settings = printer.configfile.settings %} 76 | {% set new_probe_z = (settings.probe | default(settings.bltouch) | 77 | default(settings.smart_effector) | default({}) 78 | ).z_offset|default(0.0)|float %} 79 | {% set new_endstop_z = (settings.stepper_z | default({})).position_endstop | 80 | default(0.0)|float %} 81 | {% set diff = (surfaces.probe_z - new_probe_z + 82 | surfaces.endstop_z - new_endstop_z)|round(6) %} 83 | {% if not params.IGNORE|default(0)|int %} 84 | {% for s in surfaces.available %} 85 | {% set offset = (surfaces.available[s].offset - diff)|round(6) %} 86 | {% set dummy = surfaces.available.__setitem__(s, {'offset' : offset}) %} 87 | {% endfor %} 88 | { action_respond_info("All bed surfaces now adjusted by %1.4f"| 89 | format(diff))} 90 | {% elif diff != 0 %} 91 | { action_respond_info("Status cleared without adjustment") } 92 | {% endif %} 93 | {% set dummy = surfaces.__setitem__('endstop_z', new_endstop_z| round(6)) %} 94 | {% set dummy = surfaces.__setitem__('probe_z', new_probe_z|round(6)) %} 95 | SAVE_VARIABLE VARIABLE=bed_surfaces VALUE="{surfaces}" 96 | 97 | [gcode_macro set_surface_offset] 98 | description: Sets the offset for a surface and moves the toolhead (if homed). 99 | Usage: SET_SURFACE_OFFSET [OFFSET=] [SURFACE=] 100 | gcode: 101 | {% set surfaces = printer.save_variables.variables.bed_surfaces %} 102 | {% set SURFACE = params.SURFACE|default(surfaces.active)|lower %} 103 | {% if SURFACE not in surfaces.available %} 104 | { action_raise_error("Bed surface %s does not exist." | format(SURFACE)) } 105 | {% endif %} 106 | {% set active = surfaces.available[SURFACE] %} 107 | # If no offset is provided just print out the current offset. 108 | {% set OFFSET = params.OFFSET|default(active.offset)|float %} 109 | {% if OFFSET != active.offset %} 110 | {% set dummy = surfaces.available[SURFACE].__setitem__("offset", OFFSET) %} 111 | SAVE_VARIABLE VARIABLE=bed_surfaces VALUE="{surfaces}" 112 | {% if SURFACE == surfaces.active %} 113 | _km_set_gcode_offset_base Z="{OFFSET}" MOVE={ 114 | 1 if printer.toolhead.homed_axes == 'xyz' else 0} 115 | {% endif %} 116 | {% endif %} 117 | { action_respond_info("Bed surface: %s Offset: %.3f" 118 | | format(SURFACE, OFFSET)) } 119 | # Dummy argument block for Mainsail 120 | {% set dummy = None if True else " 121 | {% set dummy = params.SURFACE|default(active surface) %} 122 | {% set dummy = params.OFFSET|default(none)|float %} 123 | " %} # End argument block for Mainsail 124 | 125 | [gcode_macro set_surface_active] 126 | description: Sets the active bed surface and moves the toolhead (if homed). If 127 | no SURFACE argument is present the available surfaces are listed and the 128 | active one is preceded by a "*". 129 | Usage: SET_SURFACE_ACTIVE [SURFACE=] 130 | gcode: 131 | {% set surfaces = printer.save_variables.variables.bed_surfaces %} 132 | {% if "SURFACE" in params %} 133 | {% set SURFACE = params.SURFACE|lower %} 134 | {% if SURFACE not in surfaces.available %} 135 | { action_raise_error("Bed surface %s does not exist." | format(SURFACE)) } 136 | {% endif %} 137 | {% if SURFACE != surfaces.active %} 138 | {% set dummy = surfaces.__setitem__("active", SURFACE) %} 139 | SAVE_VARIABLE VARIABLE=bed_surfaces VALUE="{surfaces}" 140 | {% endif %} 141 | {% if surfaces.available[SURFACE].offset != 142 | printer.gcode_move.homing_origin.z %} 143 | _km_set_gcode_offset_base Z="{surfaces.available[SURFACE].offset 144 | }" MOVE={1 if printer.toolhead.homed_axes == 'xyz' else 0} 145 | {% endif %} 146 | {action_respond_info("Active bed surface: %s; offset: %.3f" 147 | | format(SURFACE, surfaces.available[SURFACE].offset))} 148 | {% else %} 149 | {% set output = [] %} 150 | {% for s in surfaces.available|list|sort %} 151 | {% set dummy = output.append("%s %s - offset: %.3f" 152 | | format("*" if s == surfaces.active else " ", 153 | s, surfaces.available[s].offset)) %} 154 | {% endfor %} 155 | {action_respond_info(output|join('\n'))} 156 | {% endif %} 157 | # Dummy argument block for Mainsail 158 | {% set dummy = None if True else " 159 | {% set dummy = params.SURFACE|default(none) %} 160 | " %} # End argument block for Mainsail 161 | 162 | [gcode_macro set_gcode_offset] 163 | description: Wraps SET_GCODE_OFFSET to update the current bed sheet offset. 164 | Usage: SET_GCODE_OFFSET [X=|X_ADJUST=] 165 | [Y=|Y_ADJUST=] 166 | [Z=|Z_ADJUST=] 167 | [MOVE=1 [MOVE_SPEED=]] 168 | rename_existing: _KM_SET_GCODE_OFFSET_BASE 169 | gcode: 170 | {% set surfaces = printer.save_variables.variables.bed_surfaces %} 171 | {% if surfaces.active and 172 | not printer["gcode_macro _km_save_state"].is_ephemeral %} 173 | {% set Z = params.Z|default(0.0)|float|round(6) %} 174 | {% set Z_ADJUST = params.Z_ADJUST|default(0.0)|float %} 175 | {% if 'Z' in params and 176 | Z != surfaces.available[surfaces.active].offset %} 177 | {% set dummy = surfaces.available[surfaces.active].__setitem__("offset", 178 | Z) %} 179 | SAVE_VARIABLE VARIABLE=bed_surfaces VALUE="{surfaces}" 180 | {% elif Z_ADJUST != 0.0 %} 181 | {% set dummy = surfaces.available[surfaces.active].__setitem__( 182 | "offset", (Z_ADJUST + printer.gcode_move.homing_origin.z)|round(6)) %} 183 | SAVE_VARIABLE VARIABLE=bed_surfaces VALUE="{surfaces}" 184 | {% endif %} 185 | {% endif %} 186 | _km_set_gcode_offset_base{% for k in params%}{' '~k~'="'~params[k]~'"' 187 | }{% endfor %} 188 | 189 | [gcode_macro make_surface_mesh] 190 | description: Generates and saves a mesh to automatically load in PRINT_START. 191 | Usage: MAKE_SURFACE_MESH [SURFACE=] [BED=] 192 | [EXTRUDER=] 193 | [MESH_MULTIPLIER=] 194 | [bed_mesh_calibrate parameters] 195 | gcode: 196 | {% set surfaces = printer.save_variables.variables.bed_surfaces %} 197 | {% set SURFACE = params.SURFACE|default(surfaces.active)|lower %} 198 | {% if SURFACE not in surfaces.available %} 199 | { action_raise_error("Bed surface %s does not exist." | format(SURFACE)) } 200 | {% endif %} 201 | {% set dummy = params.__setitem__('PROFILE', SURFACE) %} 202 | {% set BED = params.BED|default(70) | int %} 203 | {% set km = printer["gcode_macro _km_globals"] %} 204 | {% set EXTRUDER = params.EXTRUDER|default(km.start_extruder_probing_temp) | 205 | int %} 206 | {% set MESH_MULTIPLIER = (params.MESH_MULTIPLIER|default(2)|int, 1)|max %} 207 | 208 | M104 S{EXTRUDER} 209 | M140 S{BED} 210 | G28 211 | 212 | # Adjust offset before running mesh 213 | {% if surfaces.available[SURFACE].offset != 214 | printer.gcode_move.homing_origin.z %} 215 | _km_set_gcode_offset_base Z="{surfaces.available[SURFACE].offset 216 | }" MOVE=1 217 | {% endif %} 218 | 219 | # If no offset is provided just print out the current offset. 220 | {% if BED > 0 %} 221 | {action_respond_info("Stabilizing bed at %iC" | format(BED,))} 222 | _KM_PARK_IF_NEEDED HEATER=heater_bed RANGE=0.5 223 | {% if BED < (printer.heater_bed.temperature - 0.2) %} 224 | M190 R{BED} 225 | G4 P{((km.start_bed_heat_delay * 10, 30000)|min, 226 | km.start_bed_heat_delay)|max} 227 | {% else %} 228 | G4 P{km.start_bed_heat_delay} 229 | {% endif %} 230 | M190 R{BED} 231 | {% endif %} 232 | 233 | {% if EXTRUDER > 0 %} 234 | _KM_PARK_IF_NEEDED HEATER={printer.toolhead.extruder} RANGE=2 235 | M109 R{km.start_extruder_probing_temp} 236 | {% endif %} 237 | 238 | {% if km.start_home_z_at_temp and not bed_at_target %} 239 | G28 Z # Re-home only the Z axis now that the bed has stabilized. 240 | {% endif %} 241 | 242 | # Scale the mesh grid size while preserving the original points and relative 243 | # reference index. 244 | {% set probe_count = printer.configfile.settings.bed_mesh.probe_count 245 | if not params.PROBE_COUNT else 246 | params.PROBE_COUNT.split(",")|map('int')|list %} 247 | {% set dummy = params.__setitem__('PROBE_COUNT',( 248 | MESH_MULTIPLIER * (probe_count[0] - 1) + 1, 249 | MESH_MULTIPLIER * (probe_count[-1] - 1) + 1,)|join(',')) %} 250 | 251 | BED_MESH_CLEAR 252 | BED_MESH_CALIBRATE_FAST {% 253 | for k in params|reject('in',['BED','SURFACE'])|list %}{ 254 | ' ' ~ k ~ '=' ~ params[k] }{% endfor %} 255 | SAVE_CONFIG 256 | 257 | # Dummy argument block for Mainsail 258 | {% set dummy = None if True else " 259 | {% set dummy = params.MESH_MULTIPLIER|default(2) %} 260 | {% set dummy = params.SURFACE|default(active surface) %} 261 | " %} # End argument block for Mainsail 262 | 263 | [gcode_macro load_surface_mesh] 264 | description: Attempts to load a mesh associated with the specified surface. 265 | Usage: LOAD_SURFACE_MESH [SURFACE=] 266 | gcode: 267 | {% set surfaces = printer.save_variables.variables.bed_surfaces %} 268 | {% set SURFACE = params.SURFACE|default(surfaces.active)|lower %} 269 | {% if SURFACE != surfaces.active %} 270 | SET_SURFACE_ACTIVE SURFACE={SURFACE} 271 | {% endif %} 272 | 273 | {% if SURFACE in printer.bed_mesh.profiles %} 274 | {% set mesh = printer.bed_mesh.profiles[SURFACE].mesh_params %} 275 | {% set default = printer.configfile.settings.bed_mesh %} 276 | # Ensure the saved mesh has at least the resolution of the default. 277 | {% if mesh.min_x <= (default.mesh_min[0] + 0.5) and 278 | mesh.min_y <= (default.mesh_min[1] + 0.5) and 279 | mesh.max_x >= (default.mesh_max[0] - 0.5) and 280 | mesh.max_y >= (default.mesh_max[1] - 0.5) and 281 | mesh.x_count >= default.probe_count[0] and 282 | mesh.y_count >= default.probe_count[-1] %} 283 | # Skip the bed level if we have a good profile. 284 | BED_MESH_PROFILE LOAD={SURFACE} 285 | {action_respond_info("Loaded mesh: %s" | format(SURFACE,))} 286 | {% endif %} 287 | {% endif %} 288 | -------------------------------------------------------------------------------- /beep.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | [gcode_macro m300] 5 | description: Emits and audible beep. 6 | Usage: M300 [P] [S] 7 | gcode: 8 | {% set settings = printer.configfile.settings %} 9 | {% if "output_pin beeper" in printer or "pwm_cycle_time beeper" in printer %} 10 | {% set P = (params.P|default(100)|int, 0)|max %} 11 | {% set S = (params.S|default(1000)|int, 1)|max %} 12 | SET_PIN PIN=beeper VALUE={% if "output_pin beeper" in settings %}1{%else%}{ 13 | settings["pwm_cycle_time beeper"].scale|default(1.0) * 0.5 14 | } CYCLE_TIME={ 1.0 / S }{% endif %} 15 | G4 P{P} 16 | SET_PIN PIN=beeper VALUE=0 17 | {% else %} 18 | {action_respond_info( 19 | "M300 is disabled. To enable create an [pwm_cycle_time beeper] config.")} 20 | {% endif %} 21 | 22 | [gcode_macro _km_beep_if_available] 23 | description: Wraps beeper to avoid console spam 24 | gcode: 25 | {% if "output_pin beeper" in printer or "pwm_cycle_time beeper" in printer %} 26 | {% for i in range(params.BEEPS|int) %} 27 | M300 P100 28 | G4 P200 29 | {% endfor %} 30 | {% endif %} 31 | -------------------------------------------------------------------------------- /draw.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro set_draw_params] 6 | description: Sets the default parameters used by DRAW_LINE_TO. 7 | Usage: SET_DRAW_PARAMS [HEIGHT=] [WIDTH=] [FEEDRATE=] 8 | variable_height: 0.2 9 | variable_width: 0.0 # Set to nozzle_diameter at startup 10 | variable_feedrate: 1200 11 | gcode: 12 | {% set dparams = printer["gcode_macro set_draw_params"] %} 13 | {% for k in params %} 14 | {% set kl = k|lower %} 15 | {% if kl in dparams %} 16 | {% if dparams[kl] is float %} 17 | {% set v = params[k]|float %} 18 | {% elif dparams[kl] is integer %} 19 | {% set v = params[k]|int %} 20 | {% endif %} 21 | SET_GCODE_VARIABLE MACRO=set_draw_params VARIABLE={kl} VALUE="{v}" 22 | {% endif %} 23 | {% endfor %} 24 | 25 | [gcode_macro draw_line_to] 26 | description: Extrudes a line of filament at the specified height and width from 27 | the current coordinate to the supplied XY coordinate. (The height is used only 28 | to calculate the extrusion volume.) 29 | Usage: DRAW_LINE_TO [X=] [Y=] [HEIGHT=] [WIDTH=] 30 | [FEEDRATE=] 31 | gcode: 32 | {% set dparams = printer["gcode_macro set_draw_params"] %} 33 | {% set position = printer.gcode_move.gcode_position %} 34 | {% set X = params.X|default(position.x)|float %} 35 | {% set Y = params.Y|default(position.y)|float %} 36 | {% set HEIGHT = params.HEIGHT|default(dparams.height)|float %} 37 | {% set WIDTH = params.WIDTH|default(dparams.width)|float %} 38 | {% set FEEDRATE = params.FEEDRATE|default(dparams.feedrate)|int %} 39 | 40 | {% set distance = ((X - position.x) ** 2 + (Y - position.y) ** 2) ** 0.5 %} 41 | 42 | {% set filament_area = 3.14159 * 43 | (printer.configfile.settings[ 44 | printer.toolhead.extruder].filament_diameter ** 2) / 4 %} 45 | {% set E = distance * ((WIDTH * HEIGHT) / filament_area) %} 46 | 47 | # Use the base state call here so offset adjustments get persisted. 48 | _KM_SAVE_GCODE_STATE NAME=_KM_PURGE 49 | G90 50 | G92 E0.0 51 | G1 X{"%.3f" % X} Y{"%.3f" % Y} E{"%.5f" % E} F{FEEDRATE} 52 | _KM_RESTORE_GCODE_STATE NAME=_KM_PURGE MOVE=0 53 | 54 | [gcode_macro draw_purge_line] 55 | description: Purges the specified length of filament as a line (or rows of 56 | lines) in front of the supplied print area. If no print area is specified the 57 | purge lines are drawn at the front edge of the maximum printable area. If no 58 | printable area is set it defaults to the XY axis limits. 59 | Usage: DRAW_PURGE_LINE [PRINT_MIN=] [PRINT_MAX=] [HEIGHT=] 60 | [WIDTH=] [LENGTH=] 61 | gcode: 62 | # TODO: Make this work for delta printers. 63 | {% set km = printer["gcode_macro _km_globals"] %} 64 | {% set origin = printer.gcode_move.homing_origin %} 65 | {% set dummy = km.__setitem__('print_min', (km.print_min[0] - origin.x, 66 | km.print_min[1] - origin.y)) %} 67 | {% set dummy = km.__setitem__('print_max', (km.print_max[0] - origin.x, 68 | km.print_max[1] - origin.y)) %} 69 | 70 | {% if "PRINT_MIN" in params %} 71 | {% set PRINT_MIN = ( 72 | (params.PRINT_MIN.split(",")[0]|float, km.print_min[0])|max, 73 | (params.PRINT_MIN.split(",")[1]|float, km.print_min[1])|max 74 | ) %} 75 | {% else %} 76 | {% set PRINT_MIN = km.print_min %} 77 | {% endif %} 78 | {% if "PRINT_MAX" in params %} 79 | {% set PRINT_MAX = ( 80 | (params.PRINT_MAX.split(",")[0]|float, km.print_max[0])|min, 81 | (params.PRINT_MAX.split(",")[1]|float, km.print_max[1])|min 82 | ) %} 83 | {% else %} 84 | {% set PRINT_MAX = km.print_max %} 85 | {% endif %} 86 | {% set extruder = printer.toolhead.extruder|string %} 87 | {% set HEIGHT = params.HEIGHT|default( 88 | printer.configfile.settings[extruder].nozzle_diameter * 0.625)|float %} 89 | {% set WIDTH = params.WIDTH|default( 90 | printer.configfile.settings[extruder].nozzle_diameter * 1.25)|float %} 91 | {% set LENGTH = params.LENGTH|default(km.start_purge_length)|float %} 92 | 93 | {% set dparams = printer["gcode_macro set_draw_params"] %} 94 | {% set filament_area = 3.14159 * 95 | (printer.configfile.settings[extruder].filament_diameter ** 2) / 4 %} 96 | {% set purge_length = (LENGTH * filament_area) / (WIDTH * HEIGHT) %} 97 | {% set printable_length = PRINT_MAX[0] - PRINT_MIN[0] %} 98 | {% set purge_rows = (purge_length / printable_length)|round(0,'ceil')|int %} 99 | {% set printable_inset = (printable_length - purge_length / purge_rows) / 2 %} 100 | {% set PRINT_MIN = (PRINT_MIN[0] + printable_inset, PRINT_MIN[1]) %} 101 | {% set PRINT_MAX = (PRINT_MAX[0] - printable_inset, PRINT_MAX[1]) %} 102 | # This will purge into the print area when the bed is filled to the front. 103 | {% set y_start = (km.print_min[1], PRINT_MIN[1] - km.start_purge_clearance - 104 | (purge_rows + 0.5) * WIDTH )|max %} 105 | G90 106 | # Jog to the front left corner to get strings out of the print area. 107 | G1 X{"%.3f" % (PRINT_MIN[0] - 30, km.print_min[0])|max} Y{ 108 | "%.3f" % (y_start - 10, km.print_min[1])|max} F{km.travel_speed_xy} 109 | # Move to the starting corner. 110 | G1 X{"%.3f" % (PRINT_MIN[0] - km.start_purge_prime_length / WIDTH, 111 | km.print_min[0])|max} Y{"%.3f" % y_start} Z{ 112 | "%.4f" % HEIGHT} F{km.travel_speed_xy} 113 | # Prime the extruder before beginning the purge lines. 114 | G92 E0.0 115 | # Move slowly during priming to prevent excessive blobbing 116 | G1 X{"%.3f" % PRINT_MIN[0]} E{"%.3f" % km.start_purge_prime_length 117 | } F{km.load_priming_speed} 118 | G92 E0.0 119 | # Purge. 120 | {% for n in range(purge_rows - 1) %} 121 | {% set x_pos = PRINT_MIN[0] if n % 2 else PRINT_MAX[0] %} 122 | DRAW_LINE_TO HEIGHT="{HEIGHT}" WIDTH="{WIDTH}" X="{x_pos}" Y="{ 123 | WIDTH * n + y_start}" 124 | DRAW_LINE_TO HEIGHT="{HEIGHT}" WIDTH="{WIDTH}" X="{x_pos}" Y="{ 125 | WIDTH * (n + 1) + y_start}" 126 | {% endfor %} 127 | {% set x_pos = PRINT_MAX[0] if purge_rows % 2 else PRINT_MIN[0] %} 128 | DRAW_LINE_TO HEIGHT="{HEIGHT}" WIDTH="{WIDTH}" X="{x_pos}" Y="{ 129 | WIDTH * (purge_rows - 1) + y_start}" 130 | G92 E0.0 131 | -------------------------------------------------------------------------------- /fans.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro _check_fan_params] 6 | gcode: 7 | {% set MAXIMUM = params.MAXIMUM|default( 8 | printer["gcode_macro set_fan_scaling"].maximum)|int %} 9 | {% set MINIMUM = params.MINIMUM|default( 10 | printer["gcode_macro set_fan_scaling"].minimum)|int %} 11 | 12 | {% if params.SCALE and params.SCALE|float <= 0 %} 13 | { action_raise_error("SCALE must be a positive value.") } 14 | {% elif MINIMUM < 0 or MINIMUM > 255 %} 15 | { action_raise_error("MINIMUM must be between 0 and 255.") } 16 | {% elif MAXIMUM < 0 or MAXIMUM > 255 %} 17 | { action_raise_error("MAXIMUM must be between 0 and 255.") } 18 | {% elif params.SPEED and (params.SPEED|int < 0 or params.SPEED|int > 255) %} 19 | { action_raise_error("SPEED must be between 0 and 255.") } 20 | {% elif params.BOOST and (params.BOOST|int < 0 or params.BOOST|int > 255) %} 21 | { action_raise_error("BOOST must be between 0 and 255.") } 22 | {% elif MINIMUM > MAXIMUM %} 23 | { action_raise_error("MINIMUM must be less than or equal to MAXIMUM.") } 24 | {% endif %} 25 | 26 | # Sets optional scaling factor, minimum, and maximum applied to M106 commmand. 27 | # If a MINIMUM greater than 0 is specified the fan will not stop unless an 28 | # M107 command is issued. SET_FAN_SCALING always displays the current paramaters 29 | # if scaling is active. SET_FAN_SCALING without any arguments will display the 30 | # current scaling parameters without changing them. 31 | [gcode_macro set_fan_scaling] 32 | description: Sets fan scaling factors applied to M106 command. If a speed is 33 | provided it will be adjusted according to the scaling parameters. 34 | Usage: SET_FAN_SCALING [SCALE=] [BOOST=] [MAXIMUM=] 35 | [MINIMUM=] [SPEED=] 36 | variable_scale: 1.0 37 | variable_boost: 0 38 | variable_minimum: 0 39 | variable_maximum: 255 40 | variable_real_speed: 0 41 | gcode: 42 | _CHECK_FAN_PARAMS{% for k in params %}{' '~k~'='~params[k]}{% endfor %} 43 | {% set SCALE = params.SCALE|default(scale)|float %} 44 | {% set BOOST = params.BOOST|default(boost)|float %} 45 | {% set MAXIMUM = params.MAXIMUM|default(maximum)|int %} 46 | {% set MINIMUM = params.MINIMUM|default(minimum)|int %} 47 | {% set SPEED = params.SPEED|default(real_speed)|int %} 48 | 49 | {% if SCALE != 1.0 or BOOST != 0 or MAXIMUM != 255 or MINIMUM != 0 %} 50 | {action_respond_info("Fan: Scale: %.2f Minimum:%i Maximum: %i Speed: %i"| 51 | format(SCALE, MINIMUM, MAXIMUM, SPEED))} 52 | {% endif %} 53 | 54 | # Update parameters on change. 55 | {% if params|length > 0 %} 56 | SET_GCODE_VARIABLE MACRO=set_fan_scaling VARIABLE=scale VALUE="{SCALE}" 57 | SET_GCODE_VARIABLE MACRO=set_fan_scaling VARIABLE=boost VALUE="{BOOST}" 58 | SET_GCODE_VARIABLE MACRO=set_fan_scaling VARIABLE=minimum VALUE="{MINIMUM}" 59 | SET_GCODE_VARIABLE MACRO=set_fan_scaling VARIABLE=maximum VALUE="{MAXIMUM}" 60 | # Run fan at adusted speed 61 | M106 S{SPEED} 62 | {% endif %} 63 | # Dummy argument block for Mainsail 64 | {% set dummy = None if True else " 65 | {% set dummy = params.SCALE|default(1.0)|float %} 66 | {% set dummy = params.BUMP|default(0)|int %} 67 | {% set dummy = params.MAXIMUM|default(255)|int %} 68 | {% set dummy = params.MINIMUM|default(0)|int %} 69 | {% set dummy = params.SPEED|default(current speed)|int %} 70 | " %} # End argument block for Mainsail 71 | 72 | [gcode_macro reset_fan_scaling] 73 | description: Clears all fan scaling factors. 74 | Usage: RESET_FAN_SCALING 75 | gcode: 76 | SET_FAN_SCALING SCALE=1.0 BOOST=0 MAXIMUM=255 MINIMUM=0 77 | 78 | [gcode_macro m106] 79 | description: Wraps M106 to implement scaling overrides. 80 | rename_existing: M106.6245197 81 | gcode: 82 | {% set S = params.S|default(255)|int %} 83 | {% set scale = printer["gcode_macro set_fan_scaling"] %} 84 | SET_GCODE_VARIABLE MACRO=set_fan_scaling VARIABLE=real_speed VALUE="{S}" 85 | M106.6245197 S{((((S + scale.boost) * scale.scale) | round | int, 86 | scale.minimum) | max, scale.maximum) | min} 87 | -------------------------------------------------------------------------------- /filament.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro _load_unload] 6 | gcode: 7 | {% set saved_extruder = printer.toolhead.extruder %} 8 | {% set EXTRUDER = params.EXTRUDER|default(saved_extruder)|lower %} 9 | {% set km = printer["gcode_macro _km_globals"] %} 10 | # Use the global min as default if provided, else use per extruder min + 5. 11 | {% set default_minimum = km.load_min_temp if km.load_min_temp else 12 | (printer.configfile.settings[EXTRUDER].min_extrude_temp + 5) %} 13 | {% if 'MINIMUM' in params %} 14 | {% set MINIMUM = params.MINIMUM|int %} 15 | # This is the special case for a filament change after an idle timeout. 16 | {% elif printer.pause_resume.is_paused and printer[EXTRUDER].target == 0 and 17 | printer["gcode_macro resume"].saved_extruder_temp %} 18 | {% set MINIMUM = printer["gcode_macro resume"].saved_extruder_temp %} 19 | # Use the target temp if higher than the default. 20 | {% elif printer[EXTRUDER].target > default_minimum %} 21 | {% set MINIMUM = printer[EXTRUDER].target %} 22 | {% else %} 23 | {% set MINIMUM = default_minimum %} 24 | {% endif %} 25 | {% if MINIMUM < printer.configfile.settings[EXTRUDER].min_extrude_temp %} 26 | { action_raise_error("Extrude below minimum temp.") } 27 | {% elif printer.pause_resume.is_paused %} 28 | # Clear the saved E if we're (un-)loading while paused. 29 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_e VALUE="{0.0}" 30 | {% endif %} 31 | {% set SPEED = params.SPEED|default(km.load_speed)|int %} 32 | {% set priming_length = km.load_priming_length %} 33 | {% set LENGTH = params.LENGTH|default(km.load_length)|float - priming_length%} 34 | {% if LENGTH < 0 %} 35 | {% set priming_length = (priming_length + LENGTH, 0)|max %} 36 | {% set LENGTH = 0 %} 37 | {% endif %} 38 | SAVE_GCODE_STATE NAME=_KM_LOAD_UNLOAD 39 | {% if EXTRUDER != saved_extruder%} 40 | ACTIVATE_EXTRUDER EXTRUDER={EXTRUDER} 41 | {% endif %} 42 | _KM_PRINT_STATUS ACTION=PUSH_STATUS 43 | {% if not printer.extruder.can_extrude or 44 | printer[EXTRUDER].target < default_minimum %} 45 | {action_respond_info("Preheating %s to %d" | format(EXTRUDER, MINIMUM))} 46 | M109 S{MINIMUM} 47 | {% endif %} 48 | _KM_PRINT_STATUS ACTION=CHANGE STATUS={"filament_load" 49 | if params.LOAD|int else "filament_unload"} 50 | M83 51 | {% set priming_speed = (km.load_priming_speed, SPEED)|min %} 52 | {% if params.LOAD|int %} 53 | G0 E{LENGTH} F{SPEED} 54 | G0 E{priming_length} F{priming_speed} 55 | G0 E{'%.4f' % -printer["gcode_macro resume"].saved_e} F{km.load_speed} 56 | {% else %} 57 | {% set pre_prime_distance = 5.0 %} 58 | {% set shaping_moves = 5 %} 59 | {% set shaping_distance = (shaping_moves * (1 + shaping_moves)/20) %} 60 | # Push forward to heat up, then retract to the edge of the meltzone. 61 | G0 E{pre_prime_distance} F{SPEED} 62 | G4 P500 63 | G0 E{'%.4f' % -(priming_length - shaping_distance)} F{SPEED} 64 | # Shape the tip with a pairs of short extrusions and retractions, where 65 | # the retractions get increasingly longer than the extrusion. 66 | {% for i in range(1, shaping_moves + 1) %} 67 | G0 E2 F{priming_speed} 68 | G0 E-{2 + (0.1 * i)} F{priming_speed} 69 | {% endfor %} 70 | # Retract the rest of the length. 71 | G0 E{'%.4f' % -(LENGTH + pre_prime_distance)} F{SPEED} 72 | {% endif %} 73 | RESTORE_GCODE_STATE NAME=_KM_LOAD_UNLOAD 74 | 75 | # Beep on completion 76 | _KM_BEEP_IF_AVAILABLE BEEPS={params.BEEPS|default(8)} 77 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=pop_status 78 | 79 | # TODO: Fix casing after front-ends get fixed 80 | [gcode_macro LOAD_FILAMENT] 81 | description: Loads filament to the extruder. 82 | Usage: LOAD_FILAMENT [LENGTH=] [SPEED=] 83 | [EXTRUDER=] [MINIMUM=] 84 | [BEEPS=] 85 | gcode: 86 | _LOAD_UNLOAD LOAD=1{% for k in params 87 | %}{' '~k~'="'~params[k]~'"'}{% endfor %} 88 | 89 | # Dummy argument block for Mainsail 90 | {% set dummy = None if True else " 91 | M109 92 | {% set dummy = params.LENGTH|default(variable_load_length)|float %} 93 | {% set dummy = params.SPEED|default(variable_load_speed)|float %} 94 | {% set dummy = params.EXTRUDER|default(current extruder) %} 95 | {% set dummy = params.MINIMUM|default(min_extrude_temp)|int %} 96 | {% set dummy = params.BEEPS|default(10)|int %} 97 | " %} # End argument block for Mainsail 98 | 99 | # TODO: Fix casing after front-ends get fixed 100 | [gcode_macro UNLOAD_FILAMENT] 101 | description: Unloads filament from the extruder. 102 | Usage: UNLOAD_FILAMENT [LENGTH=] [SPEED=] 103 | [EXTRUDER=] [MINIMUM=] 104 | [BEEPS=] 105 | gcode: 106 | _LOAD_UNLOAD LOAD=0{% for k in params 107 | %}{' '~k~'="'~params[k]~'"'}{% endfor %} 108 | 109 | # Dummy argument block for Mainsail 110 | {% set dummy = None if True else " 111 | M109 112 | {% set dummy = params.LENGTH|default(variable_load_length)|float %} 113 | {% set dummy = params.SPEED|default(variable_load_speed)|float %} 114 | {% set dummy = params.EXTRUDER|default(default extruder) %} 115 | {% set dummy = params.MINIMUM|default(min_extrude_temp)|int %} 116 | {% set dummy = params.BEEPS|default(10)|int %} 117 | " %} # End argument block for Mainsail 118 | 119 | [gcode_macro _pause_inner_m700] 120 | gcode: 121 | {% set extruder = "extruder" ~ params.T|replace('0', '') 122 | if "T" in params else printer.toolhead.extruder %} 123 | {% if extruder != printer.toolhead.extruder%} 124 | ACTIVATE_EXTRUDER EXTRUDER={extruder} 125 | {% endif %} 126 | 127 | {% set z_param = (' Z="%f"' % params.Z) if 'Z' in params else "" %} 128 | 129 | {% if printer.idle_timeout.state|string == "Printing" %} 130 | PAUSE B="{0}" P=2{z_param} 131 | {% elif not printer.pause_resume.is_paused%} 132 | PARK B="{0}" P=2{z_param} 133 | {% endif %} 134 | 135 | [gcode_macro m701] 136 | description: Pauses/parks the toolhead then loads filament to the extruder. 137 | Usage: M701 [L] [Z] [T] 138 | gcode: 139 | {% if 'U' in params %} 140 | {% if not 'L' in params %} 141 | RESPOND TYPE=error MSG="Argument \"U\" substituted for missing \"L\"." 142 | {% set dummy = params.__setitem__("L", params.U) %} 143 | {% else %} 144 | RESPOND TYPE=error MSG="Invalid argument \"U\" ignored." 145 | {% endif %} 146 | {% endif %} 147 | 148 | _PAUSE_INNER_M700 {% for k in params %}{' '~k~'="'~params[k]~'"'}{% endfor %} 149 | LOAD_FILAMENT BEEPS="{10}" LENGTH={ 150 | params.L|default(printer["gcode_macro _km_globals"].load_length)|float} 151 | 152 | [gcode_macro m702] 153 | description: Pauses/parks the toolhead then unloads filament from the extruder. 154 | Usage: M702 [U] [Z] [T] 155 | gcode: 156 | {% if 'L' in params %} 157 | {% if not 'U' in params %} 158 | RESPOND TYPE=error MSG="Argument \"L\" substituted for missing \"U\"." 159 | {% set dummy = params.__setitem__("U", params.L) %} 160 | {% else %} 161 | RESPOND TYPE=error MSG="Invalid argument \"L\" ignored." 162 | {% endif %} 163 | {% endif %} 164 | 165 | _PAUSE_INNER_M700 {% for k in params %}{' '~k~'="'~params[k]~'"'}{% endfor %} 166 | UNLOAD_FILAMENT BEEPS="{10}" LENGTH={ 167 | params.U|default(printer["gcode_macro _km_globals"].load_length)|float} 168 | -------------------------------------------------------------------------------- /globals.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | ################################################################################ 6 | # 7 | # Declare any of the below variables in your own [gcode_macro _km_options] to 8 | # to override the values here. 9 | # 10 | # DO NOT CHANGE ANYTHING IN THIS FILE!!! 11 | # 12 | # This file handles the initialization for all the macros, and difficult to 13 | # diagnose errors will result from unexpected values or code changes. 14 | # 15 | ################################################################################ 16 | [gcode_macro _km_globals] 17 | # Available bed surfaces for offset adjustments. 18 | variable_bed_surface_max_name_length: 10 19 | # Available bed surfaces for offset adjustments. 20 | variable_bed_surfaces: ['default'] 21 | # Total length (in mm) of filament to load (bowden tubes will be much longer). 22 | variable_load_length: 90.0 23 | # Global minimum extruder temp for loading (default: min_extrude_temp + 5). 24 | variable_load_min_temp: 0 25 | # Length (in mm) of the extruder meltzone (feeds at priming speed). 26 | variable_load_priming_length: 20.0 27 | # Filament priming speed (in mm/m). 28 | variable_load_priming_speed: 200 29 | # Filament loading speed (in mm/m). 30 | variable_load_speed: 1200 31 | # Set to False to hide the Octoprint LCD menus. 32 | variable_menu_show_octoprint: True 33 | # Set to False to hide the SD Card LCD menus. 34 | variable_menu_show_sdcard: True 35 | # List up to 10 pre-heat settings in order for the LCD "Temperature" menu 36 | variable_menu_temperature: [ 37 | {'name' : 'PLA', 'extruder' : 200, 'bed' : 60}, 38 | {'name' : 'PETG', 'extruder' : 230, 'bed' : 85}, 39 | {'name' : 'ABS', 'extruder' : 245, 'bed' : 110}] 40 | # X position to park toolhead (set "max" or "min" to infer from stepper config). 41 | variable_park_x: 0.0 42 | # Y position to park toolhead (set "max" or "min" to infer from stepper config). 43 | variable_park_y: 0.0 44 | # Z position to park toolhead (set "max" or "min" to infer from stepper config). 45 | variable_park_z: 20.0 46 | # Minimum printable XY coordinate. Defaults to X and Y position_min. 47 | variable_print_min: () # example: (0, 0) 48 | # Maximum printable XY coordinate. Defaults to X and Y position_max. 49 | variable_print_max: () # example: (220, 220) 50 | # Scaling factor for M900 command (negative values make M900 a no-op). 51 | variable_pressure_advance_scale: -1.0 52 | # Additional padding around the specified print area for a bed mesh. 53 | variable_probe_mesh_padding : 5.0 54 | # Minimum number of probes per axis for partial probing of a bed mesh. 55 | variable_probe_min_count: 3 56 | # Scaling factor to increase probe count for partial bed probes. 57 | variable_probe_count_scale: 1.0 58 | # Additional delay (in ms) during bed heating, to allow the bed to stabilize. 59 | variable_start_bed_heat_delay: 2000 60 | # Amount (in degrees C) to overshoot bed target temp before stabilizing. 61 | variable_start_bed_heat_overshoot: 2.0 62 | # Set to clear adjustments (e.g. feedrate, extrusion, heater) at end of print. 63 | variable_start_clear_adjustments_at_end: True 64 | # PRINT_END Y park position (set "max" or "min" to infer from stepper config). 65 | variable_start_end_park_y: 0.0 # Defaults to print_max Y. 66 | # Extruder scale factor during pre-warmup in PRINT_START. 67 | variable_start_extruder_preheat_scale: 0.5 68 | # If non-zero the extruder will stabilize at this temp before probing the bed. 69 | variable_start_extruder_probing_temp: 0 70 | # Set to rehome Z in PRINT_START after bed temp stabilizes; False to disable. 71 | variable_start_home_z_at_temp: True 72 | # Set to level bed in PRINT_START after bed temp stabilizes; False to disable. 73 | variable_start_level_bed_at_temp: True 74 | # Distance (in millimeters) between the purge lines and the print area. 75 | variable_start_purge_clearance: 2.0 76 | # Length of filament (in millimeters) to purge at print start. 77 | variable_start_purge_length: 0.0 # 30 is a good starting point. 78 | # Length of filament (in millimeters) to prime before drawing purge lines. 79 | variable_start_purge_prime_length: 12.0 80 | # Level gantry in PRINT_START after bed temp stabilizes; False to disable. 81 | variable_start_quad_gantry_level_at_temp: True 82 | # Maximum distance to relocate print in random XY location to reduce bed wear. 83 | variable_start_random_placement_max: 0 84 | # The relocation will be at least this far from the printable edge of the bed. 85 | variable_start_random_placement_padding: 10.0 86 | # Skip level and load saved mesh for current sheet (if found); False to disable. 87 | variable_start_try_saved_surface_mesh: False 88 | # Adjust Z tilt in PRINT_START after bed temp stabilizes; False to disable. 89 | variable_start_z_tilt_adjust_at_temp: True 90 | # X and Y travel speed (in mm/m) for movement macros. 91 | variable_travel_speed_xy: 3000 92 | # Z travel speed in (mm/m) for movement macros. 93 | variable_travel_speed_z: 600 94 | ################################################################################ 95 | description: Initializes our globals, including any _km_options overrides. 96 | gcode: 97 | # Doing a shutdown here is a bit aggressive, but if we're missing required 98 | # sections then a lot of things could go very bad later. 99 | # To minimize the annoyance we try to identify all the fatal errors at once. 100 | # format is: 101 | # key = required config section 102 | # value[0] = required field in section 103 | # value[1] = required string in field 104 | # A "None" value means there's no required field 105 | {% set required_sections = {"heater_bed" : None, 106 | "extruder" : None, 107 | "gcode_macro _km_options" : None, 108 | "idle_timeout" : ("gcode", "_KM_IDLE_TIMEOUT"), 109 | "pause_resume" : None, 110 | "respond" : None, 111 | "save_variables" : None, 112 | "virtual_sdcard" : 113 | ("on_error_gcode", "CANCEL_PRINT") 114 | } %} 115 | {% set warn_removed = { 116 | "start_extruder_set_target_before_level" : 117 | "The start_extruder_set_target_before_level option has been removed. " 118 | "Use the start_extruder_probing_temp option instead to set a fixed " 119 | "probing temperature.", 120 | "start_gcode_before_print" : 121 | "The start_gcode_before_print option has been removed. The same effect " 122 | "can now be achieved by inserting custom gcode before the " 123 | "_PRINT_START_PHASE_PURGE line in your slicer's start gcode, or by " 124 | "wrapping the _PRINT_START_PHASE_PURGE macro. See the Slicer " 125 | "Configuration section in the readme for more information.", 126 | "velocity_decel_scale" : 127 | "The velocity_decel_scale option has been removed. Klipper's input " 128 | "shaping provides a superior mechanism for improving print quality " 129 | "at higher speeds.", 130 | } %} 131 | {% set output = [] %} 132 | {% for s in required_sections %} 133 | {% set f = required_sections[s][0] if required_sections[s] else None %} 134 | {% set v = required_sections[s][1] if required_sections[s] else None %} 135 | {% if s not in printer.configfile.config %} 136 | {% set dummy = output.append("Missing [%s] section.\n" | format(s)) %} 137 | {% elif f and 138 | (v not in printer.configfile.config[s][f]|default("")|upper) %} 139 | {% set dummy = output.append("Missing %s in %s for [%s] section.\n" 140 | | format(v, f, s)) %} 141 | {% endif %} 142 | {% endfor %} 143 | {% if output %} 144 | { action_emergency_stop(( 145 | "required printer.cfg section(s) missing:\n" 146 | ~ output | join("\n")) ~ 147 | "See readme: https://github.com/jschuh/klipper-macros\x23klipper-setup") 148 | } 149 | {% endif %} 150 | 151 | # These are all set to their defaults based on config options: 152 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_level_bed_at_temp VALUE="{ 153 | 1 if printer.bed_mesh is defined else 0}" 154 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_quad_gantry_level_at_temp VALUE="{ 155 | 1 if printer.quad_gantry_level is defined else 0}" 156 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_z_tilt_adjust_at_temp VALUE="{ 157 | 1 if printer.z_tilt is defined else 0}" 158 | {% set toolhead = printer.toolhead %} 159 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=print_min VALUE="{ 160 | (toolhead.axis_minimum.x, toolhead.axis_minimum.y)}" 161 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=print_max VALUE="{ 162 | (toolhead.axis_maximum.x, toolhead.axis_maximum.y)}" 163 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_end_park_y VALUE="{ 164 | toolhead.axis_maximum.y}" 165 | {% set settings = printer.configfile.settings %} 166 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE=start_home_z_at_temp VALUE="{ 167 | 1 if ("stepper_z" in settings and 168 | settings.stepper_z.endstop_pin.split()|join("")|lower == 169 | "probe:z_virtual_endstop") else 0}" 170 | 171 | {% set options = printer["gcode_macro _km_options"] %} 172 | {% set km = printer["gcode_macro _km_globals"] %} 173 | 174 | # Allow placeholders for parking positions. 175 | {% if options.park_x|default("")|string|lower == "min" %} 176 | {% set dummy = options.__setitem__("park_x", 177 | printer.configfile.settings.stepper_x.position_min) %} 178 | {% elif options.park_x|default("")|string|lower == "max" %} 179 | {% set dummy = options.__setitem__("park_x", 180 | printer.configfile.settings.stepper_x.position_max) %} 181 | {% endif %} 182 | {% if options.park_y|default("")|string|lower == "min" %} 183 | {% set dummy = options.__setitem__("park_y", 184 | printer.configfile.settings.stepper_y.position_min) %} 185 | {% elif options.park_y|default("")|string|lower == "max" %} 186 | {% set dummy = options.__setitem__("park_y", 187 | printer.configfile.settings.stepper_y.position_max) %} 188 | {% endif %} 189 | {% if options.start_end_park_y|default("")|string|lower == "min" %} 190 | {% set dummy = options.__setitem__("start_end_park_y", 191 | printer.configfile.settings.stepper_y.position_min) %} 192 | {% elif options.start_end_park_y|default("")|string|lower == "max" %} 193 | {% set dummy = options.__setitem__("start_end_park_y", 194 | printer.configfile.settings.stepper_y.position_max) %} 195 | {% endif %} 196 | {% if options.park_z|default("")|string|lower == "min" %} 197 | {% set dummy = options.__setitem__("park_z", 198 | printer.configfile.settings.stepper_z.position_min) %} 199 | {% elif options.park_z|default("")|string|lower == "max" %} 200 | {% set dummy = options.__setitem__("park_z", 201 | printer.configfile.settings.stepper_z.position_max) %} 202 | {% endif %} 203 | 204 | # Force overrides to use the original types in _KM_GLOBALS. 205 | {% for k in options %} 206 | {% if k not in km %} 207 | {% if k in warn_removed %} 208 | {action_respond_info(warn_removed[k])} 209 | {% else %} 210 | {% set dummy = output.append("%s is not valid for _KM_OPTIONS." | 211 | format(k)) %} 212 | {% endif %} 213 | {% elif km[k] is string %} 214 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k 215 | } VALUE="'{options[k]|replace('\\','\\\\')|replace('\'','\\\'') 216 | |replace('\"','\\\"')}'" 217 | {% elif km[k] is float %} 218 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k 219 | } VALUE="{options[k]|float}" 220 | {% elif km[k] is integer or km[k] is boolean %} 221 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k} VALUE="{options[k]|int}" 222 | {% elif km[k] is mapping %} 223 | {% if options[k] is not mapping %} 224 | {% set dummy = output.append("%s requires a mapping type." | 225 | format(k)) %} 226 | {% endif %} 227 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k 228 | } VALUE="{options[k]|replace('\"','\\\"')}" 229 | {% elif km[k] is sequence %} 230 | {% if options[k] is not sequence %} 231 | {% set dummy = output.append("%s requires a sequence type." | 232 | format(k)) %} 233 | {% endif %} 234 | SET_GCODE_VARIABLE MACRO=_km_globals VARIABLE={k 235 | } VALUE="{options[k]|replace('\"','\\\"')}" 236 | {% else %} 237 | {% set dummy = output.append("%s is not a valid type for _KM_OPTIONS." | 238 | format(k)) %} 239 | {% endif %} 240 | {% endfor %} 241 | 242 | {% if "homing_override" in printer.configfile.config %} 243 | {% for l in printer.configfile.config.homing_override.gcode.split("\n") %} 244 | {% if " g28 " in (" " ~ l.split("\x23")[0].split(";")[0]|lower ~ " ") %} 245 | {% set dummy = output.append( 246 | "G28 in [homing_override] gcode. Replace with G28.6245197 to " 247 | "fix recursive macro call.\n" 248 | "See readme: https://github.com/jschuh/klipper-macros\x23g28") %} 249 | {% endif %} 250 | {% endfor %} 251 | {% endif %} 252 | SET_GCODE_VARIABLE MACRO=check_km_config VARIABLE=load_errors VALUE="{ 253 | output|replace('\"','\\\"')}" 254 | M400 255 | 256 | [delayed_gcode INIT_GLOBALS] 257 | # This runs once at startup and initializes all macros. 258 | initial_duration: 1 259 | gcode: 260 | LIST_MACROS SILENT=1 # Build the macro cache. 261 | _KM_GLOBALS 262 | # This needs to be its own macro so it gets evaluated after _KM_GLOBALS runs. 263 | CHECK_KM_CONFIG 264 | _INIT_SURFACES 265 | BED_MESH_CHECK 266 | # Sets the default drawing parameters. 267 | SET_DRAW_PARAMS WIDTH="{printer.configfile.settings.extruder.nozzle_diameter}" 268 | # This is any end-user gcode that need to run after macro initialization. 269 | _KM_OPTIONS 270 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=ready 271 | 272 | [gcode_macro check_km_config] 273 | variable_load_errors: [] 274 | description: Checks global variables and throws an error on any invalid values. 275 | Does nothing if the config has no errors. 276 | gcode: 277 | {% set km = printer["gcode_macro _km_globals"] %} 278 | {% set toolhead = printer.toolhead %} 279 | {% set output = load_errors %} 280 | {% if km.park_x > toolhead.axis_maximum.x or 281 | km.park_x < toolhead.axis_minimum.x %} 282 | {% set dummy = output.append("park_x is invalid.") %} 283 | {% endif %} 284 | {% if km.park_y > toolhead.axis_maximum.y or 285 | km.park_y < toolhead.axis_minimum.y %} 286 | {% set dummy = output.append("park_y is invalid.") %} 287 | {% endif %} 288 | {% if km.park_z > toolhead.axis_maximum.z or 289 | km.park_z < toolhead.axis_minimum.z %} 290 | {% set dummy = output.append("park_z is invalid.") %} 291 | {% endif %} 292 | {% if km.print_max[0] > toolhead.axis_maximum.x or 293 | km.print_max[1] > toolhead.axis_maximum.y %} 294 | {% set dummy = output.append("print_max is invalid.") %} 295 | {% endif %} 296 | {% if km.print_min[0] < toolhead.axis_minimum.x or 297 | km.print_min[1] < toolhead.axis_minimum.y %} 298 | {% set dummy = output.append("print_min is invalid.") %} 299 | {% endif %} 300 | {% if km.start_extruder_preheat_scale > 1.0 or 301 | km.start_extruder_preheat_scale < 0.0 %} 302 | {% set dummy = output.append("extruder_preheat_scale is invalid.") %} 303 | {% endif %} 304 | {% if km.load_length > 305 | printer.configfile.settings["extruder"].max_extrude_only_distance %} 306 | {% set dummy = output.append( 307 | "load_length exceeds max_extrude_only_distance.") %} 308 | {% endif %} 309 | {% if km.load_length < km.load_priming_length %} 310 | {% set dummy = output.append( 311 | "load_length is shorter than load_priming_length.") %} 312 | {% endif %} 313 | {% if km.load_length < 0.0 %} 314 | {% set dummy = output.append("load_length is negative.") %} 315 | {% endif %} 316 | {% if km.load_priming_length < 0.0 %} 317 | {% set dummy = output.append("load_priming_length is negative.") %} 318 | {% endif %} 319 | 320 | # Emit all the config errors. 321 | {% if output %} 322 | { action_raise_error(output|sort|join('\nError: ')) } 323 | {% endif %} 324 | M400 325 | 326 | [gcode_macro kmvars] 327 | description: Lists global variables used by klipper-macros. 328 | Usage: KMVARS [SEARCH=] 329 | gcode: 330 | {% set SEARCH = params.SEARCH|default(params.S|default(""))|lower %} 331 | {% set km = printer["gcode_macro _km_globals"] %} 332 | {% set output = [] %} 333 | {% for k in km %} 334 | {% if SEARCH in k %} 335 | {% set dummy = output.append(k ~ ": " ~ km[k]) %} 336 | {% endif %} 337 | {% endfor %} 338 | { action_respond_info(output|sort|join('\n')) } 339 | 340 | [gcode_macro check_macro_docs] 341 | description: Lists macros lacking proper documentation. 342 | Usage: CHECK_MACRO_DOCS [USAGE=<0|1>] [HIDDEN=<1|0>] [RENAMED=<1|0>] 343 | gcode: 344 | {% set USAGE = params.USAGE|default(0)|int %} 345 | {% set HIDDEN = params.HIDDEN|default(0)|int %} 346 | {% set RENAMED = params.RENAMED|default(0)|int %} 347 | {% set output = [] %} 348 | {%set config = printer.configfile.config %} 349 | {% for k in config|sort %} 350 | {% if k.startswith("gcode_macro") %} 351 | {% set name = k.split()[1] %} 352 | {% set desc = config[k].description|default("") %} 353 | {% set is_renamed = config[k].rename_existing|default("") %} 354 | {% if (not desc or (USAGE and not "Usage: "~name.upper() in desc)) and 355 | (HIDDEN or not name.startswith('_')) and (RENAMED or is_renamed) %} 356 | {% set dummy = output.append("%s %s: missing %s." 357 | | format("*" if is_renamed else " ", name, 358 | "description" if not desc else "usage")) %} 359 | {% endif %} 360 | {% endif %} 361 | {% endfor %} 362 | {action_respond_info(output|join("\n"))} 363 | 364 | # The below macro is a lightly edited version of the one found here: 365 | # https://klipper.discourse.group/t/example-search-printer-objects/164 366 | [gcode_macro listvars] 367 | description: Lists per-macro variables with a name containing SEARCH. This is 368 | useful for debugging macros by allowing you to probe printer state. Be very 369 | careful, however, as an overly broad SEARCH parameter can take a long time 370 | to process and potentially hang or crash klipper. 371 | Usage: LISTVARS SEARCH= 372 | gcode: 373 | 374 | {% if 'SEARCH' not in params and 'S' not in params %} 375 | { action_raise_error("Must provide a SEARCH parameter.") } 376 | {% endif %} 377 | {% set SEARCH = params.SEARCH|default(params.S)|lower %} 378 | {% set ns = namespace() %} 379 | {% set output = [] %} 380 | {% for item in printer %} 381 | {% if item is not string %} 382 | {% set ns.path = ['printer', "[%s]" % (item|string), ''] %} 383 | {% elif ' ' in item %} 384 | {% set ns.path = ['printer', "['%s']" % (item), ''] %} 385 | {% else %} 386 | {% set ns.path = ['printer.', item, ''] %} 387 | {% endif %} 388 | 389 | {% if SEARCH in ns.path|lower %} 390 | {% set dummy = output.append(ns.path|join) %} 391 | {% endif %} 392 | 393 | {% if printer[item].items() %} 394 | {% for childkey, child in printer[item].items() recursive %} 395 | {% set ns.path = ns.path[:loop.depth|int + 1] %} 396 | {% if childkey is not string %} 397 | {% set null = ns.path.append("[%s]" % (childkey|string)) %} 398 | {% elif ' ' in childkey %} 399 | {% set null = ns.path.append("['%s']" % (childkey)) %} 400 | {% else %} 401 | {% set null = ns.path.append(".%s" % (childkey)) %} 402 | {% endif %} 403 | 404 | {% if child is mapping %} 405 | {loop(child.items())} 406 | {% else %} 407 | {% if SEARCH in ns.path|lower %} 408 | {% set dummy = output.append("%s : %s" % (ns.path|join, child)) %} 409 | {% endif %} 410 | {% endif %} 411 | {% endfor %} 412 | {% endif %} 413 | {% endfor %} 414 | { action_respond_info(output|join("\n")) } 415 | 416 | [gcode_macro list_macros] 417 | description: Lists registered macros (and optionally show variable state). 418 | Usage: LISTVARS SEARCH= VARS=<0|1> SILENT=<0|1> 419 | variable_macros: {} 420 | gcode: 421 | # Load the config state once and save it. 422 | {% if not macros %} 423 | {% set renames = {} %} 424 | {% for k in printer.configfile.config %} 425 | {% if k.lower().startswith("gcode_macro") and 426 | printer.configfile.config[k].rename_existing %} 427 | {% set name = k.split(None, 1)[1] | lower %} 428 | {% set dummy = renames.__setitem__(name, 429 | [printer.configfile.config[k].rename_existing|lower] + 430 | renames[name]|default([])) %} 431 | {% endif %} 432 | {% endfor %} 433 | {% for k in printer %} 434 | {% if k.lower().startswith("gcode_macro") %} 435 | {% set name = k.split(None, 1)[1] | lower %} 436 | {% set dummy = macros.__setitem__(name, renames[name]|default([])) %} 437 | {% endif %} 438 | {% endfor %} 439 | {% endif %} 440 | 441 | {% if params.SILENT|default(0)|int == 0 %} 442 | _LIST_MACROS_DISPLAY {rawparams} 443 | {% endif %} 444 | 445 | [gcode_macro _list_macros_display] 446 | gcode: 447 | {% set SEARCH = params.SEARCH | default(params.S) | default("") | lower %} 448 | {% set VARS = params.VARS | default(params.V) | default(0) | int != 0 %} 449 | 450 | {% set macros = printer["gcode_macro list_macros"].macros %} 451 | {% set output = [] %} 452 | {% for k in macros %} 453 | {% if SEARCH in k | lower %} 454 | {% set line = k ~ ((" (renames: %s)" % (macros[k]|join(","))) if macros[k] 455 | else "") %} 456 | {% set outvars = [] %} 457 | {% if VARS %} 458 | {% for v in printer["gcode_macro " ~ k] | sort %} 459 | {% set dummy = outvars.append("\n* %s: %s" % 460 | (v, printer["gcode_macro " ~ k][v]|string)) %} 461 | {% endfor %} 462 | {% endif %} 463 | {% set dummy = output.append(line + outvars | join("")) %} 464 | {% endif %} 465 | {% endfor %} 466 | { action_respond_info(output | sort | join("\n")) } 467 | -------------------------------------------------------------------------------- /heaters.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro set_heater_temperature_scaled] 6 | gcode: 7 | {% set HEATER = params.HEATER.lower() %} 8 | {% set TARGET = params.TARGET|default(0.0)|float %} 9 | {% set scaled_heaters = 10 | printer["gcode_macro set_heater_scaling"].scaled_heaters %} 11 | {% if HEATER in scaled_heaters %} 12 | {% set scales = scaled_heaters[HEATER] %} 13 | {% set dummy = scales.__setitem__("real_target", TARGET) %} 14 | {%if TARGET > 0.0 %} 15 | {% set TARGET = (((TARGET + scales.bump) * scales.scale, scales.minimum) 16 | | max, scales.maximum)|min %} 17 | {% endif %} 18 | {% endif %} 19 | SET_HEATER_TEMPERATURE HEATER="{HEATER}" TARGET={TARGET} 20 | 21 | [gcode_macro temperature_wait_scaled] 22 | gcode: 23 | {% set SENSOR = params.SENSOR.lower() %} 24 | {% set heater = SENSOR if not SENSOR.startswith("heater_generic") else 25 | SENSOR.split()[1] %} 26 | {% set scaled_heaters = 27 | printer["gcode_macro set_heater_scaling"].scaled_heaters %} 28 | {% if heater in scaled_heaters %} 29 | {% set scales = scaled_heaters[heater] %} 30 | {% if "MINIMUM" in params and MINIMUM > 0.0 %} 31 | {% set MINIMUM = (((MINIMUM + scales.bump) * scales.scale, scales.minimum) 32 | | max, scales.maximum)|min %} 33 | {% endif %} 34 | {% if "MAXIMUM" in params and MAXIMUM > 0.0 %} 35 | {% set MAXIMUM = (((MAXIMUM + scales.bump) * scales.scale, scales.minimum) 36 | | max, scales.maximum)|min %} 37 | {% endif %} 38 | {% else %} 39 | {% set settings = printer.configfile.settings[SENSOR] %} 40 | {% set MINIMUM = params.MINIMUM|default(settings.min_temp) %} 41 | {% set MAXIMUM = params.MAXIMUM|default(settings.max_temp) %} 42 | {% endif %} 43 | {% if printer[sensor].temperature < MINIMUM or 44 | printer[sensor].temperature > MAXIMUM %} 45 | TEMPERATURE_WAIT SENSOR="{SENSOR}" MINIMUM={MINIMUM} MAXIMUM={MAXIMUM} 46 | {% endif %} 47 | 48 | [gcode_macro _gcode_wait_wrapper_inner] 49 | gcode: 50 | # Macro variables are evaluated at instantiation, so this inner macro is what 51 | # gets us a scaled target value. 52 | {% set sensor = params.HEATER if params.HEATER in 53 | printer.heaters.available_heaters 54 | else ("heater_generic " ~ params.HEATER) %} 55 | {% set target = printer[sensor].target %} 56 | {% if 'R' in params and target > 0.0 %} 57 | {% set T = params.T|default("") %} 58 | M{params.M}.6245197 S{target} { (" T"~T) if T else "" } 59 | {% elif printer[sensor].temperature < target %} 60 | TEMPERATURE_WAIT SENSOR="{sensor}" MINIMUM={target} 61 | {% endif %} 62 | 63 | [gcode_macro _gcode_wait_wrapper] 64 | gcode: 65 | {% set target = params.S | default(params.R | default(0))| float %} 66 | SET_HEATER_TEMPERATURE_SCALED HEATER="{params.HEATER}" TARGET={target} 67 | _GCODE_WAIT_WRAPPER_INNER{% 68 | for k in params %}{' '~k~'="'~params[k]~'"'}{% endfor %} 69 | 70 | [gcode_macro m109] 71 | rename_existing: M109.6245197 72 | gcode: 73 | {% set extruder = "extruder" ~ params.T|replace('0', '') 74 | if "T" in params else printer.toolhead.extruder %} 75 | _KM_PRINT_STATUS ACTION=PUSH_STATUS 76 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=extruder_heating 77 | _GCODE_WAIT_WRAPPER HEATER={extruder}{% 78 | for k in params %}{' '~k~'="'~params[k]~'"'}{% endfor %} 79 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=pop_status 80 | 81 | [gcode_macro m190] 82 | rename_existing: M190.6245197 83 | gcode: 84 | _KM_PRINT_STATUS ACTION=PUSH_STATUS 85 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=bed_heating 86 | _GCODE_WAIT_WRAPPER HEATER=heater_bed {% 87 | for k in params %}{' '~k~'="'~params[k]~'"'}{% endfor %} 88 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=pop_status 89 | 90 | [gcode_macro m191] 91 | description: Sets chamber temperature (with wait for heating). 92 | Usage: M191 [S] 93 | gcode: 94 | # Just fake the R parameter for the chamber. 95 | {% if "R" in params %} 96 | {% set dummy = params.__setitem__("S", params.R) %} 97 | {% endif %} 98 | _KM_PRINT_STATUS ACTION=PUSH_STATUS 99 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=chamber_heating 100 | _GCODE_WAIT_WRAPPER HEATER=chamber {% 101 | for k in params %}{' '~k~'="'~params[k]~'"'}{% endfor %} 102 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=pop_status 103 | 104 | [gcode_macro m104] 105 | rename_existing: M104.6245197 106 | gcode: 107 | {% set extruder = "extruder" ~ params.T|replace('0', '') 108 | if "T" in params else printer.toolhead.extruder %} 109 | SET_HEATER_TEMPERATURE_SCALED HEATER={extruder} TARGET={params.S|default(0)} 110 | 111 | [gcode_macro m140] 112 | rename_existing: M140.6245197 113 | gcode: 114 | SET_HEATER_TEMPERATURE_SCALED HEATER=heater_bed TARGET={params.S|default(0)} 115 | 116 | [gcode_macro m141] 117 | description: Sets chamber temperature. 118 | Usage: M141 [S] 119 | gcode: 120 | SET_HEATER_TEMPERATURE_SCALED HEATER=chamber TARGET={params.S|default(0)} 121 | 122 | [gcode_macro _check_heater_params] 123 | gcode: 124 | {% set HEATER = params.HEATER|lower %} 125 | {% set sensor = params.HEATER %} 126 | {% if HEATER not in printer.heaters.available_heaters %} 127 | {% set sensor = "heater_generic " ~ HEATER %} 128 | {% if sensor not in printer.heaters.available_heaters %} 129 | { action_raise_error("The value '%s' is not valid for HEATER" 130 | | format(HEATER)) } 131 | {% endif %} 132 | {% endif %} 133 | {% set settings = printer.configfile.settings[sensor] %} 134 | {% set scaled_heaters = 135 | printer["gcode_macro set_heater_scaling"].scaled_heaters %} 136 | {% if HEATER is in scaled_heaters %} 137 | {% set scales = scaled_heaters[HEATER] %} 138 | {% else %} 139 | {% set scales = { "scale": 1.0, "bump": 0.0, "minimum": settings.min_temp, 140 | "maximum": settings.max_temp, 141 | "real_target": printer[sensor].target} %} 142 | {% endif %} 143 | {% set SCALE = params.SCALE|default(scales.scale)|float %} 144 | {% set BUMP = params.BUMP|default(scales.bump)|float %} 145 | {% set MINIMUM = params.MINIMUM|default(scales.minimum)|float %} 146 | {% set MAXIMUM = params.MAXIMUM|default(scales.maximum)|float %} 147 | 148 | {% if SCALE <= 0 %} 149 | { action_raise_error("SCALE must be a positive value.") } 150 | {% elif MINIMUM < settings.min_temp or MINIMUM > settings.max_temp %} 151 | { action_raise_error("MINIMUM must be between %.1f and %.1f" | 152 | format(settings.min_temp, settings.max_temp)) } 153 | {% elif MAXIMUM < settings.min_temp or MAXIMUM > settings.max_temp %} 154 | { action_raise_error("MAXIMUM must be between %.1f and %.1f" | 155 | format(settings.min_temp, settings.max_temp)) } 156 | {% elif MINIMUM >= MAXIMUM %} 157 | { action_raise_error("MINIMUM must be less than MAXIMUM.") } 158 | {% elif "TARGET" in params and (params.TARGET|float < MINIMUM or 159 | params.TARGET|float > MAXIMUM) %} 160 | { action_raise_error("TARGET must be between %.1f and %.1f" | 161 | format(settings.min_temp, settings.max_temp)) } 162 | {% endif %} 163 | 164 | [gcode_macro set_heater_scaling] 165 | description: Sets scaling parameters for heater. If a new target temperature is 166 | passed it will be adjusted to the scaling parameters. 167 | Usage: SET_HEATER_SCALING [HEATER=] [SCALE=] 168 | [BUMP=] [MAXIMUM=] 169 | [MINIMUM=] [TARGET=] 170 | variable_scaled_heaters: {} 171 | gcode: 172 | # If no heater is supplied just list out all the scaled heaters. 173 | {% if "HEATER" is not in params %} 174 | {% set output = [] %} 175 | {% for h in scaled_heaters %} 176 | {% set dummy = output.append( 177 | "%s: Scale: %.2f Bump: %.1f Minimum:%.1f Maximum: %.1f" 178 | | format(h, scaled_heaters[h].scale, scaled_heaters[h].bump, 179 | scaled_heaters[h].minimum, scaled_heaters[h].maximum)) %} 180 | {% endfor %} 181 | {% if output %}}{action_respond_info(output|join('\n'))}{% endif %} 182 | {% else %} 183 | # See if we need a new scaling entry for this heater. 184 | {% set HEATER = params.HEATER.lower() %} 185 | {% set settings = printer.configfile.settings[HEATER] %} 186 | {% if HEATER is not in scaled_heaters %} 187 | {% set dummy = scaled_heaters.__setitem__(HEATER, {"scale": 1.0, 188 | "bump": 0.0, "minimum": settings.min_temp, 189 | "maximum": settings.max_temp, 190 | "real_target": printer[HEATER].target}) %} 191 | {% endif %} 192 | _CHECK_HEATER_PARAMS{% for k in params %}{' '~k~'='~params[k]}{% endfor %} 193 | {% set scales = scaled_heaters[HEATER] %} 194 | {% set SCALE = params.SCALE|default(scales.scale)|float %} 195 | {% set BUMP = params.BUMP|default(scales.bump)|float %} 196 | {% set MAXIMUM = params.MAXIMUM|default(scales.maximum)|float %} 197 | {% set MINIMUM = params.MINIMUM|default(scales.minimum)|float %} 198 | {% set TARGET = params.TARGET|default(scales.real_target)|float %} 199 | {% set dummy = scales.__setitem__("scale", SCALE) %} 200 | {% set dummy = scales.__setitem__("bump", BUMP) %} 201 | {% set dummy = scales.__setitem__("maximum", MAXIMUM) %} 202 | {% set dummy = scales.__setitem__("minimum", MINIMUM) %} 203 | {% set dummy = scales.__setitem__("real_target", TARGET) %} 204 | 205 | {% set settings = printer.configfile.settings[HEATER] %} 206 | {% if SCALE != 1.0 or BUMP != 0.0 or MINIMUM != settings.min_temp or 207 | MAXIMUM != settings.max_temp %} 208 | {% set dummy = scaled_heaters.__setitem__(HEATER, scales) %} 209 | {% else %} # Remove a redundant scaling entry. 210 | {% set dummy = scaled_heaters.__delitem__(HEATER) %} 211 | {% endif %} 212 | SET_HEATER_TEMPERATURE_SCALED HEATER={HEATER} TARGET={TARGET} 213 | {action_respond_info( 214 | "%s: Scale: %.2f Bump: %.1f Minimum:%.1f Maximum: %.1f Target: %.1f" 215 | | format(HEATER, SCALE, BUMP, MINIMUM, MAXIMUM, TARGET))} 216 | {% endif %} 217 | # Dummy argument block for Mainsail 218 | {% set dummy = None if True else " 219 | {% set dummy = params.HEATER|default(e.g. extruder) %} 220 | {% set dummy = params.SCALE|default(1.0)|float %} 221 | {% set dummy = params.BUMP|default(0.0)|float %} 222 | {% set dummy = params.MAXIMUM|default(max_temp)|float %} 223 | {% set dummy = params.MINIMUM|default(min_temp)|float %} 224 | {% set dummy = params.TARGET|default(current target)|float %} 225 | " %} # End argument block for Mainsail 226 | 227 | [gcode_macro reset_heater_scaling] 228 | description: Clears scaling for heater (or all heaters if none specified). 229 | Usage: RESET_HEATER_SCALING [HEATER=] 230 | gcode: 231 | {% if "HEATER" in params %} 232 | {% set HEATER = params.HEATER.lower() %} 233 | {% if HEATER not in printer.heaters.available_heaters %} 234 | { action_raise_error("The value '%s' is not valid for HEATER" 235 | | format(HEATER)) } 236 | {% endif %} 237 | {% set settings = printer.configfile.settings[HEATER] %} 238 | SET_HEATER_SCALING HEATER={HEATER 239 | } SCALE=1.0 BUMP=0.0 MINIMUM={settings.min_temp 240 | } MAXIMUM={settings.max_temp} 241 | {% else %} 242 | # Clear everything if no heater was provided. 243 | SET_GCODE_VARIABLE MACRO=set_heater_scaling VARIABLE=scaled_heaters VALUE={ 244 | "{}"} 245 | {% endif %} 246 | -------------------------------------------------------------------------------- /idle.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro _km_idle_timeout] 6 | gcode: 7 | {% if printer.pause_resume.is_paused %} 8 | {action_respond_info("Extruder powered down on idle timeout.")} 9 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_extruder_temp VALUE="{ 10 | printer[printer.toolhead.extruder].target}" 11 | M104; Turn off extruder but leave the bed on. 12 | {% else %} 13 | TURN_OFF_HEATERS 14 | M107; turn off fan 15 | M84 16 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=ready 17 | {% endif %} 18 | -------------------------------------------------------------------------------- /kinematics.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro _check_kinematic_limits] 6 | gcode: 7 | {% set toolhead = printer.toolhead %} 8 | {% if params.X and (params.X|float < toolhead.axis_minimum.x or 9 | params.X|float > toolhead.axis_maximum.x) %} 10 | {action_raise_error("X[%.3f] must be between %.3f and %.3f." 11 | | format(params.X|float, toolhead.axis_minimum.x, 12 | toolhead.axis_maximum.x))} 13 | {% elif params.Y and (params.Y|float < toolhead.axis_minimum.y or 14 | params.Y|float > toolhead.axis_maximum.y) %} 15 | {action_raise_error("Y[%.3f] must be between %.3f and %.3f." 16 | | format(params.Y|float, toolhead.axis_minimum.y, 17 | toolhead.axis_maximum.y))} 18 | {% elif params.Z and (params.Z|float < toolhead.axis_minimum.z or 19 | params.Z|float > toolhead.axis_maximum.z) %} 20 | {action_raise_error("Z[%.3f] must be between %.3f and %.3f." 21 | | format(params.Z|float, toolhead.axis_minimum.z, 22 | toolhead.axis_maximum.z))} 23 | {% elif params.E and (params.E|float|abs > printer.configfile.settings[ 24 | "extruder"].max_extrude_only_distance) %} 25 | {action_raise_error("E[%.4f] exceeds max_extrude_only_distance[%.4f]." 26 | | format(params.E|float|abs, printer.configfile.settings[ 27 | "extruder"].max_extrude_only_distance))} 28 | {% endif %} 29 | 30 | [gcode_macro lazy_home] 31 | description: Homes the specified axes. If lazy is true, already homed axes 32 | are skipped. 33 | Usage: LAZY_HOME [LAZY=<1|0>] [AXES=] 34 | gcode: 35 | # This is split apart so we can force the macro rename cache to be ready. 36 | LIST_MACROS SILENT=1 37 | _LAZY_HOME_INNER {rawparams} 38 | 39 | [gcode_macro _lazy_home_inner] 40 | gcode: 41 | # Find the real g28 command. 42 | {% set G28 = (printer["gcode_macro list_macros"].macros.g28| 43 | default(["g28"],True))[-1] %} 44 | {% set axes = 'XYZ'|select('in', params.AXES|default("XYZ")|upper|list) %} 45 | {% if not axes %} # No axes means home everything. 46 | {% set axes = 'XYZ' %} 47 | {% endif %} 48 | {% if params.LAZY|default(1)|int %} # Prune out the already homed axes. 49 | {% set axes = axes|reject('in', printer.toolhead.homed_axes|upper)|join() %} 50 | {% endif %} 51 | 52 | {% if axes %} 53 | _KM_PRINT_STATUS ACTION=PUSH_STATUS 54 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=homing 55 | {G28}{% for k in axes %}{' ' ~ k}{% endfor %} 56 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=pop_status 57 | {% endif %} 58 | 59 | [gcode_macro g28] 60 | description: Wraps the G28 command to add the Marlin "O" parameter so that 61 | already homed axes will not be homed again. See the Klipper documentation on 62 | G28 for the behavior of the other parameters. 63 | Usage: G28 [O] ... 64 | rename_existing: G28.6245197 65 | gcode: 66 | {% set axes = 'XYZ'|select('in', params)|join() %} 67 | LAZY_HOME LAZY={('O' in params)|int}{%if axes%} AXES={axes}{%endif%} -------------------------------------------------------------------------------- /layers.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro before_layer_change] 6 | description: Add this to the "before layer change" input box in the slicer. 7 | Usage: BEFORE_LAYER_CHANGE HEIGHT= LAYER= 8 | gcode: 9 | {% set height = params.HEIGHT|default(printer.toolhead.position.z)|float %} 10 | {% set layer = params.LAYER|default(-1)|int + 1 %} 11 | {% if height >= 0.0 and layer >= 0 %} 12 | SET_PRINT_STATS_INFO CURRENT_LAYER="{layer}" 13 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_height VALUE="{height}" 14 | {% if printer["gcode_macro _km_layer_run"].clearance_z < height %} 15 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=clearance_z VALUE="{ 16 | height}" 17 | {% endif %} 18 | {% endif %} 19 | 20 | [gcode_macro after_layer_change] 21 | description: Add this to the "after layer change" input box in the slicer. 22 | Usage: AFTER_LAYER_CHANGE 23 | gcode: 24 | _KM_LAYER_RUN 25 | 26 | [gcode_macro gcode_at_layer] 27 | description: Schedules the specified g-code command to be run at the specified 28 | layer. LAYER=next will cause the command to run at the next layer change. 29 | Usage: GCODE_AT_LAYER { HEIGHT= | LAYER= } COMMAND= 30 | [CANCEL=<0|1>] 31 | gcode: 32 | {% set tot_layers = printer.print_stats.info.total_layer %} 33 | {% if params|length > 0 %} 34 | _KM_CHECK_IS_PRINTING 35 | 36 | {% set CANCEL = params.CANCEL|default(0)|int != 0 %} 37 | {% set COMMAND = params.COMMAND|default(None) %} 38 | {% if COMMAND %} # This makes it easier to match commands for cancellation. 39 | {% set COMMAND = COMMAND.lstrip().split(None, 1) %} 40 | {% set COMMAND = " ".join([COMMAND[0]|upper] + COMMAND[1:]) %} 41 | {% endif %} 42 | 43 | {% if "LAYER" in params %} 44 | {% set cmd_container = "commands_layer" %} 45 | {% set cur_layer = printer.print_stats.info.current_layer|int %} 46 | {% if "HEIGHT" in params %} 47 | {action_raise_error("Conflicting HEIGHT and LAYER arguments provided.")} 48 | {% elif params.LAYER|string|lower == "next" %} 49 | {% set LAYER = cur_layer + 1 %} 50 | {% else %} 51 | {% set LAYER = params.LAYER|int %} 52 | {% endif %} 53 | {% if LAYER <= cur_layer %} 54 | {action_raise_error("LAYER[%i] must be above current print layer[%i]." 55 | | format(LAYER, cur_layer))} 56 | {% elif tot_layers and LAYER > tot_layers %} 57 | {action_raise_error("LAYER[%i] must not be above top layer[%i]." 58 | | format(LAYER, tot_layers))} 59 | {% endif %} 60 | {% set key = LAYER %} 61 | 62 | {% elif "HEIGHT" in params %} 63 | {% set cmd_container = "commands_height" %} 64 | {% set HEIGHT = params.HEIGHT|float %} 65 | {% set cur_height = printer["gcode_macro _km_layer_run"].cur_height %} 66 | {% if HEIGHT <= cur_height %} 67 | {action_raise_error( 68 | "HEIGHT[%.3f] must be above current print height[%.3f].") 69 | | format(HEIGHT, cur_height)} 70 | {% elif HEIGHT >= printer.toolhead.axis_maximum.z %} 71 | {action_raise_error( 72 | "HEIGHT[%.3f] must be below maximum Z height[%.3f].") 73 | | format(HEIGHT, printer.toolhead.axis_maximum.z)} 74 | {% endif %} 75 | {% set key = HEIGHT %} 76 | 77 | {% else %} 78 | {action_raise_error("No HEIGHT or LAYER argument provided.")} 79 | {% endif %} 80 | 81 | {% set commands = printer["gcode_macro _km_layer_run"][cmd_container] %} 82 | {% if key not in commands and not CANCEL %} 83 | {% set dummy = commands.__setitem__(key, []) %} 84 | {% endif %} 85 | 86 | {% if CANCEL %} 87 | {% if key in commands %} 88 | {% set pos = ("%i"|format(key)) if key is integer else 89 | ("%.3fmm"|format(key)) %} 90 | {% if COMMAND %} 91 | {% set dummy = commands[key].remove(COMMAND) %} 92 | {% if commands[key]|length == 0 %} 93 | {% set dummy = commands.__delitem__(key) %} 94 | {% endif %} 95 | {action_respond_info("Cancelled %s %s:\n* %s" | 96 | format("layer" if k is integer else "height", 97 | pos, COMMAND))} 98 | {% else %} 99 | {% set dummy = commands.__delitem__(key) %} 100 | {action_respond_info("Cancelled all commands at %s %s." | 101 | format("layer" if k is integer else "height", 102 | pos))} 103 | {% endif %} 104 | {% endif %} 105 | {% elif not COMMAND %} 106 | {action_raise_error("No COMMAND argument provided.")} 107 | {% elif COMMAND in commands[key] %} 108 | {action_raise_error("Duplicate command previously scheduled.")} 109 | {% else %} 110 | {% set dummy = commands[key].append(COMMAND) %} 111 | {% set pos = ("%i"|format(key)) if key is integer else 112 | ("%.3fmm"|format(key)) %} 113 | {action_respond_info("%s %s:\n* %s" | 114 | format("layer" if key is integer else "height", 115 | pos, COMMAND))} 116 | {% endif %} 117 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE={cmd_container} VALUE="{ 118 | commands|replace('\"','\\\"')}" 119 | _UPDATE_LAYER_COMPAT 120 | 121 | # No arguments means just list all the triggers. 122 | {% else %} 123 | {% set output = [] %} 124 | {% set commands = printer["gcode_macro _km_layer_run"].commands_layer %} 125 | {% for key in commands|list|sort %} 126 | {% set dummy = output.append("layer %i:" | format(key)) %} 127 | {% for c in commands[key] %} 128 | {% set dummy = output.append("* %s" | format(c)) %} 129 | {% endfor %} 130 | {% endfor %} 131 | {% set commands = printer["gcode_macro _km_layer_run"].commands_height %} 132 | {% for key in commands|list|sort %} 133 | {% set dummy = output.append("height %.3fmm:" | format(key)) %} 134 | {% for c in commands[key] %} 135 | {% set dummy = output.append("* %s" | format(c)) %} 136 | {% endfor %} 137 | {% endfor %} 138 | {action_respond_info(output|join('\n'))} 139 | {% endif %} 140 | 141 | [gcode_macro _km_layer_run] 142 | description: Runs pending commands for the current layer change. 143 | Usage: _KM_LAYER_RUN 144 | variable_cur_height: 0.0 145 | variable_clearance_z: 0.0 146 | variable_commands_layer: {} 147 | variable_commands_height: {} 148 | gcode: 149 | {% set cur_layer = printer.print_stats.info.current_layer %} 150 | {% for key in commands_layer | select("<=", cur_layer) | sort %} 151 | {action_respond_info("Executing scheduled commands at layer %d:\n%s" | 152 | format(key, commands_layer[key]|join('\n')))} 153 | {% for c in commands_layer[key] %} 154 | {c} 155 | {% endfor %} 156 | {% set dummy = commands_layer.__delitem__(key) %} 157 | {% endfor %} 158 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands_layer VALUE="{ 159 | commands_layer|replace('\"','\\\"')}" 160 | {% for key in commands_height | select("<=", cur_height) | sort %} 161 | {action_respond_info("Executing scheduled commands at height %.3f:\n%s" | 162 | format(key, commands_height[key]|join('\n')))} 163 | {% for c in commands_height[key] %} 164 | {c} 165 | {% endfor %} 166 | {% set dummy = commands_height.__delitem__(key) %} 167 | {% endfor %} 168 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands_height VALUE="{ 169 | commands_height|replace('\"','\\\"')}" 170 | _UPDATE_LAYER_COMPAT 171 | 172 | [gcode_macro init_layer_gcode] 173 | description: Clears scheduled gcode commands and state for all layers. 174 | Usage: INIT_LAYER_GCODE LAYERS= 175 | gcode: 176 | SET_PRINT_STATS_INFO TOTAL_LAYER="{params.LAYERS|int + 1}" CURRENT_LAYER="{0}" 177 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_height VALUE="{0.0}" 178 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=clearance_z VALUE="{0.0}" 179 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands_layer VALUE="{{}}" 180 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands_height VALUE="{{}}" 181 | _UPDATE_LAYER_COMPAT 182 | 183 | [gcode_macro _reset_layer_gcode] 184 | description: Clears scheduled gcode commands and state for all layers. 185 | Usage: _RESET_LAYER_GCODE 186 | gcode: 187 | SET_PRINT_STATS_INFO TOTAL_LAYER="{0}" CURRENT_LAYER="{0}" 188 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=cur_height VALUE="{0.0}" 189 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=clearance_z VALUE="{0.0}" 190 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands_layer VALUE="{{}}" 191 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands_height VALUE="{{}}" 192 | _UPDATE_LAYER_COMPAT 193 | 194 | [gcode_macro cancel_all_layer_gcode] 195 | description: Clears all scheduled gcode commands. 196 | Usage: CANCEL_ALL_LAYER_GCODE 197 | gcode: 198 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands_layer VALUE="{{}}" 199 | SET_GCODE_VARIABLE MACRO=_km_layer_run VARIABLE=commands_height VALUE="{{}}" 200 | _UPDATE_LAYER_COMPAT 201 | 202 | # 203 | # Begin Mainsail/Fluidd compat 204 | # 205 | 206 | [gcode_macro SET_PAUSE_NEXT_LAYER] 207 | description: Enable a pause if the next layer is reached 208 | gcode: 209 | _KM_CHECK_IS_PRINTING 210 | {% set pause_next_layer = 211 | printer['gcode_macro SET_PRINT_STATS_INFO'].pause_next_layer %} 212 | {% set ENABLE = params.ENABLE | default(1) | int != 0 %} 213 | {% set MACRO = params.MACRO | default(pause_next_layer.call, True) %} 214 | SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VALUE="{ 215 | { 'enable': False, 'call': MACRO }}" VARIABLE=pause_next_layer 216 | GCODE_AT_LAYER COMMAND="{MACRO|replace('\"','\\\"') 217 | }" CANCEL="{0 if ENABLE else 1}" LAYER="next" 218 | 219 | [gcode_macro SET_PAUSE_AT_LAYER] 220 | description: Enable/disable a pause if a given layer number is reached 221 | gcode: 222 | _KM_CHECK_IS_PRINTING 223 | {% set pause_at_layer = 224 | printer['gcode_macro SET_PRINT_STATS_INFO'].pause_at_layer %} 225 | # This enable logic is copied directly from Fluidd/Mainsail. 226 | {% set ENABLE = params.ENABLE | int != 0 if params.ENABLE is defined else 227 | params.LAYER is defined %} 228 | {% set LAYER = params.LAYER | 229 | default((pause_at_layer.layer|int, 230 | printer.print_stats.info.current_layer|int + 1)|max)%} 231 | {% set MACRO = params.MACRO | default(pause_at_layer.call, True) %} 232 | 233 | SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_at_layer VALUE="{ 234 | { 'enable': False, 'layer': 0, 'call': MACRO }}" 235 | {% if ENABLE and pause_at_layer.enable %} 236 | # Remove the previously scheduled command if we're replacing it. 237 | GCODE_AT_LAYER COMMAND="{pause_at_layer.call|replace('\"','\\\"') 238 | }" CANCEL="{1}" LAYER="{pause_at_layer.layer}" 239 | {% endif %} 240 | # Add the new command. 241 | GCODE_AT_LAYER COMMAND="{MACRO|replace('\"','\\\"') 242 | }" CANCEL="{0 if ENABLE else 1}" LAYER="{LAYER}" 243 | 244 | [gcode_macro SET_PRINT_STATS_INFO] 245 | rename_existing: _KM_SET_PRINT_STATS_INFO 246 | description: Overwrite, to get pause_next_layer and pause_at_layer feature 247 | variable_pause_next_layer: { 'enable': False, 'call': "PAUSE" } 248 | variable_pause_at_layer : { 'enable': False, 'layer': 0, 'call': "PAUSE" } 249 | gcode: 250 | _KM_SET_PRINT_STATS_INFO {rawparams} 251 | 252 | [gcode_macro _update_layer_compat] 253 | gcode: 254 | {% set next_layer = printer.print_stats.info.current_layer|int + 1 %} 255 | {% set commands_layer = printer["gcode_macro _km_layer_run"].commands_layer %} 256 | {% set keys = commands_layer | sort(reverse=True) %} 257 | 258 | {% set pause_next_layer = {'enable': False, 'call': 259 | printer['gcode_macro SET_PRINT_STATS_INFO'].pause_next_layer.call} %} 260 | {% if pause_next_layer.call in commands_layer[next_layer] | default([]) %} 261 | {% set dummy = pause_next_layer.__setitem__('enable', True) %} 262 | {% endif %} 263 | SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_next_layer VALUE="{ 264 | pause_next_layer|replace('\"','\\\"') }" 265 | 266 | # Don't just make pause_at_layer a copy of pause_next_layer. 267 | {% set pause_at_layer = {'enable': False, 'layer': 0, 'call': 268 | printer['gcode_macro SET_PRINT_STATS_INFO'].pause_at_layer.call} %} 269 | {% if pause_next_layer.enable and 270 | pause_next_layer.call == pause_at_layer.call %} 271 | {% set keys = keys | reject("==", next_layer) %} 272 | {% endif %} 273 | 274 | # We iterate through the entire reverse sorted key list because Jinja2 doesn't 275 | # have a filter for dict values. It's ugly, but there should be only a few 276 | # items in the dict. 277 | {% for key in keys %} 278 | {% if pause_at_layer.call in commands_layer[key] %} 279 | {% set dummy = pause_at_layer.__setitem__('enable', True) %} 280 | {% set dummy = pause_at_layer.__setitem__('layer', key) %} 281 | {% endif %} 282 | {% endfor %} 283 | SET_GCODE_VARIABLE MACRO=SET_PRINT_STATS_INFO VARIABLE=pause_at_layer VALUE="{ 284 | pause_at_layer|replace('\"','\\\"') }" 285 | 286 | # 287 | # End Mainsail/Fluidd compat 288 | # 289 | 290 | [gcode_macro pause_next_layer] 291 | description: Convenience macro to schedule the current print to pause at the 292 | next layer change. See PAUSE for additional arguments. 293 | Usage: PAUSE_NEXT_LAYER ... 294 | gcode: 295 | _CHECK_KINEMATIC_LIMITS{% for k in params%}{' ' ~k~ '=' ~ params[k] 296 | }{% endfor %} 297 | GCODE_AT_LAYER LAYER=NEXT COMMAND="PAUSE{% for k in params %}{ 298 | ' ' ~ k ~ '=' ~ params[k]}{% endfor %}" 299 | 300 | [gcode_macro pause_at_layer] 301 | description: Convenience macro to schedule the current print to pause at the 302 | specified layer change. LAYER=next will cause the command to run at the next 303 | layer change. See PAUSE for additional arguments. 304 | Usage: PAUSE_AT_LAYER { HEIGHT= | LAYER= } ... 305 | gcode: 306 | # Dummy argument block for Mainsail 307 | {% set dummy = None if True else " 308 | {% set dummy = params.LAYER|default(layer number)|float %} 309 | {% set dummy = params.HEIGHT|default(Z height)|int %} 310 | " %} # End argument block for Mainsail 311 | {% set filtered_params = params|reject('in',['HEIGHT','LAYER'])|list|sort %} 312 | _CHECK_KINEMATIC_LIMITS{% for k in filtered_params%}{' ' ~k~ '=' ~ params[k] 313 | }{% endfor %} 314 | GCODE_AT_LAYER {% for k in params|select('in',['HEIGHT','LAYER'])|list %}{ 315 | ' ' ~ k ~ '=' ~ params[k] }{% endfor 316 | %} COMMAND="PAUSE{% for k in filtered_params %}{ 317 | ' ' ~ k ~ '=' ~ params[k]}{% endfor %}" 318 | 319 | [gcode_macro speed_at_layer] 320 | description: Convenience macro to schedule a feedrate adjustment at the 321 | specified layer change. LAYER=next will cause the command to run at the next 322 | layer change. (SPEED parameter behaves the same as the M220 S parameter.) 323 | Usage: SPEED_AT_LAYER { HEIGHT= | LAYER= } SPEED= 324 | gcode: 325 | {% set SPEED = params.SPEED|default(0)|int %} 326 | {% if SPEED < 1 or SPEED > 500 %} 327 | {action_raise_error("SPEED[%i] parameter between 1 and 500 is required." 328 | % SPEED)} 329 | {% endif %} 330 | GCODE_AT_LAYER {% for k in params|select('in',['HEIGHT','LAYER'])|list %}{ 331 | ' ' ~ k ~ '=' ~ params[k] }{% endfor %} COMMAND="M220 S{SPEED|int}" 332 | # Dummy argument block for Mainsail 333 | {% set dummy = None if True else " 334 | {% set dummy = params.LAYER|default(layer number)|float %} 335 | {% set dummy = params.HEIGHT|default(Z height)|int %} 336 | {% set dummy = params.SPEED|default(percentage)|int %} 337 | " %} # End argument block for Mainsail 338 | 339 | [gcode_macro flow_at_layer] 340 | description: Convenience macro to schedule a flow percentage adjustment at the 341 | specified layer change. LAYER=next will cause the command to run at the next 342 | layer change. (FLOW parameter behaves the same as the M221 S parameter.) 343 | Usage: FLOW_AT_LAYER { HEIGHT= | LAYER= } FLOW= 344 | gcode: 345 | {% set FLOW = params.FLOW|default(0)|int %} 346 | {% if FLOW < 1 or FLOW > 500 %} 347 | {action_raise_error("FLOW[%i] parameter between 1 and 500 is required." 348 | % FLOW)} 349 | {% endif %} 350 | GCODE_AT_LAYER {% for k in params|select('in',['HEIGHT','LAYER'])|list %}{ 351 | ' ' ~ k ~ '=' ~ params[k] }{% endfor %} COMMAND="M221 S{FLOW|int}" 352 | # Dummy argument block for Mainsail 353 | {% set dummy = None if True else " 354 | {% set dummy = params.LAYER|default(layer number)|float %} 355 | {% set dummy = params.HEIGHT|default(Z height)|int %} 356 | {% set dummy = params.FLOW|default(percentage)|int %} 357 | " %} # End argument block for Mainsail 358 | 359 | [gcode_macro fan_at_layer] 360 | description: Convenience macro to schedule a fan adjustment at the specified 361 | layer change. LAYER=next will cause the command to run at the next layer 362 | change. See SET_FAN_SCALING for additional arguments. 363 | Usage: FAN_AT_LAYER { HEIGHT= | LAYER= } ... 364 | gcode: 365 | # Dummy argument block for Mainsail 366 | {% set dummy = None if True else " 367 | {% set dummy = params.LAYER|default(layer number)|float %} 368 | {% set dummy = params.HEIGHT|default(Z height)|int %} 369 | {% set dummy = params.SCALE|default(1.0)|float %} 370 | {% set dummy = params.BUMP|default(0)|int %} 371 | {% set dummy = params.MAXIMUM|default(0)|int %} 372 | {% set dummy = params.MINIMUM|default(255)|int %} 373 | {% set dummy = params.SPEED|default(current speed)|int %} 374 | " %} # End argument block for Mainsail 375 | {% set filtered_params = params|reject('in',['HEIGHT','LAYER'])|list|sort %} 376 | {% if filtered_params|length == 0 %} 377 | {action_raise_error("No fan parameters provided.")} 378 | {% endif %} 379 | _CHECK_FAN_PARAMS{% for k in filtered_params %}{' '~k~'='~params[k] 380 | }{% endfor %} 381 | GCODE_AT_LAYER {% for k in params|select('in',['HEIGHT','LAYER'])|list %}{ 382 | ' ' ~ k ~ '=' ~ params[k] }{% endfor 383 | %} COMMAND="SET_FAN_SCALING{% for k in filtered_params %}{ 384 | ' ' ~ k ~ '=' ~ params[k]}{% endfor %}" 385 | 386 | [gcode_macro heater_at_layer] 387 | description: Convenience macro to schedule a heater adjustment at the specified 388 | layer change. LAYER=next will cause the command to run at the next layer 389 | change. See SET_HEATER_SCALING for additional arguments. 390 | Usage: HEATER_AT_LAYER { HEIGHT= | LAYER= } ... 391 | gcode: 392 | # Dummy argument block for Mainsail 393 | {% set dummy = None if True else " 394 | {% set dummy = params.LAYER|default(layer number)|float %} 395 | {% set dummy = params.HEIGHT|default(Z height)|int %} 396 | {% set dummy = params.HEATER|default(e.g. extruder) %} 397 | {% set dummy = params.SCALE|default(1.0)|float %} 398 | {% set dummy = params.BUMP|default(0.0)|float %} 399 | {% set dummy = params.MAXIMUM|default(max_temp)|float %} 400 | {% set dummy = params.MINIMUM|default(min_temp)|float %} 401 | {% set dummy = params.TARGET|default(current target)|float %} 402 | " %} # End argument block for Mainsail 403 | {% set filtered_params = params|reject('in',['HEIGHT','LAYER'])|list|sort %} 404 | _CHECK_HEATER_PARAMS{% for k in filtered_params%}{' ' ~ k ~ '=' ~ params[k] 405 | }{% endfor %} 406 | GCODE_AT_LAYER{% for k in params|select('in',['HEIGHT','LAYER'])|list %}{ 407 | ' ' ~ k ~ '=' ~ params[k] }{% endfor 408 | %} COMMAND="SET_HEATER_SCALING{% for k in filtered_params %}{ 409 | ' ' ~ k ~ '=\\\"' ~ params[k]|replace('\\','\\\\')|replace('\'','\\\'') 410 | |replace('\"','\\\"') ~ '\\\"' 411 | }{% endfor %}" 412 | -------------------------------------------------------------------------------- /optional/bed_mesh.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro bed_mesh_calibrate] 6 | rename_existing: _KM_BED_MESH_CALIBRATE_BASE 7 | description: Wraps BED_MESH_CALIBRATE, scaling probe count to specified area. 8 | Usage: See Klipper documentation. 9 | gcode: 10 | BED_MESH_CALIBRATE_FAST{%for k in params%}{' '~k~'="'~params[k]~'"'}{%endfor%} 11 | 12 | [gcode_macro g29] 13 | gcode: 14 | BED_MESH_CALIBRATE 15 | -------------------------------------------------------------------------------- /optional/lcd_menus.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | ################################################################################ 6 | # Existing menu refinements. 7 | ################################################################################ 8 | 9 | # Hide unused menus 10 | 11 | [menu __main __octoprint] 12 | type: list 13 | name: OctoPrint 14 | enable: {printer["gcode_macro _km_globals"].menu_show_octoprint} 15 | 16 | 17 | # Get the file list out of the SD card menu while printing. 18 | [menu __main __sdcard] 19 | type: list 20 | enable: {'virtual_sdcard' in printer and 21 | printer["gcode_macro _km_globals"].menu_show_sdcard} 22 | name: SD Card 23 | 24 | [menu __main __sdcard __start] 25 | type: command 26 | enable: {printer.virtual_sdcard.file_path and 27 | not printer.virtual_sdcard.is_active and 28 | printer.print_stats.state != "printing" and 29 | printer.print_stats.state != "paused"} 30 | name: Print: {printer.virtual_sdcard.file_path.split('/')|last} 31 | gcode: 32 | M24 33 | {menu.back()} 34 | 35 | [menu __main __sdcard __select] 36 | type: vsdlist 37 | enable: {not printer.virtual_sdcard.is_active and 38 | printer.print_stats.state != "printing" and 39 | printer.print_stats.state != "paused"} 40 | name: Select file 41 | index: 1 42 | 43 | [menu __main __sdcard __select __start] 44 | type: command 45 | enable: {printer.virtual_sdcard.file_path and 46 | not printer.virtual_sdcard.is_active} 47 | name: Print: {printer.virtual_sdcard.file_path.split('/')|last} 48 | gcode: 49 | M24 50 | {menu.back()} 51 | 52 | [menu __main __setup __calib __delta_calib_auto] 53 | type: command 54 | enable: {'delta_calibrate' in printer.configfile.settings and 55 | not printer.idle_timeout.state == "Printing"} 56 | name: Delta cal. auto 57 | gcode: 58 | G28 59 | DELTA_CALIBRATE 60 | 61 | [menu __main __setup __calib __delta_calib_man] 62 | type: list 63 | enable: {'delta_calibrate' in printer.configfile.settings and 64 | not printer.idle_timeout.state == "Printing"} 65 | name: Delta cal. man 66 | 67 | # Require confirmation for anything that would abort an in-progress print. 68 | 69 | # Steppers off 70 | [menu __main __control __disable] 71 | type: command 72 | name: Steppers off 73 | enable: {printer.idle_timeout.state != "Printing"} 74 | gcode: 75 | M84 76 | M18 77 | 78 | [menu __main __control __disable_printing] 79 | type: list 80 | index: 3 81 | enable: {printer.idle_timeout.state == "Printing"} 82 | name: Steppers off 83 | 84 | [menu __main __control __disable_printing __confirm] 85 | type: command 86 | name: Confirm steppers off 87 | gcode: 88 | M84 89 | M18 90 | {menu.back()} 91 | 92 | # Add a park menu item. 93 | [menu __main __control __park] 94 | type: command 95 | name: Park toolhead 96 | enable: {printer.idle_timeout.state != "Printing" or 97 | printer.pause_resume.is_paused} 98 | index: 1 99 | gcode: 100 | PARK LAZY=1 101 | 102 | # Octoprint abort 103 | [menu __main __octoprint __abort] 104 | type: list 105 | enable: {printer.idle_timeout.state == "Printing"} 106 | name: Abort printing 107 | 108 | [menu __main __octoprint __abort __confirm] 109 | type: command 110 | name: Confirm abort printing 111 | gcode: 112 | {action_respond_info('action:cancel')} 113 | {menu.back()} 114 | 115 | # SD card cancel 116 | [menu __main __sdcard __cancel] 117 | type: list 118 | enable: {('virtual_sdcard' in printer) and 119 | (printer.print_stats.state == "printing" or 120 | printer.print_stats.state == "paused")} 121 | name: Cancel printing 122 | 123 | [menu __main __sdcard __cancel __confirm] 124 | type: command 125 | name: Confirm cancel printing 126 | gcode: 127 | {% if 'pause_resume' in printer %} 128 | CANCEL_PRINT 129 | {% else %} 130 | M25 131 | M27 132 | M26 S0 133 | TURN_OFF_HEATERS 134 | G91 135 | G0 Z{(printer.toolhead.position.z, printer.toolhead.axis_maximum.z - 5)|min 136 | } F1000 137 | G90 138 | {% endif %} 139 | {menu.back()} 140 | 141 | # Extra setup menu options 142 | 143 | # Shutdown and reboot 144 | [menu __main __setup __restart] 145 | type: list 146 | name: Host Control 147 | 148 | [menu __main __setup __restart __reboot] 149 | type: command 150 | name: Reboot host 151 | gcode: 152 | M117 Rebooting host 153 | M118 Rebooting host 154 | {menu.exit()} 155 | G4 S2 ; Let the user see the console message. 156 | {action_call_remote_method("reboot_machine")} ; Try Moonraker. 157 | G4 S1 ; give Moonraker a chance to finish. 158 | {action_respond_info('action:poweroff')} ; Try Octoprint. 159 | 160 | [menu __main __setup __restart __shutdown] 161 | type: command 162 | name: Shutdown host 163 | gcode: 164 | M117 Shutting down 165 | M118 Shutting down 166 | {menu.exit()} 167 | G4 S2 ; Let the user see the console message. 168 | {action_call_remote_method("shutdown_machine")} ; Try Moonraker. 169 | G4 S1 ; give Moonraker a chance to finish. 170 | {action_respond_info('action:poweroff')} ; Try Octoprint. 171 | 172 | # Speed and flow 173 | [menu __main __setup __speed] 174 | type: input 175 | name: Speed: {'%3d' % (menu.input*100)}% 176 | input: {printer.gcode_move.speed_factor} 177 | input_min: 0.01 178 | input_max: 5 179 | input_step: 0.01 180 | realtime: True 181 | index: 4 182 | gcode: 183 | M220 S{'%d' % (menu.input*100)} 184 | 185 | [menu __main __setup __flow] 186 | type: input 187 | name: Flow: {'%3d' % (menu.input*100)}% 188 | input: {printer.gcode_move.extrude_factor} 189 | input_min: 0.01 190 | input_max: 2 191 | input_step: 0.01 192 | realtime: True 193 | index: 5 194 | gcode: 195 | M221 S{'%d' % (menu.input*100)} 196 | 197 | ################################################################################ 198 | # Replace filament loading with our own macros. 199 | ################################################################################ 200 | 201 | [menu __main __filament] 202 | type: list 203 | name: Filament 204 | enable: {printer.idle_timeout.state != "Printing" or 205 | printer.pause_resume.is_paused} 206 | 207 | # Hide the old load/unload commands. 208 | [menu __main __filament __loadf] 209 | type: command 210 | name: Load Fil. fast 211 | enable: False 212 | 213 | [menu __main __filament __loads] 214 | type: command 215 | name: Load Fil. slow 216 | enable: False 217 | 218 | [menu __main __filament __unloadf] 219 | type: command 220 | name: Unload Fil.fast 221 | enable: False 222 | 223 | [menu __main __filament __unloads] 224 | type: command 225 | name: Unload Fil.slow 226 | enable: False 227 | 228 | # Add new load/unload using our macros. 229 | [menu __main __filament __load] 230 | type: command 231 | index: 1 232 | name: Load Filament 233 | gcode: 234 | LOAD_FILAMENT 235 | 236 | [menu __main __filament __unload] 237 | type: command 238 | index: 2 239 | name: Unload Filament 240 | gcode: 241 | UNLOAD_FILAMENT 242 | 243 | [menu __main __filament __feed] 244 | type: input 245 | name: Feed: {'%.1f' % menu.input} 246 | input: 0.0 247 | input_min: -50.0 248 | input_max: 50.0 249 | input_step: 1.0 250 | gcode: 251 | SAVE_GCODE_STATE NAME=_KM_FILAMENT_LOAD 252 | M83 253 | G1 E{'%.1f' % menu.input 254 | } F{printer["gcode_macro _km_globals"].load_priming_speed} 255 | RESTORE_GCODE_STATE NAME=_KM_FILAMENT_LOAD 256 | 257 | ################################################################################ 258 | # Layer triggers. 259 | ################################################################################ 260 | 261 | [menu __main __sdcard __pause_layer] 262 | type: input 263 | index: 4 264 | enable: {('virtual_sdcard' in printer) and 265 | printer.print_stats.state == "printing"} 266 | name: Pause {% set layer = printer.print_stats.info.current_layer %}{% 267 | if layer >= menu.input|int %}layer{% 268 | elif layer + 1 == menu.input|int %}at: next{% 269 | else %}at: {menu.input|int}{% endif %} 270 | input: {printer.print_stats.info.current_layer} 271 | input_min: {printer.print_stats.info.current_layer} 272 | input_max: {printer.print_stats.info.total_layer} 273 | input_step: 1 274 | gcode: 275 | {% if menu.input|int > printer.print_stats.info.current_layer %} 276 | PAUSE_AT_LAYER LAYER={menu.input} 277 | {% endif %} 278 | 279 | [menu __main __octoprint __pause_layer] 280 | type: input 281 | index: 1 282 | enable: {printer.idle_timeout.state == "Printing"} 283 | name: Pause {% set layer = printer.print_stats.info.current_layer %}{% 284 | if layer >= menu.input|int %}layer{% 285 | elif layer + 1 == menu.input|int + 1 %}at: next{% 286 | else %}at: {menu.input|int}{% endif %} 287 | input: {printer.print_stats.info.current_layer} 288 | input_min: {printer.print_stats.info.current_layer} 289 | input_max: {printer.print_stats.info.total_layer} 290 | input_step: 1 291 | gcode: 292 | {% if menu.input|int > printer.print_stats.info.current_layer %} 293 | GCODE_AT_LAYER LAYER={menu.input|int 294 | } COMMAND="RESPOND TYPE=command MSG=action:pause" 295 | {% endif %} 296 | 297 | ################################################################################ 298 | # Bed surface. 299 | ################################################################################ 300 | 301 | [menu __main __setup __bed_surface] 302 | type: input 303 | name: Bed: {(printer.save_variables.variables.bed_surfaces.available 304 | | list | sort)[menu.input|int]} 305 | input: {% set surfaces = printer.save_variables.variables.bed_surfaces 306 | %}{(surfaces.available | list | sort).index(surfaces.active) | int} 307 | input_min: 0 308 | input_max: {((printer.save_variables.variables.bed_surfaces.available 309 | | length) - 1)} 310 | input_step: 1 311 | index: 4 312 | gcode: 313 | SET_SURFACE_ACTIVE SURFACE={ 314 | (printer.save_variables.variables.bed_surfaces.available 315 | | list | sort)[menu.input|int]} 316 | 317 | [menu __main __setup __offsetz] 318 | type: input 319 | name: Offset Z:{ '%05.3f' % menu.input } 320 | input: {% set surfaces = printer.save_variables.variables.bed_surfaces 321 | %}{ surfaces.available[surfaces.active].offset | float } 322 | input_min: -5 323 | input_max: 5 324 | input_step: 0.005 325 | index: 5 326 | realtime: True 327 | gcode: 328 | SET_SURFACE_OFFSET OFFSET={menu.input} 329 | 330 | [menu __main __tune __offsetz] 331 | type: input 332 | name: Offset Z:{ '%05.3f' % menu.input } 333 | input: { printer.gcode_move.homing_origin.z } 334 | input_min: -5 335 | input_max: 5 336 | input_step: 0.005 337 | realtime: True 338 | gcode: 339 | SET_SURFACE_OFFSET OFFSET={menu.input} 340 | 341 | ################################################################################ 342 | # Heater overrides. 343 | ################################################################################ 344 | 345 | ### menu temperature ### 346 | 347 | # Hide the original menu 348 | [menu __main __temp] 349 | type: list 350 | name: Temperature 351 | enable: False 352 | 353 | [menu __main __temp_km] 354 | type: list 355 | name: Temperature 356 | index: 4 357 | 358 | [menu __main __temp_km __hotend0_target] 359 | type: input 360 | enable: {'extruder' in printer} 361 | name: {"Ex0:%3.0f (%4.0f)" % (menu.input, printer.extruder.temperature)} 362 | input: {printer.extruder.target} 363 | input_min: 0 364 | input_max: {printer.configfile.config.extruder.max_temp} 365 | input_step: 1 366 | gcode: SET_HEATER_TEMPERATURE HEATER=extruder TARGET={'%.0f' % menu.input} 367 | 368 | [menu __main __temp_km __hotend1_target] 369 | type: input 370 | enable: {'extruder1' in printer} 371 | name: {"Ex1:%3.0f (%4.0f)" % (menu.input, printer.extruder1.temperature)} 372 | input: {printer.extruder1.target} 373 | input_min: 0 374 | input_max: {printer.configfile.config.extruder1.max_temp} 375 | input_step: 1 376 | gcode: SET_HEATER_TEMPERATURE HEATER=extruder1 TARGET={'%.0f' % menu.input} 377 | 378 | [menu __main __temp_km __hotbed_target] 379 | type: input 380 | enable: {'heater_bed' in printer} 381 | name: {"Bed:%3.0f (%4.0f)" % (menu.input, printer.heater_bed.temperature)} 382 | input: {printer.heater_bed.target} 383 | input_min: 0 384 | input_max: {printer.configfile.config.heater_bed.max_temp} 385 | input_step: 1 386 | gcode: SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={'%.0f' % menu.input} 387 | 388 | # We just create 10 preheat placeholders below, and dynamically enable and fill 389 | # them in from the dictionary in variable_menu_temperature. 390 | 391 | ## Pre-heat [0] ## 392 | [menu __main __temp_km __preheat_0] 393 | type: list 394 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[0].name} 395 | enable: {printer.idle_timeout.state != "Printing" and 396 | printer["gcode_macro _km_globals"].menu_temperature|length > 0} 397 | 398 | [menu __main __temp_km __preheat_0 __all] 399 | type: command 400 | enable: {printer["gcode_macro _km_globals"].menu_temperature[0] | list | 401 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 402 | (('extruder' in printer) + ('heater_bed' in printer) + 403 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 404 | name: Preheat all 405 | gcode: 406 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[0] %} 407 | {% if 'chamber' in targets and 408 | 'heater_generic chamber' in printer.heaters.available_heaters %} 409 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 410 | {% endif %} 411 | {% if 'bed' in targets and 'heater_bed' in printer %} 412 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 413 | {% endif %} 414 | {% if 'extruder' in targets and 'extruder' in printer %} 415 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 416 | targets.extruder} 417 | {% endif %} 418 | 419 | [menu __main __temp_km __preheat_0 __hotend] 420 | type: command 421 | enable: {'extruder' in printer and 422 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[0]} 423 | name: Preheat hotend 424 | gcode: 425 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 426 | printer["gcode_macro _km_globals"].menu_temperature[0].extruder} 427 | 428 | [menu __main __temp_km __preheat_0 __hotbed] 429 | type: command 430 | enable: {'heater_bed' in printer and 431 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[0]} 432 | name: Preheat bed 433 | gcode: 434 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 435 | printer["gcode_macro _km_globals"].menu_temperature[0].bed} 436 | 437 | [menu __main __temp_km __preheat_0 __chamber] 438 | type: command 439 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 440 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[0]} 441 | name: Preheat chamber 442 | gcode: 443 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 444 | printer["gcode_macro _km_globals"].menu_temperature[0].chamber} 445 | 446 | ## Pre-heat [1] ## 447 | [menu __main __temp_km __preheat_1] 448 | type: list 449 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[1].name} 450 | enable: {printer.idle_timeout.state != "Printing" and 451 | printer["gcode_macro _km_globals"].menu_temperature|length > 1} 452 | 453 | [menu __main __temp_km __preheat_1 __all] 454 | type: command 455 | enable: {printer["gcode_macro _km_globals"].menu_temperature[1] | list | 456 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 457 | (('extruder' in printer) + ('heater_bed' in printer) + 458 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 459 | name: Preheat all 460 | gcode: 461 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[1] %} 462 | {% if 'chamber' in targets and 463 | 'heater_generic chamber' in printer.heaters.available_heaters %} 464 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 465 | {% endif %} 466 | {% if 'bed' in targets and 'heater_bed' in printer %} 467 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 468 | {% endif %} 469 | {% if 'extruder' in targets and 'extruder' in printer %} 470 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 471 | targets.extruder} 472 | {% endif %} 473 | 474 | [menu __main __temp_km __preheat_1 __hotend] 475 | type: command 476 | enable: {'extruder' in printer and 477 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[1]} 478 | name: Preheat hotend 479 | gcode: 480 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 481 | printer["gcode_macro _km_globals"].menu_temperature[1].extruder} 482 | 483 | [menu __main __temp_km __preheat_1 __hotbed] 484 | type: command 485 | enable: {'heater_bed' in printer and 486 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[1]} 487 | name: Preheat bed 488 | gcode: 489 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 490 | printer["gcode_macro _km_globals"].menu_temperature[1].bed} 491 | 492 | [menu __main __temp_km __preheat_1 __chamber] 493 | type: command 494 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 495 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[1]} 496 | name: Preheat chamber 497 | gcode: 498 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 499 | printer["gcode_macro _km_globals"].menu_temperature[1].chamber} 500 | 501 | ## Pre-heat [2] ## 502 | [menu __main __temp_km __preheat_2] 503 | type: list 504 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[2].name} 505 | enable: {printer.idle_timeout.state != "Printing" and 506 | printer["gcode_macro _km_globals"].menu_temperature|length > 2} 507 | 508 | [menu __main __temp_km __preheat_2 __all] 509 | type: command 510 | enable: {printer["gcode_macro _km_globals"].menu_temperature[2] | list | 511 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 512 | (('extruder' in printer) + ('heater_bed' in printer) + 513 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 514 | name: Preheat all 515 | gcode: 516 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[2] %} 517 | {% if 'chamber' in targets and 518 | 'heater_generic chamber' in printer.heaters.available_heaters %} 519 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 520 | {% endif %} 521 | {% if 'bed' in targets and 'heater_bed' in printer %} 522 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 523 | {% endif %} 524 | {% if 'extruder' in targets and 'extruder' in printer %} 525 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 526 | targets.extruder} 527 | {% endif %} 528 | 529 | [menu __main __temp_km __preheat_2 __hotend] 530 | type: command 531 | enable: {'extruder' in printer and 532 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[2]} 533 | name: Preheat hotend 534 | gcode: 535 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 536 | printer["gcode_macro _km_globals"].menu_temperature[2].extruder} 537 | 538 | [menu __main __temp_km __preheat_2 __hotbed] 539 | type: command 540 | enable: {'heater_bed' in printer and 541 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[2]} 542 | name: Preheat bed 543 | gcode: 544 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 545 | printer["gcode_macro _km_globals"].menu_temperature[2].bed} 546 | 547 | [menu __main __temp_km __preheat_2 __chamber] 548 | type: command 549 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 550 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[2]} 551 | name: Preheat chamber 552 | gcode: 553 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 554 | printer["gcode_macro _km_globals"].menu_temperature[2].chamber} 555 | 556 | ## Pre-heat [3] ## 557 | [menu __main __temp_km __preheat_3] 558 | type: list 559 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[3].name} 560 | enable: {printer.idle_timeout.state != "Printing" and 561 | printer["gcode_macro _km_globals"].menu_temperature|length > 3} 562 | 563 | [menu __main __temp_km __preheat_3 __all] 564 | type: command 565 | enable: {printer["gcode_macro _km_globals"].menu_temperature[3] | list | 566 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 567 | (('extruder' in printer) + ('heater_bed' in printer) + 568 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 569 | name: Preheat all 570 | gcode: 571 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[3] %} 572 | {% if 'chamber' in targets and 573 | 'heater_generic chamber' in printer.heaters.available_heaters %} 574 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 575 | {% endif %} 576 | {% if 'bed' in targets and 'heater_bed' in printer %} 577 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 578 | {% endif %} 579 | {% if 'extruder' in targets and 'extruder' in printer %} 580 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 581 | targets.extruder} 582 | {% endif %} 583 | 584 | [menu __main __temp_km __preheat_3 __hotend] 585 | type: command 586 | enable: {'extruder' in printer and 587 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[3]} 588 | name: Preheat hotend 589 | gcode: 590 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 591 | printer["gcode_macro _km_globals"].menu_temperature[3].extruder} 592 | 593 | [menu __main __temp_km __preheat_3 __hotbed] 594 | type: command 595 | enable: {'heater_bed' in printer and 596 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[3]} 597 | name: Preheat bed 598 | gcode: 599 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 600 | printer["gcode_macro _km_globals"].menu_temperature[3].bed} 601 | 602 | [menu __main __temp_km __preheat_3 __chamber] 603 | type: command 604 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 605 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[3]} 606 | name: Preheat chamber 607 | gcode: 608 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 609 | printer["gcode_macro _km_globals"].menu_temperature[3].chamber} 610 | 611 | ## Pre-heat [4] ## 612 | [menu __main __temp_km __preheat_4] 613 | type: list 614 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[4].name} 615 | enable: {printer.idle_timeout.state != "Printing" and 616 | printer["gcode_macro _km_globals"].menu_temperature|length > 4} 617 | 618 | [menu __main __temp_km __preheat_4 __all] 619 | type: command 620 | enable: {printer["gcode_macro _km_globals"].menu_temperature[4] | list | 621 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 622 | (('extruder' in printer) + ('heater_bed' in printer) + 623 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 624 | name: Preheat all 625 | gcode: 626 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[4] %} 627 | {% if 'chamber' in targets and 628 | 'heater_generic chamber' in printer.heaters.available_heaters %} 629 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 630 | {% endif %} 631 | {% if 'bed' in targets and 'heater_bed' in printer %} 632 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 633 | {% endif %} 634 | {% if 'extruder' in targets and 'extruder' in printer %} 635 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 636 | targets.extruder} 637 | {% endif %} 638 | 639 | [menu __main __temp_km __preheat_4 __hotend] 640 | type: command 641 | enable: {'extruder' in printer and 642 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[4]} 643 | name: Preheat hotend 644 | gcode: 645 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 646 | printer["gcode_macro _km_globals"].menu_temperature[4].extruder} 647 | 648 | [menu __main __temp_km __preheat_4 __hotbed] 649 | type: command 650 | enable: {'heater_bed' in printer and 651 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[4]} 652 | name: Preheat bed 653 | gcode: 654 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 655 | printer["gcode_macro _km_globals"].menu_temperature[4].bed} 656 | 657 | [menu __main __temp_km __preheat_4 __chamber] 658 | type: command 659 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 660 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[4]} 661 | name: Preheat chamber 662 | gcode: 663 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 664 | printer["gcode_macro _km_globals"].menu_temperature[4].chamber} 665 | 666 | ## Pre-heat [5] ## 667 | [menu __main __temp_km __preheat_5] 668 | type: list 669 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[5].name} 670 | enable: {printer.idle_timeout.state != "Printing" and 671 | printer["gcode_macro _km_globals"].menu_temperature|length > 5} 672 | 673 | [menu __main __temp_km __preheat_5 __all] 674 | type: command 675 | enable: {printer["gcode_macro _km_globals"].menu_temperature[5] | list | 676 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 677 | (('extruder' in printer) + ('heater_bed' in printer) + 678 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 679 | name: Preheat all 680 | gcode: 681 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[5] %} 682 | {% if 'chamber' in targets and 683 | 'heater_generic chamber' in printer.heaters.available_heaters %} 684 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 685 | {% endif %} 686 | {% if 'bed' in targets and 'heater_bed' in printer %} 687 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 688 | {% endif %} 689 | {% if 'extruder' in targets and 'extruder' in printer %} 690 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 691 | targets.extruder} 692 | {% endif %} 693 | 694 | [menu __main __temp_km __preheat_5 __hotend] 695 | type: command 696 | enable: {'extruder' in printer and 697 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[5]} 698 | name: Preheat hotend 699 | gcode: 700 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 701 | printer["gcode_macro _km_globals"].menu_temperature[5].extruder} 702 | 703 | [menu __main __temp_km __preheat_5 __hotbed] 704 | type: command 705 | enable: {'heater_bed' in printer and 706 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[5]} 707 | name: Preheat bed 708 | gcode: 709 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 710 | printer["gcode_macro _km_globals"].menu_temperature[5].bed} 711 | 712 | [menu __main __temp_km __preheat_5 __chamber] 713 | type: command 714 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 715 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[5]} 716 | name: Preheat chamber 717 | gcode: 718 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 719 | printer["gcode_macro _km_globals"].menu_temperature[5].chamber} 720 | 721 | ## Pre-heat [6] ## 722 | [menu __main __temp_km __preheat_6] 723 | type: list 724 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[6].name} 725 | enable: {printer.idle_timeout.state != "Printing" and 726 | printer["gcode_macro _km_globals"].menu_temperature|length > 6} 727 | 728 | [menu __main __temp_km __preheat_6 __all] 729 | type: command 730 | enable: {printer["gcode_macro _km_globals"].menu_temperature[6] | list | 731 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 732 | (('extruder' in printer) + ('heater_bed' in printer) + 733 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 734 | name: Preheat all 735 | gcode: 736 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[6] %} 737 | {% if 'chamber' in targets and 738 | 'heater_generic chamber' in printer.heaters.available_heaters %} 739 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 740 | {% endif %} 741 | {% if 'bed' in targets and 'heater_bed' in printer %} 742 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 743 | {% endif %} 744 | {% if 'extruder' in targets and 'extruder' in printer %} 745 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 746 | targets.extruder} 747 | {% endif %} 748 | 749 | [menu __main __temp_km __preheat_6 __hotend] 750 | type: command 751 | enable: {'extruder' in printer and 752 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[6]} 753 | name: Preheat hotend 754 | gcode: 755 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 756 | printer["gcode_macro _km_globals"].menu_temperature[6].extruder} 757 | 758 | [menu __main __temp_km __preheat_6 __hotbed] 759 | type: command 760 | enable: {'heater_bed' in printer and 761 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[6]} 762 | name: Preheat bed 763 | gcode: 764 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 765 | printer["gcode_macro _km_globals"].menu_temperature[6].bed} 766 | 767 | [menu __main __temp_km __preheat_6 __chamber] 768 | type: command 769 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 770 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[6]} 771 | name: Preheat chamber 772 | gcode: 773 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 774 | printer["gcode_macro _km_globals"].menu_temperature[6].chamber} 775 | 776 | ## Pre-heat [7] ## 777 | [menu __main __temp_km __preheat_7] 778 | type: list 779 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[7].name} 780 | enable: {printer.idle_timeout.state != "Printing" and 781 | printer["gcode_macro _km_globals"].menu_temperature|length > 7} 782 | 783 | [menu __main __temp_km __preheat_7 __all] 784 | type: command 785 | enable: {printer["gcode_macro _km_globals"].menu_temperature[7] | list | 786 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 787 | (('extruder' in printer) + ('heater_bed' in printer) + 788 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 789 | name: Preheat all 790 | gcode: 791 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[7] %} 792 | {% if 'chamber' in targets and 793 | 'heater_generic chamber' in printer.heaters.available_heaters %} 794 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 795 | {% endif %} 796 | {% if 'bed' in targets and 'heater_bed' in printer %} 797 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 798 | {% endif %} 799 | {% if 'extruder' in targets and 'extruder' in printer %} 800 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 801 | targets.extruder} 802 | {% endif %} 803 | 804 | [menu __main __temp_km __preheat_7 __hotend] 805 | type: command 806 | enable: {'extruder' in printer and 807 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[7]} 808 | name: Preheat hotend 809 | gcode: 810 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 811 | printer["gcode_macro _km_globals"].menu_temperature[7].extruder} 812 | 813 | [menu __main __temp_km __preheat_7 __hotbed] 814 | type: command 815 | enable: {'heater_bed' in printer and 816 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[7]} 817 | name: Preheat bed 818 | gcode: 819 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 820 | printer["gcode_macro _km_globals"].menu_temperature[7].bed} 821 | 822 | [menu __main __temp_km __preheat_7 __chamber] 823 | type: command 824 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 825 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[7]} 826 | name: Preheat chamber 827 | gcode: 828 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 829 | printer["gcode_macro _km_globals"].menu_temperature[7].chamber} 830 | 831 | ## Pre-heat [8] ## 832 | [menu __main __temp_km __preheat_8] 833 | type: list 834 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[8].name} 835 | enable: {printer.idle_timeout.state != "Printing" and 836 | printer["gcode_macro _km_globals"].menu_temperature|length > 8} 837 | 838 | [menu __main __temp_km __preheat_8 __all] 839 | type: command 840 | enable: {printer["gcode_macro _km_globals"].menu_temperature[8] | list | 841 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 842 | (('extruder' in printer) + ('heater_bed' in printer) + 843 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 844 | name: Preheat all 845 | gcode: 846 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[8] %} 847 | {% if 'chamber' in targets and 848 | 'heater_generic chamber' in printer.heaters.available_heaters %} 849 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 850 | {% endif %} 851 | {% if 'bed' in targets and 'heater_bed' in printer %} 852 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 853 | {% endif %} 854 | {% if 'extruder' in targets and 'extruder' in printer %} 855 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 856 | targets.extruder} 857 | {% endif %} 858 | 859 | [menu __main __temp_km __preheat_8 __hotend] 860 | type: command 861 | enable: {'extruder' in printer and 862 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[8]} 863 | name: Preheat hotend 864 | gcode: 865 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 866 | printer["gcode_macro _km_globals"].menu_temperature[8].extruder} 867 | 868 | [menu __main __temp_km __preheat_8 __hotbed] 869 | type: command 870 | enable: {'heater_bed' in printer and 871 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[8]} 872 | name: Preheat bed 873 | gcode: 874 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 875 | printer["gcode_macro _km_globals"].menu_temperature[8].bed} 876 | 877 | [menu __main __temp_km __preheat_8 __chamber] 878 | type: command 879 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 880 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[8]} 881 | name: Preheat chamber 882 | gcode: 883 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 884 | printer["gcode_macro _km_globals"].menu_temperature[8].chamber} 885 | 886 | ## Pre-heat [9] ## 887 | [menu __main __temp_km __preheat_9] 888 | type: list 889 | name: Preheat {printer["gcode_macro _km_globals"].menu_temperature[9].name} 890 | enable: {printer.idle_timeout.state != "Printing" and 891 | printer["gcode_macro _km_globals"].menu_temperature|length > 9} 892 | 893 | [menu __main __temp_km __preheat_9 __all] 894 | type: command 895 | enable: {printer["gcode_macro _km_globals"].menu_temperature[9] | list | 896 | select('in', ['extruder', 'bed', 'chamber']) | list | length > 1 and 897 | (('extruder' in printer) + ('heater_bed' in printer) + 898 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 899 | name: Preheat all 900 | gcode: 901 | {% set targets = printer["gcode_macro _km_globals"].menu_temperature[9] %} 902 | {% if 'chamber' in targets and 903 | 'heater_generic chamber' in printer.heaters.available_heaters %} 904 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={targets.chamber} 905 | {% endif %} 906 | {% if 'bed' in targets and 'heater_bed' in printer %} 907 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={targets.bed} 908 | {% endif %} 909 | {% if 'extruder' in targets and 'extruder' in printer %} 910 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 911 | targets.extruder} 912 | {% endif %} 913 | 914 | [menu __main __temp_km __preheat_9 __hotend] 915 | type: command 916 | enable: {'extruder' in printer and 917 | 'extruder' in printer["gcode_macro _km_globals"].menu_temperature[9]} 918 | name: Preheat hotend 919 | gcode: 920 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET={ 921 | printer["gcode_macro _km_globals"].menu_temperature[9].extruder} 922 | 923 | [menu __main __temp_km __preheat_9 __hotbed] 924 | type: command 925 | enable: {'heater_bed' in printer and 926 | 'bed' in printer["gcode_macro _km_globals"].menu_temperature[9]} 927 | name: Preheat bed 928 | gcode: 929 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET={ 930 | printer["gcode_macro _km_globals"].menu_temperature[9].bed} 931 | 932 | [menu __main __temp_km __preheat_9 __chamber] 933 | type: command 934 | enable: {'heater_generic chamber' in printer.heaters.available_heaters and 935 | 'chamber' in printer["gcode_macro _km_globals"].menu_temperature[9]} 936 | name: Preheat chamber 937 | gcode: 938 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET={ 939 | printer["gcode_macro _km_globals"].menu_temperature[9].chamber} 940 | 941 | ## Cooldown ## 942 | [menu __main __temp_km __cooldown_all] 943 | type: command 944 | enable: {printer.idle_timeout.state != "Printing" and 945 | (('extruder' in printer) + ('heater_bed' in printer) + 946 | ('heater_generic chamber' in printer.heaters.available_heaters)) > 1} 947 | name: Cooldown all 948 | gcode: 949 | {% if 'heater_generic chamber' in printer.heaters.available_heaters %} 950 | SET_HEATER_TEMPERATURE HEATER=chamber TARGET=0 951 | {% endif %} 952 | {% if 'heater_bed' in printer %} 953 | SET_HEATER_TEMPERATURE HEATER=heater_bed TARGET=0 954 | {% endif %} 955 | {% if 'extruder' in printer%} 956 | SET_HEATER_TEMPERATURE HEATER={printer.toolhead.extruder} TARGET=0 957 | {% endif %} 958 | 959 | [menu __main __temp_km __cooldown_hotend] 960 | type: command 961 | enable: {printer.idle_timeout.state != "Printing" and 'extruder' in printer} 962 | name: Cooldown hotend 963 | gcode: M104 S0 964 | 965 | [menu __main __temp_km __cooldown_hotbed] 966 | type: command 967 | enable: {printer.idle_timeout.state != "Printing" and 'heater_bed' in printer} 968 | name: Cooldown bed 969 | gcode: M140 S0 970 | 971 | [menu __main __temp_km __cooldown_chamber] 972 | type: command 973 | enable: {printer.idle_timeout.state != "Printing" and 974 | 'heater_generic chamber' in printer.heaters.available_heaters} 975 | name: Cooldown chamber 976 | gcode: M141 S0 977 | -------------------------------------------------------------------------------- /park.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro park] 6 | description: Park the toolhead 7 | Usage: PARK [P=<0|1|2>] [X=] [Y=] [Z=] [LAZY=<1|0>] 8 | gcode: 9 | {% set km = printer["gcode_macro _km_globals"] %} 10 | {% set LAZY = params.LAZY|default(1)|int %} 11 | {% if printer.toolhead.homed_axes != "xyz" %} 12 | {% if LAZY %} 13 | LAZY_HOME 14 | {% else %} 15 | {action_raise_error("Must home axes first.")} 16 | {% endif %} 17 | {% endif %} 18 | 19 | # Z position type from G27 (if below, absolute, relative) 20 | {% set P = (params.P|default(2))|int %} # Default to 2 because it's sanest. 21 | {% set X = params.X|default(km.park_x)|float %} 22 | {% set Y = params.Y|default(km.park_y)|float %} 23 | {% set Z = params.Z|default(km.park_z)|float %} 24 | 25 | M400 26 | _CHECK_KINEMATIC_LIMITS X="{X}" Y="{Y}" Z="{Z}" 27 | _PARK_INNER X="{X}" Y="{Y}" Z="{Z}" P="{P}" LAZY="{LAZY}" 28 | # Dummy argument block for Mainsail 29 | {% set dummy = None if True else " 30 | {% set dummy = params.P|default(mode=<0|1|2>)|int %} 31 | {% set dummy = params.X|default(X position)|int %} 32 | {% set dummy = params.Y|default(Y position)|int %} 33 | {% set dummy = params.Z|default(Z position)|int %} 34 | " %} # End argument block for Mainsail 35 | 36 | [gcode_macro _park_inner] 37 | gcode: 38 | {% set km = printer["gcode_macro _km_globals"] %} 39 | {% set travel_speed_xy = km.travel_speed_xy %} 40 | {% set travel_speed_z = km.travel_speed_z %} 41 | 42 | {% set position = printer.gcode_move.gcode_position %} 43 | {% set origin = printer.gcode_move.homing_origin%} 44 | 45 | # Use the taller of the highest printed layer or the current Z height, which 46 | # should help avoid crashes (e.g. when a sequential print in progress). 47 | {% set clearance_z = (printer["gcode_macro _km_layer_run"].clearance_z, 48 | position.z) | max %} 49 | {% set P = params.P|int %} 50 | {% set X = params.X|float - origin.x %} 51 | {% set Y = params.Y|float - origin.y %} 52 | {% set Z = params.Z|float %} 53 | {% set LAZY = params.LAZY|int %} 54 | 55 | # Convert everything to absolute coordinates. 56 | {% if P == 0 %} # Move absolute to Z if below current Z 57 | {% if clearance_z > Z %} 58 | {% set Z = clearance_z %} 59 | {% endif %} 60 | {% elif P == 1 %} # Move Z absolute. 61 | {% set Z = Z - origin.z %} 62 | {% elif P == 2 %} # Move Z relative 63 | {% set Z = Z + clearance_z %} 64 | {% else %} 65 | {action_raise_error("Invalid parameter P=%i. Value must be 0, 1, or 2." | 66 | format(P)) } 67 | {% endif %} 68 | 69 | # Clamp to the printer limits. 70 | {% set Z = ((Z, printer.toolhead.axis_maximum.z - origin.z)|min, 71 | printer.toolhead.axis_minimum.z - origin.z)|max %} 72 | 73 | # Don't move if it's a lazy park and we're already in position. 74 | {% if (not LAZY) or P != 2 or X != position.x or Y != position.y 75 | or Z < clearance_z %} 76 | SAVE_GCODE_STATE NAME=_KM_PARK 77 | G90 78 | G0 Z{Z} F{travel_speed_z} 79 | G0 X{X} Y{Y} F{travel_speed_xy} 80 | RESTORE_GCODE_STATE NAME=_KM_PARK MOVE=0 81 | {% endif %} 82 | 83 | 84 | [gcode_macro g27] 85 | description: Parks the toolhead. 86 | Usage: G27 [P=<0|1|2>] 87 | gcode: 88 | # Wraps any arguments for the PARK macro and defaults P=0 for Marlin compat. 89 | PARK P={params.P|default(0)} {% for k in params|reject("in", "GP") %}{ 90 | ' '~k~'="'~params[k]~'"' 91 | }{% endfor %} 92 | -------------------------------------------------------------------------------- /pause_resume_cancel.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | # Enables pause/resume functionality 6 | [gcode_macro pause] 7 | description: Pauses the current print. 8 | Usage: PAUSE [X=] [Y=] [Z=] [E=] [B=] 9 | rename_existing: _KM_PAUSE_BASE 10 | gcode: 11 | {% set km = printer["gcode_macro _km_globals"] %} 12 | # Retract length (negative) 13 | {% set E = (params.E|default(5))|float %} 14 | 15 | {% if printer.pause_resume.is_paused %} 16 | { action_respond_info("Print already paused") } 17 | {% elif printer.idle_timeout.state | string == "Printing" or 18 | (printer.virtual_sdcard|default({})).is_active|default(False) %} 19 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=pausing RESET_STACK=1 20 | {% set position = printer.gcode_move.gcode_position %} 21 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_x VALUE="{position.x}" 22 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_y VALUE="{position.y}" 23 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_z VALUE="{position.z}" 24 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_e VALUE="{E}" 25 | SAVE_GCODE_STATE NAME=_KM_PAUSE_OVERRIDE_STATE 26 | _KM_PAUSE_BASE 27 | M83 28 | {% if printer.extruder.can_extrude %} 29 | G1 E{'%.4f' % -E} F{km.load_speed} 30 | {% endif %} 31 | PARK P=2{% for k in params|select("in", "XYZ") %}{ 32 | ' '~k~'="'~params[k]~'"'}{% endfor %} 33 | _KM_BEEP_IF_AVAILABLE BEEPS={params.B|default(10)} 34 | {% else %} 35 | { action_respond_info("Print not in progress") } 36 | {% endif %} 37 | 38 | [gcode_macro m600] 39 | description: Pauses the current print. 40 | Usage: M600 [B] [E] [L] [R] [U] [X] [Y] 41 | [Z] 42 | gcode: 43 | PAUSE B="{0}" P=2{% for k in params|select("in", "EXYZ") %}{ 44 | ' '~k~'="'~params[k]~'"'}{% endfor %} 45 | UNLOAD_FILAMENT{% if 'U' in params %} LENGTH={params.U}{% endif 46 | %} BEEPS="{params.B|default(10)|int}" 47 | {% if 'R' in params %}M109 S{params.R}{% endif %} 48 | 49 | [gcode_macro m601] 50 | description: Pauses the current print. 51 | Usage: M601 52 | gcode: 53 | PAUSE 54 | 55 | [gcode_macro m602] 56 | description: Resumes the currently paused print. 57 | Usage: M602 58 | gcode: 59 | RESUME 60 | 61 | [gcode_macro m24] 62 | rename_existing: M24.6245197 63 | gcode: 64 | {% if printer.pause_resume.is_paused %} 65 | RESUME 66 | {% else %} 67 | M24.6245197 68 | {% endif %} 69 | 70 | [gcode_macro m25] 71 | rename_existing: M25.6245197 72 | gcode: 73 | PAUSE 74 | 75 | [gcode_macro resume] 76 | description: Resumes the currently paused print. 77 | Usage: RESUME [E] 78 | rename_existing: _KM_RESUME_BASE 79 | variable_saved_extruder_temp: 0 80 | variable_saved_x: 0.0 81 | variable_saved_y: 0.0 82 | variable_saved_z: 0.0 83 | variable_saved_e: 0.0 84 | gcode: 85 | {% if printer.pause_resume.is_paused %} 86 | {% set km = printer["gcode_macro _km_globals"] %} 87 | # Warm the extruder back up if needed. 88 | {% set extruder = printer[printer.toolhead.extruder] %} 89 | {% if extruder.target <= printer.configfile.settings[ 90 | printer.toolhead.extruder].min_temp 91 | | float + 0.5 %} 92 | M109 S{saved_extruder_temp} 93 | {% endif %} 94 | 95 | # If there's no saved_e assume we're completing a filament change and 96 | # retract enough to avoid drooling on the model. 97 | {% if 'E' not in params and not saved_e %} 98 | {% set saved_e = 5.0 %} 99 | G1 E{'%.4f' % -saved_e } F{km.load_speed} 100 | {% endif %} 101 | 102 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_extruder_temp VALUE="{0}" 103 | G90 104 | # Move back to last position before unretracting. 105 | G0 X{saved_x} Y{saved_y} F{km.travel_speed_xy} 106 | G0 Z{saved_z} F{km.travel_speed_z} 107 | G91 108 | # Unretract 109 | G1 E{'%.4f' % (params.E|default(saved_e))} F{km.load_speed} 110 | RESTORE_GCODE_STATE NAME=_KM_PAUSE_OVERRIDE_STATE MOVE=1 111 | _KM_RESUME_BASE 112 | {% else %} 113 | { action_respond_info("Printer is not paused.") } 114 | {% endif %} 115 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=printing RESET_STACK=1 116 | 117 | # TODO: Fix casing after front-ends get fixed 118 | [gcode_macro CANCEL_PRINT] 119 | description: Cancels the current print. 120 | Usage: CANCEL_PRINT 121 | rename_existing: _KM_CANCEL_PRINT_BASE 122 | gcode: 123 | _KM_CHECK_IS_PRINTING 124 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=cancelling RESET_STACK=1 125 | SET_GCODE_VARIABLE MACRO=_print_end_inner VARIABLE=cancelled VALUE="{True}" 126 | PRINT_END 127 | _KM_CANCEL_PRINT_BASE 128 | {% if printer.pause_resume.is_paused %} 129 | RESTORE_GCODE_STATE NAME=_KM_PAUSE_OVERRIDE_STATE MOVE=0 130 | {% endif %} 131 | CLEAR_PAUSE 132 | _KM_APPLY_PRINT_OFFSET RESET=1 133 | {% if 'virtual_sdcard' in printer and not printer.virtual_sdcard.is_active %} 134 | SDCARD_RESET_FILE 135 | {% endif %} 136 | 137 | [gcode_macro clear_pause] 138 | description: Clears the current pause state. 139 | Usage: CLEAR_PAUSE 140 | rename_existing: _KM_CLEAR_PAUSE 141 | gcode: 142 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_e VALUE="{0.0}" 143 | SET_GCODE_VARIABLE MACRO=resume VARIABLE=saved_extruder_temp VALUE="{0}" 144 | _KM_CLEAR_PAUSE 145 | -------------------------------------------------------------------------------- /start_end.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro print_start] 6 | description: Inserted by slicer at start of print. Rather than using this macro 7 | directly you should configure your slicer as instructed in the readme. 8 | Usage: PRINT_START BED= EXTRUDER= [CHAMBER=] 9 | [MESH_MIN=] [MESH_MAX=] [LAYERS=] 10 | [NOZZLE_SIZE=] 11 | gcode: 12 | {action_respond_info( 13 | "This file is using an old The PRINT_START format. This print will run " 14 | "fine, but you should update your slicer config to take advantage of the " 15 | "phased PRINT_START macros. The slicer documentation is here:\n" 16 | "https://github.com/jschuh/klipper-macros\x23slicer-configuration" 17 | )} 18 | 19 | _PRINT_START_PHASE_INIT {rawparams} 20 | _PRINT_START_PHASE_PREHEAT 21 | _PRINT_START_PHASE_PROBING 22 | _PRINT_START_PHASE_EXTRUDER 23 | _PRINT_START_PHASE_PURGE 24 | 25 | [gcode_macro _print_start_phase_init] 26 | description: Inserted by slicer at start of print. Initializes PRINT_START 27 | phases. 28 | Usage: See PRINT_START. 29 | gcode: 30 | CHECK_KM_CONFIG # Need this in case startup errors were missed. 31 | SET_GCODE_VARIABLE MACRO=_print_end_inner VARIABLE=cancelled VALUE="{False}" 32 | _KM_APPLY_PRINT_OFFSET RESET=1 33 | _PRINT_START_PHASE_CHECK PHASE=none 34 | {% set km = printer["gcode_macro _km_globals"] %} 35 | 36 | {% if not params.BED %} 37 | {% set dummy = params.__setitem__('BED', params.BED_TEMP|int) %} 38 | {% endif %} 39 | {% if not params.EXTRUDER %} 40 | {% set dummy = params.__setitem__('EXTRUDER', params.EXTRUDER_TEMP|int) %} 41 | {% endif %} 42 | 43 | # Stash all the params for use by the other phases. 44 | PRINT_START_SET PRINT_START_PHASE="init" {% for k in params %}{' %s=\"%s\"' % 45 | (k,params[k]|replace('\\','\\\\')|replace('\'','\\\'')|replace('\"','\\\"')) 46 | }{% endfor %} 47 | 48 | # Check and propogate the printable bounds.' 49 | _km_check_and_set_print_bounds 50 | 51 | M107 # Turn off part cooling fan in case it was on. 52 | CLEAR_PAUSE 53 | # Kick off the longest preheats in the init. 54 | M140 S{params.BED} 55 | {% if params.CHAMBER %}M141 S{params.CHAMBER|int}{% endif %} 56 | {% if printer.bed_mesh %}BED_MESH_CLEAR{% endif %} 57 | # Load a saved mesh if configured. 58 | {% if km.start_try_saved_surface_mesh and printer.bed_mesh %} 59 | LOAD_SURFACE_MESH 60 | {% endif %} 61 | PRINT_START_SET PRINT_START_PHASE="preheat" 62 | 63 | [gcode_macro _print_start_phase_preheat] 64 | description: Inserted by slicer at start of print. Handles the bed and chamber 65 | heating phases and ends when both are stabilized at their target temperatures. 66 | Usage: See PRINT_START. 67 | gcode: 68 | _PRINT_START_PHASE_CHECK PHASE=preheat 69 | {% set print = printer["gcode_macro print_start_set"].print %} 70 | {% set BED = print.BED|int %} 71 | {% set EXTRUDER = print.EXTRUDER|int %} 72 | {% set CHAMBER = print.CHAMBER|default(0)|int %} 73 | {% set LAYERS = print.LAYERS|default(0)|int %} 74 | {% set km = printer["gcode_macro _km_globals"] %} 75 | # The bed started at no more than 0.2C below and 1.0C above the target temp. 76 | {% set bed_at_target = (BED + 0.4 - printer.heater_bed.temperature) | 77 | abs <= 0.6 %} 78 | PRINT_START_SET BED_AT_TARGET={1 if bed_at_target else 0} 79 | {% set start_level_bed_at_temp = km.start_level_bed_at_temp and 80 | not printer.bed_mesh.profile_name %} 81 | {% set actions_at_temp = start_level_bed_at_temp or 82 | km.start_quad_gantry_level_at_temp or 83 | km.start_z_tilt_adjust_at_temp or 84 | (km.start_home_z_at_temp and not bed_at_target) %} 85 | {% set bed_overshoot = (BED + (km.start_bed_heat_overshoot if 86 | (BED and not bed_at_target) else 0.0), 87 | printer.configfile.settings.heater_bed.max_temp ) | min %} 88 | 89 | INIT_LAYER_GCODE LAYERS="{LAYERS}" 90 | {% if CHAMBER > 0.0 %} 91 | M141 S{CHAMBER} 92 | {% endif %} 93 | # Start bed heating 94 | M140 S{bed_overshoot} 95 | {% if actions_at_temp %} 96 | # If we're going to run a bed level we either have a probing temp specified 97 | # or we heat the extruder part way to avoid oozing while probing. 98 | M104 S{km.start_extruder_probing_temp if km.start_extruder_probing_temp > 0 99 | else (km.start_extruder_preheat_scale * EXTRUDER)|round(0,'ceil')|int} 100 | {% else %} 101 | # Honor the extruder probing temp, in case we just want to delay extruder 102 | # heating until after the bed is ready. 103 | M104 S{km.start_extruder_probing_temp if km.start_extruder_probing_temp > 0 104 | else EXTRUDER} 105 | {% endif %} 106 | # home all axes 107 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=homing RESET_STACK=1 108 | G28 109 | G90 110 | {% if BED > 0.0 %} 111 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=bed_heating RESET_STACK=1 112 | # Skip this if the bed was already at target when START_PRINT was called. 113 | {% if not bed_at_target %} 114 | PARK 115 | # Overshoot the target a bit. 116 | M190 S{bed_overshoot} 117 | G4 P{km.start_bed_heat_delay / 2} 118 | M190 R{BED} # Settle down after the overshoot. 119 | G4 P{km.start_bed_heat_delay / 2} 120 | {% endif %} 121 | {% endif %} 122 | 123 | {% if CHAMBER > 0.0 %} 124 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=chamber_heating RESET_STACK=1 125 | _KM_PARK_IF_NEEDED HEATER="chamber" RANGE=ABOVE 126 | M191 S{CHAMBER} 127 | {% endif %} 128 | 129 | {% if BED > 0.0 and bed_at_target%} 130 | M190 R{BED} # Extra bed stabilization if we skipped it earlier. 131 | {% endif %} 132 | PRINT_START_SET PRINT_START_PHASE="probing" 133 | 134 | [gcode_macro _print_start_phase_probing] 135 | description: Inserted by slicer at start of print. Performs probing (including 136 | mesh bed level) and other operations that should be run when the bed and 137 | chamber are stabilized at their target temps. 138 | Usage: See PRINT_START. 139 | gcode: 140 | _PRINT_START_PHASE_CHECK PHASE=probing 141 | {% set print = printer["gcode_macro print_start_set"].print %} 142 | {% set km = printer["gcode_macro _km_globals"] %} 143 | {% set MESH_MIN = print.MESH_MIN|default(None) %} 144 | {% set MESH_MAX = print.MESH_MAX|default(None) %} 145 | # Randomize the placement of the print on the bed. 146 | {% if km.start_random_placement_max > 0 and print.PRINT_MIN and MESH_MIN %} 147 | {% set PRINT_MIN = print.PRINT_MIN.split(",")|map('float')|list %} 148 | {% set PRINT_MAX = print.PRINT_MAX.split(",")|map('float')|list %} 149 | {% set x_offset = (((km.print_max[0] - km.print_min[0] - PRINT_MAX[0] + 150 | PRINT_MIN[0] - 2 * km.start_random_placement_padding)|int, 151 | km.start_random_placement_max * 2)|min, 0)|max %} 152 | {% set y_offset = (((km.print_max[1] - km.print_min[1] - PRINT_MAX[1] + 153 | PRINT_MIN[1] - 2 * km.start_random_placement_padding)|int, 154 | km.start_random_placement_max * 2)|min, 0)|max %} 155 | {% if x_offset > 0 %} 156 | {% set x_offset = range(x_offset)|random + km.print_min[0] - 157 | PRINT_MIN[0] + km.start_random_placement_padding %} 158 | {% endif %} 159 | {% if y_offset > 0 %} 160 | {% set y_offset = range(y_offset)|random + km.print_min[1] - 161 | PRINT_MIN[1] + km.start_random_placement_padding %} 162 | {% endif %} 163 | # This MESH_MIN/MESH_MAX gets passed to BED_MESH_CALIBRATE below, but the 164 | # rest of the macros rely on SET_GCODE_OFFSET performing the adjustment. 165 | {% set MESH_MIN = MESH_MIN.split(",")|map('float')|list %} 166 | {% set MESH_MAX = MESH_MAX.split(",")|map('float')|list %} 167 | {% set MESH_MIN_NEW = (MESH_MIN[0] + x_offset, MESH_MIN[1] + y_offset) %} 168 | {% set MESH_MAX_NEW = (MESH_MAX[0] + x_offset, MESH_MAX[1] + y_offset) %} 169 | {action_respond_info( 170 | "Relocating print origin from (%.3f,%.3f) "|format(*MESH_MIN) + 171 | "to (%.3f,%.3f)"|format(*MESH_MIN_NEW))} 172 | {% set MESH_MIN = (MESH_MIN_NEW[0], MESH_MIN_NEW[1])|join(',') %} 173 | {% set MESH_MAX = (MESH_MAX_NEW[0], MESH_MAX_NEW[1])|join(',') %} 174 | PRINT_START_SET PRINT_OFFSET={"%d,%d" % (x_offset,y_offset)} 175 | {% endif %} 176 | 177 | {% set EXTRUDER = print.EXTRUDER|int %} 178 | {% set km = printer["gcode_macro _km_globals"] %} 179 | {% set start_level_bed_at_temp = km.start_level_bed_at_temp and 180 | not printer.bed_mesh.profile_name %} 181 | {% set start_home_z_at_temp = km.start_home_z_at_temp and 182 | not print.BED_AT_TARGET|int %} 183 | {% set actions_at_temp = start_level_bed_at_temp or 184 | km.start_quad_gantry_level_at_temp or 185 | km.start_z_tilt_adjust_at_temp or 186 | start_home_z_at_temp %} 187 | {% if actions_at_temp %} 188 | {% if km.start_extruder_probing_temp > 0 %} 189 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=extruder_heating RESET_STACK=1 190 | _KM_PARK_IF_NEEDED HEATER={printer.toolhead.extruder} RANGE=2 191 | M109 R{km.start_extruder_probing_temp} 192 | {% else %} 193 | M104 S{EXTRUDER} # set the final extruder target temperature 194 | {% endif %} 195 | {% if km.start_z_tilt_adjust_at_temp %} 196 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=calibrating_z RESET_STACK=1 197 | Z_TILT_ADJUST 198 | {% endif %} 199 | {% if km.start_quad_gantry_level_at_temp %} 200 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=leveling_gantry RESET_STACK=1 201 | QUAD_GANTRY_LEVEL 202 | {% endif %} 203 | {% if start_home_z_at_temp %} 204 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=homing RESET_STACK=1 205 | G28 Z # Re-home only the Z axis now that the bed has stabilized. 206 | {% endif %} 207 | {% if start_level_bed_at_temp %} 208 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=meshing RESET_STACK=1 209 | _km_mesh_if_needed {% if MESH_MIN %} MESH_MIN={MESH_MIN}{% endif 210 | %}{% if MESH_MAX %} MESH_MAX={MESH_MAX}{% endif %} 211 | {% endif %} 212 | {% if km.start_extruder_probing_temp > 0 %} 213 | M104 S{EXTRUDER} # set the final extruder target temperature 214 | {% endif %} 215 | G4 216 | {% endif %} 217 | PRINT_START_SET PRINT_START_PHASE="extruder" 218 | 219 | [gcode_macro _print_start_phase_extruder] 220 | description: Inserted by slicer at start of print. Preheats the extruder. 221 | Usage: See PRINT_START. 222 | gcode: 223 | _PRINT_START_PHASE_CHECK PHASE=extruder 224 | {% set print = printer["gcode_macro print_start_set"].print %} 225 | {% set EXTRUDER = print.EXTRUDER|default(print.EXTRUDER_TEMP)|float %} 226 | {% set km = printer["gcode_macro _km_globals"] %} 227 | 228 | # Wait for extruder to reach temperature 229 | {% if EXTRUDER > 0 %} 230 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=extruder_heating RESET_STACK=1 231 | _KM_PARK_IF_NEEDED HEATER={printer.toolhead.extruder} RANGE=ABOVE 232 | M109 S{EXTRUDER} 233 | {% endif %} 234 | PRINT_START_SET PRINT_START_PHASE="purge" 235 | 236 | [gcode_macro _print_start_phase_purge] 237 | description: Inserted by slicer at start of print. Generates purge lines. 238 | Usage: See PRINT_START. 239 | gcode: 240 | _PRINT_START_PHASE_CHECK PHASE=purge 241 | # Apply the offset for bed placement randomization. 242 | _KM_APPLY_PRINT_OFFSET 243 | # apply Z offset for bed surface (just in case it was reset). 244 | _APPLY_BED_SURFACE_OFFSET 245 | {% set print = printer["gcode_macro print_start_set"].print %} 246 | {% set MESH_MIN = print.MESH_MIN|default(None) %} 247 | {% set MESH_MAX = print.MESH_MAX|default(None) %} 248 | {% set NOZZLE_SIZE = print.NOZZLE_SIZE|default(print.NOZZLE_SIZE)| 249 | default(printer.configfile.settings.extruder.nozzle_diameter)|float %} 250 | {% set km = printer["gcode_macro _km_globals"] %} 251 | {% if km.start_purge_length > 0.0 and printer.extruder.can_extrude %} 252 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=purging RESET_STACK=1 253 | DRAW_PURGE_LINE WIDTH="{NOZZLE_SIZE * 1.25}" HEIGHT="{NOZZLE_SIZE * 0.625 254 | }"{% if MESH_MIN %} PRINT_MIN={MESH_MIN}{% endif 255 | %}{% if MESH_MAX %} PRINT_MAX={MESH_MAX}{% endif %} 256 | {% endif %} 257 | PRINT_START_SET PRINT_START_PHASE="printing" 258 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=printing RESET_STACK=1 259 | 260 | [gcode_macro _km_park_if_needed] 261 | description: Parks the extruder if the current temperature of the supplied 262 | heater is not within the specified target range. 263 | Usage: _KM_PARK_IF_NEEDED HEATER= RANGE=[|ABOVE|BELOW] 264 | gcode: 265 | # This needs to get called as its own macro to get the current temp evaluated. 266 | {% set HEATER = params.HEATER if params.HEATER in 267 | printer.heaters.available_heaters else 268 | ("heater_generic " ~ params.HEATER) %} 269 | {% set RANGE = (params.RANGE|default(1))|string|upper %} 270 | 271 | {% if printer[HEATER].target %} 272 | {% if RANGE == "ABOVE" %} 273 | {% if printer[HEATER].temperature < printer[HEATER].target %} 274 | PARK 275 | {% endif %} 276 | {% elif RANGE == "BELOW" %} 277 | {% if printer[HEATER].temperature > printer[HEATER].target %} 278 | PARK 279 | {% endif %} 280 | {% elif (printer[HEATER].temperature - printer[HEATER].target)|abs > 281 | (printer[HEATER].target * RANGE|float * 0.01)|abs %} 282 | PARK 283 | {% endif %} 284 | {% endif %} 285 | 286 | [gcode_macro _km_apply_print_offset] 287 | variable_offset: [] 288 | gcode: 289 | {% set print = printer["gcode_macro print_start_set"].print %} 290 | {% if params.RESET|default(0)|int and offset and 291 | not printer["gcode_macro _km_save_state"].is_ephemeral%} 292 | {% set PRINT_OFFSET = [offset.pop(0) * -1, offset.pop() * -1] %} 293 | {% elif print.PRINT_OFFSET and not offset and 294 | not printer["gcode_macro _km_save_state"].is_ephemeral %} 295 | {% set PRINT_OFFSET = print.PRINT_OFFSET.split(",")|map('float')|list %} 296 | {% set dummy = offset.extend(PRINT_OFFSET) %} 297 | {% endif %} 298 | 299 | {% if PRINT_OFFSET %} 300 | _KM_SET_GCODE_OFFSET_BASE {"X_ADJUST=%.2f Y_ADJUST=%.2f"| 301 | format(*PRINT_OFFSET)} 302 | {% endif %} 303 | 304 | [gcode_macro _km_mesh_if_needed] 305 | gcode: 306 | # TODO: Instead of blindly using the loaded mesh we could probe a few key 307 | # points on the saved grid. If those probes show that the saved grid is no 308 | # longer in tolerance we could just run BED_MESH_CALIBRATE_FAST anyway. 309 | {% if not printer.bed_mesh.profile_name %} 310 | BED_MESH_CALIBRATE_FAST {rawparams} 311 | {% endif %} 312 | 313 | [gcode_macro print_start_set] 314 | description: Inserted by slicer to set values used by PRINT_START. 315 | Usage: PRINT_START_SET = 316 | variable_print: {} 317 | gcode: 318 | {%for k in params %} 319 | {% set dummy = print.__setitem__(k|upper, params[k]) %} 320 | {% endfor %} 321 | 322 | [gcode_macro _print_start_phase_check] 323 | gcode: 324 | {% set print = printer["gcode_macro print_start_set"].print %} 325 | {% set PRINT_START_PHASE = print.PRINT_START_PHASE|default("none") %} 326 | {% if PRINT_START_PHASE != params.PHASE %} 327 | # Reset the phases manually just to be sure. 328 | SET_GCODE_VARIABLE MACRO=print_start_set VARIABLE=print VALUE="{{}}" 329 | {% if params.PHASE != 'none' %} 330 | {% set error = "PRINT_START phase error. Expected '%s' but found '%s'" % 331 | (params.PHASE, PRINT_START_PHASE) %} 332 | # Do the cancel manually if we're not confident it will fire. 333 | {% if not 'virtual_sdcard' in printer or 334 | not printer.virtual_sdcard.is_active or 'CANCEL_PRINT' not in 335 | printer.configfile.settings.virtual_sdcard.on_error_gcode| 336 | default("")|upper %} 337 | {action_respond_info(error)} 338 | CANCEL_PRINT 339 | {% else %} 340 | {action_raise_error(error)} 341 | {% endif %} 342 | {% else %} 343 | { action_respond_info("Expected phase '%s' but found '%s'. Resetting." 344 | % (params.PHASE, PRINT_START_PHASE)) } 345 | {% endif %} 346 | {% endif %} 347 | 348 | [gcode_macro print_end] 349 | description: Inserted by slicer at end of print. 350 | Usage: PRINT_END 351 | gcode: 352 | _KM_CHECK_IS_PRINTING 353 | M400 354 | _PRINT_END_INNER 355 | 356 | {% set km = printer["gcode_macro _km_globals"] %} 357 | 358 | {% if km.start_clear_adjustments_at_end != 0 %} 359 | RESET_HEATER_SCALING 360 | RESET_FAN_SCALING 361 | M220 S100 362 | M221 S100 363 | {% endif %} 364 | _RESET_LAYER_GCODE 365 | _RESET_VELOCITY_LIMITS 366 | TURN_OFF_HEATERS 367 | M107; turn off fan 368 | {% if printer.bed_mesh %}BED_MESH_CLEAR{% endif %} 369 | # Park the toolhead and present the bed 370 | {% if printer.toolhead.homed_axes|lower == "xyz" %} 371 | PARK Y="{km.start_end_park_y}" 372 | {% endif %} 373 | M84 ; disable steppers 374 | CLEAR_PAUSE 375 | SET_GCODE_VARIABLE MACRO=print_start_set VARIABLE=print VALUE="{{}}" 376 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=ready RESET_STACK=1 377 | 378 | [gcode_macro _print_end_inner] 379 | variable_cancelled: False 380 | gcode: 381 | SET_GCODE_VARIABLE MACRO=_print_end_inner VARIABLE=cancelled VALUE="{False}" 382 | {% set km = printer["gcode_macro _km_globals"] %} 383 | {% set toolhead = printer.toolhead %} 384 | {% set origin = printer.gcode_move.homing_origin%} 385 | {% set max_x = km.print_max[0] - origin.x %} 386 | {% set max_y = km.print_max[1] - origin.y %} 387 | {% set max_z = toolhead.axis_maximum.z - origin.z %} 388 | 389 | {% if not cancelled %} 390 | _KM_PRINT_STATUS ACTION=CHANGE STATUS=completing 391 | {% endif %} 392 | 393 | {% if printer.extruder.can_extrude %} 394 | # Wipe if we're not cancelling a paused print. 395 | {% if not printer.pause_resume.is_paused and not cancelled and 396 | toolhead.homed_axes|lower == "xyz" %} 397 | {% set x_safe = (max_x - toolhead.position.x, 2.0)|min %} 398 | {% set y_safe = (max_y - toolhead.position.y, 2.0)|min %} 399 | {% set z_safe = (max_z - toolhead.position.z, 2.0)|min %} 400 | G91 401 | G0 Z{z_safe} E-1.0 F{km.travel_speed_z * 2} ; move nozzle up 402 | G0 X{x_safe} Y{y_safe} E-1.0 F{km.travel_speed_xy} ; remove stringing 403 | # Remove the offset now that we're done. 404 | _KM_APPLY_PRINT_OFFSET RESET=1 405 | {% endif %} 406 | 407 | # Small retract to prevent ooze 408 | G92 E0 409 | G1 E{"%.2f" % ((0, 2 - km.load_priming_length / 4)|min)} F1200 410 | M400 411 | {% endif %} 412 | 413 | [gcode_macro _km_check_is_printing] 414 | variable_debug_state: False # Disables print state check for debugging. 415 | description: Throws an error if print is not currently in progress. 416 | gcode: 417 | {% if not debug_state and 418 | printer.idle_timeout.state|string != "Printing" and 419 | not (printer.virtual_sdcard|default({})).is_active|default(False) and 420 | not printer.pause_resume.is_paused %} 421 | { action_raise_error("No active print.") } 422 | {% endif %} 423 | 424 | [gcode_macro _km_check_and_set_print_bounds] 425 | description: Validates all print bounds and caches their values. 426 | gcode: 427 | {% set km = printer["gcode_macro _km_globals"] %} 428 | {% set print = printer["gcode_macro print_start_set"].print %} 429 | 430 | # Check the mesh bounds. 431 | {% if print.MESH_MIN %} 432 | {% set MESH_MIN = print.MESH_MIN.split(",")|map('float')|list %} 433 | {% set MESH_MAX = print.MESH_MAX.split(",")|map('float')|list %} 434 | {%if MESH_MIN[0] < km.print_min[0] or MESH_MIN[1] < km.print_min[1] %} 435 | {action_raise_error("MESH_MIN %s is outside the printable bounds %s" % 436 | (MESH_MIN|string, km.print_min|string))} 437 | {%elif MESH_MAX[0] > km.print_max[0] or MESH_MAX[1] > km.print_max[1] %} 438 | {action_raise_error("MESH_MAX %s is outside the printable bounds %s" % 439 | (MESH_MAX|string, km.print_max|string))} 440 | {% endif %} 441 | {% endif %} 442 | 443 | # Find all the model bounds (including any bounds passed in). 444 | {% set points = [] %} 445 | {% if print.MODEL_MIN or print.MODEL_MAX %} 446 | {% set MODEL_MIN = print.MODEL_MIN.split(",")|map('float')|list %} 447 | {% set MODEL_MAX = print.MODEL_MAX.split(",")|map('float')|list %} 448 | {% set points = [MODEL_MIN, MODEL_MAX] %} 449 | {% endif %} 450 | {% if (printer.exclude_object|default({})).objects %} 451 | {% set points = printer.exclude_object.objects|selectattr('polygon')| 452 | map(attribute='polygon')|sum(start=points) %} 453 | {% set points_len = points|length %} 454 | {% if points_len >= 2 %} 455 | {% set x_coords = (points|map(attribute=0)|sort|list)[0::points_len-1] %} 456 | {% set y_coords = (points|map(attribute=1)|sort|list)[0::points_len-1] %} 457 | {% set MODEL_MIN = (x_coords[0],y_coords[0])|map('float')|list %} 458 | {% set MODEL_MAX = (x_coords[1],y_coords[1])|map('float')|list %} 459 | PRINT_START_SET MODEL_MIN="{MODEL_MIN|join(',') 460 | }" MODEL_MAX="{MODEL_MAX|join(',')}" 461 | {% endif %} 462 | {% endif %} 463 | 464 | {% if MODEL_MIN %} 465 | # Check the model bounds. 466 | {% if MODEL_MIN[0] < km.print_min[0] or MODEL_MIN[1] < km.print_min[1] %} 467 | {action_raise_error("MODEL_MIN %s is outside the printable bounds %s" % 468 | (MODEL_MIN|string, km.print_min|string))} 469 | {% elif MODEL_MAX[0] > km.print_max[0] or MODEL_MAX[1] > km.print_max[1] %} 470 | {action_raise_error("MODEL_MAX %s is outside the printable bounds %s" % 471 | (MODEL_MAX|string, km.print_max|string))} 472 | {% endif %} 473 | {% endif %} 474 | 475 | # Set the PRINT_LIMITS 476 | {% if MESH_MIN and MODEL_MIN %} 477 | PRINT_START_SET PRINT_MIN="{((MODEL_MIN[0],MESH_MIN[0])|min, 478 | (MODEL_MIN[1],MESH_MIN[1])|min)|join(',') 479 | }" PRINT_MAX="{((MODEL_MAX[0],MESH_MAX[0])|max, 480 | (MODEL_MAX[1],MESH_MAX[1])|max)|join(',')}" 481 | {% else %} 482 | PRINT_START_SET PRINT_MIN="{km.print_min|join(',') 483 | }" PRINT_MAX="{km.print_max|join(',')}" 484 | {% endif %} 485 | -------------------------------------------------------------------------------- /state.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro _km_save_state] 6 | description: Tracks gcode state. 7 | variable_state_set: {} 8 | variable_is_ephemeral: 0 9 | gcode: 10 | {% if params.SAVE|int %} 11 | {% set dummy = state_set.__setitem__(params.NAME, None) %} 12 | {% else %} 13 | {% set dummy = state_set.__delitem__(params.NAME) %} 14 | {% endif %} 15 | SET_GCODE_VARIABLE MACRO=_km_save_state VARIABLE=is_ephemeral VALUE="{ 16 | 1 if state_set|length > 0 else 0 }" 17 | 18 | [gcode_macro save_gcode_state] 19 | description: Wraps SAVE_GCODE_STATE to track persistence state. 20 | Usage: See Klipper documentation 21 | rename_existing: _KM_SAVE_GCODE_STATE 22 | gcode: 23 | _KM_SAVE_GCODE_STATE {rawparams} 24 | {% set NAME = params.NAME|default("default") %} 25 | _km_save_state NAME={NAME} SAVE=1 26 | 27 | [gcode_macro restore_gcode_state] 28 | description: Wraps RESTORE_GCODE_STATE to track persistence state. 29 | Usage: See Klipper documentation 30 | rename_existing: _KM_RESTORE_GCODE_STATE 31 | gcode: 32 | _KM_RESTORE_GCODE_STATE {rawparams} 33 | {% set NAME = params.NAME|default("default") %} 34 | _km_save_state NAME={NAME} SAVE=0 35 | 36 | [gcode_macro _abort_on_gcode_state] 37 | gcode: 38 | {% set save_state = printer["gcode_macro _km_save_state"] %} 39 | {% if save_state.is_ephemeral %} 40 | {action_raise_error("Encountered unexpected save state " + 41 | save_state.state_set|list|sort|string)} 42 | {% endif %} 43 | -------------------------------------------------------------------------------- /status_events.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2023 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | 6 | [gcode_macro _km_print_status] 7 | variable_last_status: 'none' 8 | variable_status_stack: [] 9 | variable_command_list: {} 10 | variable_status_list: [ 11 | 'ready', # Printer is ready to receive a job 12 | 'filament_load', # Loading filament 13 | 'filament_unload', # Unloading filament 14 | 'bed_heating', # Waiting for the bed to reach target 15 | 'chamber_heating', # Waiting for the chamber to reach target 16 | 'homing', # Homing any axis 17 | 'leveling_gantry', # Performing quad gantry-leveling 18 | 'calibrating_z', # Performing z-tilt adjustment 19 | 'meshing', # Calibrating a bed mesh 20 | 'extruder_heating', # Waiting for the extruder to reach target 21 | 'purging', # Printing purge line 22 | 'printing', # Actively printing 23 | 'pausing', # Print is paused 24 | 'cancelling', # Print is being cancelled 25 | 'completing', # Print completed 26 | ] 27 | gcode: 28 | {% set ACTION = params.ACTION|trim|upper %} 29 | {% set STATUS = params.STATUS|default("")|trim|lower %} 30 | 31 | # Add a status handler. 32 | {% if ACTION == "ADD_EVENT" %} 33 | {% set COMMAND = params.COMMAND %} 34 | {% set ARGS = params.ARGS|default(0)|int != 0 %} 35 | {% set TYPE = params.TYPE|default('ENTER')|trim|upper %} 36 | {% set WHEN = params.WHEN|default('PRINTING')|trim|upper %} 37 | {% set FILTER_ENTER = 38 | (params.FILTER_ENTER|default("")|trim|lower).split(',')| 39 | select()|unique|list %} 40 | {% set FILTER_LEAVE = 41 | (params.FILTER_LEAVE|default("")|trim|lower).split(',')| 42 | select()|unique|list %} 43 | 44 | {% set STATUSES = STATUS.split(',')|map('trim')|list %} 45 | {% for s in (STATUSES if STATUSES[0] != 'all' else status_list) %} 46 | {% if not s in command_list %} 47 | {% set dummy = command_list.__setitem__(s,[]) %} 48 | {% endif %} 49 | {% set dummy = command_list[s].append({'cmd':COMMAND, 'args':ARGS, 50 | 'type':TYPE, 'when':WHEN, 51 | 'filt_e':FILTER_ENTER, 52 | 'filt_l':FILTER_LEAVE}) %} 53 | {% endfor %} 54 | 55 | # Change the current status. 56 | {% elif ACTION == "CHANGE" %} 57 | {% if params.RESET_STACK|default(0)|int %} 58 | {% for dummy in range(status_stack|length) %} 59 | {% set dummy = status_stack.pop() %} 60 | {% endfor %} 61 | # TODO: Once python 3 is required, switch the for loop above to this: 62 | #{% set dummy = status_stack.clear() %} 63 | {% elif STATUS == "pop_status" %} 64 | {% set STATUS = (status_stack|default(['ready'], True)).pop() %} 65 | {% endif %} 66 | 67 | {% if STATUS not in status_list %} 68 | {action_raise_error("Status '%s' not valid."|format(STATUS))} 69 | {% endif %} 70 | 71 | {% if STATUS != last_status %} 72 | {% set is_printing = 73 | printer["gcode_macro print_start_set"].print.PRINT_START_PHASE| 74 | default("")|length != 0 %} 75 | {% set print_states = ('ALWAYS', 'PRINTING' if is_printing else 'IDLE') %} 76 | # Process commands for the state we're leaving first. 77 | {% for c in command_list[last_status]|default([]) %} 78 | {% if c.type in ('BOTH','LEAVE') and c.when in print_states and 79 | (not c.filt_l or STATUS in c.filt_l) %} 80 | M400 81 | {c.cmd}{% if c.args %} TYPE=LEAVE WHEN={print_states[1] 82 | } LAST_STATUS={last_status} NEXT_STATUS={STATUS}{% endif %} 83 | {% endif %} 84 | {% endfor %} 85 | # Process commands for the state we're entering last. 86 | {% for c in command_list[STATUS]|default([]) %} 87 | {% if c.type in ('BOTH','ENTER') and c.when in print_states and 88 | (not c.filt_e or STATUS in c.filt_e) %} 89 | M400 90 | {c.cmd}{% if c.args %} TYPE=ENTER WHEN={print_states[1] 91 | } LAST_STATUS={last_status} NEXT_STATUS={STATUS}{% endif %} 92 | {% endif %} 93 | {% endfor %} 94 | SET_GCODE_VARIABLE MACRO=_km_print_status VARIABLE=last_status VALUE="'{ 95 | STATUS}'" 96 | {% endif %} 97 | 98 | # Push the current status onto the stack. 99 | {% elif ACTION == "PUSH_STATUS" %} 100 | {% set dummy = status_stack.append(last_status) %} 101 | 102 | # Illegal operation. 103 | {% else %} 104 | {action_raise_error("Action '%s' not valid."|format(ACTION))} 105 | {% endif %} 106 | 107 | [gcode_macro gcode_on_print_status] 108 | description: Adds a gcode command for a status event. 109 | Usage: GCODE_ON_PRINT_STATUS STATUS= COMMAND= [ARGS=<1|0>] 110 | [WHEN=] 111 | [TYPE=] 112 | [FILTER_ENTER=] 113 | [FILTER_LEAVE=] 114 | gcode: 115 | {% set STATUS = (params.STATUS|lower).split(',')|map('trim')|list %} 116 | {% set TYPE = params.TYPE|default('ENTER')|trim|upper %} 117 | {% set WHEN = params.WHEN|default('PRINTING')|trim|upper %} 118 | {% set FILTER_ENTER = 119 | (params.FILTER_ENTER|default("")|trim|lower).split(',')|select()|list %} 120 | {% set FILTER_LEAVE = 121 | (params.FILTER_LEAVE|default("")|trim|lower).split(',')|select()|list %} 122 | 123 | # Error checking 124 | {% set status_list = printer["gcode_macro _km_print_status"].status_list %} 125 | {% for s in STATUS %} 126 | {% if not (s in status_list or s == 'all' and STATUS|length == 1) %} 127 | {action_raise_error("STATUS parameter '%s' not valid."|format(s))} 128 | {% endif %} 129 | {% endfor %} 130 | 131 | {% if TYPE not in ('ENTER', 'LEAVE', 'BOTH') %} 132 | {action_raise_error("TYPE paramater '%s' not valid."|format(TYPE))} 133 | {% elif WHEN not in ('PRINTING', 'IDLE', 'ALWAYS') %} 134 | {action_raise_error("WHEN parameter '%s' not valid."|format(WHEN))} 135 | {% elif TYPE == 'ENTER' and FILTER_LEAVE %} 136 | {action_raise_error("FILTER_LEAVE not valid with TYPE=ENTER.")} 137 | {% elif TYPE == 'LEAVE' and FILTER_ENTER %} 138 | {action_raise_error("FILTER_ENTER not valid with TYPE=LEAVE.")} 139 | {% endif %} 140 | {% for f in FILTER_ENTER %} 141 | {% if f not in status_list %} 142 | {action_raise_error("FILTER_ENTER parameter '%s' not valid."|format(f))} 143 | {% endif %} 144 | {% endfor %} 145 | {% for f in FILTER_LEAVE %} 146 | {% if f not in status_list %} 147 | {action_raise_error("FILTER_LEAVE parameter '%s' not valid."|format(f))} 148 | {% endif %} 149 | {% endfor %} 150 | 151 | # Run the command. 152 | _KM_PRINT_STATUS ACTION=ADD_EVENT {rawparams} 153 | -------------------------------------------------------------------------------- /velocity.cfg: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2022 Justin Schuh 2 | # 3 | # This file may be distributed under the terms of the GNU GPLv3 license. 4 | 5 | [gcode_macro m201] 6 | description: Sets maximum accelleration. 7 | Usage: M201 [X] [Y] 8 | variable_max_accel: 1.7976931348623157e+308 9 | gcode: 10 | {% set km = printer["gcode_macro _km_globals"] %} 11 | {% if 'X' in params or 'Y' in params %} 12 | {% set accel = (params.X|default(params.Y)|float, 13 | params.Y|default(params.X)|float)|min %} 14 | SET_GCODE_VARIABLE MACRO=m201 VARIABLE=max_accel VALUE="{accel}" 15 | {% else %} 16 | SET_VELOCITY_LIMIT 17 | {% endif %} 18 | 19 | [gcode_macro m203] 20 | description: Sets maximum velocity. 21 | Usage: M203 [X] [Y] 22 | gcode: 23 | {% if 'X' in params or 'Y' in params %} 24 | {% set velocity = (params.X|default(params.Y)|float, 25 | params.Y|default(params.X)|float)|min %} 26 | SET_VELOCITY_LIMIT VELOCITY="{velocity}" 27 | {% else %} 28 | SET_VELOCITY_LIMIT 29 | {% endif %} 30 | 31 | [gcode_macro m205] 32 | description: Sets square corner velocity. 33 | Usage: M203 [X] [Y] 34 | gcode: 35 | {% if 'X' in params or 'Y' in params %} 36 | SET_VELOCITY_LIMIT SQUARE_CORNER_VELOCITY="{ 37 | (params.X|default(0)|float, params.Y|default(0)|float)|min}" 38 | {% else %} 39 | SET_VELOCITY_LIMIT 40 | {% endif %} 41 | 42 | [gcode_macro m900] 43 | description: Sets pressure advance. 44 | Usage: M900 [K] [T] 45 | gcode: 46 | {% set km = printer["gcode_macro _km_globals"] %} 47 | {% if km.pressure_advance_scale > 0.0 %} 48 | {% set extruder = "extruder" ~ params.T|replace('0', '') 49 | if "T" in params else printer.toolhead.extruder %} 50 | {% if 'K' in params %} 51 | SET_PRESSURE_ADVANCE EXTRUDER="{extruder}" ADVANCE="{ 52 | params.K|float * km.pressure_advance_scale}" 53 | {% endif %} 54 | {% endif %} 55 | 56 | 57 | [gcode_macro _reset_velocity_limits] 58 | description: Sets maximum accelleration. 59 | Usage: M204 [S] [P T] 60 | gcode: 61 | SET_GCODE_VARIABLE MACRO=m201 VARIABLE=max_accel VALUE="{1.7976931348623157e+308}" 62 | --------------------------------------------------------------------------------