Allow user to select which LED is updated by the button.

qcpfix
Phil Taylor 2023-04-15 21:13:43 +01:00
rodzic 8ad74ac7f6
commit 34655f6348
5 zmienionych plików z 51 dodań i 23 usunięć

Wyświetl plik

@ -94,12 +94,17 @@ void controllerSetup::init(usbDevMap* dev, QVector<BUTTON>* but, QVector<KNOB>*
udLayout->addWidget(knobEvent,2,1);
knobLabel->setBuddy(knobEvent);
ledNumber = new QSpinBox();
ledNumber->setPrefix("LED: ");
ledNumber->setMinimum(0);
udLayout->addWidget(ledNumber,3,1);
buttonLatch = new QCheckBox();
buttonLatch->setText("Toggle");
udLayout->addWidget(buttonLatch,3,0);
udLayout->addWidget(buttonLatch,4,0);
QHBoxLayout* colorLayout = new QHBoxLayout();
udLayout->addLayout(colorLayout,3,1);
udLayout->addLayout(colorLayout,4,1);
buttonOnColor = new QPushButton("Color");
colorLayout->addWidget(buttonOnColor);
@ -108,11 +113,10 @@ void controllerSetup::init(usbDevMap* dev, QVector<BUTTON>* but, QVector<KNOB>*
colorLayout->addWidget(buttonOffColor);
buttonIcon = new QPushButton("Icon");
udLayout->addWidget(buttonIcon,4,0);
udLayout->addWidget(buttonIcon,5,0);
iconLabel = new QLabel("<None>");
udLayout->addWidget(iconLabel,4,1);
udLayout->addWidget(iconLabel,5,1);
udLayout->setAlignment(iconLabel,Qt::AlignCenter);
udLayout->setSizeConstraint(QLayout::SetFixedSize);
updateDialog->hide();
@ -148,8 +152,9 @@ void controllerSetup::init(usbDevMap* dev, QVector<BUTTON>* but, QVector<KNOB>*
connect(buttonOffColor, SIGNAL(clicked()), this, SLOT(buttonOffColorClicked()));
connect(buttonIcon, SIGNAL(clicked()), this, SLOT(buttonIconClicked()));
connect(buttonLatch, SIGNAL(stateChanged(int)), this, SLOT(latchStateChanged(int)));
connect(ledNumber, SIGNAL(valueChanged(int)), this, SLOT(ledNumberChanged(int)));
}
void controllerSetup::showMenu(controllerScene* scene, QPoint p)
{
Q_UNUSED (scene) // We might want it in the future?
@ -191,8 +196,21 @@ void controllerSetup::showMenu(controllerScene* scene, QPoint p)
buttonLatch->blockSignals(false);
buttonLatch->show();
ledNumber->blockSignals(true);
ledNumber->setMaximum(currentButton->parent->type.leds);
ledNumber->setValue(currentButton->led);
ledNumber->blockSignals(false);
switch (currentButton->parent->type.model)
{
case RC28:
case eCoderPlus:
ledNumber->show();
buttonOnColor->hide();
buttonOffColor->hide();
buttonIcon->hide();
iconLabel->hide();
break;
case StreamDeckMini:
case StreamDeckMiniV2:
case StreamDeckOriginal:
@ -214,6 +232,7 @@ void controllerSetup::showMenu(controllerScene* scene, QPoint p)
buttonOffColor->hide();
buttonIcon->hide();
iconLabel->hide();
ledNumber->hide();
break;
}
@ -248,6 +267,7 @@ void controllerSetup::showMenu(controllerScene* scene, QPoint p)
buttonOffColor->hide();
buttonIcon->hide();
iconLabel->hide();
ledNumber->hide();
updateDialog->show();
updateDialog->move(gp);
@ -291,6 +311,12 @@ void controllerSetup::offEventIndexChanged(int index) {
}
}
void controllerSetup::ledNumberChanged(int index) {
if (currentButton != Q_NULLPTR) {
QMutexLocker locker(mutex);
currentButton->led = index;
}
}
void controllerSetup::knobEventIndexChanged(int index) {

Wyświetl plik

@ -137,6 +137,7 @@ public slots:
void onEventIndexChanged(int index);
void offEventIndexChanged(int index);
void knobEventIndexChanged(int index);
void ledNumberChanged(int index);
void sensitivityMoved(USBDEVICE* dev, int val);
void brightnessChanged(USBDEVICE* dev, int index);
void orientationChanged(USBDEVICE* dev, int index);
@ -185,6 +186,7 @@ private:
QCheckBox *buttonLatch;
QPushButton* buttonIcon;
QLabel* iconLabel;
QSpinBox* ledNumber;
QString deviceName;
QMutex* mutex;

Wyświetl plik

@ -47,7 +47,7 @@ usbController::~usbController()
sendRequest(dev,usbFeatureType::featureOverlay,60,"Goodbye from wfview");
if (dev->type.model == RC28) {
sendRequest(dev,usbFeatureType::featureLEDControl,3,"0");
sendRequest(dev,usbFeatureType::featureLEDControl,4,"0");
}
hid_close(dev->handle);
dev->handle = NULL;
@ -326,10 +326,10 @@ void usbController::run()
if (dev->type.model == RC28)
{
QTimer::singleShot(0, this, [=]() { sendRequest(dev,usbFeatureType::featureLEDControl,0,"0"); });
QTimer::singleShot(0, this, [=]() { sendRequest(dev,usbFeatureType::featureLEDControl,1,"0"); });
QTimer::singleShot(0, this, [=]() { sendRequest(dev,usbFeatureType::featureLEDControl,2,"0"); });
QTimer::singleShot(0, this, [=]() { sendRequest(dev,usbFeatureType::featureLEDControl,3,"1"); });
QTimer::singleShot(0, this, [=]() { sendRequest(dev,usbFeatureType::featureLEDControl,3,"0"); });
QTimer::singleShot(0, this, [=]() { sendRequest(dev,usbFeatureType::featureLEDControl,4,"1"); });
}
else if (dev->type.model == QuickKeys)
{
@ -808,11 +808,11 @@ void usbController::receivePTTStatus(bool on) {
if (on && !ptt) {
lastColour = currentColour;
QColor newColor = QColor(255,0,0);
sendRequest(dev,usbFeatureType::featureLEDControl,0,"1");
sendRequest(dev,usbFeatureType::featureLEDControl,1,"1");
sendRequest(dev,usbFeatureType::featureColor,0, "", Q_NULLPTR, &newColor);
}
else {
sendRequest(dev,usbFeatureType::featureLEDControl,0,"0");
sendRequest(dev,usbFeatureType::featureLEDControl,1,"0");
sendRequest(dev,usbFeatureType::featureColor,0, "", Q_NULLPTR, &lastColour);
}
}
@ -1264,9 +1264,9 @@ void usbController::sendRequest(USBDEVICE *dev, usbFeatureType feature, int val,
case usbFeatureType::featureLEDControl:
data[1] = 0x01;
if (text == "0")
dev->ledStatus |= 1UL << val;
dev->ledStatus |= 1UL << (val-1);
else
dev->ledStatus &= ~(1UL << val);
dev->ledStatus &= ~(1UL << (val-1));
data[2] = dev->ledStatus;
break;
default:
@ -1300,7 +1300,7 @@ void usbController::programDisable(USBDEVICE* dev, bool disabled)
sendRequest(dev,usbFeatureType::featureOverlay,60,"Goodbye from wfview");
if (dev->type.model == RC28) {
sendRequest(dev,usbFeatureType::featureLEDControl,3,"0");
sendRequest(dev,usbFeatureType::featureLEDControl,4,"1");
}
QMutexLocker locker(mutex);
@ -1347,9 +1347,9 @@ void usbController::loadButtons()
defaultButtons.append(BUTTON(shuttlePro2, 14, QRect(280, 195, 25, 80), Qt::red, &commands[0], &commands[0]));
// RC28
defaultButtons.append(BUTTON(RC28, 0, QRect(52, 445, 238, 64), Qt::red, &commands[1], &commands[2],false,0)); // PTT On/OFF
defaultButtons.append(BUTTON(RC28, 1, QRect(52, 373, 98, 46), Qt::red, &commands[0], &commands[0],false,1));
defaultButtons.append(BUTTON(RC28, 2, QRect(193, 373, 98, 46), Qt::red, &commands[0], &commands[0],false,2));
defaultButtons.append(BUTTON(RC28, 0, QRect(52, 445, 238, 64), Qt::red, &commands[1], &commands[2],false,1)); // PTT On/OFF
defaultButtons.append(BUTTON(RC28, 1, QRect(52, 373, 98, 46), Qt::red, &commands[0], &commands[0],false,2));
defaultButtons.append(BUTTON(RC28, 2, QRect(193, 373, 98, 46), Qt::red, &commands[0], &commands[0],false,3));
// Xbox Gamepad
defaultButtons.append(BUTTON(xBoxGamepad, "UP", QRect(256, 229, 50, 50), Qt::red, &commands[0], &commands[0]));
@ -1837,8 +1837,8 @@ void usbController::receiveLevel(cmds cmd, unsigned char level)
dev->knobValues[kb->num].previous = level/dev->sensitivity;
}
auto bt = std::find_if(buttonList->begin(), buttonList->end(), [dev, cmd](const BUTTON& b)
{ return (b.onCommand && dev->connected && b.path == dev->path && b.page == dev->currentPage && b.onCommand->getCommand == cmd && b.led != -1);});
if (bt != buttonList->end() && bt->led < dev->type.leds) {
{ return (b.onCommand && dev->connected && b.path == dev->path && b.page == dev->currentPage && b.onCommand->getCommand == cmd && b.led != 0 && b.led <= dev->type.leds);});
if (bt != buttonList->end()) {
qInfo(logUsbControl()) << "Received value:" << level << "for led" << bt->led;
QTimer::singleShot(0, this, [=]() { sendRequest(dev,usbFeatureType::featureLEDControl,bt->led,QString("%1").arg(level)); });
}

Wyświetl plik

@ -165,7 +165,7 @@ struct COMMAND {
struct BUTTON {
BUTTON() {}
BUTTON(usbDeviceType dev, int num, QRect pos, const QColor textColour, COMMAND* on, COMMAND* off, bool graphics=false, int led=-1) :
BUTTON(usbDeviceType dev, int num, QRect pos, const QColor textColour, COMMAND* on, COMMAND* off, bool graphics=false, int led=0) :
dev(dev), num(num), name(""), pos(pos), textColour(textColour), onCommand(on), offCommand(off), on(onCommand->text), off(offCommand->text), graphics(graphics), led(led){}
BUTTON(usbDeviceType dev, QString name, QRect pos, const QColor textColour, COMMAND* on, COMMAND* off) :
dev(dev), num(-1), name(name), pos(pos), textColour(textColour), onCommand(on), offCommand(off), on(onCommand->text), off(offCommand->text) {}
@ -191,7 +191,7 @@ struct BUTTON {
bool toggle = false;
bool isOn = false;
bool graphics = false;
int led = -1;
int led = 0;
};

Wyświetl plik

@ -2622,7 +2622,7 @@ void wfmain::loadSettings()
butt.on = settings->value("OnCommand", "None").toString();
butt.off = settings->value("OffCommand", "None").toString();
butt.graphics = settings->value("Graphics", false).toBool();
butt.led = settings->value("Led", -1).toInt();
butt.led = settings->value("Led", 0).toInt();
if (!butt.path.isEmpty())
usbButtons.append(butt);
}
@ -3136,7 +3136,7 @@ void wfmain::saveSettings()
if (usbButtons[nb].offCommand != Q_NULLPTR)
settings->setValue("OffCommand", usbButtons[nb].offCommand->text);
settings->setValue("Graphics",usbButtons[nb].graphics);
if (usbButtons[nb].led > -1) {
if (usbButtons[nb].led) {
settings->setValue("Led", usbButtons[nb].led);
}
}