Changeset View
Changeset View
Standalone View
Standalone View
src/atcore.cpp
Show First 20 Lines • Show All 43 Lines • ▼ Show 20 Line(s) | |||||
44 | 44 | | |||
45 | struct AtCorePrivate { | 45 | struct AtCorePrivate { | ||
46 | IFirmware *fwPlugin = nullptr; | 46 | IFirmware *fwPlugin = nullptr; | ||
47 | SerialLayer *serial = nullptr; | 47 | SerialLayer *serial = nullptr; | ||
48 | QPluginLoader pluginLoader; | 48 | QPluginLoader pluginLoader; | ||
49 | QDir pluginsDir; | 49 | QDir pluginsDir; | ||
50 | QMap<QString, QString> plugins; | 50 | QMap<QString, QString> plugins; | ||
51 | QByteArray lastMessage; | 51 | QByteArray lastMessage; | ||
52 | PrinterStatus printerStatus; | | |||
53 | int extruderCount = 1; | 52 | int extruderCount = 1; | ||
54 | Temperature temperature; | 53 | Temperature temperature; | ||
55 | QStringList commandQueue; | 54 | QStringList commandQueue; | ||
56 | bool ready = false; | 55 | bool ready = false; | ||
57 | QTimer *tempTimer = nullptr; | 56 | QTimer *tempTimer = nullptr; | ||
57 | float percentage; | ||||
58 | QByteArray posString; | ||||
59 | Temperature temps; | ||||
60 | PrinterState printerState; | ||||
58 | }; | 61 | }; | ||
59 | 62 | | |||
60 | AtCore::AtCore(QObject *parent) : | 63 | AtCore::AtCore(QObject *parent) : | ||
61 | QObject(parent), | 64 | QObject(parent), | ||
62 | d(new AtCorePrivate) | 65 | d(new AtCorePrivate) | ||
63 | { | 66 | { | ||
64 | qRegisterMetaType<PrinterState>("PrinterState"); | 67 | qRegisterMetaType<PrinterState>("PrinterState"); | ||
65 | setState(DISCONNECTED); | 68 | setState(DISCONNECTED); | ||
▲ Show 20 Lines • Show All 141 Lines • ▼ Show 20 Line(s) | |||||
207 | { | 210 | { | ||
208 | setSerial(new SerialLayer(port, baud)); | 211 | setSerial(new SerialLayer(port, baud)); | ||
209 | if (isInitialized()) { | 212 | if (isInitialized()) { | ||
210 | setState(CONNECTING); | 213 | setState(CONNECTING); | ||
211 | } | 214 | } | ||
212 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | 215 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | ||
213 | } | 216 | } | ||
214 | 217 | | |||
215 | bool AtCore::isInitialized() | 218 | bool AtCore::isInitialized() const | ||
216 | { | 219 | { | ||
217 | if (!d->serial) { | 220 | if (!d->serial) { | ||
218 | return false; | 221 | return false; | ||
219 | } | 222 | } | ||
220 | return d->serial->isOpen(); | 223 | return d->serial->isOpen(); | ||
221 | } | 224 | } | ||
222 | 225 | | |||
223 | QList<QSerialPortInfo> AtCore::serialPorts() const | 226 | QList<QSerialPortInfo> AtCore::serialPorts() const | ||
224 | { | 227 | { | ||
225 | return QList<QSerialPortInfo>(); | 228 | return QList<QSerialPortInfo>(); | ||
226 | } | 229 | } | ||
227 | 230 | | |||
228 | void AtCore::newMessage(const QByteArray &message) | 231 | void AtCore::newMessage(const QByteArray &message) | ||
229 | { | 232 | { | ||
230 | d->lastMessage = message; | 233 | d->lastMessage = message; | ||
231 | if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { | 234 | if (message.startsWith(QString::fromLatin1("X:").toLocal8Bit())) { | ||
232 | d->printerStatus.posString = message; | 235 | d->posString = message; | ||
233 | d->printerStatus.posString.resize(d->printerStatus.posString.indexOf('E')); | 236 | d->posString.resize(d->posString.indexOf('E')); | ||
234 | d->printerStatus.posString.replace(':', ""); | 237 | d->posString.replace(':', ""); | ||
patrickelectric: ':', '' | |||||
Unfortunately that doesn't build so i will use QChar::Null instead rizzitello: Unfortunately that doesn't build so i will use QChar::Null instead | |||||
patrickelectric: can you use remove ? | |||||
patrickelectric: After some research, "" is the best solution | |||||
235 | } | 238 | } | ||
236 | 239 | | |||
237 | //Check if have temperature info and decode it | 240 | //Check if have temperature info and decode it | ||
238 | temperature().decodeTemp(message); | 241 | temperature().decodeTemp(message); | ||
239 | emit(receivedMessage(d->lastMessage)); | 242 | emit(receivedMessage(d->lastMessage)); | ||
240 | } | 243 | } | ||
241 | 244 | | |||
242 | void AtCore::setRelativePosition() | 245 | void AtCore::setRelativePosition() | ||
243 | { | 246 | { | ||
244 | pushCommand(GCode::toCommand(GCode::G91)); | 247 | pushCommand(GCode::toCommand(GCode::G91)); | ||
245 | } | 248 | } | ||
246 | 249 | | |||
247 | void AtCore::setAbsolutePosition() | 250 | void AtCore::setAbsolutePosition() | ||
248 | { | 251 | { | ||
249 | pushCommand(GCode::toCommand(GCode::G90)); | 252 | pushCommand(GCode::toCommand(GCode::G90)); | ||
250 | } | 253 | } | ||
251 | 254 | | |||
252 | float AtCore::percentagePrinted() | 255 | float AtCore::percentagePrinted() const | ||
253 | { | 256 | { | ||
254 | return d->printerStatus.percentage; | 257 | return d->percentage; | ||
255 | } | 258 | } | ||
256 | 259 | | |||
257 | void AtCore::print(const QString &fileName) | 260 | void AtCore::print(const QString &fileName) | ||
258 | { | 261 | { | ||
259 | if (state() == CONNECTING) { | 262 | if (state() == CONNECTING) { | ||
260 | qCDebug(ATCORE_CORE) << "Load a firmware plugin to print."; | 263 | qCDebug(ATCORE_CORE) << "Load a firmware plugin to print."; | ||
261 | return; | 264 | return; | ||
262 | } | 265 | } | ||
Show All 34 Lines | 291 | if (isInitialized()) { | |||
297 | } | 300 | } | ||
298 | serial()->close(); | 301 | serial()->close(); | ||
299 | setState(DISCONNECTED); | 302 | setState(DISCONNECTED); | ||
300 | } | 303 | } | ||
301 | } | 304 | } | ||
302 | 305 | | |||
303 | PrinterState AtCore::state(void) | 306 | PrinterState AtCore::state(void) | ||
304 | { | 307 | { | ||
305 | return d->printerStatus.printerState; | 308 | return d->printerState; | ||
306 | } | 309 | } | ||
307 | 310 | | |||
308 | void AtCore::setState(PrinterState state) | 311 | void AtCore::setState(PrinterState state) | ||
309 | { | 312 | { | ||
310 | if (state != d->printerStatus.printerState) { | 313 | if (state != d->printerState) { | ||
311 | qCDebug(ATCORE_CORE) << "Atcore state changed from [" \ | 314 | qCDebug(ATCORE_CORE) << "Atcore state changed from [" \ | ||
312 | << d->printerStatus.printerState << "] to [" << state << "]"; | 315 | << d->printerState << "] to [" << state << "]"; | ||
313 | d->printerStatus.printerState = state; | 316 | d->printerState = state; | ||
314 | emit(stateChanged(d->printerStatus.printerState)); | 317 | emit(stateChanged(d->printerState)); | ||
315 | } | 318 | } | ||
316 | } | 319 | } | ||
317 | 320 | | |||
318 | QByteArray AtCore::popCommand() | 321 | QByteArray AtCore::popCommand() const | ||
319 | { | 322 | { | ||
320 | return serial()->popCommand(); | 323 | return serial()->popCommand(); | ||
321 | } | 324 | } | ||
322 | 325 | | |||
323 | void AtCore::stop() | 326 | void AtCore::stop() | ||
324 | { | 327 | { | ||
325 | setState(STOP); | 328 | setState(STOP); | ||
326 | d->commandQueue.clear(); | 329 | d->commandQueue.clear(); | ||
Show All 16 Lines | |||||
343 | void AtCore::requestFirmware() | 346 | void AtCore::requestFirmware() | ||
344 | { | 347 | { | ||
345 | qCDebug(ATCORE_CORE) << "Sending " << GCode::toString(GCode::M115); | 348 | qCDebug(ATCORE_CORE) << "Sending " << GCode::toString(GCode::M115); | ||
346 | if (isInitialized()) { | 349 | if (isInitialized()) { | ||
347 | serial()->pushCommand(GCode::toCommand(GCode::M115).toLocal8Bit()); | 350 | serial()->pushCommand(GCode::toCommand(GCode::M115).toLocal8Bit()); | ||
348 | } | 351 | } | ||
349 | } | 352 | } | ||
350 | 353 | | |||
351 | bool AtCore::pluginLoaded() | 354 | bool AtCore::pluginLoaded() const | ||
352 | { | 355 | { | ||
353 | if (plugin()) { | 356 | if (plugin()) { | ||
354 | return true; | 357 | return true; | ||
355 | } else { | 358 | } else { | ||
356 | return false; | 359 | return false; | ||
357 | } | 360 | } | ||
358 | } | 361 | } | ||
359 | void AtCore::findPlugins() | 362 | void AtCore::findPlugins() | ||
Show All 23 Lines | 375 | #endif | |||
383 | QString pluginString; | 386 | QString pluginString; | ||
384 | pluginString.append(d->pluginsDir.path()); | 387 | pluginString.append(d->pluginsDir.path()); | ||
385 | pluginString.append(QChar::fromLatin1('/')); | 388 | pluginString.append(QChar::fromLatin1('/')); | ||
386 | pluginString.append(f); | 389 | pluginString.append(f); | ||
387 | d->plugins[file] = pluginString; | 390 | d->plugins[file] = pluginString; | ||
388 | qCDebug(ATCORE_CORE) << tr("plugins[%1]=%2").arg(file, pluginString); | 391 | qCDebug(ATCORE_CORE) << tr("plugins[%1]=%2").arg(file, pluginString); | ||
389 | } | 392 | } | ||
390 | } | 393 | } | ||
391 | QStringList AtCore::availablePlugins() | 394 | QStringList AtCore::availablePlugins() const | ||
392 | { | 395 | { | ||
393 | return d->plugins.keys(); | 396 | return d->plugins.keys(); | ||
394 | } | 397 | } | ||
395 | 398 | | |||
396 | void AtCore::detectFirmware() | 399 | void AtCore::detectFirmware() | ||
397 | { | 400 | { | ||
398 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | 401 | connect(serial(), &SerialLayer::receivedCommand, this, &AtCore::findFirmware); | ||
399 | requestFirmware(); | 402 | requestFirmware(); | ||
400 | } | 403 | } | ||
401 | 404 | | |||
402 | void AtCore::pause(const QString &pauseActions) | 405 | void AtCore::pause(const QString &pauseActions) | ||
403 | { | 406 | { | ||
404 | pushCommand(GCode::toCommand(GCode::M114)); | 407 | pushCommand(GCode::toCommand(GCode::M114)); | ||
405 | setState(PAUSE); | 408 | setState(PAUSE); | ||
406 | if (!pauseActions.isNull()) { | 409 | if (!pauseActions.isNull()) { | ||
407 | QStringList temp = pauseActions.split(QChar::fromLatin1(',')); | 410 | QStringList temp = pauseActions.split(QChar::fromLatin1(',')); | ||
408 | for (int i = 0; i < temp.length(); i++) { | 411 | for (int i = 0; i < temp.length(); i++) { | ||
409 | pushCommand(temp.at(i)); | 412 | pushCommand(temp.at(i)); | ||
410 | } | 413 | } | ||
411 | } | 414 | } | ||
412 | } | 415 | } | ||
413 | 416 | | |||
414 | void AtCore::resume() | 417 | void AtCore::resume() | ||
415 | { | 418 | { | ||
416 | pushCommand(GCode::toCommand(GCode::G0, QString::fromLatin1(d->printerStatus.posString))); | 419 | pushCommand(GCode::toCommand(GCode::G0, QString::fromLatin1(d->posString))); | ||
417 | setState(BUSY); | 420 | setState(BUSY); | ||
418 | } | 421 | } | ||
419 | 422 | | |||
420 | /*~~~~~Control Slots ~~~~~~~~*/ | 423 | /*~~~~~Control Slots ~~~~~~~~*/ | ||
421 | 424 | | |||
422 | void AtCore::home() | 425 | void AtCore::home() | ||
423 | { | 426 | { | ||
424 | pushCommand(GCode::toCommand(GCode::G28)); | 427 | pushCommand(GCode::toCommand(GCode::G28)); | ||
▲ Show 20 Lines • Show All 52 Lines • ▼ Show 20 Line(s) | 479 | } else if (axis & Y) { | |||
477 | pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("Y %1").arg(QString::number(arg)))); | 480 | pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("Y %1").arg(QString::number(arg)))); | ||
478 | } else if (axis & Z) { | 481 | } else if (axis & Z) { | ||
479 | pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("Z %1").arg(QString::number(arg)))); | 482 | pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("Z %1").arg(QString::number(arg)))); | ||
480 | } else if (axis & E) { | 483 | } else if (axis & E) { | ||
481 | pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("E %1").arg(QString::number(arg)))); | 484 | pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("E %1").arg(QString::number(arg)))); | ||
482 | } | 485 | } | ||
483 | } | 486 | } | ||
484 | 487 | | |||
485 | int AtCore::extruderCount() | 488 | int AtCore::extruderCount() const | ||
486 | { | 489 | { | ||
487 | return d->extruderCount; | 490 | return d->extruderCount; | ||
488 | } | 491 | } | ||
489 | 492 | | |||
490 | void AtCore::processQueue() | 493 | void AtCore::processQueue() | ||
491 | { | 494 | { | ||
492 | d->ready = true; | 495 | d->ready = true; | ||
493 | 496 | | |||
▲ Show 20 Lines • Show All 45 Lines • Show Last 20 Lines |
':', ''