Commit 2d7cb0aa authored by Adam Honse's avatar Adam Honse

Add enable control for each device and initialize devices without a Direct mode to disabled

parent 5aed3248
Pipeline #184567212 failed with stage
in 4 minutes and 46 seconds
This diff is collapsed.
......@@ -94,8 +94,15 @@ typedef struct
typedef struct
{
RGBController * controller_ptr;
bool enabled;
std::vector<ZoneIndexType> zones;
} ControllerIndexType;
} ControllerSettingsType;
typedef struct
{
NetworkClient * client_ptr;
std::vector<ControllerSettingsType *> controller_settings;
} ClientSettingsType;
class Visualizer
{
......@@ -215,8 +222,11 @@ public:
std::vector<NetworkClient*> rgb_clients;
std::vector<RGBController*> rgb_controllers;
//Zone index maps
std::vector<ControllerIndexType> ZoneIndex;
std::vector<ClientSettingsType*> rgb_client_settings;
void UpdateClientSettings();
void RegisterClientInfoChangeCallback(NetClientCallback new_callback, void * new_callback_arg);
void ClientInfoChanged();
private:
#ifdef WIN32
......@@ -267,6 +277,10 @@ private:
unsigned char buffer[256];
void DrawSingleColorForeground(float amplitude, vis_pixels *fg_pixels, vis_pixels *out_pixels);
std::mutex ClientInfoChangeMutex;
std::vector<NetClientCallback> ClientInfoChangeCallbacks;
std::vector<void *> ClientInfoChangeCallbackArgs;
};
#endif
......@@ -143,6 +143,8 @@ void KeyboardVisDlg::SetVisualizer(Visualizer* v)
{
vis_ptr = v;
vis_ptr->RegisterClientInfoChangeCallback(UpdateOpenRGBClientListCallback, this);
ui->lineEdit_Normalization_Offset->setText(QString::number(vis_ptr->nrml_ofst));
ui->lineEdit_Normalization_Scale->setText(QString::number(vis_ptr->nrml_scl));
ui->lineEdit_Animation_Speed->setText(QString::number(vis_ptr->anim_speed));
......@@ -369,6 +371,12 @@ public:
NetworkClient * net_client;
};
class EnableCheckboxArg : public QObject
{
public:
ControllerSettingsType * settings_ptr;
};
void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
{
ui->tree_Devices->clear();
......@@ -380,14 +388,29 @@ void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
ui->tree_Devices->setColumnWidth(1, 100);
ui->tree_Devices->setHeaderLabels(QStringList() << "Connected Clients" << "");
/*-----------------------------------------------------*\
| Create a signal mapper for Disconnect buttons |
\*-----------------------------------------------------*/
QSignalMapper* signalMapper = new QSignalMapper(this);
connect(signalMapper, SIGNAL(mapped(QObject *)), this, SLOT(on_button_Disconnect_clicked(QObject *)));
/*-----------------------------------------------------*\
| Create a signal mapper for Enabled checkboxes |
\*-----------------------------------------------------*/
QSignalMapper* checkMapper = new QSignalMapper(this);
connect(checkMapper, SIGNAL(mapped(QObject *)), this, SLOT(on_button_Enabled_clicked(QObject *)));
/*-----------------------------------------------------*\
| Loop through all active clients and populate list |
\*-----------------------------------------------------*/
for(int client_idx = 0; client_idx < vis_ptr->rgb_clients.size(); client_idx++)
{
QTreeWidgetItem* new_top_item = new QTreeWidgetItem(ui->tree_Devices);
new_top_item->setText(0, QString::fromStdString(vis_ptr->rgb_clients[client_idx]->GetIP()));
/*-----------------------------------------------------*\
| Create a Disconnect button for this client and map it |
\*-----------------------------------------------------*/
QPushButton* new_button = new QPushButton( "Disconnect" );
ui->tree_Devices->setItemWidget(new_top_item, 1, new_button);
......@@ -398,20 +421,42 @@ void Ui::KeyboardVisDlg::UpdateOpenRGBClientList()
signalMapper->setMapping(new_button, new_arg);
for(int dev_idx = 0; dev_idx < vis_ptr->rgb_clients[client_idx]->server_controllers.size(); dev_idx++)
/*-----------------------------------------------------*\
| Loop through all devices on this client |
\*-----------------------------------------------------*/
for(int controller_idx = 0; controller_idx < vis_ptr->rgb_clients[client_idx]->server_controllers.size(); controller_idx++)
{
QTreeWidgetItem* new_item = new QTreeWidgetItem(new_top_item);
new_item->setText(0, QString::fromStdString(vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->name));
new_item->setText(0, QString::fromStdString(vis_ptr->rgb_clients[client_idx]->server_controllers[controller_idx]->name));
/*-----------------------------------------------------*\
| Create an Enabled checkbox for this device and map it |
\*-----------------------------------------------------*/
QCheckBox* new_check = new QCheckBox( "Enabled" );
ui->tree_Devices->setItemWidget(new_item, 1, new_check);
if(controller_idx < vis_ptr->rgb_client_settings[client_idx]->controller_settings.size())
{
new_check->setChecked(vis_ptr->rgb_client_settings[client_idx]->controller_settings[controller_idx]->enabled);
connect(new_check, SIGNAL(clicked()), checkMapper, SLOT(map()));
EnableCheckboxArg * check_arg = new EnableCheckboxArg();
check_arg->settings_ptr = vis_ptr->rgb_client_settings[client_idx]->controller_settings[controller_idx];
checkMapper->setMapping(new_check, check_arg);
}
for(int zone_idx = 0; zone_idx < vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones.size(); zone_idx++)
/*-----------------------------------------------------*\
| Loop through all zones on this device |
\*-----------------------------------------------------*/
for(int zone_idx = 0; zone_idx < vis_ptr->rgb_clients[client_idx]->server_controllers[controller_idx]->zones.size(); zone_idx++)
{
QTreeWidgetItem* new_child = new QTreeWidgetItem();
std::string zone_str = vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones[zone_idx].name + ", ";
zone_str.append(std::to_string(vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones[zone_idx].leds_count));
std::string zone_str = vis_ptr->rgb_clients[client_idx]->server_controllers[controller_idx]->zones[zone_idx].name + ", ";
zone_str.append(std::to_string(vis_ptr->rgb_clients[client_idx]->server_controllers[controller_idx]->zones[zone_idx].leds_count));
zone_str.append(" LEDs, ");
switch(vis_ptr->rgb_clients[client_idx]->server_controllers[dev_idx]->zones[zone_idx].type)
switch(vis_ptr->rgb_clients[client_idx]->server_controllers[controller_idx]->zones[zone_idx].type)
{
case ZONE_TYPE_SINGLE:
zone_str.append("Single");
......@@ -442,12 +487,24 @@ void Ui::KeyboardVisDlg::on_button_Disconnect_clicked(QObject * arg)
vis_ptr->OpenRGBDisconnect(disconnect_client);
}
void Ui::KeyboardVisDlg::on_button_Enabled_clicked(QObject * arg)
{
EnableCheckboxArg * checkbox_arg = ((EnableCheckboxArg *)arg);
if(checkbox_arg->settings_ptr->enabled)
{
checkbox_arg->settings_ptr->enabled = false;
}
else
{
checkbox_arg->settings_ptr->enabled = true;
}
}
void Ui::KeyboardVisDlg::on_button_Connect_clicked()
{
unsigned short port = std::stoi(ui->lineEdit_Port->text().toStdString());
std::string ip = ui->lineEdit_IP->text().toStdString();
NetworkClient * new_client = vis_ptr->OpenRGBConnect(ip.c_str(), port);
new_client->RegisterClientInfoChangeCallback(UpdateOpenRGBClientListCallback, this);
}
......@@ -76,6 +76,8 @@ private slots:
void on_button_Disconnect_clicked(QObject *);
void on_button_Enabled_clicked(QObject *);
private:
Ui::KeyboardVisualizerDlg *ui;
QSystemTrayIcon* trayIcon;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment