Skip to content

Commit 5183b8a

Browse files
authored
Merge pull request #144 from kipr/eventMode
Event mode
2 parents 0dc85b5 + dede304 commit 5183b8a

17 files changed

+1519
-403
lines changed

include/botui/AboutWidget.h

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#ifndef _ABOUTWIDGET_H_
22
#define _ABOUTWIDGET_H_
33

4-
#include "StandardWidget.h"
4+
#include "StandardWidget.h" // Include here if needed for inheritance
55
#include <QProcess>
66

77
namespace Ui
@@ -11,17 +11,27 @@ namespace Ui
1111

1212
class AboutWidget : public StandardWidget
1313
{
14-
Q_OBJECT
14+
Q_OBJECT
15+
1516
public:
16-
AboutWidget(Device *device, QWidget *parent = 0);
17+
AboutWidget(Device *device, QWidget *parent = nullptr);
1718
~AboutWidget();
18-
19+
20+
bool getEventModeState();
21+
void setEventModeState(QString newState);
22+
QString getRaspberryPiType();
23+
24+
signals:
25+
void eventModeEnabled();
26+
void eventModeDisabled();
27+
1928
public slots:
2029
void developerList();
30+
void eventModeBackground(int checked);
31+
2132
private:
2233
Ui::AboutWidget *ui;
2334
QProcess proc;
2435
};
2536

26-
2737
#endif

include/botui/HomeWidget.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ public slots:
2424
void shutDown();
2525
void reboot();
2626
void lock();
27-
27+
void handleEventMode();
28+
void updateEventModeLabel();
2829
private:
2930
Ui::HomeWidget *ui;
3031
};

include/botui/NetworkManager.h

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,37 +44,39 @@ class NetworkManager : public QObject, public Singleton<NetworkManager>
4444
~NetworkManager();
4545

4646
void init(const Device *device);
47-
4847
void addNetwork(const Network &network);
4948
void forgetNetwork(const Network &network);
50-
NetworkList networks() const;
51-
52-
Network active() const;
53-
54-
QString activeConnectionPassword() const;
55-
49+
void getAPConnection(QString ssid) const;
50+
void changeWifiBands(QString band, int channel);
5651
void requestScan();
52+
void deactivateAP();
53+
5754

5855
bool isOn() const;
5956
bool isPersistentOn() const;
60-
61-
State state() const;
57+
bool isActiveConnectionOn() const;
58+
bool eventModeState();
59+
60+
QString ipAddress() const;
61+
QString ip4Address() const;
62+
QString currentActiveConnectionName() const;
63+
QString getAPName();
64+
QString activeConnectionPassword() const;
65+
QString getAPConnectionConfig();
6266

6367
NetworkList accessPoints() const;
68+
NetworkList networks() const;
6469

65-
QString ipAddress() const;
70+
Network active() const;
6671

67-
QString ip4Address() const;
72+
State state() const;
6873

6974
Connection createAPConfig() const;
7075

71-
QString currentActiveConnectionName() const;
72-
7376
QDBusObjectPath getAPSettingsObjectPath() const;
7477

75-
bool isActiveConnectionOn() const;
78+
OrgFreedesktopNetworkManagerInterface *networkManagerInterface();
7679

77-
QString getAPName();
7880
public slots:
7981
bool turnOn();
8082
void turnOff();
@@ -90,6 +92,7 @@ public slots:
9092
void accessPointRemoved(const Network &network);
9193

9294
void stateChanged(const NetworkManager::State &newState, const NetworkManager::State &oldState);
95+
void stateChangedBandBouncer(const QString &oldBand, const QString &newBand, int oldChannel, int newChannel);
9396

9497
private slots:
9598
void nmAccessPointAdded(const QDBusObjectPath &path);

include/botui/NetworkSettingsWidget.h

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,36 @@ namespace Ui
2020

