smoothie port to mbed online compiler (smoothieware.org)

Dependencies:   mbed

For documentation, license, ..., please check http://smoothieware.org/

This version has been tested with a 3 axis machine

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?

UserRevisionLine numberNew 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 #ifndef CONFIGVALUE_H
scachat 0:31e91bb0ef3c 9 #define CONFIGVALUE_H
scachat 0:31e91bb0ef3c 10
scachat 0:31e91bb0ef3c 11 #include "libs/Kernel.h"
scachat 0:31e91bb0ef3c 12 #include "libs/utils.h"
scachat 0:31e91bb0ef3c 13 #include "libs/Pin.h"
scachat 0:31e91bb0ef3c 14
scachat 0:31e91bb0ef3c 15
scachat 0:31e91bb0ef3c 16 #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
scachat 0:31e91bb0ef3c 17
scachat 0:31e91bb0ef3c 18 using namespace std;
scachat 0:31e91bb0ef3c 19 #include <vector>
scachat 0:31e91bb0ef3c 20 #include <string>
scachat 0:31e91bb0ef3c 21 #include <stdio.h>
scachat 0:31e91bb0ef3c 22
scachat 0:31e91bb0ef3c 23
scachat 0:31e91bb0ef3c 24 class ConfigValue{
scachat 0:31e91bb0ef3c 25 public:
scachat 0:31e91bb0ef3c 26 ConfigValue(){
scachat 0:31e91bb0ef3c 27 this->found = false;
scachat 0:31e91bb0ef3c 28 this->default_set = false;
scachat 0:31e91bb0ef3c 29 };
scachat 0:31e91bb0ef3c 30
scachat 0:31e91bb0ef3c 31 ConfigValue* required(){
scachat 0:31e91bb0ef3c 32 if( this->found == true ){
scachat 0:31e91bb0ef3c 33 return this;
scachat 0:31e91bb0ef3c 34 }else{
scachat 0:31e91bb0ef3c 35 error("could not find config setting with checksum %u, please see http://smoothieware.org/configuring-smoothie\r\n", this->check_sum );
scachat 0:31e91bb0ef3c 36 return NULL;
scachat 0:31e91bb0ef3c 37 }
scachat 0:31e91bb0ef3c 38 }
scachat 0:31e91bb0ef3c 39
scachat 0:31e91bb0ef3c 40 double as_number(){
scachat 0:31e91bb0ef3c 41 if( this->found == false && this->default_set == true ){
scachat 0:31e91bb0ef3c 42 return this->default_double;
scachat 0:31e91bb0ef3c 43 }else{
scachat 0:31e91bb0ef3c 44 double result = atof(remove_non_number(this->value).c_str());
scachat 0:31e91bb0ef3c 45 if( result == 0.0 && this->value.find_first_not_of("0.") != string::npos ){
scachat 0:31e91bb0ef3c 46 error("config setting with value '%s' is not a valid number, please see http://smoothieware.org/configuring-smoothie\r\n", this->value.c_str() );
scachat 0:31e91bb0ef3c 47 }
scachat 0:31e91bb0ef3c 48 return result;
scachat 0:31e91bb0ef3c 49 }
scachat 0:31e91bb0ef3c 50
scachat 0:31e91bb0ef3c 51 }
scachat 0:31e91bb0ef3c 52
scachat 0:31e91bb0ef3c 53 std::string as_string(){
scachat 0:31e91bb0ef3c 54 if( this->found == false && this->default_set == true ){
scachat 0:31e91bb0ef3c 55 return this->default_string;
scachat 0:31e91bb0ef3c 56 }else{
scachat 0:31e91bb0ef3c 57 return this->value;
scachat 0:31e91bb0ef3c 58 }
scachat 0:31e91bb0ef3c 59 }
scachat 0:31e91bb0ef3c 60
scachat 0:31e91bb0ef3c 61 bool as_bool(){
scachat 0:31e91bb0ef3c 62 if( this->found == false && this->default_set == true ){
scachat 0:31e91bb0ef3c 63 return this->default_double;
scachat 0:31e91bb0ef3c 64 }else{
scachat 0:31e91bb0ef3c 65 if( this->value.find_first_of("t1") != string::npos ){
scachat 0:31e91bb0ef3c 66 return true;
scachat 0:31e91bb0ef3c 67 }else{
scachat 0:31e91bb0ef3c 68 return false;
scachat 0:31e91bb0ef3c 69 }
scachat 0:31e91bb0ef3c 70 }
scachat 0:31e91bb0ef3c 71 }
scachat 0:31e91bb0ef3c 72
scachat 0:31e91bb0ef3c 73 Pin* as_pin(){
scachat 0:31e91bb0ef3c 74 Pin* pin = new Pin();
scachat 0:31e91bb0ef3c 75 pin->from_string(this->as_string());
scachat 0:31e91bb0ef3c 76 return pin;
scachat 0:31e91bb0ef3c 77 }
scachat 0:31e91bb0ef3c 78
scachat 0:31e91bb0ef3c 79 ConfigValue* by_default(double val){
scachat 0:31e91bb0ef3c 80 this->default_set = true;
scachat 0:31e91bb0ef3c 81 this->default_double = val;
scachat 0:31e91bb0ef3c 82 return this;
scachat 0:31e91bb0ef3c 83 }
scachat 0:31e91bb0ef3c 84
scachat 0:31e91bb0ef3c 85 ConfigValue* by_default(std::string val){
scachat 0:31e91bb0ef3c 86 this->default_set = true;
scachat 0:31e91bb0ef3c 87 this->default_string = val;
scachat 0:31e91bb0ef3c 88 return this;
scachat 0:31e91bb0ef3c 89 }
scachat 0:31e91bb0ef3c 90
scachat 0:31e91bb0ef3c 91 bool has_characters( string mask ){
scachat 0:31e91bb0ef3c 92 if( this->value.find_first_of(mask) != string::npos ){ return true; }else{ return false; }
scachat 0:31e91bb0ef3c 93 }
scachat 0:31e91bb0ef3c 94
scachat 0:31e91bb0ef3c 95 bool is_inverted(){
scachat 0:31e91bb0ef3c 96 return this->has_characters(string("!"));
scachat 0:31e91bb0ef3c 97 }
scachat 0:31e91bb0ef3c 98
scachat 0:31e91bb0ef3c 99 string value;
scachat 0:31e91bb0ef3c 100 vector<uint16_t> check_sums;
scachat 0:31e91bb0ef3c 101 uint16_t check_sum;
scachat 0:31e91bb0ef3c 102 bool found;
scachat 0:31e91bb0ef3c 103 bool default_set;
scachat 0:31e91bb0ef3c 104 double default_double;
scachat 0:31e91bb0ef3c 105 string default_string;
scachat 0:31e91bb0ef3c 106 };
scachat 0:31e91bb0ef3c 107
scachat 0:31e91bb0ef3c 108
scachat 0:31e91bb0ef3c 109
scachat 0:31e91bb0ef3c 110
scachat 0:31e91bb0ef3c 111
scachat 0:31e91bb0ef3c 112
scachat 0:31e91bb0ef3c 113
scachat 0:31e91bb0ef3c 114
scachat 0:31e91bb0ef3c 115 #endif