Commit | Line | Data |
---|---|---|
cd011f58 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 | ||
4cff3ded AW |
9 | #include <string> |
10 | using std::string; | |
11 | #include "Gcode.h" | |
838b33b4 AW |
12 | #include "libs/StreamOutput.h" |
13 | ||
14 | ||
15 | #include <stdlib.h> | |
4cff3ded | 16 | |
2bb8b390 | 17 | Gcode::Gcode(){} |
4cff3ded | 18 | |
2bb8b390 | 19 | // Whether or not a Gcode has a letter |
4cff3ded | 20 | bool Gcode::has_letter( char letter ){ |
13e4a3f9 AW |
21 | //return ( this->command->find( letter ) != string::npos ); |
22 | for (size_t i=0; i < this->command.length(); i++){ | |
23 | if( this->command.at(i) == letter ){ | |
24 | return true; | |
25 | } | |
26 | } | |
27 | return false; | |
4cff3ded AW |
28 | } |
29 | ||
13e4a3f9 AW |
30 | // Retrieve the value for a given letter |
31 | // We don't use the high-level methods of std::string because they call malloc and it's very bad to do that inside of interrupts | |
4cff3ded | 32 | double Gcode::get_value( char letter ){ |
838b33b4 | 33 | //__disable_irq(); |
13e4a3f9 AW |
34 | for (size_t i=0; i <= this->command.length()-1; i++){ |
35 | if( letter == this->command.at(i) ){ | |
36 | size_t beginning = i+1; | |
37 | char buffer[20]; | |
38 | for(size_t j=beginning; j <= this->command.length(); j++){ | |
39 | char c; | |
40 | if( j == this->command.length() ){ c = ';'; }else{ c = this->command.at(j); } | |
41 | if( c != '.' && c != '-' && ( c < '0' || c > '9' ) ){ | |
42 | buffer[j-beginning] = '\0'; | |
838b33b4 | 43 | //__enable_irq(); |
13e4a3f9 AW |
44 | return atof(buffer); |
45 | }else{ | |
46 | buffer[j-beginning] = c; | |
47 | } | |
48 | } | |
49 | } | |
50 | } | |
838b33b4 | 51 | //__enable_irq(); |
13e4a3f9 | 52 | return 0; |
4cff3ded | 53 | } |