Skip to content

Commit

Permalink
Merge pull request #144 from kipr/eventMode
Browse files Browse the repository at this point in the history
Event mode
  • Loading branch information
tcorbly authored Oct 15, 2024
2 parents 0dc85b5 + dede304 commit 5183b8a
Show file tree
Hide file tree
Showing 17 changed files with 1,519 additions and 403 deletions.
20 changes: 15 additions & 5 deletions include/botui/AboutWidget.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef _ABOUTWIDGET_H_
#define _ABOUTWIDGET_H_

#include "StandardWidget.h"
#include "StandardWidget.h" // Include here if needed for inheritance
#include <QProcess>

namespace Ui
Expand All @@ -11,17 +11,27 @@ namespace Ui

class AboutWidget : public StandardWidget
{
Q_OBJECT
Q_OBJECT

public:
AboutWidget(Device *device, QWidget *parent = 0);
AboutWidget(Device *device, QWidget *parent = nullptr);
~AboutWidget();


bool getEventModeState();
void setEventModeState(QString newState);
QString getRaspberryPiType();

signals:
void eventModeEnabled();
void eventModeDisabled();

public slots:
void developerList();
void eventModeBackground(int checked);

private:
Ui::AboutWidget *ui;
QProcess proc;
};


#endif
3 changes: 2 additions & 1 deletion include/botui/HomeWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public slots:
void shutDown();
void reboot();
void lock();

void handleEventMode();
void updateEventModeLabel();
private:
Ui::HomeWidget *ui;
};
Expand Down
33 changes: 18 additions & 15 deletions include/botui/NetworkManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,37 +44,39 @@ class NetworkManager : public QObject, public Singleton<NetworkManager>
~NetworkManager();

void init(const Device *device);

void addNetwork(const Network &network);
void forgetNetwork(const Network &network);
NetworkList networks() const;

Network active() const;

QString activeConnectionPassword() const;

void getAPConnection(QString ssid) const;
void changeWifiBands(QString band, int channel);
void requestScan();
void deactivateAP();


bool isOn() const;
bool isPersistentOn() const;

State state() const;
bool isActiveConnectionOn() const;
bool eventModeState();

QString ipAddress() const;
QString ip4Address() const;
QString currentActiveConnectionName() const;
QString getAPName();
QString activeConnectionPassword() const;
QString getAPConnectionConfig();

NetworkList accessPoints() const;
NetworkList networks() const;

QString ipAddress() const;
Network active() const;

QString ip4Address() const;
State state() const;

Connection createAPConfig() const;

QString currentActiveConnectionName() const;

QDBusObjectPath getAPSettingsObjectPath() const;

bool isActiveConnectionOn() const;
OrgFreedesktopNetworkManagerInterface *networkManagerInterface();

QString getAPName();
public slots:
bool turnOn();
void turnOff();
Expand All @@ -90,6 +92,7 @@ public slots:
void accessPointRemoved(const Network &network);

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

private slots:
void nmAccessPointAdded(const QDBusObjectPath &path);
Expand Down
21 changes: 13 additions & 8 deletions include/botui/NetworkSettingsWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,36 @@ namespace Ui

class NetworkSettingsWidget : public StandardWidget
{
Q_OBJECT
Q_OBJECT
public:
NetworkSettingsWidget(Device *device, QWidget *parent = 0);
~NetworkSettingsWidget();

QString getRaspberryPiType();
void getWombatName();
void editWifiConnectionMode(int newMode);
void eventModeEnabledState();
void eventModeDisabledState();
void getCurrentMode();
QString getConnectionConfig();

public slots:
void TournamentMode();
void connect();
void manage();
void updateInformation();



private slots:
void stateChanged(const NetworkManager::State &newState, const NetworkManager::State &oldState);
void indexChanged(int index);
void toggleChanged();
void rebootBox();
void onStateChanged(const QString &oldBand, const QString &newBand, int oldChannel, int newChannel);
private:
Ui::NetworkSettingsWidget *ui;
QTimer *enableCoolOffTimer;
QProcess proc;
QMessageBox msgBox;

QMessageBox *msgBox;
};


#endif

#endif
17 changes: 12 additions & 5 deletions include/botui/StandardWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,30 @@
class Device;
class MenuBar;
class StatusBar;
class AboutWidget;

class StandardWidget : public QWidget
{
Q_OBJECT
Q_OBJECT
public:
StandardWidget(Device *device, QWidget *parent = 0);
~StandardWidget();

void setupConnections(AboutWidget *aboutWidget);
bool getEventModeStateDefault();
void reloadStatusBar();
void deleteStatusBar();
Device *device() const;

protected:
void performStandardSetup(const QString& title, const bool &statusBar = true);
void performStandardSetup(const QString &title, const bool &statusBar = true);
void disableMenuBar();
void enableMenuBar();
void addEventModeLabel();
void removeEventModeLabel();
bool isEventModeEnabled();
MenuBar *menuBar() const;
StatusBar *statusBar() const;

private:
Device *m_device;
MenuBar *m_menuBar;
Expand Down
2 changes: 2 additions & 0 deletions include/botui/StatusBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ class StatusBar : public QStatusBar
StatusBar(QWidget *parent = 0);

void loadDefaultWidgets(Device *device);
void addPermanentEventModeLabel();
void removePermanentEventModeLabel();
private:

};
Expand Down
1 change: 1 addition & 0 deletions rc/qml.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<file>qml/50-screenlock.png</file>
<file>qml/left.png</file>
<file>qml/right.png</file>
<file>qml/Event_Mode_Background.png</file>
<file>qml/botguy_noMargin.gif</file>
</qresource>
</RCC>
Binary file added rc/qml/Event_Mode_Background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
132 changes: 128 additions & 4 deletions src/AboutWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,24 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
ui->setupUi(this);
// Setup the UI
performStandardSetup(tr("About"));
// Version Number
// ui->version->setText("Version 30.2.0");

