Skip to content

Instantly share code, notes, and snippets.

@wolfmanjm
Last active December 12, 2015 16:19
Show Gist options
  • Save wolfmanjm/4795618 to your computer and use it in GitHub Desktop.
Save wolfmanjm/4795618 to your computer and use it in GitHub Desktop.
6a3328dfe514e66a98c0cf5adc7252d333567e83 is the first bad commit
commit 6a3328dfe514e66a98c0cf5adc7252d333567e83
Author: Ben Gamari <[email protected]>
Date: Sun Feb 10 16:54:44 2013 -0500
Gcode: Make command const
This also kills allocations from indexing
:040000 040000 afb33ab780fa3149a6967e004b576ba223b29cbb 06c1edecbd41fe01df46450de010678140f4eb56 M src
// Retrieve the value for a given letter
// 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
double Gcode::get_value( char letter ){
//__disable_irq();
<<<<<<< HEAD
const char* cs = command.c_str();
char* cn = NULL;
for (; *cs; cs++){
if( letter == *cs ){
cs++;
double r = strtod(cs, &cn);
if (cn > cs)
return r;
=======
for (size_t i=0; i <= this->command.length()-1; i++){
const char& c = this->command.at(i);
if( letter == c ){
size_t beginning = i+1;
char buffer[20];
for(size_t j=beginning; j <= this->command.length(); j++){
char c;
if( j == this->command.length() ){ c = ';'; }else{ c = this->command.at(j); }
if( c != '.' && c != '-' && ( c < '0' || c > '9' ) ){
buffer[j-beginning] = '\0';
//__enable_irq();
return atof(buffer);
}else{
buffer[j-beginning] = c;
}
}
>>>>>>> parent of 6a3328d... Gcode: Make command const
}
}
//__enable_irq();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment