コード例 #1
0
bool SoftwareI2CPort::_read(uint8_t u8SlaveAddress, void* pData, uint16_t u16Size, bool holdLow)
{
    uint8_t * transfer_data = reinterpret_cast<uint8_t *>(pData);

    m_scl.setDirection(GpioPin::kInput);
    m_sda.setDirection(GpioPin::kInput);

    m_scl.clear();
    m_sda.clear();

    sendStart();

    bool ret = sendByte((u8SlaveAddress << 1) | 0x01, true);
    if (!ret)
    {
        sendStop();
    
        return ret;
    }

    while (u16Size--)
    {
        // The last byte in the transfer must NAK the byte.  This tells
        // the slave device that the transfer is finished.
        bool isLast = (u16Size == 0);
        *transfer_data++ = readByte(!isLast, (isLast && holdLow));
    }

    sendStop();

    return true;
}
コード例 #2
0
ファイル: qsfcanvas.cpp プロジェクト: AntipodGames/Fly
void QSFcanvas::gamePadEvent(){
    sf::Event Event;
    if (this->GetEvent(Event))
    {
        if((Event.Type == sf::Event::JoyMoved) && ((Event.JoyMove.Axis == sf::Joy::AxisX)) ){
            axisXPos = Event.JoyMove.Position/100;
          //  std::cout << this->GetInput().GetJoystickAxis(0,sf::Joy::AxisX) << std::endl;
        }
        if((Event.Type == sf::Event::JoyButtonPressed)){
            if(Event.JoyButton.Button == 4) //L1
                emit activBoost(true);
            if(Event.JoyButton.Button == 0) //Triangle
                emit sendStop(true);

        }
        if((Event.Type == sf::Event::JoyButtonReleased)){
            if(Event.JoyButton.Button == 4) //L1
                emit activBoost(false);
            if(Event.JoyButton.Button == 0) //Triangle
                emit sendStop(false);

        }
    }
    emit sendPadPos(axisXPos);


}
コード例 #3
0
int SoftwareI2CPort::send(uint8_t address, uint32_t subaddress, uint32_t subaddressLength, const void * data, uint32_t dataLength)
{
    fillAddressBuffer(address, subaddress, subaddressLength);
    
    m_scl.setDirection(GpioPin::kInput);
    m_sda.setDirection(GpioPin::kInput);

    m_scl.clear();
    m_sda.clear();

    sendStart();

    bool ret = sendByte((address << 1), true);
    if (!ret)
    {
        sendStop();
    
        return I2C_ERROR_NO_SLAVE_ACK;
    }

    const uint8_t * subaddressData = (const uint8_t *)&m_addressBuffer[1];
    while (subaddressLength--)
    {
        ret = sendByte(*subaddressData++, true);
        if (!ret)
        {
            sendStop();
    
            return I2C_ERROR_GOT_NAK;
        }
    }

    const uint8_t * transfer_data = reinterpret_cast<const uint8_t *>(data);
    uint32_t u16Size = dataLength;
    while (u16Size--)
    {
        ret = sendByte(*transfer_data++, true);
        if (!ret)
        {
            sendStop();
    
            return I2C_ERROR_GOT_NAK;
        }
    }

    sendStop();
    
    return I2C_OK;
}
コード例 #4
0
void Interpreter::handleSaveParams(bool reject)
{
    bool running;
    int32_t response;

    // 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();

    // notify monmodules
    sendMonModulesParamChange();
    // save them in pixy
    if (!reject)
        handlePixySaveParams(false);

    // reset the shadow parameters because we've saved all params
    m_chirp->callSync(m_reset_shadows, END_OUT_ARGS, &response, END_IN_ARGS);


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

}
コード例 #5
0
ファイル: risccomm.cpp プロジェクト: elpuri/shitty-RISC
void RiscComm::onConsoleInput(QString input)
{
    m_sp->readAll();    // flush any residual crap out (from FPGA reset for example)

    if (input.compare("s") == 0) {
        sendStep();
        doScan();
    }
    else if (input.compare("sc") == 0)
        doScan();
    else if (input.compare("q") == 0)
        QCoreApplication::exit();
    else if (input.compare("r") == 0)
        sendRun();
    else if (input.compare("rs") == 0)
        sendReset();
    else if (input.compare("st") == 0) {
        sendStop();
        doScan();
    } else if (input.startsWith("wp")) {
        QStringList args = input.split(" ");
        if (args.length() == 2) {     // upload a file
            sendProgram(args.at(1));
        }
    } else if (input.compare("clrmem") == 0) {
        QByteArray zeros;
        zeros.fill(0, 256);
        writeMem(zeros, 0, true);
    } else if (input.compare("dm") == 0) {
        dumpMem();
    }
    else
        qDebug() << "Unknown command:" << input;
}
コード例 #6
0
ファイル: interpreter.cpp プロジェクト: BallisticPain/pixy
void Interpreter::handlePendingCommand()
{
    QMutexLocker locker(&m_mutexQueue);
    if (m_commandQueue.empty())
        return;
    const Command command = m_commandQueue.front();
    m_commandQueue.pop();
    locker.unlock();

    switch (command.first)
    {
    case STOP:
        sendStop();
        break;

    case RUN:
        sendRun();
        break;

    case GET_ACTION:
        sendGetAction(command.second.toInt());
        break;

    case LOAD_PARAMS:
        handleLoadParams();
        break;

    case SAVE_PARAMS:
        handleSaveParams();
        break;
    }

}
コード例 #7
0
void DebuggerMagager::stop(const ast::Exp* pExp, int index)
{
    //send stop information to all debuggers
    setExp(pExp);
    sendStop(index);
    internal_stop();
    clearExp();
}
コード例 #8
0
bool SoftwareI2CPort::_write(uint8_t u8SlaveAddress, const void* pData, uint16_t u16Size, bool doSendStart, bool bStop, bool holdLow)
{
    const uint8_t * transfer_data = reinterpret_cast<const uint8_t *>(pData);

    if (doSendStart)
    {
        m_scl.setDirection(GpioPin::kInput);
    }
    m_sda.setDirection(GpioPin::kInput);

    m_scl.clear();
    m_sda.clear();

    if (doSendStart)
    {
        sendStart();
    }

    bool ret = sendByte((u8SlaveAddress << 1), true);
    if (!ret)
    {
        sendStop();
    
        return ret;
    }

    while (u16Size--)
    {
        bool isLast = (u16Size == 0);
        ret = sendByte(*transfer_data++, (isLast && holdLow));
        if (!ret)
        {
            sendStop();
    
            return ret;
        }
    }

    if (bStop)
    {
        sendStop();
    }

    return true;
}
コード例 #9
0
ファイル: universalpana.cpp プロジェクト: delight/Pana
UniversalPana::UniversalPana(KInstance *inst,QObject *parent,QWidget *widgetParent, QString &desktopName, const char* name):
                   KonqSidebarPlugin(inst,parent,widgetParent,desktopName,name)
{
    KGlobal::iconLoader()->addAppDir( "pana" );
    widget = new panaWidget( widgetParent );
//    widgetParent->resize(580,300);
    KToolBar *topBar = new KToolBar( widget, "Topbar" );
    topBar->setIconSize(16);
    topBar->insertButton( "today",    0, SIGNAL( clicked() ), this, SLOT( currentTrack() ) );
    topBar->insertButton( "document", 0, SIGNAL( clicked() ), this, SLOT( lyrics() ) );
    topBar->insertButton( "personal", 0, SIGNAL( clicked() ), this, SLOT( wiki() ) );

    browser = new KHTMLPart(widget, "widget-browser");
//browser=new KHTMLPart(widget);
    kdDebug() << "parentPart() << " << browser->parentPart() << endl;
    browser->setDNDEnabled( true );
    browser->setEncoding( "utf8", true );
    updateBrowser( HTML_FILE );
    browser->view()->installEventFilter( widget );
    panaDCOP = new DCOPClient();
    panaDCOP->attach();

    playerStub   = new PanaPlayerInterface_stub( panaDCOP, "pana", "player");
    playlistStub = new PanaPlaylistInterface_stub( panaDCOP, "pana", "playlist");
    contextStub = new PanaContextBrowserInterface_stub (panaDCOP, "pana", "contextbrowser");

    KToolBar* toolBar=new KToolBar(widget, "PlayerControls");

    toolBar->setIconSize(16);
    toolBar->insertButton( "player_start",0, SIGNAL( clicked() ), this, SLOT( sendPrev() ) );
    toolBar->insertButton( "player_play", 0, SIGNAL( clicked() ), this, SLOT( sendPlay() ) );
    toolBar->insertButton( "player_pause",0, SIGNAL( clicked() ), this, SLOT( sendPause() ) );
    toolBar->insertButton( "player_stop", 0, SIGNAL( clicked() ), this, SLOT( sendStop() ) );
    toolBar->insertButton( "player_end",  0, SIGNAL( clicked() ), this, SLOT( sendNext() ) );

    toolBar->insertSeparator();
    toolBar->insertButton( "arts",        0, SIGNAL( clicked() ), this, SLOT( sendMute() ) );

    vol_slider = new QSlider(0,100,1,0,Qt::Horizontal, toolBar,"volume");
    vol_slider->setLineStep(2);

    connect(vol_slider, SIGNAL( valueChanged(int) ), this, SLOT(volChanged(int ) ) );
    toolBar->insertWidget(1,2, vol_slider);

    fileInfo  = new QFileInfo(HTML_FILE);
    QTimer *t = new QTimer( this );

    connect( t, SIGNAL(timeout()), SLOT(updateStatus() ) );
    t->start( 2000, false );
    kdDebug() << "Connecting widget signal" << endl;

    connect( widget,                      SIGNAL( emitURL( const KURL &)),
             this,                        SLOT( openURLRequest( const KURL &) ) );
    connect( browser->browserExtension(), SIGNAL( openURLRequest( const KURL &, const KParts::URLArgs & ) ),
             this,                        SLOT( openURLRequest( const KURL & ) ) );
    widget->show();
}
コード例 #10
0
void Interpreter::handlePendingCommand()
{
    QMutexLocker locker(&m_mutexQueue);
    if (m_commandQueue.empty())
        return;
    const Command command = m_commandQueue.front();
    m_commandQueue.pop_front();
    locker.unlock();

    switch (command.m_type)
    {
    case STOP:
        sendStop();
        break;

    case RUN:
        sendRun();
        break;

    case STOP_LOCAL:
        m_localProgramRunning = false;
        emit runState(false);
        break;

    case RUN_LOCAL:
        if (m_program.size()>0)
        {
            m_localProgramRunning = true;
            emit runState(true);
            emit enableConsole(false);
            m_pc = 0;
        }
        break;

    case LOAD_PARAMS:
        handleLoadParams();
        break;

    case SAVE_PARAMS:
        handleSaveParams(command.m_arg0.toBool());
        break;

    case UPDATE_PARAM:
        handleUpdateParam();
        break;

    case CLOSE:
        emit runState(-1);
        break;
    }
}
コード例 #11
0
tHandle cJuryTransmitter::CreateView()
{
    QWidget* pWidget = (QWidget*)m_pViewport->VP_GetWindow();
    m_pWidget = new DisplayWidget(pWidget);

    connect(m_pWidget, SIGNAL(sendNotAus()), this, SLOT(OnNotAus()));
    connect(m_pWidget, SIGNAL(sendStart(tInt16)), this, SLOT(OnStart(tInt16)));
    connect(m_pWidget, SIGNAL(sendStop(tInt16)), this, SLOT(OnStop(tInt16)));
    connect(m_pWidget, SIGNAL(sendReadyRequest(tInt16)), this, SLOT(OnRequestReady(tInt16)));
    connect(this, SIGNAL(sendDriverState(int, int)), m_pWidget, SLOT(OnDriverState(int, int)));
    connect(this, SIGNAL(sendMessage(QString)), m_pWidget, SLOT(OnAppendText(QString)));
    
    
    return (tHandle)m_pWidget;
}
コード例 #12
0
ファイル: HMC.cpp プロジェクト: felipehfj/Arduino
// note that you need to wait at least 5ms after power on to initialize
void HMC5843::init()
{
  PORTC = 0b00110000; // Use the internal pull up resistors
  
  // Choose 100KHz for the bus.  Formula from 21.5.2 in ATmega168 datasheet.
  TWSR &= ~((1<<TWPS1)&(1<<TWPS0));
	TWBR = (unsigned char)(F_CPU/200000l-8);
	
	// Put the HMC5843 into continuous mode
	sendStart();
	sendByte(0x3C);
	sendByte(0x02);
	sendByte(0x00);
	sendStop();
	// note that you need to wait 100ms after this before first calling recieve
}
コード例 #13
0
ファイル: interpreter.cpp プロジェクト: CodeMonkey1959/pixy
void Interpreter::handlePendingCommand()
{
    switch (m_pendingCommand)
    {
    case NONE:
        break;

    case STOP:
        sendStop();
        break;

    case RUN:
        sendRun();
        break;
    }
    m_pendingCommand = NONE;
}
コード例 #14
0
ファイル: HMC.cpp プロジェクト: felipehfj/Arduino
// This can be called at 100ms intervals to get new data
void HMC5843::getValues(int *x, int *y, int *z)
{
  unsigned char xin, yin, zin;
  // start the reading
  sendStart();
  sendByte(0x3D);
  // read out the 3 values, 2 bytes each.  lsb first, then msb.
  xin = receiveByte();
  *x = (xin<<8)|receiveByte();
  yin = receiveByte();
  *y = (yin<<8)|receiveByte();
  zin = receiveByte();
  *z = (zin<<8)|receiveByte();
  // wrap back around for the next set of reads and close
  sendByte(0x3D);
  sendStop();
}
コード例 #15
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();

}
コード例 #16
0
ファイル: interpreter.cpp プロジェクト: BallisticPain/pixy
void Interpreter::handleSaveParams()
{
    int i;
    int res, response;
    bool dirty, 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();

    Parameters &parameters = m_pixyParameters.parameters();

    for (i=0, dirty=false; i<parameters.size(); i++)
    {
        uint8_t buf[0x100];

        if (parameters[i].dirty())
        {
            int len;
            QByteArray str = parameters[i].id().toUtf8();
            const char *id = str.constData();
            PType type = parameters[i].type();
            parameters[i].setDirty(false); // reset
            dirty = true; // keep track for sending signal

            qDebug() << id;

            if (type==PT_INT8 || type==PT_INT16 || type==PT_INT32)
            {
                int val = parameters[i].value().toInt();
                len = Chirp::serialize(NULL, buf, 0x100, type, val, END);
            }
            else if (type==PT_FLT32)
            {
                float val = parameters[i].value().toFloat();
                len = Chirp::serialize(NULL, buf, 0x100, type, val, END);
            }
            else if (type==PT_INTS8)
            {
                QByteArray a = parameters[i].value().toByteArray();
                len = a.size();
                memcpy(buf, a.constData(), len);
            }
            else
                continue; // don't know what to do!

            res = m_chirp->callSync(m_set_param, STRING(id), UINTS8(len, buf), END_OUT_ARGS, &response, END_IN_ARGS);
            if (res<0 || response<0)
            {
                emit error("There was a problem setting a parameter.");
                break;
            }
        }
    }

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

    if (dirty)  // if we updated any parameters, output paramChange signal
        emit paramChange();

}
コード例 #17
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();
    }
}
コード例 #18
0
ファイル: interpreter.cpp プロジェクト: BallisticPain/pixy
void Interpreter::run()
{
    int res;
    QTime time;

    // init
    try
    {
        ChirpProc versionProc;
        uint16_t *version;
        uint32_t verLen, responseInt;

        if (m_link.open()<0)
            throw std::runtime_error("Unable to open USB device.");
        m_chirp = new ChirpMon(this, &m_link);        

        // get version and compare
        versionProc = m_chirp->getProc("version");
        if (versionProc<0)
            throw std::runtime_error("Can't get firmware version.");
        res = m_chirp->callSync(versionProc, END_OUT_ARGS, &responseInt, &verLen, &version, END_IN_ARGS);
        if (res<0)
            throw std::runtime_error("Can't get firmware version.");
        memcpy(m_version, version, 3*sizeof(uint16_t));
        if (m_version[0]!=VER_MAJOR || m_version[1]>VER_MINOR)
        {
            char buf[0x100];
            sprintf(buf, "This Pixy's firmware version (%d.%d.%d) is not compatible with this PixyMon version (%d.%d.%d).",
                    m_version[0], m_version[1], m_version[2], VER_MAJOR, VER_MINOR, VER_BUILD);
            throw std::runtime_error(buf);
        }

        m_exec_run = m_chirp->getProc("run");
        m_exec_running = m_chirp->getProc("running");
        m_exec_stop = m_chirp->getProc("stop");
        m_exec_get_action = m_chirp->getProc("getAction");
        m_get_param = m_chirp->getProc("prm_get");
        m_getAll_param = m_chirp->getProc("prm_getAll");
        m_set_param = m_chirp->getProc("prm_set");

        if (m_exec_run<0 || m_exec_running<0 || m_exec_stop<0 || m_exec_get_action<0 ||
                m_get_param<0 || m_getAll_param<0 || m_set_param<0)
            throw std::runtime_error("Communication error with Pixy.");
    }
    catch (std::runtime_error &exception)
    {
        emit error(QString(exception.what()));
        return;
    }
    qDebug() << "*** init done";

    time.start();
    getRunning();

    handleLoadParams(); // load params upon initialization

    while(m_run)
    {
        if (!m_programming &&
                ((m_fastPoll && time.elapsed()>RUN_POLL_PERIOD_FAST) ||
                (!m_fastPoll && time.elapsed()>RUN_POLL_PERIOD_SLOW)))
        {
            getRunning();
            time.start();
        }
        else
        {
            m_chirp->service(false);
            msleep(1); // give config thread time to run
        }
        handlePendingCommand();
        if (!m_running)
        {
            if (m_localProgramRunning)
                execute();
            else
            {
                Sleeper::msleep(10);
                if (m_mutexProg.tryLock())
                {
                    if (m_argv.size())
                    {
                        if (m_externalCommand!="") // print command to make things explicit and all pretty
                            emit textOut(PROMPT " " + m_externalCommand);
                        if (m_argv[0]=="help")
                            handleHelp();
                        else
                        {
                            res = call(m_argv, true);
                            if (res<0)
                            {
                                if (m_programming)
                                {
                                    endLocalProgram();
                                    clearLocalProgram();
                                }
                                m_commandList.clear(); // abort our little scriptlet
                            }
                        }
                        m_argv.clear();
                        if (m_externalCommand=="")
                            prompt(); // print prompt only if we expect an actual human to be typing into the command window
                        else
                            m_externalCommand = "";
                        // check quickly to see if we're running after this command
                        if (!m_programming)
                            getRunning();
                        // is there another command in our little scriptlet?
                        if (m_commandList.size())
                        {
                            execute(m_commandList[0]);
                            m_commandList.removeFirst();
                        }
                    }
                    m_mutexProg.unlock();
                }
            }
        }
    }
    sendStop();
    msleep(200); // let things settle a bit
    qDebug("worker thead exiting");
}