コード例 #1
0
int KeyingGetNextAction()
{
    if(keyerLastAction==KEYER_ACTION_DOT)
    {
        if(!(KEY_IN_PORT_PIN & _BV(KEY_DASH)))
        {
            keyerLastAction=KEYER_ACTION_DASH;
            KeyingSetSymbol(3);
            ToneStart();
        }
        else if(!(KEY_IN_PORT_PIN & _BV(KEY_DOT)))
        {
            keyerLastAction=KEYER_ACTION_DOT;
            KeyingSetSymbol(1);
            ToneStart();
        }
        else
        {
            keyerLastAction=KEYER_ACTION_NONE;
        }
    }
    else if(keyerLastAction==KEYER_ACTION_DASH)
        {
            if(!(KEY_IN_PORT_PIN & _BV(KEY_DOT)))
            {
                keyerLastAction=KEYER_ACTION_DOT;
                KeyingSetSymbol(1);
                ToneStart();
            }
            else if(!(KEY_IN_PORT_PIN & _BV(KEY_DASH)))
            {
                keyerLastAction=KEYER_ACTION_DASH;
                KeyingSetSymbol(3);
                ToneStart();
            }
            else
            {
                keyerLastAction=KEYER_ACTION_NONE;
            }
        }
    else
    {
        keyerLastAction=KEYER_ACTION_NONE;
    }
    return(SUCCESS);
}
コード例 #2
0
int KeyingProcess()
{
    switch(keyerLastAction)
    {
        case KEYER_ACTION_NONE:
            if(!(KEY_IN_PORT_PIN & _BV(KEY_DOT)))
            {
                KeyingSetSymbol(1);
                ToneStart();
                keyerLastAction=KEYER_ACTION_DOT;
            }
            else
            {
                if(!(KEY_IN_PORT_PIN & _BV(KEY_DASH)))
                {
                    KeyingSetSymbol(3);
                    ToneStart();
                    keyerLastAction=KEYER_ACTION_DASH;
                }
                else
                {
                    ToneStop();
                }
            }
            break;
        case KEYER_ACTION_DOT:
        case KEYER_ACTION_DASH:
            if(TIFR1 & _BV(OCF1B))
            {
                //end of symbol
                KeyingGetNextAction();
            }
            else if(TIFR1 & _BV(OCF1A))
            {
                //endo of tone
                ToneStop();
            }
            break;
        default:
            INDICATOR_LED_PORT &= ~_BV(INDICATOR_LED_RED);
    }
    return(SUCCESS);
}
コード例 #3
0
ファイル: tone.cpp プロジェクト: wirebadger/GoKartController
void process_tone( void )
{
  static unsigned long tone_start_time;
  static unsigned int tone_count;
  unsigned long time_now = millis();
  
  switch( tone_state )
  {
    case TONE_IDLE:
      // nothing to do
      break;
    case TONE_START:
      /* start output at tones[tone_playing].frequency */
      ToneStart( tone_playing.frequency );
      tone_start_time = time_now;
      tone_count = tone_playing.repeats;
      tone_state = TONE_PLAYING;
      break;
    case TONE_PLAYING:
      if( (time_now-tone_start_time) >= tone_playing.duration_ms )
      {
        ToneStop();
        if( (tone_playing.pause_ms > 0) && (tone_count != 0) )
        {
          tone_start_time = time_now;
          tone_state = TONE_GAP;
        }
        else
        {
          tone_state = TONE_IDLE;
        }
      }
      break;
    case TONE_GAP:
      if( (time_now-tone_start_time) >= tone_playing.pause_ms )
      {
        /* we should only have come into this state if there was another
         * repeat so we restart the tone. The 'if' below is precautionary.
         */
        if( tone_count > 0 ) 
          tone_count--;
        tone_start_time = time_now;
        /* start tone */
        tone_state = TONE_PLAYING;
      }
      break;
  }
}