Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/AnnaAK/trikRuntime
Browse files Browse the repository at this point in the history
  • Loading branch information
yurii-litvinov committed May 30, 2016
2 parents 5211b38 + 49a4ab3 commit 7c2a3dc
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 1 deletion.
2 changes: 2 additions & 0 deletions trikGui/backgroundWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ BackgroundWidget::BackgroundWidget(
, mController(configPath)
, mBatteryIndicator(mController.brick())
, mWiFiIndicator(mController)
, mGamepadIndicator(mController)
, mMailboxIndicator("://resources/mailboxConnected.png", mController.mailbox()->isConnected())
, mCommunicatorIndicator("://resources/communicatorConnected.png", mController.communicatorConnectionStatus())
, mStartWidget(mController)
Expand All @@ -47,6 +48,7 @@ BackgroundWidget::BackgroundWidget(

mStatusBarLayout.addWidget(&mBatteryIndicator);
mStatusBarLayout.addStretch();
mStatusBarLayout.addWidget(&mGamepadIndicator);
mStatusBarLayout.addWidget(&mMailboxIndicator);
mStatusBarLayout.addWidget(&mCommunicatorIndicator);
mStatusBarLayout.addWidget(&mWiFiIndicator);
Expand Down
2 changes: 2 additions & 0 deletions trikGui/backgroundWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "controller.h"
#include "batteryIndicator.h"
#include "wiFiIndicator.h"
#include "gamepadIndicator.h"
#include "openSocketIndicator.h"
#include "startWidget.h"
#include "runningWidget.h"
Expand Down Expand Up @@ -114,6 +115,7 @@ private slots:
QStackedLayout mMainWidgetsLayout;
BatteryIndicator mBatteryIndicator;
WiFiIndicator mWiFiIndicator;
GamepadIndicator mGamepadIndicator;
OpenSocketIndicator mMailboxIndicator;
OpenSocketIndicator mCommunicatorIndicator;
StartWidget mStartWidget;
Expand Down
12 changes: 12 additions & 0 deletions trikGui/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ Controller::Controller(const QString &configPath)
, correctedConfigPath + "model-config.xml");

mGamepad.reset(trikNetwork::GamepadFactory::create(configurer));
connect(mGamepad.data(), SIGNAL(disconnect()), this, SIGNAL(gamepadDisconnected()));
connect(mGamepad.data(), SIGNAL(connected()), this, SIGNAL(gamepadConnected()));

mMailbox.reset(trikNetwork::MailboxFactory::create(configurer));
mTelemetry.reset(new trikTelemetry::TrikTelemetry(*mBrick, *mGamepad));
mScriptRunner.reset(new trikScriptRunner::TrikScriptRunner(*mBrick, mMailbox.data(), mGamepad.data()));
Expand Down Expand Up @@ -136,6 +139,15 @@ bool Controller::communicatorConnectionStatus()
return mTelemetry->activeConnections() > 0 && mCommunicator->activeConnections() > 0;
}

bool Controller::gamepadConnectionStatus() const
{
if (mGamepad != nullptr) {
return mGamepad->isConnected();
} else {
return false;
}
}

void Controller::updateCommunicatorStatus()
{
emit communicatorStatusChanged(communicatorConnectionStatus());
Expand Down
9 changes: 9 additions & 0 deletions trikGui/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ class Controller : public QObject
/// Returns communicator connection status (whether or not both Telemetry and Communicator servers are connected).
bool communicatorConnectionStatus();

/// Returns gamepad connection status.
bool gamepadConnectionStatus() const;

public slots:
/// Cancels execution of current program.
void abortExecution();
Expand All @@ -91,6 +94,12 @@ public slots:
/// clutter from videosensors.
void brickStopped();

/// Emitted when a robot is disconnected from a gamepad.
void gamepadDisconnected();

/// Emitted when a robot is connected to a gamepad.
void gamepadConnected();

/// Emitted when a robot is connected to a network.
void wiFiConnected();

Expand Down
54 changes: 54 additions & 0 deletions trikGui/gamepadIndicator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/* Copyright 2016 Anna Kudryashova
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */

#include "gamepadIndicator.h"

#include "trikKernel/paths.h"

using namespace trikGui;

GamepadIndicator::GamepadIndicator(Controller &controller, QWidget *parent)
: QLabel(parent)
, mController(controller)
{
connect(&mController, SIGNAL(gamepadDisconnected()), this, SLOT(setOff()));
connect(&mController, SIGNAL(gamepadConnected()), this, SLOT(setOn()));

updateStatus();
connect(&mUpdateTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
mUpdateTimer.start(7000);
}

void GamepadIndicator::setOn()
{
QPixmap icon("://resources/gamepad_on.png");
setPixmap(icon);
show();
}

void GamepadIndicator::setOff()
{
hide();
}

void GamepadIndicator::connected(bool connected)
{
connected ? setOn() : setOff();
}

void GamepadIndicator::updateStatus()
{
connected(mController.gamepadConnectionStatus());
}

56 changes: 56 additions & 0 deletions trikGui/gamepadIndicator.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* Copyright 2016 Anna Kudryashova
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License. */

#pragma once

#include <QtCore/qglobal.h>

#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
#include <QtGui/QLabel>
#else
#include <QtWidgets/QLabel>
#endif

#include <controller.h>
#include <trikNetwork/gamepadInterface.h>

namespace trikGui {

/// A label that shows gamepad connection status.
class GamepadIndicator : public QLabel
{
Q_OBJECT
public:
/// @param controller is used to get the current gamepad info
explicit GamepadIndicator(Controller &controller, QWidget *parent = 0);

public slots:
/// Updates the status to 'connect'.
void setOn();

/// Updates the status to 'disconnect'.
void setOff();

/// Requests connection info from the controller and updates the status.
void updateStatus();

/// Updates the status according to connected parameters.
void connected(bool connected);

private:
QTimer mUpdateTimer;
Controller &mController;
};

}
Binary file added trikGui/resources/gamepad_off.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 trikGui/resources/gamepad_on.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 3 additions & 1 deletion trikGui/trikGui.pro
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2013 Yurii Litvinov
# Copyright 2013 - 2016 Yurii Litvinov, Mikhail Kita, Anna Kudryashova
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -55,6 +55,7 @@ HEADERS += \
$$PWD/sensorSettingsWidget.h \
$$PWD/sensorLever.h \
$$PWD/scriptHolder.h \
$$PWD/gamepadIndicator.h \

SOURCES += \
$$PWD/autoRunner.cpp \
Expand Down Expand Up @@ -95,6 +96,7 @@ SOURCES += \
$$PWD/sensorSettingsWidget.cpp \
$$PWD/sensorLever.cpp \
$$PWD/scriptHolder.cpp \
$$PWD/gamepadIndicator.cpp \

TRANSLATIONS = \
$$PWD/../translations/ru/trikGui_ru.ts \
Expand Down
2 changes: 2 additions & 0 deletions trikGui/trikGui.qrc
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@
<file>resources/openWifi.png</file>
<file>resources/passwordedWifi.png</file>
<file>resources/wait.png</file>
<file>resources/gamepad_off.png</file>
<file>resources/gamepad_on.png</file>
</qresource>
</RCC>

0 comments on commit 7c2a3dc

Please sign in to comment.