removed most mbed.h includes
[clinton/Smoothieware.git] / src / modules / communication / utils / Gcode.cpp
CommitLineData
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>
10using std::string;
11#include "Gcode.h"
4cff3ded 12
2bb8b390 13Gcode::Gcode(){}
4cff3ded 14
2bb8b390 15// Whether or not a Gcode has a letter
4cff3ded 16bool Gcode::has_letter( char letter ){
13e4a3f9
AW
17 //return ( this->command->find( letter ) != string::npos );
18 for (size_t i=0; i < this->command.length(); i++){
19 if( this->command.at(i) == letter ){
20 return true;
21 }
22 }
23 return false;
4cff3ded
AW
24}
25
13e4a3f9
AW
26// Retrieve the value for a given letter
27// 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 28double Gcode::get_value( char letter ){
13e4a3f9
AW
29 __disable_irq();
30 for (size_t i=0; i <= this->command.length()-1; i++){
31 if( letter == this->command.at(i) ){
32 size_t beginning = i+1;
33 char buffer[20];
34 for(size_t j=beginning; j <= this->command.length(); j++){
35 char c;
36 if( j == this->command.length() ){ c = ';'; }else{ c = this->command.at(j); }
37 if( c != '.' && c != '-' && ( c < '0' || c > '9' ) ){
38 buffer[j-beginning] = '\0';
39 __enable_irq();
40 return atof(buffer);
41 }else{
42 buffer[j-beginning] = c;
43 }
44 }
45 }
46 }
47 __enable_irq();
48 return 0;
4cff3ded 49}