-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Use own QDialog class SelectDevice and clean up main.cpp. * USBDevice: Introduce a unique usb id for a connected device * USBDevice: Introduce iteration field, to remember in which find round a device was found
- Loading branch information
David Graeff
committed
Dec 24, 2017
1 parent
3ccfb5b
commit 4a1617f
Showing
15 changed files
with
434 additions
and
154 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <QString> | ||
#include "usb/usbdevice.h" | ||
|
||
/** | ||
* Represents an entry in the {@link DevicesListModel}. | ||
*/ | ||
struct DeviceListEntry { | ||
UniqueUSBid id; | ||
QString name; | ||
bool canConnect; | ||
bool needFirmware; | ||
QString errorMessage; | ||
QString getStatus() const { | ||
return errorMessage.size()? errorMessage : (canConnect?"Ready":(needFirmware?"Firmware upload":"Cannot connect")); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#include "deviceslistmodel.h" | ||
#include "usb/finddevices.h" | ||
#include "usb/uploadFirmware.h" | ||
#include "dsomodel.h" | ||
#include <QColor> | ||
|
||
DevicesListModel::DevicesListModel(FindDevices *findDevices) :findDevices(findDevices) {} | ||
|
||
int DevicesListModel::rowCount(const QModelIndex &) const | ||
{ | ||
return entries.size(); | ||
} | ||
|
||
int DevicesListModel::columnCount(const QModelIndex &parent) const | ||
{ | ||
return 2; | ||
} | ||
|
||
QVariant DevicesListModel::headerData(int section, Qt::Orientation orientation, int role) const | ||
{ | ||
if (orientation == Qt::Vertical) | ||
return QAbstractTableModel::headerData(section, orientation, role); | ||
if (role == Qt::DisplayRole) { | ||
switch(section) { | ||
case 0: return tr("Devicename"); | ||
case 1: return tr("Status"); | ||
default: return QVariant(); | ||
} | ||
} | ||
return QAbstractTableModel::headerData(section, orientation, role); | ||
} | ||
|
||
QVariant DevicesListModel::data(const QModelIndex &index, int role) const | ||
{ | ||
if (!index.isValid()) return QVariant(); | ||
if (role==Qt::UserRole) return QVariant::fromValue(entries[index.row()].id); | ||
else if (role==Qt::UserRole+1) return QVariant::fromValue(entries[index.row()].canConnect); | ||
else if (role==Qt::UserRole+2) return QVariant::fromValue(entries[index.row()].needFirmware); | ||
|
||
if (role == Qt::DisplayRole) { | ||
if (index.column() == 0) { | ||
return entries[index.row()].name; | ||
} else if (index.column() == 1) { | ||
return entries[index.row()].getStatus(); | ||
} | ||
} | ||
|
||
if (role == Qt::BackgroundRole) { | ||
if (entries[index.row()].canConnect) return QColor(Qt::darkGreen).lighter(); | ||
else if (entries[index.row()].needFirmware) return QColor(Qt::yellow).lighter(); | ||
} | ||
|
||
return QVariant(); | ||
} | ||
|
||
void DevicesListModel::updateDeviceList() | ||
{ | ||
beginResetModel(); | ||
entries.clear(); | ||
endResetModel(); | ||
const FindDevices::DeviceList* devices = findDevices->getDevices(); | ||
beginInsertRows(QModelIndex(),0,devices->size()); | ||
for (auto &i : *devices) { | ||
DeviceListEntry entry; | ||
entry.name= QString::fromStdString(i.second->getModel()->name); | ||
entry.id = i.first; | ||
if (i.second->needsFirmware()) { | ||
UploadFirmware uf; | ||
if (!uf.startUpload(i.second.get())) { | ||
entry.errorMessage = uf.getErrorMessage(); | ||
} | ||
entry.needFirmware = true; | ||
} else if (i.second->connectDevice(entry.errorMessage)) { | ||
entry.canConnect = true; | ||
i.second->disconnectFromDevice(); | ||
} else { | ||
entry.canConnect = false; | ||
} | ||
entries.push_back(entry); | ||
} | ||
endInsertRows(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
|
||
#include <QAbstractTableModel> | ||
#include "devicelistentry.h" | ||
|
||
class FindDevices; | ||
|
||
/** | ||
* Provides a Model for the Qt Model/View concept. The {@see FindDevices} is required | ||
* to update the list of available devices. | ||
*/ | ||
class DevicesListModel: public QAbstractTableModel { | ||
public: | ||
DevicesListModel(FindDevices* findDevices); | ||
// QAbstractItemModel interface | ||
virtual int rowCount(const QModelIndex &parent) const override; | ||
virtual int columnCount(const QModelIndex &parent) const override; | ||
virtual QVariant headerData(int section, Qt::Orientation orientation, int role) const override; | ||
virtual QVariant data(const QModelIndex &index, int role) const override; | ||
void updateDeviceList(); | ||
private: | ||
std::vector<DeviceListEntry> entries; | ||
FindDevices* findDevices; | ||
}; |
Oops, something went wrong.