backend.cpp 1.37 KB
Newer Older
Artem Sidyakin's avatar
Artem Sidyakin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#include "backend.h"

Backend::Backend(QObject *parent) : QObject(parent)
{
    process.setProgram("python");
}

bool Backend::movePanTilt(QString basePath, int pan, int tilt)
{
    //qDebug() << "pan:" << pan << " | tilt:" << tilt;

    QString errorMsg = QString();

    if (process.state() != 0)
    {
        errorMsg = "waiting till previously started process ends...";
        qDebug() << errorMsg;
        emit someError(errorMsg);
        return false;
    }

    process.setArguments(QStringList()
                << QString("%1/scripts/move.py").arg(basePath)
                << QString::number(pan)
                << QString::number(tilt)
                );
    process.start();
    process.waitForFinished(500);

    if (process.exitCode() != 0)
    {
        errorMsg = process.readAllStandardError();
        qDebug() << "error:" << errorMsg;
        emit someError(errorMsg);
        return false;
    }
    else
    {
        //qDebug() << "output:" << process.readAllStandardOutput();
        return true;
    }

}

QString Backend::getBasePath(QString applicationDirPath)
{
    QString baseFolder = QString();
    QString pathLastMile = baseFolder.prepend("/");
#if defined(Q_OS_MAC)
    pathLastMile = baseFolder.prepend("/../../..");
#elif defined(Q_OS_WIN)
    pathLastMile = baseFolder.prepend("/..");
#endif
    return QString("%1%2").arg(applicationDirPath).arg(pathLastMile);
}