Skip to content

Commit

Permalink
Adding toggle switch functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
erinharrington-12 committed Jan 25, 2024
1 parent a8fc68f commit b0adc79
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 70 deletions.
1 change: 1 addition & 0 deletions include/botui/Create3Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ private slots:
void sensorList();
void exampleList();
QString getIP();
void indexChanged();


private:
Expand Down
106 changes: 37 additions & 69 deletions src/Create3Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class Create3SensorItemDelegate : public QItemDelegate
const QPixmap _down;
};

QByteArray output;

Create3Widget::Create3Widget(Device *device, QWidget *parent)
: StandardWidget(device, parent),
ui(new Ui::Create3Widget), _model(new Create3SensorModel(this))
Expand All @@ -41,19 +43,52 @@ Create3Widget::Create3Widget(Device *device, QWidget *parent)
// connect(ui->ResetServerButton, SIGNAL(clicked()), SLOT(resetServer()));
connect(ui->Create3SensorListButton, SIGNAL(clicked()), SLOT(sensorList()));
connect(ui->Create3ExampleProgramButton, SIGNAL(clicked()), SLOT(exampleList()));

ui->create3IP->setText(getIP());

QStringList arguments;
arguments << "/home/erin/Desktop/qt6Upgrade/wombat-os/configFiles/create3_server_ip.txt";

QProcess *myProcess = new QProcess(parent);
myProcess->start("cat", arguments);
myProcess->waitForFinished();
output = myProcess->readAllStandardOutput();

qDebug() << output;

QString ipOutput = QString(output);

if(ipOutput == "192.168.125.1"){
ui->toggleSwitch->setChecked(false);
}
else if (ipOutput == "192.168.186.3") {
ui->toggleSwitch->setChecked(true);
}
}

Create3Widget::~Create3Widget()
{
delete ui;
}

void Create3Widget::indexChanged()
{

bool isChecked = ui->toggleSwitch->isChecked();

if (isChecked)
{
qDebug() << "toggle: Ethernet";
}
else
{
qDebug() << "toggle: WiFi";
}
}

QString Create3Widget::getIP()
{

// The command to execute
// The command to execute
const char *command = "arp -a | grep 'iRobot' | awk -F '[()]' '{print $2}'";

// Open a pipe to the command
Expand Down Expand Up @@ -81,78 +116,11 @@ QString Create3Widget::getIP()
std::cout << "Output:\n"
<< result << std::endl;


QString output = QString::fromStdString(result);

return output;
}

// void Create3Widget::resetServer()
// {
// QProcess stopCreate3Service;
// QString stopCommand = "systemctl";
// QStringList stopArgs = {
// "stop",
// "create3_server.service"
// };

// stopCreate3Service.start(stopCommand, stopArgs);
// if(stopCreate3Service.waitForFinished())
// {
// QByteArray data = stopCreate3Service.readAllStandardOutput();
// qDebug() << "Create3 Server successfully stopped\n" << data;
// }
// else
// {
// QByteArray data = stopCreate3Service.readAllStandardError();
// qDebug() << "Create3 Server failed to stop or crashed\n" << data;
// }

// // Need a command to run between start and stop for some reason for things to work
// QProcess statusCreate3Service;
// QString statusCommand = "systemctl";
// QStringList statusArgs = {
// "status",
// "create3_server.service",
// "--no-pager"
// };

// statusCreate3Service.start(statusCommand, statusArgs);
// if(statusCreate3Service.waitForFinished())
// {
// QByteArray data = statusCreate3Service.readAllStandardOutput();
// qDebug() << "Create3 Server status\n" << data;
// }
// else
// {
// QByteArray data = statusCreate3Service.readAllStandardError();
// qDebug() << "Create3 Server failed to get status\n" << data;
// }



// QProcess startCreate3Service;
// QString startCommand = "systemctl";
// QStringList startArgs = {
// "start",
// "create3_server.service"
// };

// startCreate3Service.start(startCommand, startArgs);
// if(startCreate3Service.waitForFinished())
// {
// QByteArray data = startCreate3Service.readAllStandardOutput();
// qDebug() << "Create3 Server successfully started\n" << data;
// }
// else
// {
// QByteArray data = startCreate3Service.readAllStandardError();
// qDebug() << "Create3 Server failed to start or crashed\n" << data;
// }

// RootController::ref().dismissWidget();
// }

void Create3Widget::sensorList()
{
RootController::ref().presentWidget(new Create3SensorListWidget(device()));
Expand Down
2 changes: 1 addition & 1 deletion ui/Create3Widget.ui
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ QCheckBox::indicator:unchecked{
</property>
<property name="maximumSize">
<size>
<width>140</width>
<width>134</width>
<height>16777215</height>
</size>
</property>
Expand Down

0 comments on commit b0adc79

Please sign in to comment.