Skip to content

Commit 7c2a3dc

Browse files
Merge branch 'master' of git://github.com/AnnaAK/trikRuntime
2 parents 5211b38 + 49a4ab3 commit 7c2a3dc

File tree

10 files changed

+140
-1
lines changed

10 files changed

+140
-1
lines changed

trikGui/backgroundWidget.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ BackgroundWidget::BackgroundWidget(
3232
, mController(configPath)
3333
, mBatteryIndicator(mController.brick())
3434
, mWiFiIndicator(mController)
35+
, mGamepadIndicator(mController)
3536
, mMailboxIndicator("://resources/mailboxConnected.png", mController.mailbox()->isConnected())
3637
, mCommunicatorIndicator("://resources/communicatorConnected.png", mController.communicatorConnectionStatus())
3738
, mStartWidget(mController)
@@ -47,6 +48,7 @@ BackgroundWidget::BackgroundWidget(
4748

4849
mStatusBarLayout.addWidget(&mBatteryIndicator);
4950
mStatusBarLayout.addStretch();
51+
mStatusBarLayout.addWidget(&mGamepadIndicator);
5052
mStatusBarLayout.addWidget(&mMailboxIndicator);
5153
mStatusBarLayout.addWidget(&mCommunicatorIndicator);
5254
mStatusBarLayout.addWidget(&mWiFiIndicator);

trikGui/backgroundWidget.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
#include "controller.h"
3636
#include "batteryIndicator.h"
3737
#include "wiFiIndicator.h"
38+
#include "gamepadIndicator.h"
3839
#include "openSocketIndicator.h"
3940
#include "startWidget.h"
4041
#include "runningWidget.h"
@@ -114,6 +115,7 @@ private slots:
114115
QStackedLayout mMainWidgetsLayout;
115116
BatteryIndicator mBatteryIndicator;
116117
WiFiIndicator mWiFiIndicator;
118+
GamepadIndicator mGamepadIndicator;
117119
OpenSocketIndicator mMailboxIndicator;
118120
OpenSocketIndicator mCommunicatorIndicator;
119121
StartWidget mStartWidget;

trikGui/controller.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ Controller::Controller(const QString &configPath)
4949
, correctedConfigPath + "model-config.xml");
5050

5151
mGamepad.reset(trikNetwork::GamepadFactory::create(configurer));
52+
connect(mGamepad.data(), SIGNAL(disconnect()), this, SIGNAL(gamepadDisconnected()));
53+
connect(mGamepad.data(), SIGNAL(connected()), this, SIGNAL(gamepadConnected()));
54+
5255
mMailbox.reset(trikNetwork::MailboxFactory::create(configurer));
5356
mTelemetry.reset(new trikTelemetry::TrikTelemetry(*mBrick, *mGamepad));
5457
mScriptRunner.reset(new trikScriptRunner::TrikScriptRunner(*mBrick, mMailbox.data(), mGamepad.data()));
@@ -136,6 +139,15 @@ bool Controller::communicatorConnectionStatus()
136139
return mTelemetry->activeConnections() > 0 && mCommunicator->activeConnections() > 0;
137140
}
138141

