Beispiel #1
0
int main(void)
{
  DynamixelPacket dpacketIn;
  DynamixelPacketInit(&dpacketIn);

  int c;
  int ret;
  uint8_t id;
  uint8_t type;
  uint8_t * data;
  
  uart_init();
  uart_setbaud(115200);

  //enable global interrupts 
  sei ();

  //uart_printf("hello\n\r");

  DDRC  |= _BV(PINC0);
  LaserOff();
  
  while(1)
  {
    c= uart_getchar();
    if (c != EOF)
     uart_putchar(c);
  }


  while(1)
  {
    c= uart_getchar();
    if (c != EOF)
    {
      ret = DynamixelPacketProcessChar(c,&dpacketIn);
      if (ret > 0)
      {
        id = DynamixelPacketGetId(&dpacketIn);
        if (id == LASER_POINTER_ID)
        {
          type = DynamixelPacketGetType(&dpacketIn);
          if (type == INSTRUCTION_WRITE_DATA)
          {
            data = DynamixelPacketGetData(&dpacketIn);
            if (data[0] == 0)
              LaserOff();
            else
              LaserOn();
          }
        }
      }
    }
  }
  

  return 0;
}
//---------------------------------------------------------
// This starts the bullet state machine.  The actual effects
// of the bullet will happen later.  This function schedules 
// those effects.
//
// fDirectShot indicates whether the bullet is a "direct shot"
// that is - fired with the intent that it will strike the
// enemy. Otherwise, the bullet is intended to strike a 
// decoy object or nothing at all in particular.
//---------------------------------------------------------
bool CNPC_Combine_Cannon::FireBullet( const Vector &vecTarget, bool bDirectShot )
{
	Vector vecBulletOrigin = GetBulletOrigin();
	Vector vecDir = ( vecTarget - vecBulletOrigin );
	VectorNormalize( vecDir );

	FireBulletsInfo_t info;
	info.m_iShots = 1;
	info.m_iTracerFreq = 1;
	info.m_vecDirShooting = vecDir;
	info.m_vecSrc = vecBulletOrigin;
	info.m_flDistance = MAX_TRACE_LENGTH;
	info.m_pAttacker = this;
	info.m_iAmmoType = m_iAmmoType;
	info.m_iPlayerDamage = 20;
	info.m_vecSpread = Vector( 0.015f, 0.015f, 0.015f );  // medium cone

	FireBullets( info );

	EmitSound( "NPC_Combine_Cannon.FireBullet" );

	// Don't attack for a certain amount of time
	SetNextAttack( gpGlobals->curtime + GetRefireTime() );

	// Sniper had to be aiming here to fire here, so make it the cursor
	m_vecPaintCursor = vecTarget;

	LaserOff();

	return true;
}
void CNPC_Portal_FloorTurret::InactiveThink( void )
{
	LaserOff();
	RopesOff();

	// Update our PVS state
	CheckPVSCondition();

	SetNextThink( gpGlobals->curtime + 1.0f );

	// Wake up if we're not on our side
	if ( !OnSide() && VPhysicsGetObject()->GetContactPoint( NULL, NULL ) && m_bEnabled )
	{
		// Never return to life!
		SetCollisionGroup( COLLISION_GROUP_NONE );
		//ReturnToLife();
	}
	else
	{
		IPhysicsObject *pTurretPhys = VPhysicsGetObject();

		if ( !(pTurretPhys->GetGameFlags() & FVPHYSICS_PLAYER_HELD) && pTurretPhys->IsAsleep() )
			SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER );
		else
			SetCollisionGroup( COLLISION_GROUP_NONE );
	}
}
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void CNPC_Combine_Cannon::OnScheduleChange( void )
{
	LaserOff();
	
	m_hBarrageTarget = NULL;

	BaseClass::OnScheduleChange();
}
void CNPC_Portal_FloorTurret::UpdateOnRemove( void )
{
	if ( IsDissolving() )
		EmitSound( GetTurretTalkName( PORTAL_TURRET_DISSOLVED ) );

	LaserOff();
	RopesOff();
	BaseClass::UpdateOnRemove();
}
//-----------------------------------------------------------------------------
// Purpose: The turret is not doing anything at all
//-----------------------------------------------------------------------------
void CNPC_Portal_FloorTurret::DisabledThink( void )
{
	LaserOff();
	RopesOff();

	SetNextThink( gpGlobals->curtime + 0.5 );
	if ( OnSide() )
	{
		m_OnTipped.FireOutput( this, this );
		SetEyeState( TURRET_EYE_DEAD );
		//SetCollisionGroup( COLLISION_GROUP_DEBRIS_TRIGGER );
		SetThink( NULL );
	}

}
//-----------------------------------------------------------------------------
// Purpose: Avoid aiming/drawing beams while opening and closing
// Input  :  - 
//-----------------------------------------------------------------------------
void CNPC_RocketTurret::ClosingThink()
{
	LaserOff();

	// Require these poses for this animation
	QAngle vecNeutralAngles ( 0, 90, 0 );
	m_vecGoalAngles = vecNeutralAngles;

	// Once we're within 10 degrees of the neutral pose, start close animation.
	if ( UpdateFacing() <= 10.0f )
	{
		StudioFrameAdvance();
	}

	SetNextThink( gpGlobals->curtime + ROCKET_TURRET_THINK_RATE );

	// Start following player after we're fully opened
	float flCurProgress = GetCycle();
	if ( flCurProgress >= 0.99f )
	{
		SetThink( NULL );
		SetNextThink( TICK_NEVER_THINK );
	}
}
void EffectManager :: Poll
(
    unsigned long                                   time,
    bool                                            offHook
)
{
    static bool runEffects = false;
    static unsigned short effectCount = 0;
    static bool laserMode = false;
    PollLaser(time);        
    if ((time - m_pollDelay) > EFFECT_POLL_DELAY_MS)
    {
        //EM_DEBUG("BEGIN POLL");
        //EM_DEBUG(effectCount);
        //static int ringer = 0;
        //ringer++;
        
        m_pollDelay = time;
        bool switchEffect = (effectCount == 0);

        // Which index are we in the array of effects for this mode:
        //static char *currentEffect; // 0 in case it is not specified

        //static Effect * effects;
        switch (m_mode)
        {
        case EM_MODE_RING:
        case EM_MODE_IDLE:
            if (m_disablePanels)
            {
                SetMode(EM_MODE_DISABLE);
                m_panelsDisabled = false;
            }
            if
            (
                digitalRead(PHONE_PIN_RING_DETECT)
            //||  (ringer & 32)
            )
            {
                SetMode(EM_MODE_RING);
                if (switchEffect)
                {
                    m_currentRing++;
                    if (m_currentRing >= m_sizeRing)
                    {
                        m_currentRing = 0;
                    }
                    effectCount = m_effectsRing[m_currentRing].duration;
                }
            } else {
                SetMode(EM_MODE_IDLE);
                if (switchEffect)
                {
                    m_currentIdle++;
                    if (m_currentIdle >= m_sizeIdle)
                    {
                        m_currentIdle = 0;
                    }
                    effectCount = m_effectsIdle[m_currentIdle].duration;
                }
            }
            
            if (offHook)
            {
                SetMode(EM_MODE_CALL);
            }
            break;
        case EM_MODE_CALL:
            if (m_laserCallCount == 0)
            {
                LaserOff();
                m_laserCallCount = -1;
            }
            else if (m_laserCallCount > 0)
            {
                m_laserCallCount--;
            }
                
            if (switchEffect)
            {
                m_currentCall++;
                if (m_currentCall >= m_sizeCall)
                {
                    m_currentCall = 0;
                }
                effectCount = m_effectsCall[m_currentCall].duration;

            }
            //currentEffect = m_currentCall;
            if (!offHook)
            {
                SetMode(EM_MODE_CALLENDED);
            }
            if ((time - m_duration) > MAX_CALL_DURATION_MS)
            {
                EM_DEBUG("EM:   Call went overtime.");
                SetMode(EM_MODE_CALL_OVERTIME);
            }
            break;
        case EM_MODE_CALL_OVERTIME:
            // Whoops, the person was on the line too long:
            if (switchEffect)
            {
                m_currentOver++;
                if (m_currentOver >= m_sizeOver)
                {
                    m_currentOver = 0;
                }
                effectCount = m_effectsOver[m_currentOver].duration;
            }            
            if (!offHook)
            {
                SetMode(EM_MODE_CALLENDED);
            }
            break;
        case EM_MODE_CALLENDED_REBOOTED:
            if (RebootComplete())
            {
                SetMode(EM_MODE_IDLE);
            }
            break;
        case EM_MODE_DISABLE_STANDBY:
            if (m_disablePanels == false)
            {
                m_panelsDisabled = false;
                RebootPanels();
                SetMode(EM_MODE_CALLENDED_REBOOTED);
            }
            
            // Do nothing.
            m_pollDelay += EM_FADE_DELAY_MS; // To reduce poll time.

            break;
        default:
            break;

        }

        if (m_modePrevious != m_mode)
        {
            m_modePrevious = m_mode;

            // All variables in this section must be persistent
            runEffects = false;
            // Triggered once per mode change.
            switch(m_mode)
            {
            case EM_MODE_IDLE:
                EM_DEBUG("EM:   State: IDLE");
                LaserOff();
                SET_EFFECT(m_effectsIdle, &m_currentIdle);
                break;
            case EM_MODE_RING:
                EM_DEBUG("EM:   State: RING");
                m_canvas.ClearCeiling(0);
                LaserOn();
                m_currentRing++;
                if (m_currentRing >= m_sizeRing)
                {
                    m_currentRing = 0;
                }
                effectCount = m_effectsRing[m_currentRing].duration;

                SET_EFFECT(m_effectsRing, &m_currentRing);
                break;
            case EM_MODE_CALL:
                EM_DEBUG("EM:   State: CALL");
                // The current time so we can shut down the effects if the
                // person is taking too long
                m_duration = time;
                m_currentCall++;
                if (m_currentCall >= m_sizeCall)
                {
                    m_currentCall = 0;
                }
                effectCount = m_effectsCall[m_currentCall].duration;
                LaserOn();
                m_laserCallCount = EM_LASER_CALL_COUNT;
                // Restore the lights!
                m_canvas.ClearCeiling(0);
                SET_EFFECT(m_effectsCall, &m_currentCall);
                break;               
            case EM_MODE_CALL_OVERTIME:
                EM_DEBUG("EM:   State: OVER");
                LaserOff();
                // The current time so we can shut down the effects if the
                // person is taking too long
                effectCount = 0;
                // Restore the lights!
                SET_EFFECT(m_effectsOver, &m_currentOver);
                break;             
            case EM_MODE_CALLENDED_REBOOTED:
                EM_DEBUG("EM:   State: CALLENDED_REBOOTED");
                break;  
            case EM_MODE_CALLENDED:
                EM_DEBUG("EM:   State: CALLENDED");
                LaserOff();
                // The call ended, fade those panels out.
                m_canvas.FadeToBlack();

                //EM_DEBUG2("EM:   State: CALLENDED: time: ");
                //EM_DEBUG((unsigned long)time);
                //EM_DEBUG2("EM:   State: CALLENDED: poll: ");
                //EM_DEBUG((unsigned long)m_pollDelay);

                m_pollDelay += EM_FADE_DELAY_MS;
                //EM_DEBUG2("EM:   State: CALLENDED: poll: ");
                //EM_DEBUG((unsigned long)m_pollDelay);
                //EM_DEBUG("EM:   State: CALLENDED (fading command issued)");
                
                SetMode(EM_MODE_CALLENDED_FADE_END);
                //EM_DEBUG("EM:   State: CALLENDED - FINISH");
                break;
            case EM_MODE_CALLENDED_FADE_END:
                EM_DEBUG("EM:   State: CALLENDED FADEEND");
                // Wait until the power manager is ready, and then
                // reboot the panels:
                RebootPanels();
                SetMode(EM_MODE_CALLENDED_REBOOTED);
                /*if (m_pm->Ready())
                {
                    if (m_pm->GetPowerStatus() == PM_POWER_ON)
                    {
                        m_pm->PowerDown();
                    } else {
                        m_pm->PowerUp();
                        // Idea: wait another bit before switching mode?
                        SetMode(EM_MODE_IDLE);
                    }
                }*/
                break;
            case EM_MODE_DISABLE:
                EM_DEBUG("EM:   State: DISABLE - Fading panels");
                LaserOff();
                // Fade out
                m_canvas.FadeToBlack();
                m_pollDelay += EM_FADE_DELAY_MS; // 2 seconds delay
                SetMode(EM_MODE_DISABLE_FADE_END);
                break;
            case EM_MODE_DISABLE_FADE_END:
                EM_DEBUG("EM:   State: DISABLE_FADEEND");
                // We're all faded out, terminate power.  The only way out of 
                // this mode is a call to EnableEffects().
                m_pm->PowerDown();
                SetMode(EM_MODE_DISABLE_STANDBY);
                break;
            case EM_MODE_DISABLE_STANDBY:
                EM_DEBUG("EM:   State: DISABLE_STANDBY - Low power mode activated.");
                break;
            default:
                EM_DEBUG("EM:   State: UNKNOWN!");
                break;
            };
        }
        if (runEffects)
        {
            m_spectrum.ReadSpectrum();
            switch(m_mode)
            {
            case EM_MODE_IDLE:
                m_effectsIdle[m_currentIdle].func
                (
                    &m_canvas, 
                    const_cast<EffectManager *>(this), 
                    EFFECTMODE_LOOP
                );
                break;
            case EM_MODE_RING:
                m_effectsRing[m_currentRing].func
                (
                    &m_canvas, 
                    const_cast<EffectManager *>(this), 
                    EFFECTMODE_LOOP
                );
                break;
            case EM_MODE_CALL:
                m_effectsCall[m_currentCall].func
                (
                    &m_canvas, 
                    const_cast<EffectManager *>(this), 
                    EFFECTMODE_LOOP
                );
                break;
            case EM_MODE_CALL_OVERTIME:
                m_effectsOver[m_currentOver].func
                (
                    &m_canvas, 
                    const_cast<EffectManager *>(this), 
                    EFFECTMODE_LOOP
                );
                break;
            default:
                EM_DEBUG("EM:   ERROR MODE");
                break;
            }
            
            //EM_DEBUG("runEffects");
            //EM_DEBUG((int)(*currentEffect));
            //EM_DEBUG("ringer");
            //EM_DEBUG((int)(ringer));
            //Effect *theEffect = (effects + (*currentEffect));
            
#ifndef EM_DEBUG_NOBLIT
            m_canvas.BlitToPanels();
#endif
        }
        if (effectCount > 0)
        {
            effectCount--;
        }

    }
}