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/>.
8 #include "libs/Kernel.h"
9 #include "ConfigValue.h"
10 #include "FirmConfigSource.h"
11 #include "ConfigCache.h"
18 // we use objdump in the Makefile to import your config.default file into the compiled code
19 // Since the two symbols below are derived from the filename, we need to change them if the filename changes
20 extern char _binary_config_default_start
;
21 extern char _binary_config_default_end
;
23 FirmConfigSource::FirmConfigSource(const char* name
){
24 this->name_checksum
= get_checksum(name
);
25 this->start
= &_binary_config_default_start
;
26 this->end
= &_binary_config_default_end
;
29 FirmConfigSource::FirmConfigSource(const char* name
, const char *start
, const char *end
){
30 this->name_checksum
= get_checksum(name
);
35 // Transfer all values found in the file to the passed cache
36 void FirmConfigSource::transfer_values_to_cache( ConfigCache
* cache
){
38 const char* p
= this->start
;
40 while( p
< this->end
){
43 while(eol
< this->end
) {
44 if(*eol
++ == '\n') break;
46 string
line(p
, eol
-p
);
47 //printf("firm: processing %s\n", line.c_str());
49 process_line_from_ascii_config(line
, cache
);
53 // Return true if the check_sums match
54 bool FirmConfigSource::is_named( uint16_t check_sum
){
55 return check_sum
== this->name_checksum
;
58 // Write a config setting to the file *** FirmConfigSource is read only ***
59 bool FirmConfigSource::write( string setting
, string value
){
60 //THEKERNEL->streams->printf("ERROR: FirmConfigSource is read only\r\n");
64 // Return the value for a specific checksum
65 string
FirmConfigSource::read( uint16_t check_sums
[3] ){
69 const char* p
= this->start
;
71 while( p
< this->end
){
74 while(eol
< this->end
) {
75 if(*eol
++ == '\n') break;
77 string
line(p
, eol
-p
);
79 value
= process_line_from_ascii_config(line
, check_sums
);
80 if(!value
.empty()) return value
;