Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of Smoothie by
Configurator.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 00008 00009 #include "libs/Kernel.h" 00010 #include "Configurator.h" 00011 #include "libs/nuts_bolts.h" 00012 #include "libs/utils.h" 00013 #include "libs/SerialMessage.h" 00014 #include "libs/StreamOutput.h" 00015 00016 00017 void Configurator::on_module_loaded(){ 00018 this->register_for_event(ON_CONSOLE_LINE_RECEIVED); 00019 // this->register_for_event(ON_GCODE_RECEIVED); 00020 // this->register_for_event(ON_MAIN_LOOP); 00021 } 00022 00023 // When a new line is received, check if it is a command, and if it is, act upon it 00024 void Configurator::on_console_line_received( void* argument ){ 00025 SerialMessage new_message = *static_cast<SerialMessage*>(argument); 00026 00027 // ignore comments 00028 if(new_message.message[0] == ';') return; 00029 00030 string possible_command = new_message.message; 00031 00032 // We don't compare to a string but to a checksum of that string, this saves some space in flash memory 00033 uint16_t check_sum = get_checksum( possible_command.substr(0,possible_command.find_first_of(" \r\n")) ); // todo: put this method somewhere more convenient 00034 00035 // Act depending on command 00036 if (check_sum == config_get_command_checksum) 00037 this->config_get_command( get_arguments(possible_command), new_message.stream ); 00038 else if (check_sum == config_set_command_checksum) 00039 this->config_set_command( get_arguments(possible_command), new_message.stream ); 00040 else if (check_sum == config_load_command_checksum) 00041 this->config_load_command( get_arguments(possible_command), new_message.stream ); 00042 } 00043 00044 // Process and respond to eeprom gcodes (M50x) 00045 void Configurator::on_gcode_received(void* argument){ 00046 Gcode* gcode = static_cast<Gcode*>(argument); 00047 if( gcode->has_letter('G') ){ 00048 int code = gcode->get_value('G'); 00049 switch( code ){ 00050 } 00051 } 00052 else if( gcode->has_letter('M') ){ 00053 int code = gcode->get_value('M'); 00054 switch( code ){ 00055 } 00056 } 00057 } 00058 00059 void Configurator::on_main_loop(void* argument){} 00060 00061 // Output a ConfigValue from the specified ConfigSource to the stream 00062 void Configurator::config_get_command( string parameters, StreamOutput* stream ){ 00063 string source = shift_parameter(parameters); 00064 string setting = shift_parameter(parameters); 00065 if (setting == "") { // output live setting 00066 setting = source; 00067 source = ""; 00068 uint16_t setting_checksums[3]; 00069 get_checksums(setting_checksums, setting ); 00070 ConfigValue* cv = THEKERNEL->config->value(setting_checksums); 00071 string value = ""; 00072 if(cv->found){ value = cv->as_string(); } 00073 stream->printf( "live: %s is set to %s\r\n", setting.c_str(), value.c_str() ); 00074 } else { // output setting from specified source 00075 uint16_t source_checksum = get_checksum( source ); 00076 uint16_t setting_checksums[3]; 00077 get_checksums(setting_checksums, setting ); 00078 for(unsigned int i=0; i < THEKERNEL->config->config_sources.size(); i++){ 00079 if( THEKERNEL->config->config_sources[i]->is_named(source_checksum) ){ 00080 string value = THEKERNEL->config->config_sources[i]->read(setting_checksums); 00081 stream->printf( "%s: %s is set to %s\r\n", source.c_str(), setting.c_str(), value.c_str() ); 00082 break; 00083 } 00084 } 00085 } 00086 } 00087 00088 // Write the specified setting to the specified ConfigSource 00089 void Configurator::config_set_command( string parameters, StreamOutput* stream ){ 00090 string source = shift_parameter(parameters); 00091 string setting = shift_parameter(parameters); 00092 string value = shift_parameter(parameters); 00093 if (value == "") { 00094 value = setting; 00095 setting = source; 00096 source = ""; 00097 THEKERNEL->config->set_string(setting, value); 00098 stream->printf( "live: %s has been set to %s\r\n", setting.c_str(), value.c_str() ); 00099 } else { 00100 uint16_t source_checksum = get_checksum(source); 00101 for(unsigned int i=0; i < THEKERNEL->config->config_sources.size(); i++){ 00102 if( THEKERNEL->config->config_sources[i]->is_named(source_checksum) ){ 00103 THEKERNEL->config->config_sources[i]->write(setting, value); 00104 stream->printf( "%s: %s has been set to %s\r\n", source.c_str(), setting.c_str(), value.c_str() ); 00105 break; 00106 } 00107 } 00108 } 00109 } 00110 00111 // Reload config values from the specified ConfigSource 00112 void Configurator::config_load_command( string parameters, StreamOutput* stream ){ 00113 string source = shift_parameter(parameters); 00114 if(source == ""){ 00115 THEKERNEL->config->config_cache_load(); 00116 THEKERNEL->call_event(ON_CONFIG_RELOAD); 00117 stream->printf( "Reloaded settings\r\n" ); 00118 } else if(file_exists(source)){ 00119 FileConfigSource fcs(source); 00120 fcs.transfer_values_to_cache(&THEKERNEL->config->config_cache); 00121 THEKERNEL->call_event(ON_CONFIG_RELOAD); 00122 stream->printf( "Loaded settings from %s\r\n", source.c_str() ); 00123 } else { 00124 uint16_t source_checksum = get_checksum(source); 00125 for(unsigned int i=0; i < THEKERNEL->config->config_sources.size(); i++){ 00126 if( THEKERNEL->config->config_sources[i]->is_named(source_checksum) ){ 00127 THEKERNEL->config->config_sources[i]->transfer_values_to_cache(&THEKERNEL->config->config_cache); 00128 THEKERNEL->call_event(ON_CONFIG_RELOAD); 00129 stream->printf( "Loaded settings from %s\r\n", source.c_str() ); 00130 break; 00131 } 00132 } 00133 } 00134 } 00135
Generated on Tue Jul 12 2022 20:09:00 by
1.7.2
