![]() |
Repetier-Firmware
0.80
|
00001 /* 00002 This file is part of Repetier-Firmware. 00003 00004 Repetier-Firmware is free software: you can redistribute it and/or modify 00005 it under the terms of the GNU General Public License as published by 00006 the Free Software Foundation, either version 3 of the License, or 00007 (at your option) any later version. 00008 00009 Repetier-Firmware is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 GNU General Public License for more details. 00013 00014 You should have received a copy of the GNU General Public License 00015 along with Repetier-Firmware. If not, see <http://www.gnu.org/licenses/>. 00016 00017 */ 00018 #ifndef _GCODE_H 00019 #define _GCODE_H 00020 00021 #include <avr/pgmspace.h> 00022 // Workaround for http://gcc.gnu.org/bugzilla/show_bug.cgi?id=34734 00023 //#ifdef PROGMEM 00024 //#undef PROGMEM 00025 //#define PROGMEM __attribute__((section(".progmem.data"))) 00026 //#endif 00027 00028 typedef struct { // 52 bytes per command needed 00029 unsigned int params; 00030 unsigned int params2; 00031 unsigned int N; // Line number 00032 unsigned int M; 00033 unsigned int G; 00034 float X; 00035 float Y; 00036 float Z; 00037 float E; 00038 float F; 00039 byte T; 00040 long S; 00041 long P; 00042 float I; 00043 float J; 00044 float R; 00045 char *text; //text[17]; 00046 } GCode; 00047 00048 #ifndef EXTERNALSERIAL 00049 // Implement serial communication for one stream only! 00050 /* 00051 HardwareSerial.h - Hardware serial library for Wiring 00052 Copyright (c) 2006 Nicholas Zambetti. All right reserved. 00053 00054 This library is free software; you can redistribute it and/or 00055 modify it under the terms of the GNU Lesser General Public 00056 License as published by the Free Software Foundation; either 00057 version 2.1 of the License, or (at your option) any later version. 00058 00059 This library is distributed in the hope that it will be useful, 00060 but WITHOUT ANY WARRANTY; without even the implied warranty of 00061 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00062 Lesser General Public License for more details. 00063 00064 You should have received a copy of the GNU Lesser General Public 00065 License along with this library; if not, write to the Free Software 00066 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 00067 00068 Modified 28 September 2010 by Mark Sproul 00069 00070 Modified to use only 1 queue with fixed length by Repetier 00071 */ 00072 00073 #define SERIAL_BUFFER_SIZE 128 00074 #define SERIAL_BUFFER_MASK 127 00075 00076 struct ring_buffer 00077 { 00078 unsigned char buffer[SERIAL_BUFFER_SIZE]; 00079 volatile int head; 00080 volatile int tail; 00081 }; 00082 class RFHardwareSerial : public Print 00083 { 00084 public: 00085 ring_buffer *_rx_buffer; 00086 ring_buffer *_tx_buffer; 00087 volatile uint8_t *_ubrrh; 00088 volatile uint8_t *_ubrrl; 00089 volatile uint8_t *_ucsra; 00090 volatile uint8_t *_ucsrb; 00091 volatile uint8_t *_udr; 00092 uint8_t _rxen; 00093 uint8_t _txen; 00094 uint8_t _rxcie; 00095 uint8_t _udrie; 00096 uint8_t _u2x; 00097 public: 00098 RFHardwareSerial(ring_buffer *rx_buffer, ring_buffer *tx_buffer, 00099 volatile uint8_t *ubrrh, volatile uint8_t *ubrrl, 00100 volatile uint8_t *ucsra, volatile uint8_t *ucsrb, 00101 volatile uint8_t *udr, 00102 uint8_t rxen, uint8_t txen, uint8_t rxcie, uint8_t udrie, uint8_t u2x); 00103 void begin(unsigned long); 00104 void end(); 00105 virtual int available(void); 00106 virtual int peek(void); 00107 virtual int read(void); 00108 virtual void flush(void); 00109 #ifdef COMPAT_PRE1 00110 virtual void write(uint8_t); 00111 #else 00112 virtual size_t write(uint8_t); 00113 #endif 00114 using Print::write; // pull in write(str) and write(buf, size) from Print 00115 operator bool(); 00116 }; 00117 extern RFHardwareSerial RFSerial; 00118 #define RFSERIAL RFSerial 00119 extern ring_buffer tx_buffer; 00120 #define WAIT_OUT_EMPTY while(tx_buffer.head != tx_buffer.tail) {} 00121 #else 00122 #define RFSERIAL Serial 00123 #endif 00124 00125 class SerialOutput : public Print { 00126 public: 00127 SerialOutput(); 00128 #ifdef COMPAT_PRE1 00129 void write(uint8_t); 00130 #else 00131 size_t write(uint8_t); 00132 #endif 00133 void print_P(PGM_P ptr); 00134 void println_P(PGM_P ptr); 00135 void print_long_P(PGM_P ptr,long value); 00136 void print_int_P(PGM_P ptr,int value); 00137 void print_float_P(PGM_P ptr,float value,uint8_t digits = 2); 00138 void println_long_P(PGM_P ptr,long value); 00139 void println_int_P(PGM_P ptr,int value); 00140 void println_float_P(PGM_P ptr,float value,uint8_t digits = 2); 00141 void print_error_P(PGM_P ptr,bool newline); 00142 void printFloat(double number, uint8_t digits=2); 00143 00144 }; 00145 #define OUT_P_I(p,i) out.print_int_P(PSTR(p),(int)(i)) 00146 #define OUT_P_I_LN(p,i) out.println_int_P(PSTR(p),(int)(i)) 00147 #define OUT_P_L(p,i) out.print_long_P(PSTR(p),(long)(i)) 00148 #define OUT_P_L_LN(p,i) out.println_long_P(PSTR(p),(long)(i)) 00149 #define OUT_P_F(p,i) out.print_float_P(PSTR(p),(float)(i)) 00150 #define OUT_P_F_LN(p,i) out.println_float_P(PSTR(p),(float)(i)) 00151 #define OUT_P_FX(p,i,x) out.print_float_P(PSTR(p),(float)(i),x) 00152 #define OUT_P_FX_LN(p,i,x) out.println_float_P(PSTR(p),(float)(i),x) 00153 #define OUT_P(p) out.print_P(PSTR(p)) 00154 #define OUT_P_LN(p) out.println_P(PSTR(p)) 00155 #define OUT_ERROR_P(p) out.print_error_P(PSTR(p),false) 00156 #define OUT_ERROR_P_LN(p) out.print_error_P(PSTR(p),true) 00157 #define OUT(v) out.print(v) 00158 #define OUT_LN out.println() 00159 extern SerialOutput out; 00161 extern GCode *gcode_next_command(); 00163 extern void gcode_command_finished(GCode *code); 00164 // check for new commands 00165 extern void gcode_read_serial(); 00166 extern void gcode_execute_PString(PGM_P cmd); 00167 extern void gcode_print_command(GCode *code); 00168 extern byte gcode_comp_binary_size(char *ptr); 00169 extern bool gcode_parse_binary(GCode *code,byte *buffer); 00170 extern bool gcode_parse_ascii(GCode *code,char *line); 00171 extern void emergencyStop(); 00172 00173 // Helper macros to detect, if parameter is stored in GCode struct 00174 #define GCODE_HAS_N(a) ((a->params & 1)!=0) 00175 #define GCODE_HAS_M(a) ((a->params & 2)!=0) 00176 #define GCODE_HAS_G(a) ((a->params & 4)!=0) 00177 #define GCODE_HAS_X(a) ((a->params & 8)!=0) 00178 #define GCODE_HAS_Y(a) ((a->params & 16)!=0) 00179 #define GCODE_HAS_Z(a) ((a->params & 32)!=0) 00180 #define GCODE_HAS_NO_XYZ(a) ((a->params & 56)==0) 00181 #define GCODE_HAS_E(a) ((a->params & 64)!=0) 00182 #define GCODE_HAS_F(a) ((a->params & 256)!=0) 00183 #define GCODE_HAS_T(a) ((a->params & 512)!=0) 00184 #define GCODE_HAS_S(a) ((a->params & 1024)!=0) 00185 #define GCODE_HAS_P(a) ((a->params & 2048)!=0) 00186 #define GCODE_IS_V2(a) ((a->params & 4096)!=0) 00187 #define GCODE_HAS_STRING(a) ((a->params & 32768)!=0) 00188 #define GCODE_HAS_I(a) ((a->params2 & 1)!=0) 00189 #define GCODE_HAS_J(a) ((a->params2 & 2)!=0) 00190 #define GCODE_HAS_R(a) ((a->params2 & 4)!=0) 00191 00192 extern byte debug_level; 00193 #define DEBUG_ECHO ((debug_level & 1)!=0) 00194 #define DEBUG_INFO ((debug_level & 2)!=0) 00195 #define DEBUG_ERRORS ((debug_level & 4)!=0) 00196 #define DEBUG_DRYRUN ((debug_level & 8)!=0) 00197 #define DEBUG_COMMUNICATION ((debug_level & 16)!=0) 00198 #define DEBUG_NO_MOVES ((debug_level & 32)!=0) 00199 00200 #endif 00201