Example #1
0
void signalBUZZ(BUZZMODE_t buzz_mode)
{
	switch (buzz_mode)
	{
	case BUZZMODE_OFF:
		buzzerOff();
		break;

	case BUZZMODE_ON:
		buzzerOn();
		break;

	case BUZZMODE_1:
		buzzerFreq(3000);
		buzzerOn();
		xTimerChangePeriod(BuzzerTimer, 200, 10);
		break;

	case BUZZMODE_2:
		buzzerFreq(2500);
		buzzerOn();
		xTimerChangePeriod(BuzzerTimer, 500, 10);
		break;
	}
}
Example #2
0
 inline void enterActiveState() {
   state_is_active = true;
   active_sequence_number = 1;
   active_slot_index = 0;
   timer.restart();
   buzzerOn();
 } 
Example #3
0
static void melodyplayer(uint32_t counter, uint32_t * mi, Melody * m) {
  if (m->notes[(*mi)].tone == 0xFE) {
    // Turn off buzzer since we're at the end
    (*mi) = 0;
    if (sys_effect != 0)
      sys_effect = 0;
    else
      user_effect = 0;
  } else if (mcounter == 0) {
    if (m->notes[(*mi)].tone == 0xFF)
    {
      // Loop the melody
      (*mi) = 0;
    }
    // Play current note
    buzzerOn(m->notes[(*mi)].tone);
    mcounter = (m->bpm * 100) / m->notes[(*mi)].duration;
    (*mi)++;
  }
  else if (mcounter == 1)
  {
      buzzerOff();
  }
  mcounter--;
}
Example #4
0
 // Called from loop() when in ACTIVE state.
 static inline void loopInActiveState() {
   // If within current slot time then do nothing.
   const uint16 slot_time_millis = slotTimeMillis(active_sequence_number, active_slot_index);
   if (timer.timeMillis() < slot_time_millis) {
     return;
   }
   
   // Advance to next slot.
   timer.restart();
   active_slot_index++;
   const uint16 next_slot_time_millis = slotTimeMillis(active_sequence_number, active_slot_index);
       
   // If this is a normal slot, start playing it.
   if (next_slot_time_millis) {
     // Odd slots are off, even are on.
     if (active_slot_index & 0x1) {
       buzzerOff();    
     } 
     else {
       buzzerOn();
     }  
     return;
   }
      
   // Here when we reached a terminator slot at the end of the sequence. 
   
   // If there are pending action, start a new sequence.
   if (pending_actions) {
     // Stay in active state and start another cycle.
     pending_actions = false;
     // We play sequence 1 once and then switch to sequence 2.
     active_sequence_number = 2;
     active_slot_index = 0;
     // First slot is always on (even index).
     buzzerOn();
     return;
   } 
     
   // Here when at end of sequence and no pending action. Switch
   // to off state.
   enterIdleState();
 }
