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/>.
10 #include "libs/Kernel.h"
11 #include "libs/utils.h"
14 #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
21 #define config_get_checksum 46310
22 #define config_set_checksum 55538
23 #define config_load_checksum 3143
29 this->default_set
= false;
32 ConfigValue
* required(){
33 if( this->found
== true ){
36 error("could not find config setting with checksum %u, please see http://smoothieware.org/configuring-smoothie\r\n", this->check_sum
);
41 if( this->found
== false && this->default_set
== true ){
42 return this->default_double
;
44 double result
= atof(remove_non_number(this->value
).c_str());
45 if( result
== 0.0 && this->value
.find_first_not_of("0.") != string::npos
){
46 error("config setting '%s' with value '%s' is not a valid number, please see http://smoothieware.org/configuring-smoothie\r\n", this->key
.c_str(), this->value
.c_str() );
53 std::string
as_string(){
54 if( this->found
== false && this->default_set
== true ){
55 return this->default_string
;
62 if( this->found
== false && this->default_set
== true ){
63 return this->default_double
;
65 if( this->value
.find_first_of("t1") != string::npos
){
75 pin
->from_string(this->as_string());
79 ConfigValue
* by_default(double value
){
80 this->default_set
= true;
81 this->default_double
= value
;
85 ConfigValue
* by_default(std::string value
){
86 this->default_set
= true;
87 this->default_string
= value
;
91 bool has_characters( string mask
){
92 if( this->value
.find_first_of(mask
) != string::npos
){ return true; }else{ return false; }
96 return this->has_characters(string("!"));
104 double default_double
;
105 string default_string
;
109 class Config
: public Module
{
113 void on_module_loaded();
114 void on_console_line_received( void* argument
);
115 void config_get_command( string parameters
);
116 void config_set_command( string parameters
);
117 void config_load_command(string parameters
);
118 void set_string( string setting
, string value
);
120 ConfigValue
* value(uint16_t check_sum
);
121 ConfigValue
* value(uint16_t check_sum_a
, uint16_t check_sum_b
);
122 ConfigValue
* value(uint16_t check_sum_a
, uint16_t check_sum_b
, uint16_t check_sum_c
);
123 ConfigValue
* value(vector
<uint16_t> check_sums
);
125 void get_module_list(vector
<uint16_t>* list
, uint16_t family
);
127 bool has_characters(uint16_t check_sum
, string str
);
128 string
get_config_file();
129 bool has_config_file();
130 void try_config_file(string candidate
);
132 string config_file
; // Path to the config file
133 bool config_file_found
; // Wether or not the config file's location is known