2121
class NetworkSettingsWidget : public StandardWidget
2222
{
23-
Q_OBJECT
23+
Q_OBJECT
2424
public:
2525
NetworkSettingsWidget(Device *device, QWidget *parent = 0);
2626
~NetworkSettingsWidget();
27-
27+
QString getRaspberryPiType();
28+
void getWombatName();
29+
void editWifiConnectionMode(int newMode);
30+
void eventModeEnabledState();
31+
void eventModeDisabledState();
32+
void getCurrentMode();
33+
QString getConnectionConfig();
34+
2835
public slots:
29-
void TournamentMode();
3036
void connect();
3137
void manage();
3238
void updateInformation();
33-
34-
3539

3640
private slots:
3741
void stateChanged(const NetworkManager::State &newState, const NetworkManager::State &oldState);
3842
void indexChanged(int index);
43+
void toggleChanged();
44+
void rebootBox();
45+
void onStateChanged(const QString &oldBand, const QString &newBand, int oldChannel, int newChannel);
3946
private:
4047
Ui::NetworkSettingsWidget *ui;
4148
QTimer *enableCoolOffTimer;
4249
QProcess proc;
43-
QMessageBox msgBox;
44-
50+
QMessageBox *msgBox;
4551
};
4652

47-
4853
#endif
4954

5055
#endif

include/botui/StandardWidget.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,23 +6,30 @@
66
class Device;
77
class MenuBar;
88
class StatusBar;
9+
class AboutWidget;
910

1011
class StandardWidget : public QWidget
1112
{
12-
Q_OBJECT
13+
Q_OBJECT
1314
public:
1415
StandardWidget(Device *device, QWidget *parent = 0);
1516
~StandardWidget();
16-
17+
void setupConnections(AboutWidget *aboutWidget);
18+
bool getEventModeStateDefault();
19+
void reloadStatusBar();
20+
void deleteStatusBar();
1721
Device *device() const;
18-
22+
1923
protected:
20-
void performStandardSetup(const QString& title, const bool &statusBar = true);
24+
void performStandardSetup(const QString &title, const bool &statusBar = true);
2125
void disableMenuBar();
2226
void enableMenuBar();
27+
void addEventModeLabel();
28+
void removeEventModeLabel();
29+
bool isEventModeEnabled();
2330
MenuBar *menuBar() const;
2431
StatusBar *statusBar() const;
25-
32+
2633
private:
2734
Device *m_device;
2835
MenuBar *m_menuBar;

include/botui/StatusBar.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ class StatusBar : public QStatusBar
1111
StatusBar(QWidget *parent = 0);
1212

1313
void loadDefaultWidgets(Device *device);
14+
void addPermanentEventModeLabel();
15+
void removePermanentEventModeLabel();
1416
private:
1517

1618
};

rc/qml.qrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<file>qml/50-screenlock.png</file>
66
<file>qml/left.png</file>
77
<file>qml/right.png</file>
8+
<file>qml/Event_Mode_Background.png</file>
89
<file>qml/botguy_noMargin.gif</file>
910
</qresource>
1011
</RCC>

rc/qml/Event_Mode_Background.png

172 KB
Loading

src/AboutWidget.cpp

Lines changed: 128 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,24 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
1717
ui->setupUi(this);
1818
// Setup the UI
1919
performStandardSetup(tr("About"));
20-
// Version Number
21-
// ui->version->setText("Version 30.2.0");
20+
21+
// Set up emission signals for Event Mode enabled/disabled
22+
setupConnections(this);
23+
24+
// Event Mode persistent state check
25+
bool eventModeState = getEventModeState();
26+
27+
if (eventModeState)
28+
{
29+
eventModeBackground(2);
30+
}
31+
32+
QString piType = getRaspberryPiType();
33+
34+
ui->piType->setText(piType);
35+
2236
const bool on = NetworkManager::ref().isOn();
37+
// Version Number
2338
ui->version->setText(device->name() + " v" + device->version());
2439

2540
// Display Serial Number
@@ -37,7 +52,7 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
3752
myProcess->start("cat", arguments);
3853
myProcess->waitForFinished();
3954
QByteArray output = myProcess->readAllStandardOutput();
40-
55+
4156
// If eth0 is active
4257
if (output.at(0) == '1')
4358
{
@@ -78,14 +93,123 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
7893
}
7994

8095
connect(ui->developerList, SIGNAL(clicked()), SLOT(developerList()));
81-
96+
connect(ui->toggleSwitch, SIGNAL(stateChanged(int)), this, SLOT(eventModeBackground(int)));
8297
}
8398

