2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
7 #include "CustomScreen.h"
8 #include "libs/Kernel.h"
12 #define enable_checksum CHECKSUM("enable")
13 #define custom_menu_checksum CHECKSUM("custom_menu")
14 #define name_checksum CHECKSUM("name")
15 #define command_checksum CHECKSUM("command")
19 CustomScreen::CustomScreen()
21 //printf("Setting up CustomScreen\n");
22 vector
<uint16_t> modules
;
23 THEKERNEL
->config
->get_module_list( &modules
, custom_menu_checksum
);
25 // load the custom menu items
26 for ( unsigned int i
= 0; i
< modules
.size(); i
++ ) {
27 if (THEKERNEL
->config
->value(custom_menu_checksum
, modules
[i
], enable_checksum
)->as_bool()) {
28 // Get Menu entry name
29 string name
= THEKERNEL
->config
->value(custom_menu_checksum
, modules
[i
], name_checksum
)->as_string();
30 std::replace( name
.begin(), name
.end(), '_', ' '); // replace _ with space
33 string command
= THEKERNEL
->config
->value(custom_menu_checksum
, modules
[i
], command_checksum
)->as_string();
34 std::replace( command
.begin(), command
.end(), '_', ' '); // replace _ with space
35 std::replace( command
.begin(), command
.end(), '|', '\n'); // replace | with \n for multiple commands
37 // put in menu item list
38 menu_items
.push_back(make_tuple(strdup(name
.c_str()), strdup(command
.c_str())));
39 //printf("added menu %s, command %s\n", name.c_str(), command.c_str());
44 void CustomScreen::on_enter()
46 this->panel
->enter_menu_mode();
47 this->panel
->setup_menu(menu_items
.size() + 1);
51 void CustomScreen::on_refresh()
53 if ( this->panel
->menu_change() ) {
56 if ( this->panel
->click() ) {
57 this->clicked_menu_entry(this->panel
->get_menu_current_line());
61 void CustomScreen::display_menu_line(uint16_t line
)
64 this->panel
->lcd
->printf("Back");
66 this->panel
->lcd
->printf(std::get
<0>(menu_items
[line
-1]));
70 void CustomScreen::clicked_menu_entry(uint16_t line
)
73 this->panel
->enter_screen(this->parent
);
75 command
= std::get
<1>(menu_items
[line
-1]);
79 // queuing commands needs to be done from main loop
80 void CustomScreen::on_main_loop()
83 if (this->command
.empty()) return;
84 send_command(this->command
.c_str());
85 this->command
.clear();