-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.c
107 lines (105 loc) · 2.57 KB
/
main.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
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <stdio.h>
#include "tools/motor.h"
#include "gcode/gcode.h"
#include "tools/sensor.h"
#include <string.h>
#include "osmacros.h"
#include "movimento/movimento.h"
#include "tools/cnc.h"
#include <errno.h>
#ifdef RASP_OS
#include <wiringPi.h>
#endif
int main(int argv, char *argc[]){
if(argv < 2){
perror("One argument is needed\n");
exit(EXIT_FAILURE);
}
int exec = 1;
if(argv == 3){
exec = atoi(argc[2]);
}
printf("exec %d\n", exec);
int tool = 1;
if(argv == 4){
tool = atoi(argc[3]);
}
printf("Program name %s\n", argc[0]);
printf("File name %s\n", argc[1]);
gc_list * gl = create_list();
if(gl == NULL){
perror("List cannot be created");
exit(EXIT_FAILURE);
}
read_gcodefile(argc[1], gl);
/*
for(gc_node *it = gl->head; it != NULL; it = it->next){
print_gcommand(it->elem);
}
*/
#ifdef RASP_OS
wiringPiSetup();
#endif
cnc *c;
alloc_cnc(&c);
if(c == NULL){
fprintf(stderr, "It cannot allocated cnc structure because of %s\n",
strerror(errno));
return 1;
}
read_cnc(c);
if(tool == 0){
c->type_of_work = LASER;
}else if(tool == 1){
c->type_of_work = FRESA;
}else{
c->type_of_work = LASER;
}
//print_motor(c->xm);
//c->xm = get_motor(x_axis);
//print_motor(c->xm);
mover_zero_cnc(c);
if(exec == 1){
FORWARD(c->xm);
for(int i = 0; i < 48559; i++){
MOVE(c->xm);
#ifdef RASP_OS
delay(DELAY_TIME);
#endif
}
int zvoltas = 6613;
if(tool == 0){
zvoltas = 6613;
}else if(tool == 1){
zvoltas = 9396;
}
FORWARD(c->zm);
for(int i = 0; i < zvoltas; i++){
MOVE(c->zm);
#ifdef RASP_OS
delay(DELAY_TIME);
#endif
}
ponto p;
p.x = 0; p.z = 0; p.y = 0;
printf("Starting trabalho: \n");
for(gc_node *it = gl->head; it != NULL; it = it->next){
//printf("Elemento: \n");
//print_gcommand(it->elem);
if(it->prev != NULL){
print_gcommand(it->elem);
executar(c, it->elem, NULL,&p);
//printf("Prev: \n");
//print_gcommand(it->prev->elem);
}else{
executar(c, it->elem, NULL, &p);
}
}
}
setdown_cnc(c);
free(c);
return 0;
}