-
Notifications
You must be signed in to change notification settings - Fork 16
/
Command.c
3466 lines (3193 loc) · 130 KB
/
Command.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Smartto, exclusively developed by Geeetech(http://www.geeetech.com/), is an open source firmware for desktop 3D printers.
* Smartto 3D Printer Firmware
* It adopts high-performance Cortex M3 core chip STM32F1XX, enabling users to make modifications on the basis of the source code.
* Copyright (C) 2016, 2017 ,2018 Geeetech [https://github.com/Geeetech3D]
*
* Based on Sprinter and grbl.
* Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm /
*
* You should have received a copy of the GNU General Public License version 2 (GPL v2) and a commercial license
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Geeetech Smartto dual license offers users a protective and flexible way to maximize their innovation and creativity.
* Smartto aims to be applicable to as many control boards and configurations as possible,use it on your own risk.But to exclusively support Geeetech customers,we makes sure that the
* releases here are stable and guaranted to work properly on all the printers and hardware sold by Geeetech.
* We encourage the community to be active and pursuing the spirits of sharing and mutual help.
* The GPL v2 license grants complete use of Smartto to common users. These users are not distributing proprietary modifications or derivatives of Smartto.
* If so then there is no need for them to acquire the legal protections of a commercial license.
* For other users however, who want to use Smartto in their commercial products or have other requirements that are not compatible with the GPLv2, the GPLv2 is not
* applicable to them.Even if you want to do so then you must acquire written permission from Geeetech.
* Only under written condition, Geeetech, the exclusive licensor of Smartto, offers Smartto commercial license to meet their needs.
* A Smartto commercial license gives customers legal permission to modify Smartto or incorporate it into their products without the obligation of sharing the final
* code under the
* GPL v2 license.
* Fees vary with the application and the scale of its use. For more detailed information, please contact the Geeetech marketing department directly.
*
* Geeetech commits itself to promoting the open source spirit.
*/
#include "command.h"
#include "delay.h"
#include "usart1.h"
#include "fat.h"
#include "sd.h"
#include "mmc_sd.h"
#include "setting.h"
#include "adc.h"
#include "step_motor.h"
#include "LCD2004.h"
#include "rocker.h"
#include "stdlib.h"
#include "stdio.h"
#include "endstop.h" //fdwong
#include "planner.h"
#include "wifi.h"
#include "sd_print.h"
#include "Dgus_screen.h"
#include "vector_3.h"
#include "recovery_print.h"
#include "Gta.h"
#include "variable.h"
#include "data_handle.h"
#include "qr_solve.h"
#include "Configuration_Select_Printer.h"
/**
* Look here for descriptions of G-codes:
* - https://reprap.org/wiki/G-code
*
* -----------------
* Implemented Codes
* -----------------
*
* "G" Codes
*
* G0 -> G1
* G1 - Coordinated Movement X Y Z E
* G2 - CW ARC
* G3 - CCW ARC
* G4 - Dwell S<seconds> or P<milliseconds>
* G20 - Set units to inches
* G21 - Set units to millimeters
* G28 - Home one or more axes
* G29 - Detailed Z-Probe, probes the bed at 3 or more points. Will fail if you haven't homed yet.
* G90 - Use Absolute Coordinates
* G91 - Use Relative Coordinates
* G92 - Set current position to coordinates given
*
*
*
* "M" Codes
*
* M17 - Enable/Power all stepper motors
* M18 - Disable all stepper motors; same as M84
* M20 - List SD card
* M21 - Init SD card
* M23 - Select SD file (M23 filename.g)
* M24 - Start/resume SD print
* M25 - Pause SD print
* M27 - Report SD print status
* M30 - Delete file from SD (M30 filename.g)
* M80 - Wake from sleep
* M81 - sleep (turns off LCD and some fans)
* M84 - Disable steppers
* if printing from serial, this will end the serial print and re-home all axis.
* M92 - Set axis_steps_per_unit
* M104 - Set extruder target temp
* M105 - Read current temp
* M106 - Fan on
* M107 - Fan off
* M109 - Sets the target temperature for the current build platform. S is the temperature to set the platform to, in degrees Celsius. T is the platform to heat.
* M110 - Set current line number
* M114 - Output current position to serial port
* M115 - Capabilities string
* M117 - Display a message on the controller screen
* M119 - Output Endstop status to serial port
* M140 - Set bed target temp
* M190 - Sxxx Wait for bed current temp to reach target temp.
* M201 - Set max acceleration in units/s^2 for print moves (M201 X1000 Y1000)
* M203 - Set maximum feedrate that your machine can sustain (M203 X200 Y200 Z300 E10000) in mm/sec
* M204 - Set default acceleration: P for Printing moves, R for Retract only (no X, Y, Z) moves and T for Travel (non printing) moves (ex. M204 P800 T3000 R9000) in mm/sec^2
* M205 - Advanced settings: minimum travel speed S=while printing T=travel only, B=minimum segment time X= maximum xy jerk, Z=maximum Z jerk, E=maximum E jerk
* M220 - Set speed factor override percentage: S<factor in percent>
* M280 - Set servo position absolute. P: servo index, S: angle or microseconds
* M300 - Play beep sound S<frequency Hz> P<duration ms>
* M301 - Set PID parameters P I and D
* M304 - Set bed PID parameters P I and D
* M401 - Lower BLTouch pin if present
* M402 - Raise BLTouch pin if present
* M420 - Enable/Disable Automatic Leveling (with current values) S1=enable S0=disable
* M500 - Store parameters in EEPROM
* M502 - Revert to the default "factory settings". You still need to store them in EEPROM afterwards if you want to.
* M851 - Set probe's Z offset (mm above extruder -- The value will always be negative)
*
*
*
* ************ Custom codes - The following GCODES are specific to SMARTTO software and hardware (mostly wifi module) functionality
*
* M2000 - set SN and save
* M2002 - read print setting (M2002)
* M2003 - set max printing range (M2003 X280.0 Y160.0)
* M2004 - set steps per millimeter (same as M92) (M2004 X80.0)
* M2005 - set motor move direction (M2005 X 0 Y 1 Z 1 E0 0 E1 1 E2 0)
* M2006 - set max feed rate (M2006 X400 Y400 Z30 E50)
* M2007 - set homing speed
* M2008 - set hardware version
* M2100 - file transmission
* M2101 - send printer status
* M2102 - get WiFi signal strength
* M2103 - stop print (SD)
* M2104 - network reconnection
* M2105 - extruder feed and return
* M2106 - not yet implemented
* M2107 - Bed leveling configurations
* M2108 - ?
* M2111 - stepper motor control
* M2223 - configure WiFi settings
* M2112 - get WiFi information
* M2201 - get printer information
* M2222 - control E motor positive and negative
* M2225 - configure auto leveling
* M2226 - enable/disable filament detector ("M2226 S1" to enable, "M2226" or "M2206 S0" to disable)
* M2555 - reset
* M2556 - check if WiFi module is present
* M2557 - configure WiFi through serial port "M2557 <ssid_name|password>"
*
*
* "T" Codes
*
* T0-T3 - Select a tool by index (usually an extruder) [ F<mm/min> ]
*/
static float Current_Feedrate,saved_feedrate;
static float Previous_Feedrate;
static u16 saved_feedmultiply;
static u8 Current_Active_Extruder;
static bool Gloabl_axis_go_origin_flag;
static bool Gloabl_axis_reset_coordinate_flag;
static float offset[3];
static float Arc_r;
static u8 targeted_hotend;
static u8 Up_Data_Flag =0;
static u8 motor_enable_status=0;
static u8 AUTO_LEVELE_G29_FLAG=0;
static u8 Up_CL_Flag=0;
char Command_Buffer[1280];//[CMDBUF_SIZE];//CMDBUF_SIZE
char *Strchr_Pointer;
u8 Coordinate_Axias[] = {'X','Y','Z','E'};
char DIR_Axias[6][5] = {"X ", "Y ", "Z ", "E0 ", "E1 ", "E2 "};
const char Gcode[3] = {'G','M','T'};
extern u8 SD_detec_flag;
extern char sd_file_namebuf[FILE_NUM][FILE_NAME_SIZE];//sd_file_namebuf[255][50];
long gcode_N = 0;
#ifdef BOARD_A30_MINI_S
#ifdef SERVO_ENDSTOPS
int servo_endstops[] = SERVO_ENDSTOPS;
#endif
char Firmware_version[9]="V1.00.58";
#elif BOARD_E180_MINI_S
char Firmware_version[9]="V1.00.40";
#elif BOARD_M301_Pro_S
char Firmware_version[9]="V1.0.05";
#endif
extern autohome_st Autohome;
extern char sd_file_name[32][50];
extern char SD_Path[512];
extern FATFS fats;
extern u8 serial_connect_flag;
extern FIL Print_File;
extern vu16 SD_Data_Buffer_Count;
extern DWORD fptr_buf,pre_sd_byte;
extern s32 position[4];
extern float file_size[FILE_NUM]; //gcode File size
extern u8 Leveling_SetMotor_flag; //Level the motor syatus
extern float new_Z_Max_Position; //Z-axis range
#ifdef WIFI_MODULE
extern volatile WIFI_TX_STATA Wifi_ASK_State;
extern WIFI_MESSAGE Wifi_Work_Message;
extern char Wifi_Server_message[128];
extern char WF_version[6];
#endif
extern void command_process(char* str);
extern void USART2_TxString(u8 *string);
extern void Send_SD_Dir(char *path);
u8 Auto_Levele_Offset_Flag=0;
u16 Beep_period = 0; //period in milliseconds
int Beep_duration = 0; //duration in milliseconds
#ifdef BOARD_M301_Pro_S
float delta[3] = {0.0, 0.0, 0.0};
#define SIN_60 0.8660254037844386
#define COS_60 0.5
// these are the default values, can be overriden with M665
float delta_radius;
float delta_tower1_x; // front left tower
float delta_tower1_y;
float delta_tower2_x; // front right tower
float delta_tower2_y;
float delta_tower3_x; // back middle tower
float delta_tower3_y;
float delta_diagonal_rod;
float delta_diagonal_rod_2;
float delta_segments_per_second;
extern mixer_t mixer;
void Delta_Init(void)
{
Setting.delta_radius = (Setting.delta_smooth_rod_offset-Setting.delta_effector_offset-Setting.delta_carriage_offset+Setting.delta_radius_error);//(DELTA_SMOOTH_ROD_OFFSET-DELTA_EFFECTOR_OFFSET-DELTA_CARRIAGE_OFFSET+1)
delta_radius = Setting.delta_radius;
delta_tower1_x = -SIN_60*delta_radius; // front left tower
delta_tower1_y = -COS_60*delta_radius;
delta_tower2_x = SIN_60*delta_radius; // front right tower
delta_tower2_y = -COS_60*delta_radius;
delta_tower3_x = 0.0; // back middle tower
delta_tower3_y = delta_radius;
delta_diagonal_rod = Setting.delta_diagonal_rod;
delta_diagonal_rod_2 = delta_diagonal_rod * delta_diagonal_rod;
delta_segments_per_second = Setting.delta_segments_per_sec;
}
#endif
u8 Get_Motor_Status(void)
{
return motor_enable_status;
}
char Upload_DataS[512];
/****Save change data uploaded to LCD ******/
typedef struct UPLOAD_DATA {
u8 current_SDPrintstatus;
float current_x;
float current_y;
float current_z;
u8 current_SDstatus;
u8 current_MTstatus;
float current_targeNozzle_temperature;
float current_CurrentNozzle_temperature;
float current_targebed_temperature;
float current_Currentbed_temperature;
u16 current_rate;
u16 current_CFan;
u16 current_HFan;
float current_percent;
u16 current_SPlies;
float current_Plies;
char file_name[60];
u8 wifi_status;
u8 wifi_auto;
float Cur_Feedrate; //
u8 exception_flag;
u8 auto_levele_flags;
u8 filament_decetion_statue;
u8 filament_OFF_ON;
}AUTO_UPLOAD_DATA;
static AUTO_UPLOAD_DATA auto_upload_datas;
u8 Temp_exception_flag=0;
u8 Uoload_LCDData_Flag=0;
extern u8 Firmware_Updata_Flag;
/**********************************************************
***Function: Add_Upload_data
***Description: Upload changed data to LCD screen
***Input:
***Output:
***Return:
***********************************************************/
u8 Add_Upload_data(void)
{
char str_updata[50];
u8 ret=0;
memset(Upload_DataS,0,512);
static u8 Updata_Times=0,EX_Times=0;
memset(str_updata,0,30);
sprintf(str_updata,"<AUTO_UD:");
strncat(Upload_DataS, str_updata, 30);
if(system_infor.serial_printf_flag != 1) //Printer status
{
if(auto_upload_datas.current_SDPrintstatus!=system_infor.sd_print_status && Up_Data_Flag ==0)
{
memset(str_updata,0,30);
auto_upload_datas.current_SDPrintstatus=system_infor.sd_print_status;
if(system_infor.serial_printf_flag == 1)
sprintf(str_updata,"ST:7;");
else
sprintf(str_updata,"ST:%d;",system_infor.sd_print_status);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(system_infor.sd_print_status!=SD_PRINTING) //Printer XYZ position
{
if(abs((int)((auto_upload_datas.current_x-Current_Position[X_AXIS])*100))>2)
{
memset(str_updata,0,30);
auto_upload_datas.current_x=Current_Position[X_AXIS];
sprintf(str_updata,"XP:%.2f;",Current_Position[X_AXIS]);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(abs((int)((auto_upload_datas.current_y-Current_Position[Y_AXIS])*100))>2)
{
memset(str_updata,0,30);
auto_upload_datas.current_y=Current_Position[Y_AXIS];
sprintf(str_updata,"YP:%.2f;",Current_Position[Y_AXIS]);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(abs((int)((auto_upload_datas.current_z-Current_Position[Z_AXIS])*100))>2)
{
memset(str_updata,0,30);
auto_upload_datas.current_z=Current_Position[Z_AXIS];
sprintf(str_updata,"ZP:%.2f;",Current_Position[Z_AXIS]);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
}
}
else
{
if(auto_upload_datas.current_SDPrintstatus!=system_infor.sd_print_status)
{
memset(str_updata,0,30);
auto_upload_datas.current_SDPrintstatus=system_infor.sd_print_status;
sprintf(str_updata,"ST:9;");
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
}
if(auto_upload_datas.current_SDstatus!=system_infor.sd_status) //SD status
{
memset(str_updata,0,30);
auto_upload_datas.current_SDstatus=system_infor.sd_status;
sprintf(str_updata,"SD:%d;",system_infor.sd_status);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(auto_upload_datas.current_MTstatus!=Get_Motor_Status()) //motor lock or unlock
{
memset(str_updata,0,30);
auto_upload_datas.current_MTstatus=Get_Motor_Status();
sprintf(str_updata,"MT:%d;",Get_Motor_Status());
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(abs((int)(auto_upload_datas.current_targeNozzle_temperature-Setting.targe_temperature[NOZZLE0]))>=1) //Extruder target temperature
{
memset(str_updata,0,30);
auto_upload_datas.current_targeNozzle_temperature=Setting.targe_temperature[NOZZLE0];
sprintf(str_updata,"NS:%.1f;",Setting.targe_temperature[NOZZLE0]);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(abs((int)((auto_upload_datas.current_CurrentNozzle_temperature-Current_Temperature[NOZZLE0])*10))>=5)//Extruder current temperature
{
memset(str_updata,0,30);
auto_upload_datas.current_CurrentNozzle_temperature=Current_Temperature[NOZZLE0];
sprintf(str_updata,"NC:%.1f;",Current_Temperature[NOZZLE0]);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(abs((int)(auto_upload_datas.current_targebed_temperature-Setting.targe_temperature[BED]))>=1)//Hot bed target temperature
{
memset(str_updata,0,30);
auto_upload_datas.current_targebed_temperature=Setting.targe_temperature[BED];
sprintf(str_updata,"BS:%.1f;",Setting.targe_temperature[BED]);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(abs((int)((auto_upload_datas.current_Currentbed_temperature-Current_Temperature[BED])*10))>=5)//Hot bed current temperature
{
memset(str_updata,0,30);
auto_upload_datas.current_Currentbed_temperature=Current_Temperature[BED];
sprintf(str_updata,"BC:%.1f;",Current_Temperature[BED]);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(auto_upload_datas.current_rate!=system_infor.feed_tare)//Printing rate(10%~200%)
{
memset(str_updata,0,30);
auto_upload_datas.current_rate=system_infor.feed_tare;
sprintf(str_updata,"FR:%d;",system_infor.feed_tare);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(auto_upload_datas.current_CFan!=system_infor.fan_controler_speed)
{
memset(str_updata,0,30);
auto_upload_datas.current_CFan=system_infor.fan_controler_speed;
sprintf(str_updata,"FC:%d;",(u16)(system_infor.fan_controler_speed*100.0/255.0+0.5));//fan_controler_speed
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(auto_upload_datas.current_HFan!=system_infor.fan_hotend_speed)//Main board fan speed
{
memset(str_updata,0,30);
auto_upload_datas.current_HFan=system_infor.fan_hotend_speed;
sprintf(str_updata,"FH:%d;",(u16)(system_infor.fan_hotend_speed*100.0/255.0+0.5));
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(((system_infor.print_percent-auto_upload_datas.current_percent)*10)>=1)//Print progress
{
memset(str_updata,0,30);
auto_upload_datas.current_percent=system_infor.print_percent;
sprintf(str_updata,"PP:%.2f;",system_infor.print_percent);
strncat(Upload_DataS, str_updata, 30);
if(system_infor.print_percent>99.9)
{
system_infor.print_percent = 0;
auto_upload_datas.current_percent =0;
}
ret=1;
}
if(auto_upload_datas.current_SPlies!=Sum_layers )//The total number of layers in the model
{
memset(str_updata,0,30);
auto_upload_datas.current_SPlies=Sum_layers;
sprintf(str_updata,"SL:%d;",Sum_layers);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(abs((int)((auto_upload_datas.current_Plies*10)-(Current_Position[Z_AXIS]*10)))>1)//&&abs((int)((auto_upload_datas.current_Plies*10)-(Current_Position[Z_AXIS]*10)))<15//The current layer number of the model
{
if(((Current_Position[Z_AXIS]/layer_high)<2100&&(Up_CL_Flag==0))&&(system_infor.sd_print_status==SD_PRINTING||system_infor.serial_printf_flag==1))
{
memset(str_updata,0,30);
auto_upload_datas.current_Plies=Current_Position[Z_AXIS];
sprintf(str_updata,"CL:%d;",(u16)((Current_Position[Z_AXIS]/layer_high)));
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
}
if(system_infor.sd_print_status==2&&(strstr(auto_upload_datas.file_name,"gcode")==NULL&&strstr(auto_upload_datas.file_name,"gco")==NULL&&strstr(auto_upload_datas.file_name,"GCO")==NULL))//printing gcode file name
{
memset(str_updata,0,50);
memcpy(auto_upload_datas.file_name,&Systembuf_Infos.printer_file_path[5],strlen(Systembuf_Infos.printer_file_path)-5);
sprintf(str_updata,"GC:%s;",&Systembuf_Infos.printer_file_path[5]);
strncat(Upload_DataS, str_updata, 50);
//ret=1;
}
#ifdef WIFI_MODULE
if(auto_upload_datas.wifi_status!=Wifi_Work_Message.WIFI_WORK_STATUS) //wifi status
{
memset(str_updata,0,30);
auto_upload_datas.wifi_status=Wifi_Work_Message.WIFI_WORK_STATUS;
sprintf(str_updata,"WFSU:%d;",Wifi_Work_Message.WIFI_WORK_STATUS);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(auto_upload_datas.wifi_auto!=Wifi_Work_Message.AUTO_CONNECT) //wifi auto connect flag
{
memset(str_updata,0,30);
auto_upload_datas.wifi_auto=Wifi_Work_Message.AUTO_CONNECT;
sprintf(str_updata,"WFAU:%d;",Wifi_Work_Message.AUTO_CONNECT);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
#endif
if(abs((int)(auto_upload_datas.Cur_Feedrate-Current_Feedrate))>=0.5) //Current print speed
{
memset(str_updata,0,30);
auto_upload_datas.Cur_Feedrate=Current_Feedrate;
sprintf(str_updata,"CF:%.1f;",Current_Feedrate*(system_infor.feed_tare/100.0));
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
if(auto_upload_datas.exception_flag!=Temp_exception_flag && EX_Times<5) //Temperature abnormal events
{
if(Temp_exception_flag!=0)
{
Updata_Times++;
memset(str_updata,0,30);
if(Updata_Times>3)
{
Temp_exception_flag=0;
Updata_Times=0;
}
sprintf(str_updata,"EX:%d;",Temp_exception_flag);
strncat(Upload_DataS, str_updata, 30);
EX_Times++;
ret=1;
}
}
#ifdef ENABLE_AUTO_BED_LEVELING
if(auto_upload_datas.auto_levele_flags!=system_infor.Auto_Levele_Flag) //auto leveling flag
{
memset(str_updata,0,30);
auto_upload_datas.auto_levele_flags=system_infor.Auto_Levele_Flag;
sprintf(str_updata,"AL:%d;",system_infor.Auto_Levele_Flag);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
#endif
#ifdef BOARD_A30_MINI_S
if(auto_upload_datas.filament_OFF_ON!=system_infor.Filament_Dev_Flag)//Filament_Dev_Flag
{
memset(str_updata,0,30);
auto_upload_datas.filament_OFF_ON=system_infor.Filament_Dev_Flag;
sprintf(str_updata,"FF:%d;",system_infor.Filament_Dev_Flag);
strncat(Upload_DataS, str_updata, 30);
ret=1;
}
#endif
memset(str_updata,0,30);
sprintf(str_updata,"*>\r\n");
strncat(Upload_DataS, str_updata, 30);
if(ret==1)
{
USART3_printf(Upload_DataS);
}
return ret;
}
#ifdef WIFI_MODULE
void WIF_EXIST_TEST(void)
{
if(Setting.wifi_exist_flag ==1)
{
sprintf(Printf_Buf,"<AUTO_UD:WFET:1;*>\r\n");
USART3_printf(Printf_Buf);
// my_printf("%s",Printf_Buf);
}
else if(Setting.wifi_exist_flag ==0)
{
sprintf(Printf_Buf,"<AUTO_UD:WFET:0;*>\r\n");
USART3_printf(Printf_Buf);
// my_printf("%s",Printf_Buf);
}
}
#endif
/******************************************************************************/
#pragma inline=forced
float Command_value_float(char *ch_point)
{
return (strtod(&Command_Buffer[ch_point - Command_Buffer + 1], NULL));
}
/******************************************************************************/
#pragma inline=forced
s32 Command_value_long(char *ch_point)
{
return (strtol(&Command_Buffer[ch_point - Command_Buffer + 1], NULL, 10));
}
/******************************************************************************/
#pragma inline=forced
u8 Command_is(char code, char** ch_point)
{
Strchr_Pointer = strchr(Command_Buffer, code);
*ch_point = Strchr_Pointer;
if(Strchr_Pointer != NULL)
return 1;
else
return 0;
}
/******************************************************************************/
#pragma inline=forced
u32 Command_Time_value(char* ch_point)
{ //char* ch_point;
u32 time = 0;
if(Command_is('h',&ch_point) == 1)
{
ch_point -= 3;
time = 3600 * Command_value_long(ch_point);
}
if(Command_is('m',&ch_point) == 1)
{
ch_point -= 3;
time += 60 * Command_value_long(ch_point);
}
if(Command_is('s',&ch_point) == 1)
{
ch_point -= 3;
time += Command_value_long(ch_point);
}
return time;
}
/******************************************************************************/
#pragma inline=forced
u8 CommandStr_is(char *str,char** ch_point)
{
Strchr_Pointer = strstr(Command_Buffer,str);
*ch_point=Strchr_Pointer;
if(Strchr_Pointer != NULL)
{
Strchr_Pointer = Strchr_Pointer + strlen(str) - 1;
*ch_point=Strchr_Pointer;
return 1;
}
else
return 0;
}
/******************************************************************************/
#pragma inline=forced
char Gcode_is(char** ch_point)
{
u8 i,j;
for(i=0;i<CMDBUF_SIZE;i++)
{
for(j=0;j<3;j++)
{
if(Command_Buffer[i] == Gcode[j])
{
Strchr_Pointer = Command_Buffer + i;
*ch_point=Strchr_Pointer;
return Gcode[j];
}
}
}
return NULL;
}
#ifdef define(DELTA)
static void recalc_delta_settings(float radius, float diagonal_rod)
{
delta_tower1_x= -SIN_60*radius; // front left tower
delta_tower1_y= -COS_60*radius;
delta_tower2_x= SIN_60*radius; // front right tower
delta_tower2_y= -COS_60*radius;
delta_tower3_x= 0.0; // back middle tower
delta_tower3_y= radius;
delta_diagonal_rod_2= diagonal_rod*diagonal_rod;
}
static void calculate_delta(float cartesian[3])
{
delta[X_AXIS] = sqrt(delta_diagonal_rod_2
- (delta_tower1_x-cartesian[X_AXIS])*(delta_tower1_x-cartesian[X_AXIS])
- (delta_tower1_y-cartesian[Y_AXIS])*(delta_tower1_y-cartesian[Y_AXIS])
) + cartesian[Z_AXIS];
delta[Y_AXIS] = sqrt(delta_diagonal_rod_2
- (delta_tower2_x-cartesian[X_AXIS])*(delta_tower2_x-cartesian[X_AXIS])
- (delta_tower2_y-cartesian[Y_AXIS])*(delta_tower2_y-cartesian[Y_AXIS])
) + cartesian[Z_AXIS];
delta[Z_AXIS] = sqrt(delta_diagonal_rod_2
- (delta_tower3_x-cartesian[X_AXIS])*(delta_tower3_x-cartesian[X_AXIS])
- (delta_tower3_y-cartesian[Y_AXIS])*(delta_tower3_y-cartesian[Y_AXIS])
) + cartesian[Z_AXIS];
/*
SERIAL_ECHOPGM("cartesian x="); SERIAL_ECHO(cartesian[X_AXIS]);
SERIAL_ECHOPGM(" y="); SERIAL_ECHO(cartesian[Y_AXIS]);
SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(cartesian[Z_AXIS]);
SERIAL_ECHOPGM("delta x="); SERIAL_ECHO(delta[X_AXIS]);
SERIAL_ECHOPGM(" y="); SERIAL_ECHO(delta[Y_AXIS]);
SERIAL_ECHOPGM(" z="); SERIAL_ECHOLN(delta[Z_AXIS]);
*/
}
#endif
/***************************wifi/uart select file*********************************************************/
char *strrstr(char *s, char *str)
{
char *p;
int len = strlen(s);
for (p = s; p <= s + len - 1; p++) {
if ((*p == *str) && (memcmp(p, str, strlen(str)) == 0))
return p;
}
return NULL;
}
/*************delete gcode file--M30**********************/
void SD_Delete_File(void)
{
char *str_begin,*str_end;
u8 i=0,Size_end=0;
char received_name[50];
char delete_file_name[70];
str_begin=strchr(Command_Buffer, 'M');
u8 ret=0;
if(strstr(Command_Buffer, ".gcode"))
{
Size_end=5;
str_end=strstr(Command_Buffer, ".gcode");
}
else if(strstr(Command_Buffer,".GCO"))
{
Size_end=3;
str_end=strstr(Command_Buffer,".GCO");
}
else if(strstr(Command_Buffer,".gco"))
{
Size_end=3;
str_end=strstr(Command_Buffer,".gco");
}
else
{
//sprintf(Printf_Buf,"erro\r\n");
my_printf("erro\r\n");
}
if( (str_begin!=NULL) && (str_end!=NULL) )
{
for(i=0;i<( (str_end+Size_end)-(str_begin+3) );i++)
{
if((*(str_begin+4+i)>64) && (*(str_begin+4+i)<91))
received_name[i] = *(str_begin+4+i)+32;
else
received_name[i] = *(str_begin+4+i);
}
received_name[i]='\0';
sprintf(delete_file_name,"SD1:/%s",received_name);
ret=f_unlink(delete_file_name);
if(ret==0)
{
SD_detec_flag=1;
// sprintf(Printf_Buf,"delete file succeed ok\r\n");
my_printf("delete file succeed ok\r\n");
}
else if(ret==FR_NO_FILE)
{
// sprintf(Printf_Buf,"delete file succeed ok\r\n");
system_infor.files_refresh_flag=1;
my_printf("delete file succeed ok\r\n");
}
else
{
sprintf(Printf_Buf,"delete file fail\r\n");
my_printf("delete file fail\r\n");
}
}
else
{
sprintf(Printf_Buf,"erro\r\n");
my_printf("erro\r\n");
}
my_printf("FFF:%s\r\n",received_name);
}
/**************************select gcode file -----M23***********************/
void SD_filePrint_select(void)
{
char *str_begin,*str_end;
int Size_end=0;
char received_name[50];
u8 i=0,k=0;
u8 sd_file_name_index=0;
str_begin=strchr(Command_Buffer, 'M');
if(strrstr(Command_Buffer, ".gco")||strrstr(Command_Buffer, ".gcode")||strrstr(Command_Buffer, ".GCO") )
{
if(strrstr(Command_Buffer, ".gcode"))
{
Size_end=5;
str_end=strrstr(Command_Buffer, ".gcode")+Size_end;
}
else if( strrstr(Command_Buffer, ".gco"))
{
Size_end=3;
str_end=strrstr(Command_Buffer, ".gco")+Size_end;
}
else if( strrstr(Command_Buffer, ".GCO"))
{
Size_end=3;
str_end=strrstr(Command_Buffer, ".GCO")+Size_end;
}
if( (str_begin != NULL) && (str_end != NULL) )
{
for(i = 0; i < (str_end-(str_begin+3)); i++)
{
if((*(str_begin+4+i)>64) && (*(str_begin+4+i)<91))
received_name[i] = *(str_begin+4+i)+32;
else
received_name[i] = *(str_begin+4+i);
}
received_name[i]='\0';
}
else
{
sprintf(Printf_Buf,"erro1\r\n");
my_printf("erro1\r\n");
return;//
}
}
else
{
str_end=strchr(Command_Buffer, '*');
if( (str_begin!=NULL) && (str_end!=NULL) )
{
for(i=0;i<( (str_end-1)-(str_begin+3) );i++)
{
if((*(str_begin+4+i)>64) && (*(str_begin+4+i)<91))
received_name[i] = *(str_begin+4+i)+32;
else
received_name[i]=*(str_begin+4+i);
}
received_name[i]='\0';
}
else
{
sprintf(Printf_Buf,"erro1\r\n");
my_printf("erro1\r\n");
return;//
}
}
//change file name to lowercase letters ,because the received file name is all lowercase
for(i = 0; i < system_infor.sd_file_num; i++)
{
if(sd_file_namebuf[i][0]!='\0')
{
while( (sd_file_namebuf[i][k]!='\0')&&(k<FILE_NAME_SIZE))
{
if( (sd_file_namebuf[i][k]>64)&&(sd_file_namebuf[i][k]<91) )
sd_file_namebuf[i][k]+=32;
k++;
}
k=0;
}
}
while((sd_file_name_index <= system_infor.sd_file_num))
{
if(strcmp(&sd_file_namebuf[sd_file_name_index][0],received_name)==0)
{
system_infor.sd_file_cmp=1;
system_infor.selected_file_pos=sd_file_name_index;
delay_ms(100);
sprintf(Printf_Buf,"file select succed!:%s\r\n",received_name);
my_printf("file select succed!:%s\r\n",received_name);
delay_ms(200);
break;
}
else
{
sd_file_name_index++;
}
}
}
/******************compare received file name with selected SD file*************************/
static void Serial_AXIS_Move_Cmd_Processing(void)
{
char *axis_pointer,*f_pointer,*end_pointer,temp_cmd[50],str_float[8],i;
float temp_value=0;
axis_pointer=strchr(Command_Buffer, 'X');
if(axis_pointer == NULL)
{
axis_pointer=strchr(Command_Buffer, 'Y');
if(axis_pointer == NULL)
{
axis_pointer=strchr(Command_Buffer, 'Z');
if(axis_pointer == NULL)
{
axis_pointer=strchr(Command_Buffer, 'E');
if(axis_pointer != NULL)
{
temp_value=strtod(&Command_Buffer[axis_pointer - Command_Buffer + 1], NULL);
temp_value+=Current_Position[E_AXIS];
sprintf(str_float,"%0.3f",temp_value);
f_pointer=strchr(Command_Buffer, 'F');
for(i=0;i<35;i++)
{
temp_cmd[i]=Command_Buffer[f_pointer-Command_Buffer-1+i];
}
strcpy(&Command_Buffer[axis_pointer-Command_Buffer+1],str_float);
end_pointer=strchr(Command_Buffer, '\0');
strcpy(&Command_Buffer[end_pointer-Command_Buffer],temp_cmd);
}
}
else
{
temp_value=strtod(&Command_Buffer[axis_pointer - Command_Buffer + 1], NULL);
temp_value+=Current_Position[Z_AXIS];
sprintf(str_float,"%0.3f",temp_value);
f_pointer=strchr(Command_Buffer, 'F');
for(i=0;i<35;i++)
{
temp_cmd[i]=Command_Buffer[f_pointer-Command_Buffer-1+i];
}
strcpy(&Command_Buffer[axis_pointer-Command_Buffer+1],str_float);
end_pointer=strchr(Command_Buffer, '\0');
strcpy(&Command_Buffer[end_pointer-Command_Buffer],temp_cmd);
}
}
else
{
temp_value=strtod(&Command_Buffer[axis_pointer - Command_Buffer + 1], NULL);
//if(YEndstop == MINENSTOP)
temp_value+=Current_Position[Y_AXIS];
//else
//temp_value=Setting.max_position[Y_AXIS]-(temp_value+Current_Position[Y_AXIS]);
sprintf(str_float,"%0.3f",temp_value);
f_pointer=strchr(Command_Buffer, 'F');
for(i=0;i<35;i++)
{
temp_cmd[i]=Command_Buffer[f_pointer-Command_Buffer-1+i];
}
strcpy(&Command_Buffer[axis_pointer-Command_Buffer+1],str_float);
end_pointer=strchr(Command_Buffer, '\0');
strcpy(&Command_Buffer[end_pointer-Command_Buffer],temp_cmd);
}
}
else
{
temp_value=strtod(&Command_Buffer[axis_pointer - Command_Buffer + 1], NULL);
temp_value+=Current_Position[X_AXIS];
sprintf(str_float,"%0.3f",temp_value);
f_pointer=strchr(Command_Buffer, 'F');
for(i=0;i<35;i++)
{
temp_cmd[i]=Command_Buffer[f_pointer-Command_Buffer-1+i];
}
strcpy(&Command_Buffer[axis_pointer-Command_Buffer+1],str_float);
end_pointer=strchr(Command_Buffer, '\0');
strcpy(&Command_Buffer[end_pointer-Command_Buffer],temp_cmd);
}
}