diff --git a/Controllers/YeelightController/YeelightController.cpp b/Controllers/YeelightController/YeelightController.cpp index 4bd3caa3..f330326a 100644 --- a/Controllers/YeelightController/YeelightController.cpp +++ b/Controllers/YeelightController/YeelightController.cpp @@ -9,13 +9,14 @@ using json = nlohmann::json; -YeelightController::YeelightController(std::string ip, bool music_mode_val) +YeelightController::YeelightController(std::string ip, std::string host_ip, bool music_mode_val) { /*-----------------------------------------------------------------*\ | Fill in location string with device's IP address | \*-----------------------------------------------------------------*/ location = "IP: " + ip; music_mode = music_mode_val; + this->host_ip = host_ip; /*-----------------------------------------------------------------*\ | Open a TCP client sending to the device's IP, port 38899 | @@ -120,11 +121,19 @@ void YeelightController::SetMusicMode() /*-----------------------------------------------------------------*\ | The Yeelight bulb requires this PC's local IP address for music | - | mode. Get the first IP address of this computer's hostname | + | mode. Get the first IP address of this computer's hostname, or | + | use the one defined | \*-----------------------------------------------------------------*/ - gethostname(hostname, 256); - host_entry = gethostbyname(hostname); - ip_addr = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0])); + if(host_ip.empty()) + { + gethostname(hostname, 256); + host_entry = gethostbyname(hostname); + ip_addr = inet_ntoa(*((struct in_addr*) host_entry->h_addr_list[0])); + } + else + { + ip_addr = &host_ip[0]; + } /*-----------------------------------------------------------------*\ | Fill in the set_rgb command with RGB information. | diff --git a/Controllers/YeelightController/YeelightController.h b/Controllers/YeelightController/YeelightController.h index 532ed65e..2de99aa8 100644 --- a/Controllers/YeelightController/YeelightController.h +++ b/Controllers/YeelightController/YeelightController.h @@ -16,7 +16,7 @@ class YeelightController { public: - YeelightController(std::string ip, bool music_mode_val); + YeelightController(std::string ip, std::string host_ip, bool music_mode_val); ~YeelightController(); std::string GetLocation(); @@ -33,6 +33,7 @@ public: private: std::string location; + std::string host_ip; net_port port; bool music_mode; unsigned int music_mode_port; diff --git a/Controllers/YeelightController/YeelightControllerDetect.cpp b/Controllers/YeelightController/YeelightControllerDetect.cpp index cc0708f9..ecc2864d 100644 --- a/Controllers/YeelightController/YeelightControllerDetect.cpp +++ b/Controllers/YeelightController/YeelightControllerDetect.cpp @@ -34,6 +34,13 @@ void DetectYeelightControllers(std::vector &rgb_controllers) { for(unsigned int device_idx = 0; device_idx < yeelight_settings["devices"].size(); device_idx++) { + std::string yeelight_host_ip; + + if(yeelight_settings["devices"][device_idx].contains("host_ip")) + { + yeelight_host_ip = yeelight_settings["devices"][device_idx]["host_ip"]; + } + if(yeelight_settings["devices"][device_idx].contains("ip")) { std::string yeelight_ip = yeelight_settings["devices"][device_idx]["ip"]; @@ -44,7 +51,7 @@ void DetectYeelightControllers(std::vector &rgb_controllers) music_mode = yeelight_settings["devices"][device_idx]["music_mode"]; } - new_controller = new YeelightController(yeelight_ip, music_mode); + new_controller = new YeelightController(yeelight_ip, yeelight_host_ip, music_mode); new_rgbcontroller = new RGBController_Yeelight(new_controller); rgb_controllers.push_back(new_rgbcontroller); diff --git a/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.cpp b/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.cpp index 1ac8dd2d..1ae48c94 100644 --- a/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.cpp +++ b/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.cpp @@ -1,5 +1,7 @@ #include "OpenRGBYeelightSettingsEntry.h" #include "ui_OpenRGBYeelightSettingsEntry.h" +#include "net_port.h" +#include using namespace Ui; @@ -14,3 +16,34 @@ OpenRGBYeelightSettingsEntry::~OpenRGBYeelightSettingsEntry() { delete ui; } + +void OpenRGBYeelightSettingsEntry::on_HostIPChooserButton_clicked() +{ + char hostname[256]; + gethostname(hostname, 256); + + char **in_addrs = gethostbyname(hostname)->h_addr_list; + + QStringList in_addr_list; + + while (*in_addrs != NULL) + { + in_addr_list << inet_ntoa(*((struct in_addr*) *in_addrs)); + in_addrs++; + } + + QInputDialog inp; + + inp.setOptions(QInputDialog::UseListViewForComboBoxItems); + inp.setComboBoxItems(in_addr_list); + inp.setWindowTitle("Choose an IP..."); + inp.setLabelText("Choose the correct IP for the host"); + + if(!inp.exec()) + { + return; + } + + ui->HostIPEdit->setText(inp.textValue()); +} + diff --git a/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.h b/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.h index f4589ee9..9dcbb6ac 100644 --- a/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.h +++ b/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.h @@ -16,6 +16,10 @@ public: explicit OpenRGBYeelightSettingsEntry(QWidget *parent = nullptr); ~OpenRGBYeelightSettingsEntry(); Ui::OpenRGBYeelightSettingsEntryUi *ui; + +private slots: + void on_HostIPChooserButton_clicked(); + }; #endif // OPENRGBYeelightSETTINGSENTRY_H diff --git a/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.ui b/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.ui index a102d912..35c767bb 100644 --- a/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.ui +++ b/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsEntry.ui @@ -6,8 +6,8 @@ 0 0 - 225 - 85 + 972 + 385 @@ -26,8 +26,12 @@ - - + + + + + + @@ -36,10 +40,13 @@ - - + + + + + - + ? @@ -50,14 +57,28 @@ + + + + Override host IP: + + + + + + + + + + Left blank for auto discovering host ip + + + - - IPEdit - diff --git a/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsPage.cpp b/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsPage.cpp index 959ea404..25f6587f 100644 --- a/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsPage.cpp +++ b/qt/OpenRGBYeelightSettingsPage/OpenRGBYeelightSettingsPage.cpp @@ -31,6 +31,11 @@ OpenRGBYeelightSettingsPage::OpenRGBYeelightSettingsPage(QWidget *parent) : entry->ui->IPEdit->setText(QString::fromStdString(yeelight_settings["devices"][device_idx]["ip"])); } + if(yeelight_settings["devices"][device_idx].contains("host_ip")) + { + entry->ui->HostIPEdit->setText(QString::fromStdString(yeelight_settings["devices"][device_idx]["host_ip"])); + } + if(yeelight_settings["devices"][device_idx].contains("music_mode")) { entry->ui->MusicModeCheckBox->setChecked(yeelight_settings["devices"][device_idx]["music_mode"]); @@ -103,6 +108,7 @@ void Ui::OpenRGBYeelightSettingsPage::on_SaveYeelightConfigurationButton_clicked | Required parameters | \*-------------------------------------------------*/ yeelight_settings["devices"][device_idx]["ip"] = entries[device_idx]->ui->IPEdit->text().toStdString(); + yeelight_settings["devices"][device_idx]["host_ip"] = entries[device_idx]->ui->HostIPEdit->text().toStdString(); yeelight_settings["devices"][device_idx]["music_mode"] = entries[device_idx]->ui->MusicModeCheckBox->isChecked(); }