8499
AboutWidget::~AboutWidget()
85100
{
86101
delete ui;
87102
}
88103

104+
QString AboutWidget::getRaspberryPiType()
105+
{
106+
QProcess process;
107+
QString command = "awk '/Revision/ {print $3}' /proc/cpuinfo"; // Corrected command syntax
108+
109+
process.start("bash", QStringList() << "-c" << command);
110+
process.waitForFinished();
111+
QByteArray output = process.readAllStandardOutput(); // Fixed this line to use process directly
112+
113+
QString piType;
114+
if (process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0) // Check exit code
115+
{
116+
qDebug() << "Successfully got Raspberry Pi Type:" << output.trimmed(); // Trim output to remove whitespace
117+
118+
119+
if(output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
120+
{
121+
piType = "3B+";
122+
}
123+
else if(output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
124+
{
125+
piType = "3B";
126+
}
127+
else
128+
{
129+
piType = "Unknown";
130+
}
131+
}
132+
else
133+
{
134+
qDebug() << "Failed to get Raspberry Pi type. Exit Code:" << process.exitCode();
135+
}
136+
137+
return piType; // Convert QByteArray to QString and trim
138+
}
139+
140+
bool AboutWidget::getEventModeState()
141+
{
142+
QProcess eventModeProcess;
143+
QString command = "grep '^EVENT_MODE' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt | awk '{print $2}'";
144+
145+
eventModeProcess.start("bash", QStringList() << "-c" << command);
146+
eventModeProcess.waitForFinished();
147+
148+
QString output = eventModeProcess.readAllStandardOutput().trimmed();
149+
150+
if (!output.isEmpty())
151+
{
152+
qDebug() << "CURRENT EVENT_MODE is set to:" << output;
153+
if (output == "true")
154+
{
155+
ui->toggleSwitch->setChecked(true);
156+
return true;
157+
}
158+
else
159+
{
160+
ui->toggleSwitch->setChecked(false);
161+
return false;
162+
}
163+
}
164+
else
165+
{
166+
qDebug() << "Failed to read EVENT_MODE.";
167+
}
168+
}
169+
170+
void AboutWidget::setEventModeState(QString newState)
171+
{
172+
QProcess process;
173+
QString command = QString("sed -i 's/^EVENT_MODE.*/EVENT_MODE %1/' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt").arg(newState);
174+
175+
process.start("bash", QStringList() << "-c" << command);
176+
process.waitForFinished();
177+
178+
if (process.exitStatus() == QProcess::NormalExit)
179+
{
180+
qDebug() << "Successfully set EVENT_MODE to:" << newState;
181+
}
182+
else
183+
{
184+
qDebug() << "Failed to set EVENT_MODE.";
185+
}
186+
}
187+
188+
void AboutWidget::eventModeBackground(int checked)
189+
{
190+
191+
qDebug() << "Event Mode Background toggled";
192+
qDebug() << "Checked: " << checked;
193+
194+
ui->toggleSwitch->setEnabled(false);
195+
196+
if (checked == 2) // Enable Event Mode
197+
{
198+
199+
setEventModeState("true");
200+
emit eventModeEnabled();
201+
NetworkManager::ref().deactivateAP();
202+
ui->toggleSwitch->setEnabled(true);
203+
}
204+
else // Disable Event Mode
205+
{
206+
setEventModeState("false");
207+
emit eventModeDisabled();
208+
NetworkManager::ref().enableAP();
209+
ui->toggleSwitch->setEnabled(true);
210+
}
211+
}
212+
89213
void AboutWidget::developerList()
90214
{
91215
RootController::ref().presentWidget(new DeveloperListWidget(device()));

src/FileManagerWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
#include <iostream>
1717
#include <fstream>
1818

19-
//#define HOME_PATH "/home/erin/Documents/KISS" // home programs folder for dev machine *CHANGE FOR YOUR SPECIFIC MACHINE*
19+
2020
#ifdef WOMBAT
2121
#define HOME_PATH "/home/kipr/Documents/KISS"
2222
#endif

0 commit comments

Comments
 (0)