Skip to content

Commit

Permalink
Merge pull request #141 from kipr/create3UI
Browse files Browse the repository at this point in the history
Create3 UI
  • Loading branch information
tcorbly authored Jan 27, 2024
2 parents 7ec1606 + 80d6512 commit a45a29c
Show file tree
Hide file tree
Showing 10 changed files with 400 additions and 226 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 toggleChanged();


private:
Expand Down
Binary file added left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 7 additions & 5 deletions rc/qml.qrc
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<RCC>
<qresource prefix="/">
<file>qml/loading.qml</file>
<file>qml/lock.qml</file>
<file>qml/50-screenlock.png</file>
</qresource>
<qresource prefix="/">
<file>qml/loading.qml</file>
<file>qml/lock.qml</file>
<file>qml/50-screenlock.png</file>
<file>qml/left.png</file>
<file>qml/right.png</file>
</qresource>
</RCC>
61 changes: 61 additions & 0 deletions rc/qml/Switch.qml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import QtQuick 2.0

Item {
id: toggleswitch
width: background.width; height: background.height

property bool on: false

function toggle() {
if (toggleswitch.state == "on")
toggleswitch.state = "off";
else
toggleswitch.state = "on";
}

function releaseSwitch() {
if (knob.x == 1) {
if (toggleswitch.state == "off") return;
}
if (knob.x == 78) {
if (toggleswitch.state == "on") return;
}
toggle();
}

Image {
id: background
source: "background.png"
MouseArea { anchors.fill: parent; onClicked: toggle() }
}

Image {
id: knob
x: 1; y: 2
source: "knob.png"

MouseArea {
anchors.fill: parent
drag.target: knob; drag.axis: Drag.XAxis; drag.minimumX: 1; drag.maximumX: 78
onClicked: toggle()
onReleased: releaseSwitch()
}
}

states: [
State {
name: "on"
PropertyChanges { target: knob; x: 78 }
PropertyChanges { target: toggleswitch; on: true }
},
State {
name: "off"
PropertyChanges { target: knob; x: 1 }
PropertyChanges { target: toggleswitch; on: false }
}
]

transitions: Transition {
NumberAnimation { properties: "x"; easing.type: Easing.InOutQuad; duration: 200 }
}
}
Binary file added rc/qml/left.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added rc/qml/right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added right.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
150 changes: 81 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,96 @@ 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/kipr/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);
}



connect(ui->toggleSwitch, SIGNAL(stateChanged(int)), this, SLOT(toggleChanged()));
}

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

void Create3Widget::toggleChanged()
{
QProcess checkCreate3IPState;
QString startCommand = "cat";
QStringList startArgs = {"/home/kipr/wombat-os/configFiles/create3_server_ip.txt"};

checkCreate3IPState.start(startCommand, startArgs);
checkCreate3IPState.waitForFinished();
QByteArray output = checkCreate3IPState.readAllStandardOutput();

QString ipOutput = QString(output);

qDebug() << "IP OUTPUT: " << ipOutput; // Get current IP output


if (ipOutput.contains("192.168.125.1"))
{

if (QMessageBox::question(this, "Change Interface?",
QString("You are about to change your Create 3 connection from Wifi to Ethernet. \nThe Wombat will reboot once you make this change. \n Do you want to continue? \n (Be sure to change the Fast DDS discovery server IP address to 192.168.186.3)"),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
{
return;
}
else
{
QProcess process;
process.startDetached("/bin/sh", QStringList() << "/home/kipr/wombat-os/configFiles/create3_interface_swap.sh"
<< "eth");
}


}
else if (ipOutput.contains("192.168.186.3"))
{
if (QMessageBox::question(this, "Change Interface?",
QString("You are about to change your Create 3 connection from Ethernet to Wifi. \n The Wombat will reboot once you make this change. \nDo you want to continue? \n (Be sure to change the Fast DDS discovery server IP address to 192.168.125.1)"),
QMessageBox::Yes | QMessageBox::No) != QMessageBox::Yes)
{
return;
}
else
{
QProcess process;
process.startDetached("/bin/sh", QStringList() << "/home/kipr/wombat-os/configFiles/create3_interface_swap.sh"
<< "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 +160,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
Loading

0 comments on commit a45a29c

Please sign in to comment.