Esempio n. 1
0
void
vexSonarAdd( tVexSonarChannel channel, tVexDigitalPin pa, tVexDigitalPin pb )
{
    if( channel >= kVexSonar_Num )
        return;

    if(pa > kVexDigital_12)
        return;
    if(pb > kVexDigital_12)
        return;

    // zero variables

    // setup first pin as output
    vexDigitalModeSet( pa, kVexDigitalOutput);
    vexSonars[channel].pa = pa;
    vexSonars[channel].pa_port   = vexioDefinition[pa].port;
    vexSonars[channel].pa_pad    = vexioDefinition[pa].pad;

    // setup second pin as input
    vexDigitalModeSet( pb, kVexDigitalInput);
    vexSonars[channel].pb = pb;
    vexSonars[channel].pb_port   = vexioDefinition[pb].port;
    vexSonars[channel].pb_pad    = vexioDefinition[pb].pad;
    vexExtSet( vexSonars[channel].pb_port, vexSonars[channel].pb_pad, EXT_CH_MODE_BOTH_EDGES, _vs_echo_cb );

    // installed and enabled
    vexSonars[channel].flags = (SONAR_INSTALLED | SONAR_ENABLED);
}
Esempio n. 2
0
void
vexDigitalIntrSet( tVexDigitalPin pin )
{
    vexDigitalModeSet( pin, kVexDigitalInput );
    vexExtSet( vexioDefinition[pin].port, vexioDefinition[pin].pad, EXT_CH_MODE_BOTH_EDGES, _vi_cb );

    // Fixed screwed up port4/port10 conflict
    if( vexioDefinition[pin].pad == 7 )
        {
        if( pin == kVexDigital_4 )
            vexioDefinition[kVexDigital_10].intrCount = -1;
        if( pin == kVexDigital_10 )
            vexioDefinition[kVexDigital_4].intrCount = -1;
        }

    vexioDefinition[pin].intrCount = 0;
}
Esempio n. 3
0
void
vexDigitalConfigure( vexDigiCfg *cfg, int16_t cfg_num )
{
    vexDigiCfg          *_cfg, *_cfg1, *_cfg2;
    tVexDigitalPin      i;
    tVexDigitalPin      j;
    int16_t             len;

    if( cfg == NULL ){
        _cfg = vexDefConfig;
        len = DIG_CONFIG_SIZE( vexDefConfig );
        }
    else {
        _cfg = cfg;
        len = cfg_num;
        }

    for(i=0,_cfg1=_cfg;i<len;i++,_cfg1++)
        {
        // An input ?
        if( _cfg1->cfg == kVexConfigInput )
            vexDigitalModeSet(_cfg1->pin, kVexDigitalInput );
        // An output ?
        if( _cfg1->cfg == kVexConfigOutput )
            vexDigitalModeSet(_cfg1->pin, kVexDigitalOutput );

        // An encoder ?
        if( _cfg1->cfg == kVexConfigQuadEnc1 )
            {
            // find other encoder pin
            for(j=0, _cfg2=_cfg;j<len;j++,_cfg2++)
                {
                if( (_cfg2->cfg == kVexConfigQuadEnc2) && (_cfg1->chan == _cfg2->chan ) )
                    vexEncoderAdd( _cfg1->chan, _cfg1->pin, _cfg2->pin );
                }
            }

        // A sonar ?
        if( _cfg1->cfg == kVexConfigSonarOut )
            {
            // find other encoder pin
            for(j=0, _cfg2=_cfg;j<len;j++,_cfg2++)
                {
                if( (_cfg2->cfg == kVexConfigSonarIn) && (_cfg1->chan == _cfg2->chan ) )
                    vexSonarAdd( _cfg1->chan, _cfg1->pin, _cfg2->pin );
                }
            }

        // Interrupt (experimental)
        if( _cfg1->cfg == kVexConfigInterrupt )
            {
            vexDigitalIntrSet( _cfg1->pin );
            }

        // A bit messy here
        // use the default config to save the user config.
        // obviously if there is no user config then this is superfluous.
        vexDefConfig[ _cfg1->pin ].type = _cfg1->type;
        vexDefConfig[ _cfg1->pin ].cfg  = _cfg1->cfg;
        vexDefConfig[ _cfg1->pin ].chan = _cfg1->chan;
        }
}