Skip to content

Commit

Permalink
Merge pull request #39 from romankurbatov/keysFix
Browse files Browse the repository at this point in the history
Keys fix
  • Loading branch information
yurii-litvinov committed Jun 18, 2014
2 parents c1ed98c + 8693405 commit e8105b9
Show file tree
Hide file tree
Showing 11 changed files with 60 additions and 9 deletions.
7 changes: 4 additions & 3 deletions trikControl/include/trikControl/brick.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,14 @@ class TRIKCONTROL_EXPORT Brick : public QObject

~Brick();

/// Do reset (stop motors, reset keys, clear screen, etc). We should call it before executing any script
/// with this Brick instance.
void reset();

/// Returns true if a system is in event-driven running mode, so it shall wait for events when script is executed.
/// If it is false, script will exit immediately.
bool isInEventDrivenMode() const;

/// Clears event driven mode, returning brick to a state where a script will exit immediately.
void resetEventDrivenMode();

public slots:
/// Plays given music file on a speaker (in format accepted by aplay utility).
void playSound(QString const &soundFileName);
Expand Down
4 changes: 4 additions & 0 deletions trikControl/include/trikControl/display.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ public slots:

void hide();

/// Clear everything painted with this object.
void clear();

signals:
void threadShowImage(QString const &fileName);
void threadAddLabel(QString const &text, int x, int y);
void threadRemoveLabels();
void threadSetBackground(QString const &color);
void threadHide();
void threadDelete();
void threadClear();

private:
QThread &mGuiThread;
Expand Down
3 changes: 3 additions & 0 deletions trikControl/include/trikControl/keys.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ class TRIKCONTROL_EXPORT Keys : public QObject

~Keys();

/// Clear data about previous key pressures.
void reset();

public slots:
/// Returns true, if button with given code was pressed, and clears "pressed" state for that button.
bool wasPressed(int code);
Expand Down
13 changes: 8 additions & 5 deletions trikControl/src/brick.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,14 @@ Brick::~Brick()
delete mGamepad;
}

void Brick::reset()
{
stop();
mKeys->reset();
mDisplay.clear();
mInEventDrivenMode = false;
}

void Brick::playSound(QString const &soundFileName)
{
qDebug() << soundFileName;
Expand Down Expand Up @@ -329,8 +337,3 @@ void Brick::system(QString const &command)
qDebug() << "Running:" << "sh" << args;
QProcess::startDetached("sh", args);
}

void Brick::resetEventDrivenMode()
{
mInEventDrivenMode = false;
}
6 changes: 6 additions & 0 deletions trikControl/src/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ trikControl::Display::Display(QThread &guiThread)
connect(this, SIGNAL(threadSetBackground(QString)), mGuiWorker, SLOT(setBackground(QString)));
connect(this, SIGNAL(threadHide()), mGuiWorker, SLOT(hide()));
connect(this, SIGNAL(threadDelete()), mGuiWorker, SLOT(deleteWorker()));
connect(this, SIGNAL(threadClear()), mGuiWorker, SLOT(clear()));
}

trikControl::Display::~Display()
Expand Down Expand Up @@ -81,3 +82,8 @@ void trikControl::Display::hide()
{
emit threadHide();
}

void Display::clear()
{
emit threadClear();
}
16 changes: 16 additions & 0 deletions trikControl/src/guiWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ GuiWorker::GuiWorker()
mImageWidget.setLayout(layout);
mImageWidget.setWindowState(Qt::WindowFullScreen);
mImageWidget.setWindowFlags(mImageWidget.windowFlags() | Qt::WindowStaysOnTopHint);
resetBackground();
}

void GuiWorker::showImage(QString const &fileName)
Expand Down Expand Up @@ -127,6 +128,21 @@ void GuiWorker::setBackground(QString const &color)
mImageWidget.show();
}

void GuiWorker::resetBackground()
{
QPalette palette = mImageWidget.palette();
palette.setColor(QPalette::Window, Qt::lightGray);
mImageWidget.setPalette(palette);
}

void GuiWorker::clear()
{
mImageWidget.hide();
removeLabels();
mImageLabel.setPixmap(QPixmap());
resetBackground();
}

void GuiWorker::hide()
{
mImageWidget.hide();
Expand Down
5 changes: 5 additions & 0 deletions trikControl/src/guiWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ public slots:
/// @param color - color of a background.
void setBackground(QString const &color);

/// Clear everything painted with this object.
void clear();

private:
void resetBackground();

/// Returns existing label with given coordinates or NULL if no such label exists.
QLabel *findLabel(int x, int y) const;

Expand Down
5 changes: 5 additions & 0 deletions trikControl/src/keysWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ KeysWorker::KeysWorker(QString const &keysPath)
mSocketNotifier->setEnabled(true);
}

void KeysWorker::reset()
{
mWasPressed.clear();
}

bool KeysWorker::wasPressed(int code)
{
mLock.lockForRead();
Expand Down
3 changes: 3 additions & 0 deletions trikControl/src/keysWorker.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ class KeysWorker : public QObject
/// @param keysPath - path to device file that controls brick keys.
KeysWorker(QString const &keysPath);

/// Clear data about previous key pressures.
void reset();

public slots:
bool wasPressed(int code);

Expand Down
5 changes: 5 additions & 0 deletions trikControl/src/linux/keys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ Keys::~Keys()
mWorkerThread.wait();
}

void Keys::reset()
{
mKeysWorker->reset();
}

bool Keys::wasPressed(int code)
{
return mKeysWorker->wasPressed(code);
Expand Down
2 changes: 1 addition & 1 deletion trikScriptRunner/src/scriptEngineWorker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ void ScriptEngineWorker::initScriptEngine()

connect(mEngine, SIGNAL(destroyed()), this, SLOT(onScriptEngineDestroyed()));

mBrick.resetEventDrivenMode();
mBrick.reset();

qScriptRegisterMetaType(mEngine, batteryToScriptValue, batteryFromScriptValue);
qScriptRegisterMetaType(mEngine, displayToScriptValue, displayFromScriptValue);
Expand Down

0 comments on commit e8105b9

Please sign in to comment.