Commit | Line | Data |
---|---|---|
33110301 L |
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 | #include "libs/Kernel.h" | |
9 | #include "ConfigValue.h" | |
10 | #include "FirmConfigSource.h" | |
11 | #include "ConfigCache.h" | |
12 | #include <malloc.h> | |
13 | ||
14 | ||
15 | using namespace std; | |
16 | #include <string> | |
17 | ||
e45dc2c5 MM |
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 | |
33110301 L |
20 | extern char _binary_config_default_start; |
21 | extern char _binary_config_default_end; | |
22 | ||
23 | ||
24 | FirmConfigSource::FirmConfigSource(uint16_t name_checksum){ | |
25 | this->name_checksum = name_checksum; | |
26 | } | |
27 | ||
28 | // Transfer all values found in the file to the passed cache | |
29 | void FirmConfigSource::transfer_values_to_cache( ConfigCache* cache ){ | |
30 | ||
33110301 | 31 | char* p = &_binary_config_default_start; |
33110301 L |
32 | // For each line |
33 | while( p != &_binary_config_default_end ){ | |
e45dc2c5 | 34 | process_char_from_ascii_config(*p++, cache); |
33110301 L |
35 | } |
36 | } | |
37 | ||
38 | // Return true if the check_sums match | |
39 | bool FirmConfigSource::is_named( uint16_t check_sum ){ | |
40 | return check_sum == this->name_checksum; | |
41 | } | |
42 | ||
43 | // Write a config setting to the file *** FirmConfigSource is read only *** | |
44 | void FirmConfigSource::write( string setting, string value ){ | |
314ab8f7 | 45 | //THEKERNEL->streams->printf("ERROR: FirmConfigSource is read only\r\n"); |
33110301 L |
46 | } |
47 | ||
48 | // Return the value for a specific checksum | |
49 | string FirmConfigSource::read( uint16_t check_sums[3] ){ | |
50 | ||
51 | string value = ""; | |
52 | ||
53 | char* p = &_binary_config_default_start; | |
33110301 L |
54 | // For each line |
55 | while( p != &_binary_config_default_end ){ | |
e45dc2c5 MM |
56 | value = process_char_from_ascii_config(*p++, check_sums); |
57 | if (value.length()) | |
58 | return value; | |
33110301 L |
59 | } |
60 | ||
61 | return value; | |
62 | } | |
63 |