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"
10 #include "checksumm.h"
13 #include "ConfigValue.h"
19 #define enable_checksum CHECKSUM("enable")
20 #define custom_menu_checksum CHECKSUM("custom_menu")
21 #define name_checksum CHECKSUM("name")
22 #define command_checksum CHECKSUM("command")
26 CustomScreen::CustomScreen()
28 this->command
= nullptr;
30 //printf("Setting up CustomScreen\n");
31 vector
<uint16_t> modules
;
32 THEKERNEL
->config
->get_module_list( &modules
, custom_menu_checksum
);
34 // load the custom menu items
35 for ( unsigned int i
= 0; i
< modules
.size(); i
++ ) {
36 if (THEKERNEL
->config
->value(custom_menu_checksum
, modules
[i
], enable_checksum
)->as_bool()) {
37 // Get Menu entry name
38 string name
= THEKERNEL
->config
->value(custom_menu_checksum
, modules
[i
], name_checksum
)->as_string();
39 std::replace( name
.begin(), name
.end(), '_', ' '); // replace _ with space
42 string command
= THEKERNEL
->config
->value(custom_menu_checksum
, modules
[i
], command_checksum
)->as_string();
43 std::replace( command
.begin(), command
.end(), '_', ' '); // replace _ with space
44 std::replace( command
.begin(), command
.end(), '|', '\n'); // replace | with \n for multiple commands
46 // put in menu item list
47 menu_items
.push_back(make_tuple(strdup(name
.c_str()), strdup(command
.c_str())));
48 //printf("added menu %s, command %s\n", name.c_str(), command.c_str());
53 void CustomScreen::on_enter()
55 THEPANEL
->enter_menu_mode();
56 THEPANEL
->setup_menu(menu_items
.size() + 1);
60 void CustomScreen::on_refresh()
62 if ( THEPANEL
->menu_change() ) {
65 if ( THEPANEL
->click() ) {
66 this->clicked_menu_entry(THEPANEL
->get_menu_current_line());
70 void CustomScreen::display_menu_line(uint16_t line
)
73 THEPANEL
->lcd
->printf("Back");
75 THEPANEL
->lcd
->printf(std::get
<0>(menu_items
[line
-1]));
79 void CustomScreen::clicked_menu_entry(uint16_t line
)
82 THEPANEL
->enter_screen(this->parent
);
84 command
= std::get
<1>(menu_items
[line
-1]);
88 // queuing commands needs to be done from main loop
89 void CustomScreen::on_main_loop()
92 if (this->command
== nullptr) return;
93 send_command(this->command
);
94 this->command
= nullptr;