Cleaned up default target variant selection code and some tidying

This commit is contained in:
Nav
2021-04-09 20:33:24 +01:00
parent 06e056ee18
commit 0f309e04c7
7 changed files with 29 additions and 35 deletions

View File

@@ -4,34 +4,34 @@
#include <hidapi/hidapi.h>
struct hid_device_ {
/* Handle to the actual device. */
// Handle to the actual device.
libusb_device_handle* device_handle;
/* Endpoint information */
// Endpoint information
int input_endpoint;
int output_endpoint;
int input_ep_max_packet_size;
/* The interface number of the HID */
// The interface number of the HID
int interface;
/* Indexes of Strings */
// Indexes of Strings
int manufacturer_index;
int product_index;
int serial_index;
/* Whether blocking reads are used */
int blocking; /* boolean */
// Whether blocking reads are used
int blocking; // boolean
/* Read thread objects */
// Read thread objects
pthread_t thread;
pthread_mutex_t mutex; /* Protects input_reports */
pthread_mutex_t mutex; // Protects input_reports
pthread_cond_t condition;
pthread_barrier_t barrier; /* Ensures correct startup sequence */
pthread_barrier_t barrier; // Ensures correct startup sequence
int shutdown_thread;
int cancelled;
struct libusb_transfer* transfer;
/* List of received input reports. */
// List of received input reports.
struct input_report* input_reports;
};

View File

@@ -82,6 +82,10 @@ void InsightWindow::init(
);
if (this->isVariantSupported(targetVariant)) {
this->supportedVariantsByName.insert(
std::pair(QString::fromStdString(targetVariant.name).toLower().toStdString(), targetVariant)
);
connect(
variantAction,
&QAction::triggered,
@@ -100,33 +104,21 @@ void InsightWindow::init(
this->variantMenu->addAction(variantAction);
}
std::copy_if(
this->targetDescriptor.variants.begin(),
this->targetDescriptor.variants.end(),
std::back_inserter(this->supportedVariants),
[this](auto variant) {
return this->isVariantSupported(variant);
}
);
Logger::debug("Number of target variants supported by Insight: " + std::to_string(supportedVariantsByName.size()));
Logger::debug("Number of target variants supported by Insight: " + std::to_string(supportedVariants.size()));
if (!this->supportedVariantsByName.empty()) {
if (!targetConfig.variantName.empty() && this->supportedVariantsByName.contains(targetConfig.variantName)) {
// The user has specified a valid variant name in their config file, so use that as the default
this->selectVariant(&(this->supportedVariantsByName.at(targetConfig.variantName)));
if (!supportedVariants.empty()) {
auto selectedVariant = std::find_if(
supportedVariants.begin(),
supportedVariants.end(),
[&targetConfig](const TargetVariant& variant) {
auto variantName = QString::fromStdString(variant.name).toLower().toStdString();
return !targetConfig.variantName.empty() && targetConfig.variantName == variantName;
} else {
if (!targetConfig.variantName.empty()) {
Logger::error("Invalid target variant name \"" + targetConfig.variantName
+ "\" - no such variant with the given name was found.");
}
);
/*
* If ths user specified a valid variant name in their config file, use that as the default, otherwise just
* use the first supported variant.
*/
this->selectVariant((selectedVariant != supportedVariants.end()) ? &(*selectedVariant)
: &supportedVariants.front());
this->selectVariant(&(this->supportedVariantsByName.begin()->second));
}
} else {
if (this->targetDescriptor.variants.empty()) {

View File

@@ -47,7 +47,7 @@ namespace Bloom
QLabel* targetStatusLabel = nullptr;
QLabel* programCounterValueLabel = nullptr;
std::vector<TargetVariant> supportedVariants;
std::map<std::string, TargetVariant> supportedVariantsByName;
const TargetVariant* selectedVariant = nullptr;
bool uiDisabled = false;

View File

@@ -23,7 +23,6 @@ void BodyWidget::drawWidget(QPainter& painter) {
painter.setRenderHints(QPainter::RenderHint::Antialiasing | QPainter::RenderHint::SmoothPixmapTransform, true);
// Draw target body
// auto targetBodyColor = QColor("#AFB1B3");
auto targetBodyColor = this->getBodyColor();
auto backgroundColor = QColor("#3C3F41");

View File

@@ -11,6 +11,7 @@ namespace Bloom::InsightTargetWidgets::Dip
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
private:
// These properties can be modified via Qt style sheets (see Stylesheets/DualInlinePackage.qss)
QColor bodyColor = QColor("#AFB1B3");
int disableAlphaLevel = 100;

View File

@@ -11,6 +11,7 @@ namespace Bloom::InsightTargetWidgets::Qfp
Q_PROPERTY(int disableAlphaLevel READ getDisableAlphaLevel WRITE setDisableAlphaLevel DESIGNABLE true)
private:
// These properties can be modified via Qt style sheets (see Stylesheets/QuadFlatPackage.qss)
QColor bodyColor = QColor("#AFB1B3");
int disableAlphaLevel = 100;

View File

@@ -193,6 +193,7 @@ namespace Bloom
* @param correlationId
*/
void emitErrorEvent(int correlationId);
public:
TargetController(EventManager& eventManager): eventManager(eventManager) {};