Adding a name to the LIFX controller

This commit is contained in:
Chris 2022-08-08 02:02:43 +10:00
parent 223ec45a75
commit 4d7fe885c9
5 changed files with 28 additions and 7 deletions

View file

@ -11,8 +11,10 @@
using json = nlohmann::json;
using namespace std::chrono_literals;
LIFXController::LIFXController(std::string ip)
LIFXController::LIFXController(std::string ip, std::string name)
{
this->name = name;
/*-----------------------------------------------------------------*\
| Fill in location string with device's IP address |
\*-----------------------------------------------------------------*/
@ -36,7 +38,7 @@ std::string LIFXController::GetLocation()
std::string LIFXController::GetName()
{
return("LIFX");
return(name);
}
std::string LIFXController::GetVersion()

View file

@ -42,7 +42,7 @@ enum
class LIFXController
{
public:
LIFXController(std::string ip);
LIFXController(std::string ip, std::string name);
~LIFXController();
std::string GetLocation();
@ -58,6 +58,7 @@ private:
unsigned char* data;
unsigned char sequence;
unsigned int source;
std::string name;
std::string firmware_version;
std::string module_name;
std::string module_mac;

View file

@ -34,8 +34,9 @@ void DetectLIFXControllers(std::vector<RGBController*> &rgb_controllers)
if(lifx_settings["devices"][device_idx].contains("ip"))
{
std::string lifx_ip = lifx_settings["devices"][device_idx]["ip"];
std::string name = lifx_settings["devices"][device_idx]["name"];
LIFXController* controller = new LIFXController(lifx_ip);
LIFXController* controller = new LIFXController(lifx_ip, name);
RGBController_LIFX* rgb_controller = new RGBController_LIFX(controller);
rgb_controllers.push_back(rgb_controller);

View file

@ -7,7 +7,7 @@
<x>0</x>
<y>0</y>
<width>190</width>
<height>59</height>
<height>89</height>
</rect>
</property>
<property name="sizePolicy">
@ -26,8 +26,8 @@
<string/>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="1" column="3">
<widget class="QLineEdit" name="IPEdit"/>
<item row="1" column="5">
<widget class="QLineEdit" name="NameEdit"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="IPLabel">
@ -36,6 +36,16 @@
</property>
</widget>
</item>
<item row="1" column="3">
<widget class="QLineEdit" name="IPEdit"/>
</item>
<item row="1" column="4">
<widget class="QLabel" name="NameLabel">
<property name="text">
<string>Name</string>
</property>
</widget>
</item>
</layout>
</widget>
</item>

View file

@ -31,6 +31,11 @@ OpenRGBLIFXSettingsPage::OpenRGBLIFXSettingsPage(QWidget *parent) :
entry->ui->IPEdit->setText(QString::fromStdString(lifx_settings["devices"][device_idx]["ip"]));
}
if(lifx_settings["devices"][device_idx].contains("name"))
{
entry->ui->IPEdit->setText(QString::fromStdString(lifx_settings["devices"][device_idx]["name"]));
}
entries.push_back(entry);
QListWidgetItem* item = new QListWidgetItem;
@ -52,6 +57,7 @@ OpenRGBLIFXSettingsPage::~OpenRGBLIFXSettingsPage()
void Ui::OpenRGBLIFXSettingsPage::on_AddLIFXDeviceButton_clicked()
{
OpenRGBLIFXSettingsEntry* entry = new OpenRGBLIFXSettingsEntry;
entry->ui->NameEdit->setText(QString("LIFX%1").arg(entries.size()));
entries.push_back(entry);
QListWidgetItem* item = new QListWidgetItem;
@ -98,6 +104,7 @@ void Ui::OpenRGBLIFXSettingsPage::on_SaveLIFXConfigurationButton_clicked()
| Required parameters |
\*-------------------------------------------------*/
lifx_settings["devices"][device_idx]["ip"] = entries[device_idx]->ui->IPEdit->text().toStdString();
lifx_settings["devices"][device_idx]["name"] = entries[device_idx]->ui->NameEdit->text().toStdString();
}
ResourceManager::get()->GetSettingsManager()->SetSettings("LIFXDevices", lifx_settings);