-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbedcontrol.cpp
More file actions
executable file
·239 lines (210 loc) · 6.18 KB
/
bedcontrol.cpp
File metadata and controls
executable file
·239 lines (210 loc) · 6.18 KB
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
#include "bedcontrol.h"
#include "bedserialport.h"
#include "printscheduler.h"
#include "printersetting.h"
#include <QtConcurrent/QtConcurrentRun>
#include <QJsonArray>
#include <QJsonObject>
BedControl::BedControl(char bedChar,BedSerialport* bedSerialPort,PrintScheduler *sched) :
bedChar(bedChar),
_bedSerialPort(bedSerialPort),
_sched(sched)
{
}
void BedControl::receiveFromBedSerialPort(){
switch (bedState) {
case PRINT_MOVE_UP:
bedState = PRINT_MOVE_DOWN;
moveDownCommand();
break;
case PRINT_MOVE_DOWN:
_moveFinishTime = QDateTime::currentDateTime();
_sched->setTotaltime(_moveStartTime.msecsTo(_moveFinishTime));
bedState = PRINT_MOVE_READY;
_sched->receiveFromBedControl(PRINT_MOVE_LAYER_OK );
break;
case PRINT_MOVE_INIT:
// bedState = PRINT_MOVE_PAUSE_WAIT;
bedState = PRINT_MOVE_READY;
_sched->receiveFromBedControl(PRINT_MOVE_INIT_OK );
break;
case PRINT_MOVE_READY:
break;
case PRINT_MOVE_LAYER:
break;
case PRINT_MOVE_AUTOHOME:
bedState = PRINT_MOVE_INIT;
moveDownCommandMin();
break;
case PRINT_MOVE_FINISH:
case PRINT_CANCLE:
bedState = PRINT_MOVE_NULL;
_sched->receiveFromBedControl(PRINT_MOVE_FINISH_OK );
break;
default:
break;
}
return;
}
void BedControl::receiveFromPrintScheduler(int receive){
switch (receive) {
case PRINT_MOVE_AUTOHOME:
bedState = PRINT_MOVE_AUTOHOME;
autoHome();
break;
case PRINT_MOVE_INIT:
bedState = PRINT_MOVE_INIT;
moveDownCommandMin();
break;
case PRINT_MOVE_LAYER:
break;
case PRINT_MOVE_FINISH:
bedState = PRINT_MOVE_FINISH;
moveUpCommandMax();
break;
case PRINT_DLP_WORKING:
bedState = PRINT_DLP_WORKING;
printDelay();
break;
case PRINT_MOVE_BEDCURRENT:
bedState = PRINT_MOVE_BEDCURRENT;
printDelay();
break;
case PRINT_CANCLE:
bedState = PRINT_CANCLE;
moveUpCommandMax();
break;
default:
break;
}
return;
}
int BedControl::UVtime() const
{
return _UVtime;
}
void BedControl::setUVtime(int UVtime)
{
_UVtime = UVtime;
}
int BedControl::delayTime() const
{
return _delayTime;
}
void BedControl::setDelayTime(int delayTime)
{
_delayTime = delayTime;
}
void BedControl::printDelay(){
// _sleepFuture = std::async([this](){
future = QtConcurrent::run([this](){
// qDebug() << "layer delay : " << QDateTime::currentDateTime().toString("yyyy/MM/dd hh:mm:ss,zzz");
QString material = _sched->materialName();
uint32_t curing;
if(bedState == PRINT_MOVE_BEDCURRENT){
curing = bedCuringTime;
}else if(bedState == PRINT_DLP_WORKING){
curing = curingTime;
}
auto jo = _sched->_printerSetting.UVTimeSpend;
int time;
if(jo.contains(material)){
time = 0;
jo.insert(material,0);
}else{
time = jo[material];
}
_delayTime += layerDelay;
QThread::msleep(layerDelay);
if(curing != 0){
_bedSerialPort->sendCommand("H11");
QThread::msleep(curing);
_bedSerialPort->sendCommand("H10");
}
jo[material] = time + curing;
_UVtime += curing;
_sched->_printerSetting.UVTimeSpend = jo;
_sched->_printerSetting.save();
_moveStartTime = QDateTime::currentDateTime();
moveUpCommand();
});
}
void BedControl::autoHome(){
// currentPosition = 0;
_bedSerialPort->sendCommand("G28 A225");
}
void BedControl::moveUpCommand(){
char buffer[50] = {0};
sprintf(buffer,"G01 %c%d M1",bedChar,ZHopHeight);
_bedSerialPort->sendCommand(buffer);
// _currentPosition += ZHopHeight;
_sched->receiveFromBedControl(PRINT_DLP_WORK_FINISH);
bedState = PRINT_MOVE_UP;
}
void BedControl::moveDownCommand(){
char buffer[50] = {0};
sprintf(buffer,"G01 %c%d M0",bedChar,-(ZHopHeight - LayerHeight));
// _currentPosition += -(ZHopHeight - LayerHeight);
_bedSerialPort->sendCommand(buffer);
}
void BedControl::moveUpCommandMax(){
// char buffer[50] = {0};
_bedSerialPort->sendCommand("G02 A-15000 M1");
// _currentPosition = -15000;
}
void BedControl::moveDownCommandMin(){
char buffer[50] = {0};
sprintf(buffer,"G01 %c%d M0",bedChar,-(maxHeight - LayerHeight));
// _currentPosition += -(maxHeight - LayerHeight);
_bedSerialPort->sendCommand(buffer);
}
void BedControl::setAccleSpeed(int val,int mode){
char buffer[50] = {0};
if(mode){
_upAccelSpeed = val;
}else{
_downAccelSpeed = val;
}
sprintf(buffer,"H32 %c%d M%d",bedChar,val,mode);
_bedSerialPort->sendCommand(buffer);
}
void BedControl::setDecelSpeed(int val,int mode){
char buffer[50] = {0};
if(mode){
_upDecelSpeed = val;
}else{
_downDecelSpeed = val;
}
sprintf(buffer,"H33 %c%d M%d",bedChar,val,mode);
_bedSerialPort->sendCommand(buffer);
}
void BedControl::setMaxSpeed(int val){
char buffer[50] = {0};
_maxSpeed = val;
sprintf(buffer,"H30 %c%d",bedChar,val);
_bedSerialPort->sendCommand(buffer);
}
void BedControl::setInitSpeed(int val){
char buffer[50] = {0};
_InitSpeed = val;
sprintf(buffer,"H31 %c%d",bedChar,val);
_bedSerialPort->sendCommand(buffer);
}
void BedControl::setCuringTime(const int value){
this->curingTime = value;
}
void BedControl::setBedCuringTime(const int value){
this->bedCuringTime = value;
}
void BedControl::setZHopHeightTime(const int value){
this->ZHopHeight = value;
}
void BedControl::setLayerHeightTime(const int value){
this->LayerHeight = value;
}
void BedControl::setLedOffset(int value){
char buffer[50] = {0};
this->ledOffset=value;
sprintf(buffer,"H12 %c%d",bedChar,value);
_bedSerialPort->sendCommand(buffer);
}