mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-02-06 21:54:15 +01:00
OP-322 Implement Audible alarm via PWM - Different tune for GPS and Battery Alarm
git-svn-id: svn://svn.openpilot.org/OpenPilot/trunk@3035 ebee16cc-31ac-478f-84a7-5cbb03baadba
This commit is contained in:
parent
2d847fe4d7
commit
ea512a3da7
@ -432,7 +432,6 @@ static void actuator_update_rate(UAVObjEvent * ev)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ALARM_SEQ 0b11110110110000 // pause, short, short, short, long
|
|
||||||
|
|
||||||
|
|
||||||
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
|
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
|
||||||
@ -448,27 +447,48 @@ static bool set_channel(uint8_t mixer_channel, uint16_t value) {
|
|||||||
switch(settings.ChannelType[mixer_channel]) {
|
switch(settings.ChannelType[mixer_channel]) {
|
||||||
case ACTUATORSETTINGS_CHANNELTYPE_PWMALARMBUZZER: {
|
case ACTUATORSETTINGS_CHANNELTYPE_PWMALARMBUZZER: {
|
||||||
// This is for buzzers that take a PWM input
|
// This is for buzzers that take a PWM input
|
||||||
bool buzz = false;
|
|
||||||
|
static uint32_t currBuzzTune = 0;
|
||||||
|
static uint32_t currBuzzTuneState;
|
||||||
|
uint32_t bewBuzzTune;
|
||||||
|
|
||||||
|
// Decide what tune to play
|
||||||
|
if (AlarmsGet(SYSTEMALARMS_ALARM_BATTERY) > SYSTEMALARMS_ALARM_WARNING) {
|
||||||
|
bewBuzzTune = 0b11110110110000; // pause, short, short, short, long
|
||||||
|
} else if (AlarmsGet(SYSTEMALARMS_ALARM_GPS) >= SYSTEMALARMS_ALARM_WARNING) {
|
||||||
|
bewBuzzTune = 0x80000000; // pause, short
|
||||||
|
} else {
|
||||||
|
bewBuzzTune = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Do we need to change tune?
|
||||||
|
if (bewBuzzTune != currBuzzTune) {
|
||||||
|
currBuzzTune = bewBuzzTune;
|
||||||
|
currBuzzTuneState = currBuzzTune;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Play tune
|
||||||
|
bool buzzOn = false;
|
||||||
static portTickType lastSysTime = 0;
|
static portTickType lastSysTime = 0;
|
||||||
static uint32_t alarm_seq_state = 0;
|
|
||||||
portTickType thisSysTime = xTaskGetTickCount();
|
portTickType thisSysTime = xTaskGetTickCount();
|
||||||
portTickType dT = 0;
|
portTickType dT = 0;
|
||||||
|
|
||||||
// For now, only look at the battery alarm, because functions like AlarmsHasCritical() can block for some time; to be discussed
|
// For now, only look at the battery alarm, because functions like AlarmsHasCritical() can block for some time; to be discussed
|
||||||
if (AlarmsGet(SYSTEMALARMS_ALARM_BATTERY) > SYSTEMALARMS_ALARM_WARNING) {
|
if (currBuzzTune) {
|
||||||
if(thisSysTime > lastSysTime)
|
if(thisSysTime > lastSysTime)
|
||||||
dT = thisSysTime - lastSysTime;
|
dT = thisSysTime - lastSysTime;
|
||||||
buzz = (alarm_seq_state&1); // Buzz when the LS bit is 1
|
buzzOn = (currBuzzTuneState&1); // Buzz when the LS bit is 1
|
||||||
if (dT > 80) {
|
if (dT > 80) {
|
||||||
// Go to next bit in alarm_seq_state
|
// Go to next bit in alarm_seq_state
|
||||||
alarm_seq_state >>= 1;
|
currBuzzTuneState >>= 1;
|
||||||
if (alarm_seq_state == 0)
|
if (currBuzzTuneState == 0)
|
||||||
alarm_seq_state = ALARM_SEQ; // All done, re-init alarm_seq_state
|
currBuzzTuneState = currBuzzTune; // All done, re-start the tune
|
||||||
lastSysTime = thisSysTime;
|
lastSysTime = thisSysTime;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PIOS_Servo_Set( settings.ChannelAddr[mixer_channel],
|
PIOS_Servo_Set( settings.ChannelAddr[mixer_channel],
|
||||||
buzz?settings.ChannelMax[mixer_channel]:settings.ChannelMin[mixer_channel]);
|
buzzOn?settings.ChannelMax[mixer_channel]:settings.ChannelMin[mixer_channel]);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case ACTUATORSETTINGS_CHANNELTYPE_PWM:
|
case ACTUATORSETTINGS_CHANNELTYPE_PWM:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user