smoothie port to mbed online compiler (smoothieware.org)
For documentation, license, ..., please check http://smoothieware.org/
This version has been tested with a 3 axis machine
modules/communication/utils/Gcode.cpp@0:31e91bb0ef3c, 2012-07-31 (annotated)
- Committer:
- scachat
- Date:
- Tue Jul 31 21:11:18 2012 +0000
- Revision:
- 0:31e91bb0ef3c
smoothie port to mbed online compiler
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
scachat | 0:31e91bb0ef3c | 1 | /* |
scachat | 0:31e91bb0ef3c | 2 | This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl). |
scachat | 0:31e91bb0ef3c | 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. |
scachat | 0:31e91bb0ef3c | 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. |
scachat | 0:31e91bb0ef3c | 5 | You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>. |
scachat | 0:31e91bb0ef3c | 6 | */ |
scachat | 0:31e91bb0ef3c | 7 | |
scachat | 0:31e91bb0ef3c | 8 | |
scachat | 0:31e91bb0ef3c | 9 | #include <string> |
scachat | 0:31e91bb0ef3c | 10 | using std::string; |
scachat | 0:31e91bb0ef3c | 11 | #include "Gcode.h" |
scachat | 0:31e91bb0ef3c | 12 | #include "libs/StreamOutput.h" |
scachat | 0:31e91bb0ef3c | 13 | |
scachat | 0:31e91bb0ef3c | 14 | #include <stdlib.h> |
scachat | 0:31e91bb0ef3c | 15 | |
scachat | 0:31e91bb0ef3c | 16 | |
scachat | 0:31e91bb0ef3c | 17 | Gcode::Gcode(){} |
scachat | 0:31e91bb0ef3c | 18 | |
scachat | 0:31e91bb0ef3c | 19 | // Whether or not a Gcode has a letter |
scachat | 0:31e91bb0ef3c | 20 | bool Gcode::has_letter( char letter ){ |
scachat | 0:31e91bb0ef3c | 21 | //return ( this->command->find( letter ) != string::npos ); |
scachat | 0:31e91bb0ef3c | 22 | for (size_t i=0; i < this->command.length(); i++){ |
scachat | 0:31e91bb0ef3c | 23 | if( this->command.at(i) == letter ){ |
scachat | 0:31e91bb0ef3c | 24 | return true; |
scachat | 0:31e91bb0ef3c | 25 | } |
scachat | 0:31e91bb0ef3c | 26 | } |
scachat | 0:31e91bb0ef3c | 27 | return false; |
scachat | 0:31e91bb0ef3c | 28 | } |
scachat | 0:31e91bb0ef3c | 29 | |
scachat | 0:31e91bb0ef3c | 30 | // Retrieve the value for a given letter |
scachat | 0:31e91bb0ef3c | 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 |
scachat | 0:31e91bb0ef3c | 32 | double Gcode::get_value( char letter ){ |
scachat | 0:31e91bb0ef3c | 33 | //__disable_irq(); |
scachat | 0:31e91bb0ef3c | 34 | for (size_t i=0; i <= this->command.length()-1; i++){ |
scachat | 0:31e91bb0ef3c | 35 | if( letter == this->command.at(i) ){ |
scachat | 0:31e91bb0ef3c | 36 | size_t beginning = i+1; |
scachat | 0:31e91bb0ef3c | 37 | char buffer[20]; |
scachat | 0:31e91bb0ef3c | 38 | for(size_t j=beginning; j <= this->command.length(); j++){ |
scachat | 0:31e91bb0ef3c | 39 | char c; |
scachat | 0:31e91bb0ef3c | 40 | if( j == this->command.length() ){ c = ';'; }else{ c = this->command.at(j); } |
scachat | 0:31e91bb0ef3c | 41 | if( c != '.' && c != '-' && ( c < '0' || c > '9' ) ){ |
scachat | 0:31e91bb0ef3c | 42 | buffer[j-beginning] = '\0'; |
scachat | 0:31e91bb0ef3c | 43 | //__enable_irq(); |
scachat | 0:31e91bb0ef3c | 44 | return atof(buffer); |
scachat | 0:31e91bb0ef3c | 45 | }else{ |
scachat | 0:31e91bb0ef3c | 46 | buffer[j-beginning] = c; |
scachat | 0:31e91bb0ef3c | 47 | } |
scachat | 0:31e91bb0ef3c | 48 | } |
scachat | 0:31e91bb0ef3c | 49 | } |
scachat | 0:31e91bb0ef3c | 50 | } |
scachat | 0:31e91bb0ef3c | 51 | //__enable_irq(); |
scachat | 0:31e91bb0ef3c | 52 | return 0; |
scachat | 0:31e91bb0ef3c | 53 | } |