|
@@ -107,68 +107,82 @@ char version_string[] = "1.0.0 Alpha 1";
|
107
|
107
|
|
108
|
108
|
//Stepper Movement Variables
|
109
|
109
|
|
110
|
|
-const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
|
111
|
|
-float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
112
|
|
-float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
113
|
|
-float offset[3] = {0.0, 0.0, 0.0};
|
114
|
|
-bool home_all_axis = true;
|
115
|
|
-float feedrate = 1500.0, next_feedrate, saved_feedrate;
|
116
|
|
-long gcode_N, gcode_LastN;
|
|
110
|
+//===========================================================================
|
|
111
|
+//=============================imported variables============================
|
|
112
|
+//===========================================================================
|
|
113
|
+extern float HeaterPower;
|
117
|
114
|
|
|
115
|
+//public variables
|
118
|
116
|
float homing_feedrate[] = HOMING_FEEDRATE;
|
119
|
117
|
bool axis_relative_modes[] = AXIS_RELATIVE_MODES;
|
120
|
|
-
|
121
|
|
-bool relative_mode = false; //Determines Absolute or Relative Coordinates
|
122
|
|
-bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
|
123
|
|
-
|
124
|
|
-uint8_t fanpwm=0;
|
125
|
|
-
|
126
|
118
|
volatile int feedmultiply=100; //100->1 200->2
|
127
|
119
|
int saved_feedmultiply;
|
128
|
120
|
volatile bool feedmultiplychanged=false;
|
129
|
121
|
|
|
122
|
+//===========================================================================
|
|
123
|
+//=============================private variables=============================
|
|
124
|
+//===========================================================================
|
|
125
|
+const char axis_codes[NUM_AXIS] = {'X', 'Y', 'Z', 'E'};
|
|
126
|
+static float destination[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
|
127
|
+static float current_position[NUM_AXIS] = { 0.0, 0.0, 0.0, 0.0};
|
|
128
|
+static float offset[3] = {0.0, 0.0, 0.0};
|
|
129
|
+static bool home_all_axis = true;
|
|
130
|
+static float feedrate = 1500.0, next_feedrate, saved_feedrate;
|
|
131
|
+static long gcode_N, gcode_LastN;
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
|
|
135
|
+static bool relative_mode = false; //Determines Absolute or Relative Coordinates
|
|
136
|
+static bool relative_mode_e = false; //Determines Absolute or Relative E Codes while in Absolute Coordinates mode. E is always relative in Relative Coordinates mode.
|
|
137
|
+
|
|
138
|
+static uint8_t fanpwm=0;
|
|
139
|
+
|
|
140
|
+
|
130
|
141
|
// comm variables
|
131
|
|
-#define MAX_CMD_SIZE 96
|
132
|
|
-#define BUFSIZE 4
|
133
|
|
-char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
|
134
|
|
-bool fromsd[BUFSIZE];
|
135
|
|
-int bufindr = 0;
|
136
|
|
-int bufindw = 0;
|
137
|
|
-int buflen = 0;
|
138
|
|
-int i = 0;
|
139
|
|
-char serial_char;
|
140
|
|
-int serial_count = 0;
|
141
|
|
-boolean comment_mode = false;
|
142
|
|
-char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
|
143
|
|
-extern float HeaterPower;
|
|
142
|
+
|
|
143
|
+static char cmdbuffer[BUFSIZE][MAX_CMD_SIZE];
|
|
144
|
+static bool fromsd[BUFSIZE];
|
|
145
|
+static int bufindr = 0;
|
|
146
|
+static int bufindw = 0;
|
|
147
|
+static int buflen = 0;
|
|
148
|
+static int i = 0;
|
|
149
|
+static char serial_char;
|
|
150
|
+static int serial_count = 0;
|
|
151
|
+static boolean comment_mode = false;
|
|
152
|
+static char *strchr_pointer; // just a pointer to find chars in the cmd string like X, Y, Z, E, etc
|
144
|
153
|
|
145
|
154
|
const int sensitive_pins[] = SENSITIVE_PINS; // Sensitive pin list for M42
|
146
|
155
|
|
147
|
|
-float tt = 0, bt = 0;
|
|
156
|
+static float tt = 0, bt = 0;
|
148
|
157
|
|
149
|
158
|
//Inactivity shutdown variables
|
150
|
|
-unsigned long previous_millis_cmd = 0;
|
151
|
|
-unsigned long max_inactive_time = 0;
|
152
|
|
-unsigned long stepper_inactive_time = 0;
|
|
159
|
+static unsigned long previous_millis_cmd = 0;
|
|
160
|
+static unsigned long max_inactive_time = 0;
|
|
161
|
+static unsigned long stepper_inactive_time = 0;
|
|
162
|
+
|
|
163
|
+static unsigned long starttime=0;
|
|
164
|
+static unsigned long stoptime=0;
|
153
|
165
|
|
154
|
|
-unsigned long starttime=0;
|
155
|
|
-unsigned long stoptime=0;
|
156
|
166
|
#ifdef SDSUPPORT
|
157
|
|
- Sd2Card card;
|
158
|
|
- SdVolume volume;
|
159
|
|
- SdFile root;
|
160
|
|
- SdFile file;
|
161
|
|
- uint32_t filesize = 0;
|
162
|
|
- uint32_t sdpos = 0;
|
163
|
|
- bool sdmode = false;
|
164
|
|
- bool sdactive = false;
|
165
|
|
- bool savetosd = false;
|
166
|
|
- int16_t n;
|
167
|
|
- unsigned long autostart_atmillis=0;
|
|
167
|
+ static Sd2Card card;
|
|
168
|
+ static SdVolume volume;
|
|
169
|
+ static SdFile root;
|
|
170
|
+ static SdFile file;
|
|
171
|
+ static uint32_t filesize = 0;
|
|
172
|
+ static uint32_t sdpos = 0;
|
|
173
|
+ static bool sdmode = false;
|
|
174
|
+ static bool sdactive = false;
|
|
175
|
+ static bool savetosd = false;
|
|
176
|
+ static int16_t n;
|
|
177
|
+ static unsigned long autostart_atmillis=0;
|
168
|
178
|
|
169
|
|
- bool autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
|
170
|
|
-
|
|
179
|
+ static bool autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware.
|
|
180
|
+#endif //SDSUPPORT
|
171
|
181
|
|
|
182
|
+//===========================================================================
|
|
183
|
+//=============================ROUTINES=============================
|
|
184
|
+//===========================================================================
|
|
185
|
+#ifdef SDSUPPORT
|
172
|
186
|
void initsd()
|
173
|
187
|
{
|
174
|
188
|
sdactive = false;
|
|
@@ -223,6 +237,65 @@ unsigned long stoptime=0;
|
223
|
237
|
SERIAL_ERRORLN("error writing to file");
|
224
|
238
|
}
|
225
|
239
|
}
|
|
240
|
+
|
|
241
|
+
|
|
242
|
+ void checkautostart(bool force)
|
|
243
|
+ {
|
|
244
|
+ //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
|
|
245
|
+ if(!force)
|
|
246
|
+ {
|
|
247
|
+ if(!autostart_stilltocheck)
|
|
248
|
+ return;
|
|
249
|
+ if(autostart_atmillis<millis())
|
|
250
|
+ return;
|
|
251
|
+ }
|
|
252
|
+ autostart_stilltocheck=false;
|
|
253
|
+ if(!sdactive)
|
|
254
|
+ {
|
|
255
|
+ initsd();
|
|
256
|
+ if(!sdactive) //fail
|
|
257
|
+ return;
|
|
258
|
+ }
|
|
259
|
+ static int lastnr=0;
|
|
260
|
+ char autoname[30];
|
|
261
|
+ sprintf(autoname,"auto%i.g",lastnr);
|
|
262
|
+ for(int i=0;i<(int)strlen(autoname);i++)
|
|
263
|
+ autoname[i]=tolower(autoname[i]);
|
|
264
|
+ dir_t p;
|
|
265
|
+
|
|
266
|
+ root.rewind();
|
|
267
|
+
|
|
268
|
+ bool found=false;
|
|
269
|
+ while (root.readDir(p) > 0)
|
|
270
|
+ {
|
|
271
|
+ for(int i=0;i<(int)strlen((char*)p.name);i++)
|
|
272
|
+ p.name[i]=tolower(p.name[i]);
|
|
273
|
+ //Serial.print((char*)p.name);
|
|
274
|
+ //Serial.print(" ");
|
|
275
|
+ //Serial.println(autoname);
|
|
276
|
+ if(p.name[9]!='~') //skip safety copies
|
|
277
|
+ if(strncmp((char*)p.name,autoname,5)==0)
|
|
278
|
+ {
|
|
279
|
+ char cmd[30];
|
|
280
|
+
|
|
281
|
+ sprintf(cmd,"M23 %s",autoname);
|
|
282
|
+ //sprintf(cmd,"M115");
|
|
283
|
+ //enquecommand("G92 Z0");
|
|
284
|
+ //enquecommand("G1 Z10 F2000");
|
|
285
|
+ //enquecommand("G28 X-105 Y-105");
|
|
286
|
+ enquecommand(cmd);
|
|
287
|
+ enquecommand("M24");
|
|
288
|
+ found=true;
|
|
289
|
+ }
|
|
290
|
+ }
|
|
291
|
+ if(!found)
|
|
292
|
+ lastnr=-1;
|
|
293
|
+ else
|
|
294
|
+ lastnr++;
|
|
295
|
+ }
|
|
296
|
+#else //NO SD SUPORT
|
|
297
|
+ inline void checkautostart(bool x){};
|
|
298
|
+
|
226
|
299
|
#endif //SDSUPPORT
|
227
|
300
|
|
228
|
301
|
|
|
@@ -272,66 +345,6 @@ void setup()
|
272
|
345
|
tp_init(); // Initialize temperature loop
|
273
|
346
|
}
|
274
|
347
|
|
275
|
|
-#ifdef SDSUPPORT
|
276
|
|
-
|
277
|
|
-void checkautostart(bool force)
|
278
|
|
-{
|
279
|
|
-//this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset
|
280
|
|
- if(!force)
|
281
|
|
- {
|
282
|
|
- if(!autostart_stilltocheck)
|
283
|
|
- return;
|
284
|
|
- if(autostart_atmillis<millis())
|
285
|
|
- return;
|
286
|
|
- }
|
287
|
|
- autostart_stilltocheck=false;
|
288
|
|
- if(!sdactive)
|
289
|
|
- {
|
290
|
|
- initsd();
|
291
|
|
- if(!sdactive) //fail
|
292
|
|
- return;
|
293
|
|
- }
|
294
|
|
- static int lastnr=0;
|
295
|
|
- char autoname[30];
|
296
|
|
- sprintf(autoname,"auto%i.g",lastnr);
|
297
|
|
- for(int i=0;i<(int)strlen(autoname);i++)
|
298
|
|
- autoname[i]=tolower(autoname[i]);
|
299
|
|
- dir_t p;
|
300
|
|
-
|
301
|
|
- root.rewind();
|
302
|
|
-
|
303
|
|
- bool found=false;
|
304
|
|
- while (root.readDir(p) > 0)
|
305
|
|
- {
|
306
|
|
- for(int i=0;i<(int)strlen((char*)p.name);i++)
|
307
|
|
- p.name[i]=tolower(p.name[i]);
|
308
|
|
- //Serial.print((char*)p.name);
|
309
|
|
- //Serial.print(" ");
|
310
|
|
- //Serial.println(autoname);
|
311
|
|
- if(p.name[9]!='~') //skip safety copies
|
312
|
|
- if(strncmp((char*)p.name,autoname,5)==0)
|
313
|
|
- {
|
314
|
|
- char cmd[30];
|
315
|
|
-
|
316
|
|
- sprintf(cmd,"M23 %s",autoname);
|
317
|
|
- //sprintf(cmd,"M115");
|
318
|
|
- //enquecommand("G92 Z0");
|
319
|
|
- //enquecommand("G1 Z10 F2000");
|
320
|
|
- //enquecommand("G28 X-105 Y-105");
|
321
|
|
- enquecommand(cmd);
|
322
|
|
- enquecommand("M24");
|
323
|
|
- found=true;
|
324
|
|
- }
|
325
|
|
- }
|
326
|
|
- if(!found)
|
327
|
|
- lastnr=-1;
|
328
|
|
- else
|
329
|
|
- lastnr++;
|
330
|
|
-}
|
331
|
|
-#else //NO SD SUPORT
|
332
|
|
- inline void checkautostart(bool x){}
|
333
|
|
-#endif
|
334
|
|
-
|
335
|
348
|
|
336
|
349
|
void loop()
|
337
|
350
|
{
|