예제 #1
0
파일: charging.c 프로젝트: evchar/charging
static QState Tag_Charging(Tag * const me) {
  QState status;

  switch (Q_SIG(me))
  {
  case Q_ENTRY_SIG:
    {
      printf("charging\r\n");
      START_PWM();
      LED_CHARGE_ON();
      xTimerStart( xTimers[1], 0 );
      RELAY_CHARGE_ON();
      SendChargingstatus();
      status = Q_HANDLED();
      break;
    }

  case Q_CAR_DETECTED_SIG:
    {
      status = Q_TRAN(&Tag_BatteryFull);
      break;
    }

  case Q_STANDBY_SIG:
    {
      status = Q_TRAN(&Tag_Standby);
      break;
    }

  case Q_CHECK_SERVER_SIG:
    {
       if(g_charging_en)
       {
         status = Q_HANDLED();
       }
       else
       {
         status = Q_TRAN(&Tag_ChargingOver);
       }
      break;
    }

  case Q_STOP_SIG:
    {
      status = Q_TRAN(&Tag_ChargingOver);
      break;
    }
  case Q_EXIT_SIG:
    {
      g_charging_en = false;
      xTimerStop( xTimers[1], 0 );
      RELAY_CHARGE_OFF();
      LED_READY_OFF();
      LED_CHARGE_OFF();
      STOP_PWM();
      status = Q_HANDLED();
      break;
    }
  default:
    {
      status = Q_SUPER(&Tag_Active);
      break;
    }
  }
  return status;
}
예제 #2
0
파일: dice.c 프로젝트: rblack42/RRB.AVR
void loop(void)
{
     unsigned char face, j, led_bits;

     if (sleepy_counter > (uint16_t)SLEEPY_COUNT)
     {
	  goto_sleep();
	  finish_roll = 0;
     }

     if (!button_state || !finish_roll)
	  // Button is being pressed; return
	  return;

     // Our randomness is the current value of a 16bit counter tied to
     // the CPU clock / 256 + an 8bit counter tied to the independent
     // watchdog timer oscillator all modulo 6
     face = (result_counter + wdt_counter) % N_FACES;

     // Run the animation for a tad longer
     sleepy_counter = 0;
     delay_by_tenths(3);

     sleepy_counter = 0;
     pattern_fade   = 0;
     old_leds_on    = 0;
     older_leds_on  = 0;
     finish_roll    = 0;

#if defined(SHUFFLE_STUFF)
     // Show some die faces, slowing down as we approach the selected result, i
     for (j = 0; j < 3; j++)
     {
	  START_PWM(2);
	  leds_on = pgm_read_byte(&(sequences[0][shuffle[j]+PATTERN_OFFSET]));
	  delay_by_tenths(2+2*j);
     }
#endif

     // Flash the result on and off very quickly with quick fading
     led_bits = pgm_read_byte(&(sequences[0][face+PATTERN_OFFSET]));
     for (j = 0; j < 7; j++)
     {
	  START_PWM(3);
	  leds_on = (j & 1) ? led_bits : 0;
	  delay_by_tenths(2);
     }
     STOP_PWM();

     // And now display the result (TIMER1_COMPA_vect actually does the display)
     leds_on = led_bits;

#if defined(SHUFFLE_STUFF)
     // Shuffle the list of die faces
     shuffle_faces();
#endif

     // Select a new LED sequence to show wen the button is next pressed
     sequence_index = (result_counter + wdt_counter + face) % N_SEQUENCES;
     pattern_hold   = pgm_read_byte(&(sequences[sequence_index][HOLD_OFFSET]));
     pattern_fade   = pgm_read_byte(&(sequences[sequence_index][FADE_OFFSET]));
     pattern_index  = PATTERN_OFFSET;

     // And now start the idle timer afresh
     sleepy_counter = 0;
}