Skip to content

Commit 0073c11

Browse files
committed
Switch Arctic controller to manual device detection
The USB serial chip inside the Arctic controller is a generic CH341 chip, so there is a significant risk of picking mismatching devices like Arduino boards. Prevent this by requiring the user to manually select the serial port used by the Arctic controller. Signed-off-by: Armin Wolf <W_Armin@gmx.de>
1 parent 3fcb6b4 commit 0073c11

4 files changed

Lines changed: 193 additions & 14 deletions

File tree

Controllers/ArcticController/ArcticControllerDetect.cpp

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,30 +13,34 @@
1313
#include "Detector.h"
1414
#include "ArcticController.h"
1515
#include "RGBController_Arctic.h"
16-
#include "find_usb_serial_port.h"
16+
#include "SettingsManager.h"
1717

1818
#define CH341_VID 0x1A86
1919
#define CH341_PID 0x7523
2020

2121
void DetectArcticControllers()
2222
{
23-
std::vector<std::string *> ports = find_usb_serial_port(CH341_VID, CH341_PID);
23+
json settings = ResourceManager::get()->GetSettingsManager()->GetSettings("ArcticDevices");
2424

25-
for(unsigned int device = 0; device < ports.size(); device++)
25+
if(settings.contains("devices"))
2626
{
27-
ArcticController *controller = new ArcticController(*ports[device]);
28-
29-
if(controller->IsPresent())
30-
{
31-
RGBController_Arctic *rgb_controller = new RGBController_Arctic(controller);
32-
ResourceManager::get()->RegisterRGBController(rgb_controller);
33-
}
34-
else
27+
for(unsigned int device_idx = 0; device_idx < settings["devices"].size(); device_idx++)
3528
{
36-
delete controller;
37-
}
29+
if(settings["devices"][device_idx].contains("port"))
30+
{
31+
ArcticController *controller = new ArcticController(settings["devices"][device_idx]["port"]);
3832

39-
delete ports[device];
33+
if(controller->IsPresent())
34+
{
35+
RGBController_Arctic *rgb_controller = new RGBController_Arctic(controller);
36+
ResourceManager::get()->RegisterRGBController(rgb_controller);
37+
}
38+
else
39+
{
40+
delete controller;
41+
}
42+
}
43+
}
4044
}
4145
}
4246

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*-------------------------------------------------------------*\
2+
| ArcticSettingsEntry.cpp |
3+
| |
4+
| User interface for OpenRGB Arctic controller settings entry |
5+
| |
6+
| This file is part of the OpenRGB project |
7+
| SPDX-License-Identifier: GPL-2.0-or-later |
8+
\*-------------------------------------------------------------*/
9+
10+
#include "ArcticSettingsEntry.h"
11+
#include "ui_ArcticSettingsEntry.h"
12+
13+
#include "serial_port.h"
14+
#include <QStandardItemModel>
15+
16+
ArcticSettingsEntry::ArcticSettingsEntry(QWidget *parent) :
17+
BaseManualDeviceEntry(parent),
18+
ui(new Ui::ArcticSettingsEntry)
19+
{
20+
ui->setupUi(this);
21+
22+
std::vector<std::string> serialPorts = serial_port::getSerialPorts();
23+
for(size_t i = 0; i < serialPorts.size(); ++i)
24+
{
25+
ui->PortComboBox->addItem(QString::fromStdString(serialPorts[i]));
26+
}
27+
if(serialPorts.empty())
28+
{
29+
/*---------------------------------------------------*\
30+
| When no ports were found, add an unselectable entry |
31+
| denoting this fact istead |
32+
\*---------------------------------------------------*/
33+
QStandardItemModel* comboBoxModel = qobject_cast<QStandardItemModel *>(ui->PortComboBox->model());
34+
if(comboBoxModel != nullptr)
35+
{
36+
ui->PortComboBox->addItem(tr("No serial ports found"));
37+
QStandardItem *item = comboBoxModel->item(0);
38+
item->setFlags(item->flags() & ~Qt::ItemIsEnabled);
39+
}
40+
}
41+
ui->PortComboBox->clearEditText();
42+
}
43+
44+
ArcticSettingsEntry::~ArcticSettingsEntry()
45+
{
46+
delete ui;
47+
}
48+
49+
void ArcticSettingsEntry::changeEvent(QEvent *event)
50+
{
51+
if(event->type() == QEvent::LanguageChange)
52+
{
53+
ui->retranslateUi(this);
54+
}
55+
}
56+
57+
void ArcticSettingsEntry::loadFromSettings(const json& data)
58+
{
59+
if(data.contains("port"))
60+
{
61+
ui->PortComboBox->setCurrentText(QString::fromStdString(data["port"]));
62+
}
63+
}
64+
65+
json ArcticSettingsEntry::saveSettings()
66+
{
67+
json result;
68+
69+
result["port"] = ui->PortComboBox->currentText().toStdString();
70+
71+
return result;
72+
}
73+
74+
bool ArcticSettingsEntry::isDataValid()
75+
{
76+
// stub
77+
return true;
78+
}
79+
80+
static BaseManualDeviceEntry* SpawnArcticEntry(const json& data)
81+
{
82+
ArcticSettingsEntry* entry = new ArcticSettingsEntry;
83+
entry->loadFromSettings(data);
84+
return entry;
85+
}
86+
87+
REGISTER_MANUAL_DEVICE_TYPE("Arctic", "ArcticDevices", SpawnArcticEntry);
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*-------------------------------------------------------------*\
2+
| ArcticSettingsEntry.h |
3+
| |
4+
| User interface for OpenRGB Arctic controller settings entry |
5+
| |
6+
| This file is part of the OpenRGB project |
7+
| SPDX-License-Identifier: GPL-2.0-or-later |
8+
\*-------------------------------------------------------------*/
9+
10+
#pragma once
11+
12+
#include "BaseManualDeviceEntry.h"
13+
14+
namespace Ui
15+
{
16+
class ArcticSettingsEntry;
17+
}
18+
19+
class ArcticSettingsEntry : public BaseManualDeviceEntry
20+
{
21+
Q_OBJECT
22+
23+
public:
24+
explicit ArcticSettingsEntry(QWidget *parent = nullptr);
25+
~ArcticSettingsEntry();
26+
void loadFromSettings(const json& data);
27+
json saveSettings() override;
28+
bool isDataValid() override;
29+
30+
private:
31+
Ui::ArcticSettingsEntry *ui;
32+
33+
private slots:
34+
void changeEvent(QEvent *event) override;
35+
};
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>ArcticSettingsEntry</class>
4+
<widget class="QWidget" name="ArcticSettingsEntry">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>531</width>
10+
<height>206</height>
11+
</rect>
12+
</property>
13+
<property name="sizePolicy">
14+
<sizepolicy hsizetype="Expanding" vsizetype="Expanding">
15+
<horstretch>0</horstretch>
16+
<verstretch>0</verstretch>
17+
</sizepolicy>
18+
</property>
19+
<property name="windowTitle">
20+
<string notr="true">Arctic Controller Settings Entry</string>
21+
</property>
22+
<layout class="QGridLayout" name="gridLayout">
23+
<item row="1" column="0" colspan="2">
24+
<widget class="QGroupBox" name="groupBox">
25+
<property name="title">
26+
<string>Arctic Controller Device</string>
27+
</property>
28+
<layout class="QGridLayout" name="gridLayout_2">
29+
<item row="1" column="0">
30+
<widget class="QLabel" name="PortLabel">
31+
<property name="text">
32+
<string>Port:</string>
33+
</property>
34+
</widget>
35+
</item>
36+
<item row="1" column="1">
37+
<widget class="QComboBox" name="PortComboBox">
38+
<property name="editable">
39+
<bool>true</bool>
40+
</property>
41+
<property name="insertPolicy">
42+
<enum>QComboBox::NoInsert</enum>
43+
</property>
44+
</widget>
45+
</item>
46+
</layout>
47+
</widget>
48+
</item>
49+
</layout>
50+
</widget>
51+
<resources/>
52+
<connections/>
53+
</ui>

0 commit comments

Comments
 (0)