Changeset View
Standalone View
src/core/atcore.cpp
Show All 25 Lines | |||||
26 | #include <QDir> | 26 | #include <QDir> | ||
27 | #include <QSerialPortInfo> | 27 | #include <QSerialPortInfo> | ||
28 | #include <QPluginLoader> | 28 | #include <QPluginLoader> | ||
29 | #include <QCoreApplication> | 29 | #include <QCoreApplication> | ||
30 | #include <QLoggingCategory> | 30 | #include <QLoggingCategory> | ||
31 | #include <QTime> | 31 | #include <QTime> | ||
32 | #include <QTimer> | 32 | #include <QTimer> | ||
33 | #include <QThread> | 33 | #include <QThread> | ||
34 | #include <QMetaEnum> | ||||
34 | 35 | | |||
35 | #include "atcore.h" | 36 | #include "atcore.h" | ||
36 | #include "atcore_version.h" | 37 | #include "atcore_version.h" | ||
37 | #include "seriallayer.h" | 38 | #include "seriallayer.h" | ||
38 | #include "gcodecommands.h" | 39 | #include "gcodecommands.h" | ||
39 | #include "printthread.h" | 40 | #include "printthread.h" | ||
40 | #include "atcore_default_folders.h" | 41 | #include "atcore_default_folders.h" | ||
41 | 42 | | |||
▲ Show 20 Lines • Show All 553 Lines • ▼ Show 20 Line(s) | |||||
595 | 596 | | |||
596 | void AtCore::setFlowRate(uint speed) | 597 | void AtCore::setFlowRate(uint speed) | ||
597 | { | 598 | { | ||
598 | pushCommand(GCode::toCommand(GCode::M221, QString::number(speed))); | 599 | pushCommand(GCode::toCommand(GCode::M221, QString::number(speed))); | ||
599 | } | 600 | } | ||
600 | 601 | | |||
601 | void AtCore::move(AtCore::AXES axis, int arg) | 602 | void AtCore::move(AtCore::AXES axis, int arg) | ||
602 | { | 603 | { | ||
603 | static QLatin1Char a('?'); | 604 | const auto axisAsString = QMetaEnum::fromType<AtCore::AXES>().valueToKey(axis); | ||
604 | switch (axis) { | 605 | move(QLatin1Char(axisAsString[0]), arg); | ||
leandrosantiago: I haven't really tested it. Please let me know if this is invalid use of the `QMetaEnum`. | |||||
axisAsString here will always be a non-null string, if axis ls always of type AXES. In case it isn't, that's the caller's fault, and must be handled by it. leandrosantiago: axisAsString here will always be a non-null string, if axis ls always of type AXES. In case it… | |||||
const auto axisAsString = QMetaEnum::fromType<AtCore::AXES>().valueToKey(axis); please set the type explicitly. rizzitello: const auto axisAsString = QMetaEnum::fromType<**AtCore::AXES**>().valueToKey(axis);
please… | |||||
this seams to work correctly, The problem is you cant' test this function in the atcore test gui since that calls the other move function directly . I did Test it by using that function to to set it to both valid and invalid values and then used qDebug() to read the output to be sure this works as expected. if (axisAsString != nullptr) { move(QLatin1Char(axisAsString[0], arg); } rizzitello: this seams to work correctly, The problem is you cant' test this function in the atcore test… | |||||
As this method is used only by the GUI, this maybe indicates it should be actually moved to the GUI. leandrosantiago: As this method is used only by the GUI, this maybe indicates it should be actually moved to the… | |||||
By GUI I meant client applications. This is a library after all. Every function here is for use in a Client (at least any public functions) Please check that the result is not null before sending it out. rizzitello: By GUI I meant client applications. This is a library after all. Every function here is for use… | |||||
@rizzitello The function receives a AtCore::AXES, only valid values will be accepted; patrickelectric: @rizzitello The function receives a AtCore::AXES, only valid values will be accepted; | |||||
AtCore::AXES is an Enum and you can force any int into it. Id rather be sure that our function is only sending our data for valid input. rizzitello: AtCore::AXES is an Enum and you can force any int into it. Id rather be sure that our function… | |||||
605 | case AtCore::X: | | |||
606 | a = QLatin1Char('X'); | | |||
607 | break; | | |||
608 | case AtCore::Y: | | |||
609 | a = QLatin1Char('Y'); | | |||
610 | break; | | |||
611 | case AtCore::Z: | | |||
612 | a = QLatin1Char('Z'); | | |||
613 | break; | | |||
614 | case AtCore::E: | | |||
615 | a = QLatin1Char('E'); | | |||
616 | break; | | |||
617 | default: | | |||
618 | break; | | |||
619 | }; | | |||
620 | move(a, arg); | | |||
621 | } | 606 | } | ||
622 | 607 | | |||
623 | void AtCore::move(QLatin1Char axis, int arg) | 608 | void AtCore::move(QLatin1Char axis, int arg) | ||
624 | { | 609 | { | ||
625 | pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1 %2").arg(axis).arg(QString::number(arg)))); | 610 | pushCommand(GCode::toCommand(GCode::G1, QStringLiteral("%1 %2").arg(axis).arg(QString::number(arg)))); | ||
626 | } | 611 | } | ||
627 | 612 | | |||
628 | int AtCore::extruderCount() const | 613 | int AtCore::extruderCount() const | ||
▲ Show 20 Lines • Show All 154 Lines • Show Last 20 Lines |
I haven't really tested it. Please let me know if this is invalid use of the QMetaEnum.