Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix arduino platform #4181

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions src/program/platformarduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
PlatformArduino::PlatformArduino() : Platform(QString("Arduino"))
{
setReferenceUrl(QUrl(QString("http://arduino.cc/en/Reference/")));
setIdeName("Arduino IDE");
setDownloadUrl(QUrl("http://arduino.cc/en/Main/Software"));
setMinVersion("1.5.2");
setIdeName("Arduino CLI");
setDownloadUrl(QUrl("https://github.com/arduino/arduino-cli"));
setMinVersion("1.0.0");
setCanProgram(true);
setExtensions(QStringList() << ".ino" << ".pde");

Expand Down Expand Up @@ -70,9 +70,16 @@ void PlatformArduino::upload(QWidget *source, const QString &port, const QString
}

QStringList args;
// see https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/manpage.adoc
//args.append(QString("--verbose"));
args.append(QString("--board"));
if (!usingArduinoCLI()) {
// see https://github.com/arduino/Arduino/blob/ide-1.5.x/build/shared/manpage.adoc
//args.append(QString("--verbose"));
args.append(QString("--board"));
}else {
// see https://github.com/arduino/arduino-cli
//args.append(QString("--verbose"));
args.append(QString("compile"));
args.append(QString("-b"));
}
args.append(getBoards().value(board));
args.append(QString("--port"));
args.append(port);
Expand All @@ -83,4 +90,19 @@ void PlatformArduino::upload(QWidget *source, const QString &port, const QString
if (tab != nullptr)
tab->appendToConsole(tr("Running %1 %2").arg(getCommandLocation()).arg(args.join(" ")));
process->start(getCommandLocation(), args);

}

bool PlatformArduino::usingArduinoCLI() {
//We make an error and analize if we are using the arduino-cli or not
auto * process = new QProcess(this);
QStringList args;
args.append(QString("--board"));
args.append(QString(" sssssss"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use something like "arduino-cli version" instead of producing a weird error?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, try to give feedback a bit faster. I forgot what I did that and had to spend time checking this again.

The issue is that I wanted to create an error. You can try to just have an argument "version". If you do that, you must read the standard output and not the error and then it works well if you have arduino-cli. But it will open a new
Arduino-IDE and generate a message (not able to open "version" sketch) when the Arduino IDE 1.x is used as programmer. Thus, if you do not create an error and you are using Arduino IDE (1.x), it will launch a new Arduino IDE every time you press program. If there is an error, the Arduino IDE is not launched.

Not very elegant, but it works well with arduino-cli and Arduino IDE 1.x. Of course, we could drop the support for the Arduino IDE 1.x too, but that is your decision.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine then, I agree we shouldn't launching the IDE just to probe it.


process->start(getCommandLocation(), args);
process->waitForFinished(500);
QString version = process->readAllStandardError();

return version.contains("arduino-cli");
}
1 change: 1 addition & 0 deletions src/program/platformarduino.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class PlatformArduino : public Platform
PlatformArduino();

void upload(QWidget *source, const QString &port, const QString &board, const QString &fileLocation);
bool usingArduinoCLI();
};

#endif // PLATFORMARDUINO_H