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/>.
11 #include "libs/Kernel.h"
12 #include "libs/utils.h"
17 #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
29 this->default_set
= false;
30 this->check_sums
[0] = 0x0000;
31 this->check_sums
[1] = 0x0000;
32 this->check_sums
[2] = 0x0000;
35 ConfigValue
* required(){
36 if( this->found
== true ){
39 error("could not find config setting, please see http://smoothieware.org/configuring-smoothie\r\n");
44 if( this->found
== false && this->default_set
== true ){
45 return this->default_double
;
48 double result
= strtod(remove_non_number(this->value
).c_str(), &endptr
);
49 if( endptr
<= remove_non_number(this->value
).c_str() ){
50 error("config setting with value '%s' and checksums[%u,%u,%u] is not a valid number, please see http://smoothieware.org/configuring-smoothie\r\n", this->value
.c_str(), this->check_sums
[0], this->check_sums
[1], this->check_sums
[2] );
58 if( this->found
== false && this->default_set
== true ){
59 return this->default_int
;
62 int result
= strtol(remove_non_number(this->value
).c_str(), &endptr
, 10);
63 if( endptr
<= remove_non_number(this->value
).c_str() ){
64 error("config setting with value '%s' and checksums[%u,%u,%u] is not a valid number, please see http://smoothieware.org/configuring-smoothie\r\n", this->value
.c_str(), this->check_sums
[0], this->check_sums
[1], this->check_sums
[2] );
70 std::string
as_string(){
75 if( this->found
== false && this->default_set
== true ){
76 return this->default_double
;
78 if( this->value
.find_first_of("ty1") != string::npos
){
86 ConfigValue
* by_default(int val
)
88 this->default_set
= true;
89 this->default_int
= val
;
90 this->default_double
= val
;
94 ConfigValue
* by_default(double val
){
95 this->default_set
= true;
96 this->default_double
= val
;
100 ConfigValue
* by_default(std::string val
){
101 if( this->found
){ return this; }
102 this->default_set
= true;
107 bool has_characters( string mask
){
108 if( this->value
.find_first_of(mask
) != string::npos
){ return true; }else{ return false; }
112 return this->has_characters(string("!"));
116 double default_double
;
117 uint16_t check_sums
[3];