Skip to content

Commit

Permalink
Add delay boot option to ComBundle
Browse files Browse the repository at this point in the history
This commit adds a delay boot parameter to the ComBundle class constructor. This option is needed to allow for boards, such as Arduino Due, to reset after booting up. The ComPorts implementation has also been extended to automatically detect if a reset delay is necessary by checking the board type.
  • Loading branch information
BitsAndDroids committed Nov 30, 2023
1 parent f991798 commit 14251f3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 6 deletions.
2 changes: 1 addition & 1 deletion dashboard/elements/ComPortRow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ QWidget *ComPortRow::generateElement() {
auto *comPortComboBox = new ModeIndexCombobox("comBox",index);

ComPortWidgetModel model = ComPortWidgetModel();
auto availableComPorts = model.loadAvailableComPorts();
auto availableComPorts = model.loadAvailableComPorts();
auto availableSets = model.getAvailableSets();

for (auto &availableComPort: *availableComPorts) {
Expand Down
6 changes: 3 additions & 3 deletions dashboard/models/ComBundle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ bool ComBundle::isOutputInBundle(int id){
return this->outputs.contains(id);
}

ComBundle::ComBundle(QString port){
ComBundle::ComBundle(QString port, bool delayBoot){
this->port = new SerialPort(port.toStdString().c_str());
if (this->port->getPortName().find("due") != std::string::npos){
//sleep for x seconds to allow for due boards to reset
if (delayBoot){
//sleep for x seconds to allow for boards to reset (i.e. Arduino due)
std::this_thread::sleep_for(std::chrono::seconds(3));
}
}
Expand Down
2 changes: 1 addition & 1 deletion dashboard/models/ComBundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ComBundle{
public:
ComBundle(QString port);
ComBundle(QString port, bool delayBoot);
void setOutputs(QMap<int, Output *> outputsToSet) { this->outputs = outputsToSet; };
bool isOutputInBundle(int id);
SerialPort *getSerialPort() { return this->port; };
Expand Down
23 changes: 22 additions & 1 deletion dashboard/workers/MFSWorker.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "MFSWorker.h"

#include <QSerialPortInfo>

#include "outputmenu/handlers/sethandler.h"
#include "settings/ComSettingsHandler.h"
#include "utils/InputReader.h"
Expand Down Expand Up @@ -198,8 +200,27 @@ void MFSWorker::loadRunningPortsAndSets() {
int successfullyConnected = 0;
setHandler.updateSets();
setHandler.loadSets();

auto *comPorts = new QList<QString>();
for (const QSerialPortInfo &serialPortInfo : QSerialPortInfo::availablePorts()) {
Logger::getInstance()->logDebug("Found com port: " + serialPortInfo.portName().toStdString() +
" | " + serialPortInfo.description().toStdString());
comPorts->append(serialPortInfo.portName() + " | " + serialPortInfo.description());
}

for (const auto &comSetting: comSettings) {
auto *bundle = new ComBundle(comSetting.first);
//remove slash from port string
const auto portStringNoSlash = comSetting.first.mid(4);
const auto portString = portStringNoSlash + ' ';
bool addDelayToAllowReset = false;
for_each(comPorts->begin(), comPorts->end(), [&](const QString &port) {
if (port.contains(portString)) {
if (port.toLower().contains("due")) {
addDelayToAllowReset = true;
}
}
});
auto *bundle = new ComBundle(comSetting.first, addDelayToAllowReset);
if (comSetting.second != -1) {
Logger::getInstance()->logDebug("Loading set: " + std::to_string(comSetting.second));
auto set = setHandler.getSetById(QString::number(comSetting.second));
Expand Down

0 comments on commit 14251f3

Please sign in to comment.