It may be the most straightforward to implement, but I don't think it's the easiest. Store a load filament routine on an SD card as a normal G-Code file. Well, now every time you go to run the macro, you have to find it in the SD card. And it only works if THAT SD card is in the machine at the time. I don't think it's the easiest way to do it, nor do I think it's the right way to do it.
Studying the code, I think I've managed it.
Everything happens in the ultralcd.cpp file of Marlin. The menu structure is a series of functions, so anyone familiar with C programming should be able to navigate them. You might even be able to find your way around just by knowing Marlin.
You can set a new menu item to execute some hard-coded G-Code using the following:
That will add a menu item with the text "Home Axes" that executes a G28. Note that hard coding "Home Axes" as a string like that is considered poor practice and it should be stored as a #define in one of the language files, but this will get the job done.
And yes, you can in fact do multiple G-Code commands in reasonably modern Marlin. For example:
the \n is a new line.
One limitation I've found is it doesn't seem to want to let me do long extruder moves. So a G1 E200 F2000 is okay, but it'll just skip over a G1 E500 F2000. So I've actually had to string several G1 E200\n G92 E0 commands together to run the filament the length of my bowden tube.
Now, that's one way to do it. There is another, more interesting way. See, the above just executes the G-Code. It doesn't manipulate the display. So it doesn't look like it's done anything when you click the button in the menu. So what I did was declare a function elsewhere like so:
The lcd_return line kicks you back to the info screen, then it goes on to execute the G-Code. So I have it heat up the nozzle, and it displays "Heating..." in the status line, and you can see the nozzle coming up to temp, then when it starts moving I have it display "Loading..."
Then later in the code, in the appropriate place for where you want it in the menu, put in a line that says
That refers back to the load filament function we wrote earlier. This actually puts it somewhere. There are non-G-code ways these menu items work, such as changing temperatures and such, but I haven't figured out how those work yet. But, for those who which you could add an option to execute a little G-Code to the menu, there you go. I've tried to google for it, and ended up having to examine the code and learn it the hard way. I hope this helps someone do something cool.
Studying the code, I think I've managed it.
Everything happens in the ultralcd.cpp file of Marlin. The menu structure is a series of functions, so anyone familiar with C programming should be able to navigate them. You might even be able to find your way around just by knowing Marlin.
You can set a new menu item to execute some hard-coded G-Code using the following:
MENU_ITEM(gcode, "Home Axes", PSTR("G28));
That will add a menu item with the text "Home Axes" that executes a G28. Note that hard coding "Home Axes" as a string like that is considered poor practice and it should be stored as a #define in one of the language files, but this will get the job done.
And yes, you can in fact do multiple G-Code commands in reasonably modern Marlin. For example:
MENU_ITEM(gcode, "Home and Auto Level", PSTR("G28\nG29"));
the \n is a new line.
One limitation I've found is it doesn't seem to want to let me do long extruder moves. So a G1 E200 F2000 is okay, but it'll just skip over a G1 E500 F2000. So I've actually had to string several G1 E200\n G92 E0 commands together to run the filament the length of my bowden tube.
Now, that's one way to do it. There is another, more interesting way. See, the above just executes the G-Code. It doesn't manipulate the display. So it doesn't look like it's done anything when you click the button in the menu. So what I did was declare a function elsewhere like so:
void load_filament() { lcd_return_to_status(); enqueue_and_echo_commands_P(PSTR(M117 Some G-Code Here)); }
The lcd_return line kicks you back to the info screen, then it goes on to execute the G-Code. So I have it heat up the nozzle, and it displays "Heating..." in the status line, and you can see the nozzle coming up to temp, then when it starts moving I have it display "Loading..."
Then later in the code, in the appropriate place for where you want it in the menu, put in a line that says
MENU_ITEM(function, "Load Filament", load_filament);
That refers back to the load filament function we wrote earlier. This actually puts it somewhere. There are non-G-code ways these menu items work, such as changing temperatures and such, but I haven't figured out how those work yet. But, for those who which you could add an option to execute a little G-Code to the menu, there you go. I've tried to google for it, and ended up having to examine the code and learn it the hard way. I hope this helps someone do something cool.