// Set up emission signals for Event Mode enabled/disabled
setupConnections(this);

// Event Mode persistent state check
bool eventModeState = getEventModeState();

if (eventModeState)
{
eventModeBackground(2);
}

QString piType = getRaspberryPiType();

ui->piType->setText(piType);

const bool on = NetworkManager::ref().isOn();
// Version Number
ui->version->setText(device->name() + " v" + device->version());

// Display Serial Number
Expand All @@ -37,7 +52,7 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
myProcess->start("cat", arguments);
myProcess->waitForFinished();
QByteArray output = myProcess->readAllStandardOutput();

// If eth0 is active
if (output.at(0) == '1')
{
Expand Down Expand Up @@ -78,14 +93,123 @@ AboutWidget::AboutWidget(Device *device, QWidget *parent)
}

connect(ui->developerList, SIGNAL(clicked()), SLOT(developerList()));

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

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

QString AboutWidget::getRaspberryPiType()
{
QProcess process;
QString command = "awk '/Revision/ {print $3}' /proc/cpuinfo"; // Corrected command syntax

process.start("bash", QStringList() << "-c" << command);
process.waitForFinished();
QByteArray output = process.readAllStandardOutput(); // Fixed this line to use process directly

QString piType;
if (process.exitStatus() == QProcess::NormalExit && process.exitCode() == 0) // Check exit code
{
qDebug() << "Successfully got Raspberry Pi Type:" << output.trimmed(); // Trim output to remove whitespace


if(output.trimmed() == "a020d3" || output.trimmed() == "a020d4")
{
piType = "3B+";
}
else if(output.trimmed() == "a02082" || output.trimmed() == "a22082" || output.trimmed() == "a32082" || output.trimmed() == "a52082" || output.trimmed() == "a22083")
{
piType = "3B";
}
else
{
piType = "Unknown";
}
}
else
{
qDebug() << "Failed to get Raspberry Pi type. Exit Code:" << process.exitCode();
}

return piType; // Convert QByteArray to QString and trim
}

bool AboutWidget::getEventModeState()
{
QProcess eventModeProcess;
QString command = "grep '^EVENT_MODE' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt | awk '{print $2}'";

eventModeProcess.start("bash", QStringList() << "-c" << command);
eventModeProcess.waitForFinished();

QString output = eventModeProcess.readAllStandardOutput().trimmed();

if (!output.isEmpty())
{
qDebug() << "CURRENT EVENT_MODE is set to:" << output;
if (output == "true")
{
ui->toggleSwitch->setChecked(true);
return true;
}
else
{
ui->toggleSwitch->setChecked(false);
return false;
}
}
else
{
qDebug() << "Failed to read EVENT_MODE.";
}
}

void AboutWidget::setEventModeState(QString newState)
{
QProcess process;
QString command = QString("sed -i 's/^EVENT_MODE.*/EVENT_MODE %1/' /home/kipr/wombat-os/configFiles/wifiConnectionMode.txt").arg(newState);

process.start("bash", QStringList() << "-c" << command);
process.waitForFinished();

if (process.exitStatus() == QProcess::NormalExit)
{
qDebug() << "Successfully set EVENT_MODE to:" << newState;
}
else
{
qDebug() << "Failed to set EVENT_MODE.";
}
}

void AboutWidget::eventModeBackground(int checked)
{

qDebug() << "Event Mode Background toggled";
qDebug() << "Checked: " << checked;

ui->toggleSwitch->setEnabled(false);

if (checked == 2) // Enable Event Mode
{

setEventModeState("true");
emit eventModeEnabled();
NetworkManager::ref().deactivateAP();
ui->toggleSwitch->setEnabled(true);
}
else // Disable Event Mode
{
setEventModeState("false");
emit eventModeDisabled();
NetworkManager::ref().enableAP();
ui->toggleSwitch->setEnabled(true);
}
}

void AboutWidget::developerList()
{
RootController::ref().presentWidget(new DeveloperListWidget(device()));
Expand Down
2 changes: 1 addition & 1 deletion src/FileManagerWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <iostream>
#include <fstream>

//#define HOME_PATH "/home/erin/Documents/KISS" // home programs folder for dev machine *CHANGE FOR YOUR SPECIFIC MACHINE*

#ifdef WOMBAT
#define HOME_PATH "/home/kipr/Documents/KISS"
#endif
Expand Down
Loading

0 comments on commit 5183b8a

Please sign in to comment.