1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-12-02 10:24:11 +01:00

OP-699 - refacor ugly buzzer code actuaor module

This commit is contained in:
Corvus Corax 2012-11-05 10:09:43 +01:00
parent 774dde3da5
commit e2ca9cbb45

View File

@ -556,34 +556,23 @@ static void setFailsafe(const ActuatorSettingsData * actuatorSettings, const Mix
ActuatorCommandChannelSet(Channel); ActuatorCommandChannelSet(Channel);
} }
#if defined(ARCH_POSIX) || defined(ARCH_WIN32) /**
static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSettingsData * actuatorSettings) * determine buzzer or blink sequence
{ **/
return true;
} typedef enum {BUZZ_BUZZER=0,BUZZ_ARMING=1,BUZZ_INFO=2,BUZZ_MAX=3} buzzertype;
#else
static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSettingsData * actuatorSettings) static inline bool buzzerState(buzzertype type)
{
switch(actuatorSettings->ChannelType[mixer_channel]) {
case ACTUATORSETTINGS_CHANNELTYPE_PWMALARMBUZZER:
case ACTUATORSETTINGS_CHANNELTYPE_ARMINGLED:
case ACTUATORSETTINGS_CHANNELTYPE_INFOLED:
{ {
// This is for buzzers that take a PWM input // This is for buzzers that take a PWM input
static uint32_t currBuzzTune = 0; static uint32_t tune[BUZZ_MAX]={0};
static uint32_t currBuzzTuneState; static uint32_t tunestate[BUZZ_MAX]={0};
static uint32_t currArmingTune = 0;
static uint32_t currArmingTuneState;
static uint32_t currInfoTune = 0;
static uint32_t currInfoTuneState;
uint32_t newTune = 0; uint32_t newTune = 0;
if(actuatorSettings->ChannelType[mixer_channel] == ACTUATORSETTINGS_CHANNELTYPE_PWMALARMBUZZER) if(type==BUZZ_BUZZER)
{ {
// Decide what tune to play // Decide what tune to play
if (AlarmsGet(SYSTEMALARMS_ALARM_BATTERY) > SYSTEMALARMS_ALARM_WARNING) { if (AlarmsGet(SYSTEMALARMS_ALARM_BATTERY) > SYSTEMALARMS_ALARM_WARNING) {
newTune = 0b11110110110000; // pause, short, short, short, long newTune = 0b11110110110000; // pause, short, short, short, long
@ -593,21 +582,14 @@ static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSet
newTune = 0; newTune = 0;
} }
// Do we need to change tune? } else { // BUZZ_ARMING || BUZZ_INFO
if (newTune != currBuzzTune) {
currBuzzTune = newTune;
currBuzzTuneState = currBuzzTune;
}
}
else // ACTUATORSETTINGS_CHANNELTYPE_ARMINGLED || ACTUATORSETTINGS_CHANNELTYPE_INFOLED
{
uint8_t arming; uint8_t arming;
FlightStatusArmedGet(&arming); FlightStatusArmedGet(&arming);
//base idle tune //base idle tune
newTune = 0x80000000; // 0b1000... newTune = 0x80000000; // 0b1000...
// Merge the error pattern for InfoLed // Merge the error pattern for InfoLed
if(actuatorSettings->ChannelType[mixer_channel] == ACTUATORSETTINGS_CHANNELTYPE_INFOLED) if(type==BUZZ_INFO)
{ {
if (AlarmsGet(SYSTEMALARMS_ALARM_BATTERY) > SYSTEMALARMS_ALARM_WARNING) if (AlarmsGet(SYSTEMALARMS_ALARM_BATTERY) > SYSTEMALARMS_ALARM_WARNING)
{ {
@ -622,23 +604,14 @@ static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSet
if (arming == FLIGHTSTATUS_ARMED_ARMED) if (arming == FLIGHTSTATUS_ARMED_ARMED)
newTune |= 0xA0000000; // 0b101000... newTune |= 0xA0000000; // 0b101000...
}
// Do we need to change tune? // Do we need to change tune?
if(actuatorSettings->ChannelType[mixer_channel] == ACTUATORSETTINGS_CHANNELTYPE_ARMINGLED) if (newTune != tune[type]) {
{ tune[type] = newTune;
if (newTune != currArmingTune) { // resynchronize all tunes on change, so they stay in sync
currArmingTune = newTune; for (int i=0;i<BUZZ_MAX;i++) {
// note: those are both updated so that Info and Arming are in sync if used simultaneously tunestate[i] = tune[i];
currArmingTuneState = currArmingTune;
currInfoTuneState = currInfoTune;
}
}
else
{
if (newTune != currInfoTune) {
currInfoTune = newTune;
currArmingTuneState = currArmingTune;
currInfoTuneState = currInfoTune;
}
} }
} }
@ -649,35 +622,50 @@ static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSet
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 (currBuzzTune||currArmingTune||currInfoTune) { if (tune[type]) {
if(thisSysTime > lastSysTime) if(thisSysTime > lastSysTime) {
dT = thisSysTime - lastSysTime; dT = thisSysTime - lastSysTime;
if(actuatorSettings->ChannelType[mixer_channel] == ACTUATORSETTINGS_CHANNELTYPE_PWMALARMBUZZER) } else {
buzzOn = (currBuzzTuneState&1); // Buzz when the LS bit is 1 lastSysTime = 0; // avoid the case where SysTimeMax-lastSysTime <80
else if(actuatorSettings->ChannelType[mixer_channel] == ACTUATORSETTINGS_CHANNELTYPE_ARMINGLED) }
buzzOn = (currArmingTuneState&1);
else if(actuatorSettings->ChannelType[mixer_channel] == ACTUATORSETTINGS_CHANNELTYPE_INFOLED) buzzOn = (tunestate[type]&1);
buzzOn = (currInfoTuneState&1);
if (dT > 80) { if (dT > 80) {
// Go to next bit in alarm_seq_state // Go to next bit in alarm_seq_state
currArmingTuneState >>=1; for (int i=0;i<BUZZ_MAX;i++) {
currInfoTuneState >>= 1; tunestate[i] >>=1;
currBuzzTuneState >>= 1; if (tunestate[i]==0) // All done, re-start the tune
tunestate[i]=tune[i];
if (currBuzzTuneState == 0) }
currBuzzTuneState = currBuzzTune; // All done, re-start the tune
if (currArmingTuneState == 0)
currArmingTuneState = currArmingTune;
if (currInfoTuneState == 0)
currInfoTuneState = currInfoTune;
lastSysTime = thisSysTime; lastSysTime = thisSysTime;
} }
} }
PIOS_Servo_Set(actuatorSettings->ChannelAddr[mixer_channel], return buzzOn;
buzzOn?actuatorSettings->ChannelMax[mixer_channel]:actuatorSettings->ChannelMin[mixer_channel]); }
#if defined(ARCH_POSIX) || defined(ARCH_WIN32)
static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSettingsData * actuatorSettings)
{
return true; return true;
} }
#else
static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSettingsData * actuatorSettings)
{
switch(actuatorSettings->ChannelType[mixer_channel]) {
case ACTUATORSETTINGS_CHANNELTYPE_PWMALARMBUZZER:
PIOS_Servo_Set(actuatorSettings->ChannelAddr[mixer_channel],
buzzerState(BUZZ_BUZZER)?actuatorSettings->ChannelMax[mixer_channel]:actuatorSettings->ChannelMin[mixer_channel]);
return true;
case ACTUATORSETTINGS_CHANNELTYPE_ARMINGLED:
PIOS_Servo_Set(actuatorSettings->ChannelAddr[mixer_channel],
buzzerState(BUZZ_ARMING)?actuatorSettings->ChannelMax[mixer_channel]:actuatorSettings->ChannelMin[mixer_channel]);
return true;
case ACTUATORSETTINGS_CHANNELTYPE_INFOLED:
PIOS_Servo_Set(actuatorSettings->ChannelAddr[mixer_channel],
buzzerState(BUZZ_INFO)?actuatorSettings->ChannelMax[mixer_channel]:actuatorSettings->ChannelMin[mixer_channel]);
return true;
case ACTUATORSETTINGS_CHANNELTYPE_PWM: case ACTUATORSETTINGS_CHANNELTYPE_PWM:
PIOS_Servo_Set(actuatorSettings->ChannelAddr[mixer_channel], value); PIOS_Servo_Set(actuatorSettings->ChannelAddr[mixer_channel], value);
return true; return true;
@ -686,7 +674,6 @@ static bool set_channel(uint8_t mixer_channel, uint16_t value, const ActuatorSet
return PIOS_SetMKSpeed(actuatorSettings->ChannelAddr[mixer_channel],value); return PIOS_SetMKSpeed(actuatorSettings->ChannelAddr[mixer_channel],value);
case ACTUATORSETTINGS_CHANNELTYPE_ASTEC4: case ACTUATORSETTINGS_CHANNELTYPE_ASTEC4:
return PIOS_SetAstec4Speed(actuatorSettings->ChannelAddr[mixer_channel],value); return PIOS_SetAstec4Speed(actuatorSettings->ChannelAddr[mixer_channel],value);
break;
#endif #endif
default: default:
return false; return false;