도움 부탁드립니다.
첫 글이 이런 글이라 정말 죄송합니다 ㅜ ㅜ
멀티위FC보드에 초음파센서 거리측정 값을 가지고 버저를 동작하고 싶은데
버저소스 중 어디를 건드려야 할지 모르겠어요.
==========================================================
// Current Buzzer mode
static uint8_t buzzerMode = BUZZER_STOPPED;
// Buzzer off = 0 Buzzer on = 1
static uint8_t buzzerIsOn = 0;
// Pointer to current sequence
static const uint8_t *buzzerPtr = NULL;
// Place in current sequence
static uint16_t buzzerPos = 0;
// Time when buzzer routine must act next time
static uint32_t buzzerNextToggleTime = 0;
// Variable for checking if ready beep has been done
static uint8_t readyBeepDone = 0;
void buzzer(uint8_t mode)
{
uint8_t i = 0;
// Just return if same or higher priority sound is active.
if (buzzerMode <= mode)
return;
switch (mode) {
case BUZZER_STOP:
buzzerMode = BUZZER_STOPPED;
buzzerNextToggleTime = millis();
BEEP_OFF;
buzzerIsOn = 0;
buzzerPtr = NULL;
break;
case BUZZER_READY_BEEP:
if (readyBeepDone)
return;
buzzerPtr = buzz_readyBeep;
buzzerMode = mode;
readyBeepDone = 1;
break;
case BUZZER_ARMING:
case BUZZER_DISARMING:
buzzerPtr = buzz_mediumBeepFast;
buzzerMode = mode;
buzzerNextToggleTime = 0;
break;
case BUZZER_ACC_CALIBRATION:
buzzerPtr = buzz_2shortBeeps;
buzzerMode = mode;
break;
case BUZZER_ACC_CALIBRATION_FAIL:
buzzerPtr = buzz_3shortBeeps;
buzzerMode = mode;
break;
case BUZZER_TX_LOST_ARMED:
buzzerPtr = buzz_sos;
buzzerMode = mode;
break;
case BUZZER_BAT_LOW:
buzzerPtr = buzz_longBeep;
buzzerMode = mode;
break;
case BUZZER_BAT_CRIT_LOW:
buzzerPtr = buzz_BatteryBeep;
buzzerMode = mode;
break;
case BUZZER_ARMED:
case BUZZER_TX_LOST:
buzzerPtr = buzz_mediumBeep;
buzzerMode = mode;
break;
case BUZZER_ARMING_GPS_FIX:
buzzerPtr = buzz_armed;
buzzerMode = mode;
buzzerNextToggleTime = 0;
break;
case BUZZER_TX_SET;
#ifdef GPS
if (feature(FEATURE_GPS) && f.GPS_FIX && GPS_numSat >= 5) {
do {
buzz_countSats[i] = 5;
buzz_countSats[i + 1] = 15;
i += 2;
} while (i < 20 && GPS_numSat > i / 2);
buzz_countSats[i + 1] = 100;
buzz_countSats[i + 2] = 0xFF;
buzzerPtr = buzz_countSats;
buzzerMode = mode;
break;
}
#endif
buzzerPtr = buzz_shortBeep;
buzzerMode = mode;
break;
default:
return;
}
buzzerPos = 0;
}
/* buzzerUpdate -function is used in loop. It will update buzzer state
* when the time is correct.
*/
voidbuzzerUpdate(void)
{
// If beeper option from AUX switch has been selected
if (rcOptions[BOXBEEPERON]) {
if (buzzerMode > BUZZER_TX_SET)
buzzer(BUZZER_TX_SET);
}
// Buzzer routine doesn't need to update if there aren't any sounds ongoing
if (buzzerMode == BUZZER_STOPPED || buzzerPtr == NULL)
return;
if (!buzzerIsOn && buzzerNextToggleTime <= millis()) {
buzzerIsOn = 1;
if (buzzerPtr[buzzerPos] != 0)
BEEP_ON;
buzzerCalculations();
} else if (buzzerIsOn && buzzerNextToggleTime <= millis()) {
buzzerIsOn = 0;
if (buzzerPtr[buzzerPos] != 0)
BEEP_OFF;
buzzerCalculations();
}
}
/* buzzerCalculation -function calculates position when is the next time
* to change buzzer state
*/
void buzzerCalculations(void)
{
if (buzzerPtr[buzzerPos] == 0xFE) {
// If sequence is 0xFE then repeat from start
buzzerPos = 0;
} else if (buzzerPtr[buzzerPos] == 0xFF) {
// If sequence is 0xFF then stop
buzzerMode = BUZZER_STOPPED;
BEEP_OFF;
buzzerIsOn = 0;
} else {
// Otherwise advance the sequence and calculate next toggle time
buzzerNextToggleTime = millis() + 10 * buzzerPtr[buzzerPos];
buzzerPos++;
}
}
=====================================================================
3개 함수 안의 내용은 어느정도 이해했는데,
측정값으로 버저 on/off를 하려면 어디를 건디려야 할지 도무지 모르겠습니다ㅜ ㅜ
1. 어느함수를 건드려야 하나요?
2. 정말정말 염치없지만 따로 함수가 필요하다면 어떻게 구성해야할지 대략적으로라도 알려 주실 수 있을까요?
읽어주셔서 감사합니다