repaired Pause subsystem, added M109 ( wait for temp ) gcode to
[clinton/Smoothieware.git] / src / libs / Config.h
CommitLineData
4cff3ded
AW
1/*
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/>.
6*/
7
8#ifndef CONFIG_H
9#define CONFIG_H
10#include "mbed.h"
11#include "libs/Kernel.h"
b66fb830 12#include "libs/utils.h"
e6b22382 13#include "libs/Pin.h"
3c132bd0
AW
14
15
16using namespace std;
17#include <vector>
4cff3ded 18#include <string>
4cff3ded 19
cebe90b6
AW
20#define config_get_checksum 46310
21#define config_set_checksum 55538
22#define config_load_checksum 3143
23
b66fb830
AW
24class ConfigValue{
25 public:
26 ConfigValue(){
27 this->found = false;
28 this->default_set = false;
29 };
30
31 ConfigValue* required(){
32 if( this->found == true ){
33 return this;
34 }else{
35 error("could not find config setting with checksum %u, please see http://smoothieware.org/configuring-smoothie\r\n", this->check_sum );
36 }
37 }
38
39 double as_number(){
40 if( this->found == false && this->default_set == true ){
41 return this->default_double;
42 }else{
e6b22382 43 double result = atof(remove_non_number(this->value).c_str());
b66fb830
AW
44 if( result == 0.0 && this->value.find_first_not_of("0.") != string::npos ){
45 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() );
46 }
47 return result;
48 }
e6b22382
AW
49
50 }
51
52 std::string as_string(){
53 if( this->found == false && this->default_set == true ){
54 return this->default_string;
55 }else{
56 return this->value;
57 }
b66fb830
AW
58 }
59
f5598f5b
AW
60 bool as_bool(){
61 if( this->found == false && this->default_set == true ){
62 return this->default_double;
63 }else{
64 if( this->value.find_first_of("t1") != string::npos ){
65 return true;
66 }else{
67 return false;
68 }
69 }
e6b22382 70 }
f5598f5b 71
e6b22382
AW
72 Pin* as_pin(){
73 Pin* pin = new Pin();
81b547a1 74 pin->from_string(this->as_string());
e6b22382 75 return pin;
f5598f5b
AW
76 }
77
b66fb830
AW
78 ConfigValue* by_default(double value){
79 this->default_set = true;
80 this->default_double = value;
81 return this;
82 }
83
e6b22382
AW
84 ConfigValue* by_default(std::string value){
85 this->default_set = true;
86 this->default_string = value;
87 return this;
88 }
89
b66fb830
AW
90 bool has_characters( string mask ){
91 if( this->value.find_first_of(mask) != string::npos ){ return true; }else{ return false; }
92 }
93
94 bool is_inverted(){
95 return this->has_characters(string("!"));
96 }
97
98 string value;
99 string key;
100 uint16_t check_sum;
101 bool found;
102 bool default_set;
103 double default_double;
e6b22382 104 string default_string;
b66fb830
AW
105};
106
107
4cff3ded
AW
108class Config : public Module {
109 public:
110 Config();
cebe90b6
AW
111
112 void on_module_loaded();
113 void on_console_line_received( void* argument );
26806df9
AW
114 void config_get_command( string parameters );
115 void config_set_command( string parameters );
da24d6ae 116 void config_load_command(string parameters );
3c132bd0
AW
117 void set_string( string setting , string value);
118
b66fb830 119 ConfigValue* value(uint16_t check_sum);
3c132bd0
AW
120 ConfigValue* value(uint16_t check_sum_a, uint16_t check_sum_b);
121 ConfigValue* value(uint16_t check_sum_a, uint16_t check_sum_b, uint16_t check_sum_c );
122 ConfigValue* value(vector<uint16_t> check_sums );
123
124 void get_module_list(vector<uint16_t>* list, uint16_t family);
125
a699b669 126 bool has_characters(uint16_t check_sum, string str );
4cff3ded 127 string get_config_file();
7dd8133c 128 bool has_config_file();
4cff3ded
AW
129 void try_config_file(string candidate);
130
131 string config_file; // Path to the config file
132 bool config_file_found; // Wether or not the config file's location is known
133};
134
135#endif