Skip to content

Commit e8105b9

Browse files
Merge pull request #39 from romankurbatov/keysFix
Keys fix
2 parents c1ed98c + 8693405 commit e8105b9

File tree

11 files changed

+60
-9
lines changed

11 files changed

+60
-9
lines changed

trikControl/include/trikControl/brick.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@ class TRIKCONTROL_EXPORT Brick : public QObject
5858

5959
~Brick();
6060

61+
/// Do reset (stop motors, reset keys, clear screen, etc). We should call it before executing any script
62+
/// with this Brick instance.
63+
void reset();
64+
6165
/// Returns true if a system is in event-driven running mode, so it shall wait for events when script is executed.
6266
/// If it is false, script will exit immediately.
6367
bool isInEventDrivenMode() const;
6468

65-
/// Clears event driven mode, returning brick to a state where a script will exit immediately.
66-
void resetEventDrivenMode();
67-
6869
public slots:
6970
/// Plays given music file on a speaker (in format accepted by aplay utility).
7071
void playSound(QString const &soundFileName);

trikControl/include/trikControl/display.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,17 @@ public slots:
6262

6363
void hide();
6464

65+
/// Clear everything painted with this object.
66+
void clear();
67+
6568
signals:
6669
void threadShowImage(QString const &fileName);
6770
void threadAddLabel(QString const &text, int x, int y);
6871
void threadRemoveLabels();
6972
void threadSetBackground(QString const &color);
7073
void threadHide();
7174
void threadDelete();
75+
void threadClear();
7276

7377
private:
7478
QThread &mGuiThread;

trikControl/include/trikControl/keys.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ class TRIKCONTROL_EXPORT Keys : public QObject
3636

3737
~Keys();
3838

39+
/// Clear data about previous key pressures.
40+
void reset();
41+
3942
public slots:
4043
/// Returns true, if button with given code was pressed, and clears "pressed" state for that button.
4144
bool wasPressed(int code);

trikControl/src/brick.cpp

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,14 @@ Brick::~Brick()
150150
delete mGamepad;
151151
}
152152

153+
void Brick::reset()
154+
{
155+
stop();
156+
mKeys->reset();
157+
mDisplay.clear();
158+
mInEventDrivenMode = false;
159+
}
160+
153161
void Brick::playSound(QString const &soundFileName)
154162
{
155163
qDebug() << soundFileName;
@@ -329,8 +337,3 @@ void Brick::system(QString const &command)
329337
qDebug() << "Running:" << "sh" << args;
330338
QProcess::startDetached("sh", args);
331339
}
332-
333-
void Brick::resetEventDrivenMode()
334-
{
335-
mInEventDrivenMode = false;
336-
}

trikControl/src/display.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ trikControl::Display::Display(QThread &guiThread)
3939
connect(this, SIGNAL(threadSetBackground(QString)), mGuiWorker, SLOT(setBackground(QString)));
4040
connect(this, SIGNAL(threadHide()), mGuiWorker, SLOT(hide()));
4141
connect(this, SIGNAL(threadDelete()), mGuiWorker, SLOT(deleteWorker()));
42+
connect(this, SIGNAL(threadClear()), mGuiWorker, SLOT(clear()));
4243
}
4344

4445
trikControl::Display::~Display()
@@ -81,3 +82,8 @@ void trikControl::Display::hide()
8182
{
8283
emit threadHide();
8384
}
85+
86+
void Display::clear()
87+
{
88+
emit threadClear();
89+
}

trikControl/src/guiWorker.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ GuiWorker::GuiWorker()
3838
mImageWidget.setLayout(layout);
3939
mImageWidget.setWindowState(Qt::WindowFullScreen);
4040
mImageWidget.setWindowFlags(mImageWidget.windowFlags() | Qt::WindowStaysOnTopHint);
41+
resetBackground();
4142
}
4243

4344
void GuiWorker::showImage(QString const &fileName)
@@ -127,6 +128,21 @@ void GuiWorker::setBackground(QString const &color)
127128
mImageWidget.show();
128129
}
129130

131+
void GuiWorker::resetBackground()
132+
{
133+
QPalette palette = mImageWidget.palette();
134+
palette.setColor(QPalette::Window, Qt::lightGray);
135+
mImageWidget.setPalette(palette);
136+
}
137+
138+
void GuiWorker::clear()
139+
{
140+
mImageWidget.hide();
141+
removeLabels();
142+
mImageLabel.setPixmap(QPixmap());
143+
resetBackground();
144+
}
145+
130146
void GuiWorker::hide()
131147
{
132148
mImageWidget.hide();

trikControl/src/guiWorker.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,12 @@ public slots:
6262
/// @param color - color of a background.
6363
void setBackground(QString const &color);
6464

65+
/// Clear everything painted with this object.
66+
void clear();
67+
6568
private:
69+
void resetBackground();
70+
6671
/// Returns existing label with given coordinates or NULL if no such label exists.
6772
QLabel *findLabel(int x, int y) const;
6873

trikControl/src/keysWorker.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ KeysWorker::KeysWorker(QString const &keysPath)
3535
mSocketNotifier->setEnabled(true);
3636
}
3737

38+
void KeysWorker::reset()
39+
{
40+
mWasPressed.clear();
41+
}
42+
3843
bool KeysWorker::wasPressed(int code)
3944
{
4045
mLock.lockForRead();

trikControl/src/keysWorker.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ class KeysWorker : public QObject
3131
/// @param keysPath - path to device file that controls brick keys.
3232
KeysWorker(QString const &keysPath);
3333

34+
/// Clear data about previous key pressures.
35+
void reset();
36+
3437
public slots:
3538
bool wasPressed(int code);
3639

trikControl/src/linux/keys.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@ Keys::~Keys()
3232
mWorkerThread.wait();
3333
}
3434

35+
void Keys::reset()
36+
{
37+
mKeysWorker->reset();
38+
}
39+
3540
bool Keys::wasPressed(int code)
3641
{
3742
return mKeysWorker->wasPressed(code);

0 commit comments

Comments
 (0)