コード例 #1
0
ファイル: mainwindow.cpp プロジェクト: DapperFactory/pixy
void MainWindow::connectPixy(bool state)
{
    if (state) // connect
    {
        try
        {
            if (m_pixyDFUConnected) // we're in programming mode
            {
                m_flash = new Flash();
                if (m_argvFirmwareFile!="")
                    program(m_argvFirmwareFile);
                else if (m_firmwareFile!="")
                {
                    program(m_firmwareFile);
                    m_firmwareFile = "";
                }
                else
                {
                    QString dir;
                    QFileDialog fd(this);
                    dir = m_settings->value("fw_dialog").toString();
                    fd.setWindowTitle("Select a Firmware File");
                    fd.setDirectory(QDir(dir));
                    fd.setNameFilter("Firmware (*.hex)");
                    if (fd.exec())
                    {
                        QStringList slist = fd.selectedFiles();
                        if (slist.size()==1 && m_flash)
                        {
                            program(slist.at(0));
                        }
                    }
                    dir = fd.directory().absolutePath();
                    m_settings->setValue("fw_dialog", QVariant(dir));
                }
            }
            else if (m_interpreter==NULL)
            {
                m_console->print("Pixy detected.\n");
                clearActions();
                m_interpreter = new Interpreter(m_console, m_video, &m_parameters, m_initScript);

                connect(m_interpreter, SIGNAL(runState(int)), this, SLOT(handleRunState(int)));
                connect(m_interpreter, SIGNAL(finished()), this, SLOT(interpreterFinished())); // thread will send finished event when it exits
                connect(m_interpreter, SIGNAL(connected(Device,bool)), this, SLOT(handleConnected(Device,bool)));
                connect(m_interpreter, SIGNAL(actionScriptlet(QString,QStringList)), this, SLOT(handleActionScriptlet(QString,QStringList)));
                connect(m_interpreter, SIGNAL(paramLoaded()), this, SLOT(handleLoadParams()));
                connect(m_interpreter, SIGNAL(version(ushort,ushort,ushort)), this, SLOT(handleVersion(ushort,ushort,ushort)));
                m_interpreter->start();
            }
            m_pixyConnected = true;
        }
        catch (std::runtime_error &exception)
コード例 #2
0
void Interpreter::handleLoadParams()
{
    DBG("loading...");
    uint i;
    char *id, *desc;
    uint32_t len;
    uint32_t flags;
    int response, res;
    uint8_t *data, *argList;
    int running;

    // if we're running, stop so this doesn't take too long....
    // (ie it would proceed with 1 property to returned frame, which could take 1 second or 2)
    running = m_running;
    if (running==1) // only if we're running and not in forced state (running==2)
        sendStop();

    for (i=0; true; i++)
    {
        QString category;

        res = m_chirp->callSync(m_getAll_param, UINT16(i), END_OUT_ARGS, &response, &flags, &argList, &id, &desc, &len, &data, END_IN_ARGS);
        if (res<0)
            break;

        if (response<0)
            break;

        QString sdesc(desc);
        Parameter parameter(id, (PType)argList[0]);
        parameter.setProperty(PP_FLAGS, flags);
        handleProperties(argList, &parameter, &sdesc);
        parameter.setHelp(sdesc);

        // deal with param category

        if (strlen((char *)argList)>1)
        {
            QByteArray a((char *)data, len);
            parameter.set(a);
        }
        else
        {
            if (argList[0]==CRP_INT8 || argList[0]==CRP_INT16 || argList[0]==CRP_INT32)
            {
                int32_t val = 0;
                Chirp::deserialize(data, len, &val, END);
                parameter.set(val);
            }
            else if (argList[0]==CRP_FLT32)
            {
                float val;
                Chirp::deserialize(data, len, &val, END);
                parameter.set(val);
            }
            else // not sure what to do with it, so we'll save it as binary
            {
                QByteArray a((char *)data, len);
                parameter.set(a);
            }
        }
        // it's changed! (ie, it's been loaded)
        parameter.setDirty(true);
        m_pixyParameters.add(parameter);
    }

    // if we're running, we've stopped, now resume
    if (running==1)
    {
        sendRun();
        m_fastPoll = false; // turn off fast polling...
    }

    DBG("loaded");
    emit paramLoaded();
    sendMonModulesParamChange();
    m_pixyParameters.clean();

}
コード例 #3
0
void ParamLoader::_parameterUpdated(QVariant value)
{
    Q_UNUSED(value);
    
    emit paramLoaded(true, _autopilot->getParameterFact(_paramName)->value().toFloat(), "");
}
コード例 #4
0
ファイル: interpreter.cpp プロジェクト: BallisticPain/pixy
void Interpreter::handleLoadParams()
{
    qDebug("loading...");
    uint i;
    char *id, *desc;
    uint32_t len;
    uint32_t flags;
    int response, res;
    uint8_t *data, *argList;
    int running;

    // if we're running, stop so this doesn't take too long....
    // (ie it would proceed with 1 property to returned frame, which could take 1 second or 2)
    running = m_running;
    if (running==1) // only if we're running and not in forced state (running==2)
        sendStop();

    for (i=0; true; i++)
    {
        QString category;

        res = m_chirp->callSync(m_getAll_param, UINT16(i), END_OUT_ARGS, &response, &flags, &argList, &id, &desc, &len, &data, END_IN_ARGS);
        if (res<0)
            break;

        if (response<0)
            break;

        QString sdesc(desc);

        // deal with param category
        QStringList words = QString(desc).split(QRegExp("\\s+"));
        int i = words.indexOf("@c");
        if (i>=0 && words.size()>i+1)
        {
            category = words[i+1];
            sdesc = sdesc.remove("@c "); // remove form description
            sdesc = sdesc.remove(category + " "); // remove from description
            category = category.replace('_', ' '); // make it look prettier
        }
        else
            category = CD_GENERAL;

        Parameter parameter(id, (PType)argList[0], "("+printArgType(argList[0], flags)+") "+sdesc);
        parameter.setProperty(PP_CATEGORY, category);
        parameter.setProperty(PP_FLAGS, flags);
        if (strlen((char *)argList)>1)
        {
            QByteArray a((char *)data, len);
            parameter.set(a);
        }
        else
        {
            if (argList[0]==CRP_INT8 || argList[0]==CRP_INT16 || argList[0]==CRP_INT32)
            {
                int32_t val = 0;
                Chirp::deserialize(data, len, &val, END);
                parameter.set(val);
            }
            else if (argList[0]==CRP_FLT32)
            {
                float val;
                Chirp::deserialize(data, len, &val, END);
                parameter.set(val);
            }
            else // not sure what to do with it, so we'll save it as binary
            {
                QByteArray a((char *)data, len);
                parameter.set(a);
            }
        }
        m_pixyParameters.add(parameter);
    }

    // if we're running, we've stopped, now resume
    if (running==1)
    {
        sendRun();
        m_fastPoll = false; // turn off fast polling...
    }

    qDebug("loaded");
    emit paramLoaded();
    if (m_paramDirty) // emit first time to update any modules waiting to get paramter info
    {
        m_paramDirty = false;
        emit paramChange();
    }
}