142+
bool Controller::gamepadConnectionStatus() const
143+
{
144+
if (mGamepad != nullptr) {
145+
return mGamepad->isConnected();
146+
} else {
147+
return false;
148+
}
149+
}
150+
139151
void Controller::updateCommunicatorStatus()
140152
{
141153
emit communicatorStatusChanged(communicatorConnectionStatus());

trikGui/controller.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ class Controller : public QObject
6767
/// Returns communicator connection status (whether or not both Telemetry and Communicator servers are connected).
6868
bool communicatorConnectionStatus();
6969

70+
/// Returns gamepad connection status.
71+
bool gamepadConnectionStatus() const;
72+
7073
public slots:
7174
/// Cancels execution of current program.
7275
void abortExecution();
@@ -91,6 +94,12 @@ public slots:
9194
/// clutter from videosensors.
9295
void brickStopped();
9396

97+
/// Emitted when a robot is disconnected from a gamepad.
98+
void gamepadDisconnected();
99+
100+
/// Emitted when a robot is connected to a gamepad.
101+
void gamepadConnected();
102+
94103
/// Emitted when a robot is connected to a network.
95104
void wiFiConnected();
96105

trikGui/gamepadIndicator.cpp

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/* Copyright 2016 Anna Kudryashova
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License. */
14+
15+
#include "gamepadIndicator.h"
16+
17+
#include "trikKernel/paths.h"
18+
19+
using namespace trikGui;
20+
21+
GamepadIndicator::GamepadIndicator(Controller &controller, QWidget *parent)
22+
: QLabel(parent)
23+
, mController(controller)
24+
{
25+
connect(&mController, SIGNAL(gamepadDisconnected()), this, SLOT(setOff()));
26+
connect(&mController, SIGNAL(gamepadConnected()), this, SLOT(setOn()));
27+
28+
updateStatus();
29+
connect(&mUpdateTimer, SIGNAL(timeout()), this, SLOT(updateStatus()));
30+
mUpdateTimer.start(7000);
31+
}
32+
33+
void GamepadIndicator::setOn()
34+
{
35+
QPixmap icon("://resources/gamepad_on.png");
36+
setPixmap(icon);
37+
show();
38+
}
39+
40+
void GamepadIndicator::setOff()
41+
{
42+
hide();
43+
}
44+
45+
void GamepadIndicator::connected(bool connected)
46+
{
47+
connected ? setOn() : setOff();
48+
}
49+
50+
void GamepadIndicator::updateStatus()
51+
{
52+
connected(mController.gamepadConnectionStatus());
53+
}
54+

trikGui/gamepadIndicator.h

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* Copyright 2016 Anna Kudryashova
2+
*
3+
* Licensed under the Apache License, Version 2.0 (the "License");
4+
* you may not use this file except in compliance with the License.
5+
* You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software
10+
* distributed under the License is distributed on an "AS IS" BASIS,
11+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
* See the License for the specific language governing permissions and
13+
* limitations under the License. */
14+
15+
#pragma once
16+
17+
#include <QtCore/qglobal.h>
18+
19+
#if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
20+
#include <QtGui/QLabel>
21+
#else
22+
#include <QtWidgets/QLabel>
23+
#endif
24+
25+
#include <controller.h>
26+
#include <trikNetwork/gamepadInterface.h>
27+
28+
namespace trikGui {
29+
30+
/// A label that shows gamepad connection status.
31+
class GamepadIndicator : public QLabel
32+
{
33+
Q_OBJECT
34+
public:
35+
/// @param controller is used to get the current gamepad info
36+
explicit GamepadIndicator(Controller &controller, QWidget *parent = 0);
37+
38+
public slots:
39+
/// Updates the status to 'connect'.
40+
void setOn();
41+
42+
/// Updates the status to 'disconnect'.
43+
void setOff();
44+
45+
/// Requests connection info from the controller and updates the status.
46+
void updateStatus();
47+
48+
/// Updates the status according to connected parameters.
49+
void connected(bool connected);
50+
51+
private:
52+
QTimer mUpdateTimer;
53+
Controller &mController;
54+
};
55+
56+
}

trikGui/resources/gamepad_off.png

831 Bytes
Loading

trikGui/resources/gamepad_on.png

828 Bytes
Loading

trikGui/trikGui.pro

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2013 Yurii Litvinov
1+
# Copyright 2013 - 2016 Yurii Litvinov, Mikhail Kita, Anna Kudryashova
22
#
33
# Licensed under the Apache License, Version 2.0 (the "License");
44
# you may not use this file except in compliance with the License.
@@ -55,6 +55,7 @@ HEADERS += \
5555
$$PWD/sensorSettingsWidget.h \
5656
$$PWD/sensorLever.h \
5757
$$PWD/scriptHolder.h \
58+
$$PWD/gamepadIndicator.h \
5859

5960
SOURCES += \
6061
$$PWD/autoRunner.cpp \
@@ -95,6 +96,7 @@ SOURCES += \
9596
$$PWD/sensorSettingsWidget.cpp \
9697
$$PWD/sensorLever.cpp \
9798
$$PWD/scriptHolder.cpp \
99+
$$PWD/gamepadIndicator.cpp \
98100

99101
TRANSLATIONS = \
100102
$$PWD/../translations/ru/trikGui_ru.ts \

trikGui/trikGui.qrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,7 @@
1313
<file>resources/openWifi.png</file>
1414
<file>resources/passwordedWifi.png</file>
1515
<file>resources/wait.png</file>
16+
<file>resources/gamepad_off.png</file>
17+
<file>resources/gamepad_on.png</file>
1618
</qresource>
1719
</RCC>

0 commit comments

Comments
 (0)