Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Committer:
Bigcheese
Date:
Sun Mar 02 06:33:08 2014 +0000
Revision:
3:f151d08d335c
Parent:
2:1df0b61d3b5a
Bunch of stuff. Need to locally merge in updated USB changes.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michael J. Spencer 2:1df0b61d3b5a 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.
Michael J. Spencer 2:1df0b61d3b5a 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"
Michael J. Spencer 2:1df0b61d3b5a 14 #include "Pwm.h"
scachat 0:31e91bb0ef3c 15
scachat 0:31e91bb0ef3c 16
scachat 0:31e91bb0ef3c 17 #define error(...) (fprintf(stderr, __VA_ARGS__), exit(1))
scachat 0:31e91bb0ef3c 18
scachat 0:31e91bb0ef3c 19 using namespace std;
scachat 0:31e91bb0ef3c 20 #include <vector>
scachat 0:31e91bb0ef3c 21 #include <string>
scachat 0:31e91bb0ef3c 22 #include <stdio.h>
scachat 0:31e91bb0ef3c 23
scachat 0:31e91bb0ef3c 24
scachat 0:31e91bb0ef3c 25 class ConfigValue{
scachat 0:31e91bb0ef3c 26 public:
scachat 0:31e91bb0ef3c 27 ConfigValue(){
scachat 0:31e91bb0ef3c 28 this->found = false;
Michael J. Spencer 2:1df0b61d3b5a 29 this->default_set = false;
Michael J. Spencer 2:1df0b61d3b5a 30 this->check_sums[0] = 0x0000;
Michael J. Spencer 2:1df0b61d3b5a 31 this->check_sums[1] = 0x0000;
Michael J. Spencer 2:1df0b61d3b5a 32 this->check_sums[2] = 0x0000;
scachat 0:31e91bb0ef3c 33 };
scachat 0:31e91bb0ef3c 34
scachat 0:31e91bb0ef3c 35 ConfigValue* required(){
scachat 0:31e91bb0ef3c 36 if( this->found == true ){
scachat 0:31e91bb0ef3c 37 return this;
scachat 0:31e91bb0ef3c 38 }else{
Michael J. Spencer 2:1df0b61d3b5a 39 error("could not find config setting, please see http://smoothieware.org/configuring-smoothie\r\n");
scachat 0:31e91bb0ef3c 40 }
scachat 0:31e91bb0ef3c 41 }
scachat 0:31e91bb0ef3c 42
Michael J. Spencer 2:1df0b61d3b5a 43 float as_number(){
scachat 0:31e91bb0ef3c 44 if( this->found == false && this->default_set == true ){
scachat 0:31e91bb0ef3c 45 return this->default_double;
scachat 0:31e91bb0ef3c 46 }else{
Michael J. Spencer 2:1df0b61d3b5a 47 char* endptr = NULL;
Michael J. Spencer 2:1df0b61d3b5a 48 float result = strtof(remove_non_number(this->value).c_str(), &endptr);
Michael J. Spencer 2:1df0b61d3b5a 49 if( endptr <= remove_non_number(this->value).c_str() ){
Michael J. Spencer 2:1df0b61d3b5a 50 error("config setting with value '%s' and checksums[%u,%u,%u] is not a valid number, please see http://smoothieware.org/configuring-smoothie\r\n", this->value.c_str(), this->check_sums[0], this->check_sums[1], this->check_sums[2] );
scachat 0:31e91bb0ef3c 51 }
Michael J. Spencer 2:1df0b61d3b5a 52 return result;
scachat 0:31e91bb0ef3c 53 }
Michael J. Spencer 2:1df0b61d3b5a 54 }
Michael J. Spencer 2:1df0b61d3b5a 55
Michael J. Spencer 2:1df0b61d3b5a 56 int as_int()
Michael J. Spencer 2:1df0b61d3b5a 57 {
Michael J. Spencer 2:1df0b61d3b5a 58 if( this->found == false && this->default_set == true ){
Michael J. Spencer 2:1df0b61d3b5a 59 return this->default_int;
Michael J. Spencer 2:1df0b61d3b5a 60 }else{
Michael J. Spencer 2:1df0b61d3b5a 61 char* endptr = NULL;
Michael J. Spencer 2:1df0b61d3b5a 62 int result = strtol(remove_non_number(this->value).c_str(), &endptr, 10);
Michael J. Spencer 2:1df0b61d3b5a 63 if( endptr <= remove_non_number(this->value).c_str() ){
Michael J. Spencer 2:1df0b61d3b5a 64 error("config setting with value '%s' and checksums[%u,%u,%u] is not a valid number, please see http://smoothieware.org/configuring-smoothie\r\n", this->value.c_str(), this->check_sums[0], this->check_sums[1], this->check_sums[2] );
Michael J. Spencer 2:1df0b61d3b5a 65 }
Michael J. Spencer 2:1df0b61d3b5a 66 return result;
Michael J. Spencer 2:1df0b61d3b5a 67 }
scachat 0:31e91bb0ef3c 68 }
scachat 0:31e91bb0ef3c 69
scachat 0:31e91bb0ef3c 70 std::string as_string(){
Michael J. Spencer 2:1df0b61d3b5a 71 return this->value;
scachat 0:31e91bb0ef3c 72 }
scachat 0:31e91bb0ef3c 73
scachat 0:31e91bb0ef3c 74 bool as_bool(){
scachat 0:31e91bb0ef3c 75 if( this->found == false && this->default_set == true ){
scachat 0:31e91bb0ef3c 76 return this->default_double;
scachat 0:31e91bb0ef3c 77 }else{
Michael J. Spencer 2:1df0b61d3b5a 78 if( this->value.find_first_of("ty1") != string::npos ){
scachat 0:31e91bb0ef3c 79 return true;
scachat 0:31e91bb0ef3c 80 }else{
scachat 0:31e91bb0ef3c 81 return false;
Michael J. Spencer 2:1df0b61d3b5a 82 }
scachat 0:31e91bb0ef3c 83 }
scachat 0:31e91bb0ef3c 84 }
scachat 0:31e91bb0ef3c 85
Michael J. Spencer 2:1df0b61d3b5a 86 ConfigValue* by_default(int val)
Michael J. Spencer 2:1df0b61d3b5a 87 {
Michael J. Spencer 2:1df0b61d3b5a 88 this->default_set = true;
Michael J. Spencer 2:1df0b61d3b5a 89 this->default_int = val;
Michael J. Spencer 2:1df0b61d3b5a 90 this->default_double = val;
Michael J. Spencer 2:1df0b61d3b5a 91 return this;
scachat 0:31e91bb0ef3c 92 }
scachat 0:31e91bb0ef3c 93
Michael J. Spencer 2:1df0b61d3b5a 94 ConfigValue* by_default(float val){
scachat 0:31e91bb0ef3c 95 this->default_set = true;
scachat 0:31e91bb0ef3c 96 this->default_double = val;
Michael J. Spencer 2:1df0b61d3b5a 97 return this;
scachat 0:31e91bb0ef3c 98 }
scachat 0:31e91bb0ef3c 99
scachat 0:31e91bb0ef3c 100 ConfigValue* by_default(std::string val){
Michael J. Spencer 2:1df0b61d3b5a 101 if( this->found ){ return this; }
scachat 0:31e91bb0ef3c 102 this->default_set = true;
Michael J. Spencer 2:1df0b61d3b5a 103 this->value = val;
scachat 0:31e91bb0ef3c 104 return this;
scachat 0:31e91bb0ef3c 105 }
scachat 0:31e91bb0ef3c 106
scachat 0:31e91bb0ef3c 107 bool has_characters( string mask ){
Michael J. Spencer 2:1df0b61d3b5a 108 if( this->value.find_first_of(mask) != string::npos ){ return true; }else{ return false; }
scachat 0:31e91bb0ef3c 109 }
scachat 0:31e91bb0ef3c 110
scachat 0:31e91bb0ef3c 111 bool is_inverted(){
scachat 0:31e91bb0ef3c 112 return this->has_characters(string("!"));
scachat 0:31e91bb0ef3c 113 }
scachat 0:31e91bb0ef3c 114
Michael J. Spencer 2:1df0b61d3b5a 115 int default_int;
Michael J. Spencer 2:1df0b61d3b5a 116 float default_double;
Michael J. Spencer 2:1df0b61d3b5a 117 uint16_t check_sums[3];
scachat 0:31e91bb0ef3c 118 string value;
scachat 0:31e91bb0ef3c 119 bool found;
scachat 0:31e91bb0ef3c 120 bool default_set;
scachat 0:31e91bb0ef3c 121 };
scachat 0:31e91bb0ef3c 122
scachat 0:31e91bb0ef3c 123
scachat 0:31e91bb0ef3c 124
scachat 0:31e91bb0ef3c 125
scachat 0:31e91bb0ef3c 126
scachat 0:31e91bb0ef3c 127
scachat 0:31e91bb0ef3c 128
scachat 0:31e91bb0ef3c 129
scachat 0:31e91bb0ef3c 130 #endif