Example #5
0
void failureMode(uint8_t mode)
{
	signalLED(LED_ERR, LEDMODE_ON);
	signalLED(LED_STS, LEDMODE_OFF);

	while (1)
    {
		signalLED(LED_ERR, LEDMODE_TOGGLE);
		signalLED(LED_STS, LEDMODE_TOGGLE);
        delay(50 * mode - 2);
        buzzerOn();
        delay(25);
        buzzerOff();
    }
}
Example #6
0
static void siren(uint32_t counter, uint32_t * mi, Melody * melody)
{
  siren_freq += siren_step;
  if (siren_freq > siren_stop)
  {
    siren_step *= -1;
    siren_freq = siren_stop;
  }
  if (siren_freq < siren_start)
  {
    siren_step *= -1;
    siren_freq = siren_start;
  }
  buzzerOn(siren_freq);
}
Example #7
0
static void tilt(uint32_t counter, uint32_t * mi, Melody * melody)
{
  pitchid = logGetVarId("stabilizer", "pitch");
  rollid = logGetVarId("stabilizer", "roll");

  pitch = logGetInt(pitchid);
  roll = logGetInt(rollid);
  tilt_freq = 0;
  tilt_ratio = 127;

  if (abs(pitch) > 5) {
    tilt_freq = 3000 - 50 * pitch;
  }

  buzzerOn(tilt_freq);
}
Example #8
0
void bindMode(void)
{
  uint32_t prevsend = millis();
  uint8_t  tx_buf[sizeof(bind_data) + 1];
  bool  sendBinds = 1;

  init_rfm(1);

  while (serialAvailable()) {
    serialRead();    // flush serial
  }

  Red_LED_OFF;

  while (1) {
    if (sendBinds & (millis() - prevsend > 200)) {
      prevsend = millis();
      Green_LED_ON;
      buzzerOn(BZ_FREQ);
      tx_buf[0] = 'b';
      memcpy(tx_buf + 1, &bind_data, sizeof(bind_data));
      tx_packet(tx_buf, sizeof(bind_data) + 1);
      Green_LED_OFF;
      buzzerOff();
      RF_Mode = Receive;
      rx_reset();
      delay(50);
      if (RF_Mode == Received) {
        RF_Mode = Receive;
        spiSendAddress(0x7f);   // Send the package read command
        if ('B' == spiReadData()) {
          sendBinds = 0;
        }
      }
    }

    if (!digitalRead(BTN)) {
      sendBinds = 1;
    }

    while (serialAvailable()) {
      Red_LED_ON;
      Green_LED_ON;
      switch (serialRead()) {
      case '\n':
      case '\r':
        printStrLn("Enter menu...");
        handleCLI();
        init_rfm(1);
        break;
      case '#':
        scannerMode();
        break;
      default:
        break;
      }
      Red_LED_OFF;
      Green_LED_OFF;
    }
  }
}
Example #9
0
void setup(void)
{
  watchdogConfig(WATCHDOG_OFF);

  setupSPI();
#ifdef SDN_pin
  pinMode(SDN_pin, OUTPUT); //SDN
  digitalWrite(SDN_pin, 0);
#endif
  //LED and other interfaces
  pinMode(Red_LED, OUTPUT); //RED LED
  pinMode(Green_LED, OUTPUT); //GREEN LED
#ifdef Red_LED2
  pinMode(Red_LED2, OUTPUT); //RED LED
  pinMode(Green_LED2, OUTPUT); //GREEN LED
#endif
  // pinMode(BTN, INPUT); //Button
  pinMode(SLAVE_SELECT, INPUT);
  digitalWrite(SLAVE_SELECT, HIGH); // enable pullup for TX:s with open collector output
  buzzerInit();

  serialInit(115200,SERIAL_8N1);

  checkOperatingMode();

  printStr("OpenLRSng DL starting ");
  printVersion(version);
  printStr(" on HW ");
  printUL(BOARD_TYPE);
  printStr(" (");
  printUL(RFMTYPE);
  printStr("MHz) MDOE=");

  buzzerOn(BZ_FREQ);
  digitalWrite(BTN, HIGH);
  Red_LED_ON ;
  sei();

  delay(50);
  if (!slaveMode) {
    printStrLn("MASTER");
    if (!bindReadEeprom()) {
      printStrLn("eeprom bogus reinit....");
      bindInitDefaults();
      bindWriteEeprom();
    }
    if (!digitalRead(BTN)) {
      bindMode();
    }
  } else {
    printStrLn("SLAVE");
    if (!digitalRead(BTN) || !bindReadEeprom()) {
      bindRX(false);
    } else {
      bindRX(true);
    }
  }

  packetInterval = getInterval(&bind_data);

  printStrLn("Entering normal mode");

  serialFlush();
  serialInit(bind_data.serial_baudrate, bind_data.serial_mode);

  Red_LED_OFF;
  buzzerOff();

  init_rfm(0);
  rfmSetChannel(RF_channel);
  rx_reset();

  if (slaveMode) {
    to_rx_mode();
    RF_Mode = Receive;
  }

  watchdogConfig(WATCHDOG_2S);
  lastReceived=micros();
}
Example #10
0
void beep_handler(void)
{
	uint8_t getNext;

	if (!playing)
		return;

	if (Duration > 0)
	{
		Duration--;
		return;
	}

	do
	{
		if (patternPos >= patternLen)
		{
			// Stop playing
			buzzerOff();
			playing = false;
			return;
		}

		Duration = lastDuration;
		getNext = false;

		switch(patternChar[patternPos++]) {
			case '1': Duration = 1; getNext = true; break;
			case '2': Duration = 2; getNext = true; break;
			case '4': Duration = 4; getNext = true; break;
			case '8': Duration = 8; getNext = true; break;
			case 'A': Frequency = 1760; 			break;
			case 'B': Frequency = 1976; 			break;
			case 'C': Frequency = 1046; 			break;
			case 'D': Frequency = 1175; 			break;
			case 'E': Frequency = 1319; 			break;
			case 'F': Frequency = 1397; 			break;
			case 'G': Frequency = 1568; 			break;
			case 'X': Frequency = 3000; 			break;
			case 'M': Frequency = 2850; 			break;
			case 'L': Frequency = 2700; 			break;
			default:  Frequency = 0;				break;
		}

		lastDuration = Duration;

		if (patternPos < patternLen)
		{
			if (patternChar[patternPos] == 'b')
			{
				Frequency = ((float) Frequency) / 1.05946f;
				patternPos++;
			}
			else if (patternChar[patternPos] == '#')
			{
				Frequency = ((float) Frequency) * 1.05946f;
				patternPos++;
			}
		}
	} while (getNext);

	if (Frequency)
	{
		// Play à note
		buzzerFreq(Frequency);
		buzzerOn();
	}

	else
		buzzerOff();			// Play à pause
}
Example #11
0
static void bypass(uint32_t counter, uint32_t * mi, Melody * melody)
{
  buzzerOn(static_freq);
}