Fork of Smoothie to port to mbed non-LPC targets.
Fork of Smoothie by
CustomScreen.cpp
00001 /* 00002 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl). 00003 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. 00004 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. 00005 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. 00006 */ 00007 #include "CustomScreen.h" 00008 #include "libs/Kernel.h" 00009 00010 #include <algorithm> 00011 00012 #define enable_checksum CHECKSUM("enable") 00013 #define custom_menu_checksum CHECKSUM("custom_menu") 00014 #define name_checksum CHECKSUM("name") 00015 #define command_checksum CHECKSUM("command") 00016 00017 using namespace std; 00018 00019 CustomScreen::CustomScreen() 00020 { 00021 //printf("Setting up CustomScreen\n"); 00022 vector<uint16_t> modules; 00023 THEKERNEL->config->get_module_list( &modules, custom_menu_checksum ); 00024 00025 // load the custom menu items 00026 for ( unsigned int i = 0; i < modules.size(); i++ ) { 00027 if (THEKERNEL->config->value(custom_menu_checksum, modules[i], enable_checksum )->as_bool()) { 00028 // Get Menu entry name 00029 string name = THEKERNEL->config->value(custom_menu_checksum, modules[i], name_checksum )->as_string(); 00030 std::replace( name.begin(), name.end(), '_', ' '); // replace _ with space 00031 00032 // Get Command 00033 string command = THEKERNEL->config->value(custom_menu_checksum, modules[i], command_checksum )->as_string(); 00034 std::replace( command.begin(), command.end(), '_', ' '); // replace _ with space 00035 std::replace( command.begin(), command.end(), '|', '\n'); // replace | with \n for multiple commands 00036 00037 // put in menu item list 00038 menu_items.push_back(make_tuple(strdup(name.c_str()), strdup(command.c_str()))); 00039 //printf("added menu %s, command %s\n", name.c_str(), command.c_str()); 00040 } 00041 } 00042 } 00043 00044 void CustomScreen::on_enter() 00045 { 00046 this->panel->enter_menu_mode(); 00047 this->panel->setup_menu(menu_items.size() + 1); 00048 this->refresh_menu(); 00049 } 00050 00051 void CustomScreen::on_refresh() 00052 { 00053 if ( this->panel->menu_change() ) { 00054 this->refresh_menu(); 00055 } 00056 if ( this->panel->click() ) { 00057 this->clicked_menu_entry(this->panel->get_menu_current_line()); 00058 } 00059 } 00060 00061 void CustomScreen::display_menu_line(uint16_t line) 00062 { 00063 if (line == 0) { 00064 this->panel->lcd->printf("Back"); 00065 } else { 00066 this->panel->lcd->printf(std::get<0>(menu_items[line-1])); 00067 } 00068 } 00069 00070 void CustomScreen::clicked_menu_entry(uint16_t line) 00071 { 00072 if (line == 0) { 00073 this->panel->enter_screen(this->parent); 00074 } else { 00075 command = std::get<1>(menu_items[line-1]); 00076 } 00077 } 00078 00079 // queuing commands needs to be done from main loop 00080 void CustomScreen::on_main_loop() 00081 { 00082 // issue command 00083 if (this->command.empty()) return; 00084 send_command(this->command.c_str()); 00085 this->command.clear(); 00086 }
Generated on Tue Jul 12 2022 20:09:00 by 1.7.2