-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathprinter.h
More file actions
348 lines (276 loc) · 8.99 KB
/
printer.h
File metadata and controls
348 lines (276 loc) · 8.99 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
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
// Header gaurd
#ifndef PRINTER_H
#define PRINTER_H
// Header files
#include <string>
#include "gcode.h"
#include "vector.h"
using namespace std;
// Definitions
// Printer bed size limits
#define BED_LOW_MAX_X 113.0
#define BED_LOW_MIN_X 0.0
#define BED_LOW_MAX_Y 107.0
#define BED_LOW_MIN_Y 0.0
#define BED_LOW_MAX_Z 5.0
#define BED_LOW_MIN_Z 0.0
#define BED_MEDIUM_MAX_X 110.2
#define BED_MEDIUM_MIN_X 2.8
#define BED_MEDIUM_MAX_Y 107.0
#define BED_MEDIUM_MIN_Y -6.6
#define BED_MEDIUM_MAX_Z 73.5
#define BED_MEDIUM_MIN_Z BED_LOW_MAX_Z
#define BED_HIGH_MAX_X 82.0
#define BED_HIGH_MIN_X 2.35
#define BED_HIGH_MAX_Y 92.95
#define BED_HIGH_MIN_Y 20.05
#define BED_HIGH_MAX_Z 112.0
#define BED_HIGH_MIN_Z BED_MEDIUM_MAX_Z
// Filament details
enum filamentTypes {NO_TYPE, ABS, PLA, HIPS, OTHER};
enum filamentLocations {NO_LOCATION, INTERNAL, EXTERNAL};
enum filamentColors {BLACK, BLUE, BROWN, GOLD, PINK, GREEN, LIGHT_BLUE, LIGHT_GREEN, MAGENTA, NATURAL, NEON_BLUE, NEON_ORANGE, NEON_YELLOW, ORANGE, PURPLE, RED, SILVER, WHITE, YELLOW = 0x13, OTHER_COLOR, PHANTOM_WHITE, HONEY_CLEAR, FUCHSIA_RED, CHRIMSON_RED, FIRE_ORANGE, MANGO_YELLOW, SHAMROCK_GREEN, COBALT_BLUE, CARRIBEAN_BLUE, MULBERRY_PURPLE = 0x1E, TITANIUM_SILVER, CHARCOAL_BLACK, WHITE_PEARL, CRYSTAL_CLEAR, LIGHT_FUCHSIA, DEEP_CRIMSON, DEEP_SHAMROCK, DEEP_COLBALT, LIGHT_CARRIBEAN = 0x27, DEEP_MULBERRY, SATELLITE_SILVER, DEEP_LEMON, SUNSET_ORANGE, ONYX_BLACK, DRANGON_RED_TOUCH, DRAGON_RED_HOT, ROSE_RED_TOUCH, CORAL_ORANGE_TOUCH, CORAL_ORANGE_WARM, DESPICABLE_YELLOW_TOUCH, MONSTER_GREEN_TOUCH = 0x33, GENIT_BLUE_TOUCH, GENIE_BLUE_ICE, GARGOYLE_BLACK_TOUCH, TRICHROME_NEBULA, TRICHROME_TIGER, FUTURE_ABS = 0x4000, FUTURE_FILAMENT = 0x8000};
// Class
class Printer {
// Public
public:
/*
Name: Constructor
Purpose: Initializes the variables
*/
Printer();
/*
Name: Destructor
Purpose: Uninitializes the variables
*/
~Printer();
/*
Name: Connect
Purpose: Connects or reconnects to the printer
*/
bool connect();
/*
Name: Is Bootloader Mode
Purpose: Return is the printer is in bootloader mode
*/
bool isBootloaderMode();
/*
Name: Get Firnware Version
Purpose: Returns the printer's firmware version
*/
string getFirmwareVersion();
/*
Name: Is Firmware Valid
Purpose: Checks if the printer's firmware is valid
*/
bool isFirmwareValid();
/*
Name: Update Firmware
Purpose: Updates the printer's firmware to the provided file
*/
bool updateFirmware(const char *file);
/*
Name: Is Z Valid
Purpose: Checks if the printer's Z is valid
*/
bool isZValid();
/*
Name: Calibrate Z
Purpose: Calibraters the printer's Z
*/
void calibrateZ();
/*
Name: Is Bed Orientation Valid
Purpose: Checks if the printer's bed orientation is valid
*/
bool isBedOrientationValid();
/*
Name: Calibrate orientation
Purpose: Calibraters the printer's bed orientation
*/
void calibrateBedOrientation();
/*
Name: Collect information
Purpose: Collects information from the printer
*/
bool collectInformation();
/*
Name: Send Request
Purpose: Sends data to the printer
*/
bool sendRequest(const char *data);
bool sendRequest(const string &data);
bool sendRequest(const Gcode &data);
/*
Name: Receive Response
Purpose: Receives data to the printer
*/
string receiveResponse();
/*
Name: Process File
Purpose: Processes a g-code file with the set pre-processor parameters
*/
bool processFile(const char *inputFile, const char *outputFile = NULL);
/*
Name: Print File
Purpose: Pre-processed and send a file to the printer
*/
bool printFile(const char *file);
/*
Name: Set Pre-processors
Purpose: Sets which pre-processor stages to use
*/
void setValidationPreprocessor();
void setPreparationPreprocessor();
void setWaveBondingPreprocessor();
void setThermalBondingPreprocessor();
void setBedCompensationPreprocessor();
void setBacklashCompensationPreprocessor();
void setFeedRateConversionPreprocessor();
void setCenterModelPreprocessor();
/*
Name: Set printer values
Purpose: Sets the printer settings for use in the pre-processor stages
*/
void setBacklashX(const string &value);
void setBacklashY(const string &value);
void setBacklashSpeed(const string &value);
void setBedHeightOffset(const string &value);
void setBackRightOffset(const string &value);
void setBackLeftOffset(const string &value);
void setFrontLeftOffset(const string &value);
void setFrontRightOffset(const string &value);
void setFilamentTemperature(const string &value);
void setFilamentType(const string &value);
/*
Name: Translator Mode
Purpose: Acts as a translator for other software to communicate with the printer
*/
void translatorMode();
/*
Name: Use settings file
Purpose: Reads in printer values from settings file
*/
bool useSettingsFile();
// Private
private:
// Write to eeprom
bool writeToEeprom(uint16_t address, const uint8_t *data, uint16_t length);
bool writeToEeprom(uint16_t address, uint8_t data);
// Send data to the printer
bool sendRequestAscii(char data);
bool sendRequestAscii(const char *data);
bool sendRequestAscii(const Gcode &data);
bool sendRequestBinary(const char *data);
bool sendRequestBinary(const Gcode &data);
// Receive data from the printer
string receiveResponseAscii();
string receiveResponseBinary();
// CRC32
uint32_t crc32(int32_t offset, const uint8_t *data, int32_t count);
// Create settings file
bool createSettingsFile();
// Checks if file to print doesn't go past the printer's boundaries
bool checkPrintDimensions(const char *file, bool overrideCenterModelPreprocessor);
// Get max
double max(double first, double second);
// Get bounded temperature
uint16_t getBoundedTemperature(uint16_t temperature);
// Get distance
double getDistance(const Gcode &firstPoint, const Gcode &secondPoint);
// Create tack point
Gcode createTackPoint(const Gcode &point, const Gcode &refrence);
// Is sharp corner
bool isSharpCorner(const Gcode &point, const Gcode &refrence);
// get current adjustment Z
double getCurrentAdjustmentZ();
// Calculate plane normal vector
Vector calculatePlaneNormalVector(const Vector &v1, const Vector &v2, const Vector &v3);
// Generate plane equation
Vector generatePlaneEquation(const Vector &v1, const Vector &v2, const Vector &v3);
// Get height adjustment required
double getHeightAdjustmentRequired(double x, double y);
// Get Z from XY plane
double getZFromXYAndPlane(const Vector &point, const Vector &planeABC);
// Is point in triangle
bool isPointInTriangle(const Vector &pt, const Vector &v1, const Vector &v2, const Vector &v3);
// Sign
double sign(const Vector &p1, const Vector &p2, const Vector &p3);
// Pre-processor stages
bool validationPreprocessor(const char *file);
bool preparationPreprocessor(const char *file, bool overrideCornerExcess);
bool waveBondingPreprocessor(const char *file);
bool thermalBondingPreprocessor(const char *file, bool overrideWaveBondingPreprocessor);
bool bedCompensationPreprocessor(const char *file);
bool backlashCompensationPreprocessor(const char *file);
bool feedRateConversionPreprocessor(const char *file);
bool centerModelPreprocessor(const char *file);
// Use pre-processor stages
bool useValidation;
bool usePreparation;
bool useWaveBonding;
bool useThermalBonding;
bool useBedCompensation;
bool useBacklashCompensation;
bool useFeedRateConversion;
bool useCenterModel;
bool ignorePrintDimensionLimitations;
// Print values
double maxXExtruderLow;
double maxXExtruderMedium;
double maxXExtruderHigh;
double maxYExtruderLow;
double maxYExtruderMedium;
double maxYExtruderHigh;
double maxZExtruder;
double minXExtruderLow;
double minXExtruderMedium;
double minXExtruderHigh;
double minYExtruderLow;
double minYExtruderMedium;
double minYExtruderHigh;
double minZExtruder;
// Working folder location
string workingFolderLocation;
// Bootloader mode
bool bootloaderMode;
// Valid Z
bool validZ;
// Valid bed orientation
bool validBedOrientation;
// Valid firmware
bool validFirmware;
// Firmware version
string firmwareVersion;
// Serial number
string serialNumber;
// Filament information
filamentTypes filamentType;
filamentLocations filamentLocation;
filamentColors filamentColor;
uint16_t filamentTemperature;
// Bed offsets
double backRightOffset;
double backLeftOffset;
double frontRightOffset;
double frontLeftOffset;
double bedHeightOffset;
// Backlash settings
double backlashX;
double backlashY;
uint16_t backlashSpeed;
// Bed orientations
double backRightOrientation;
double backLeftOrientation;
double frontRightOrientation;
double frontLeftOrientation;
// Status
uint8_t status;
// File descriptor
int fd;
// Virtual port descriptor
int vd;
// Virtual serial port location
string virtualSerialPortLocation;
};
#endif