1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2024-11-29 07:24:13 +01:00

LP-361 - Don't lose notifications when more than an alarm is active

, fix time between notifications condition, cleanup
This commit is contained in:
Alessio Morale 2016-07-17 17:13:09 +02:00 committed by Philippe Renon
parent 282881ba74
commit cb6319142e
3 changed files with 19 additions and 10 deletions

View File

@ -106,7 +106,7 @@ void onTimerCb(__attribute__((unused)) UAVObjEvent *ev)
SystemAlarmsAlarmGet(&alarms);
for (uint8_t i = 0; i < alarmsMapSize; i++) {
uint8_t alarm = ((uint8_t *)&alarms)[alarmsMap[i].alarmIndex];
uint8_t alarm = SystemAlarmsAlarmToArray(alarms)[alarmsMap[i].alarmIndex];
checkAlarm(alarm,
&alarmStatus[i].lastAlarm,
&alarmStatus[i].lastAlarmTime,
@ -121,16 +121,23 @@ void checkAlarm(uint8_t alarm, uint8_t *last_alarm, uint32_t *last_alm_time, uin
{
if (alarm > SYSTEMALARMS_ALARM_OK) {
uint32_t current_time = PIOS_DELAY_GetuS();
if (*last_alarm < alarm || *last_alm_time + timeBetweenNotifications * 1000 > current_time) {
if (*last_alarm < alarm || (*last_alm_time + timeBetweenNotifications * 1000) < current_time) {
uint8_t sequence = (alarm == SYSTEMALARMS_ALARM_WARNING) ? warn_sequence :
((alarm == SYSTEMALARMS_ALARM_CRITICAL) ? critical_sequence : error_sequence);
bool updated = true;
if (sequence != NOTIFY_SEQUENCE_NULL) {
PIOS_NOTIFICATION_Default_Ext_Led_Play(
updated = PIOS_NOTIFICATION_Default_Ext_Led_Play(
&notifications[sequence],
alarm == SYSTEMALARMS_ALARM_WARNING ? NOTIFY_PRIORITY_REGULAR : NOTIFY_PRIORITY_CRITICAL);
}
*last_alarm = alarm;
*last_alm_time = current_time;
if (updated) {
*last_alarm = alarm;
*last_alm_time = current_time;
}
}
// workaround timer overflow
if (*last_alm_time > current_time) {
*last_alm_time = 0;
}
} else {
*last_alarm = SYSTEMALARMS_ALARM_OK;

View File

@ -56,18 +56,19 @@ pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear)
* @param sequence Sequence to be played
* @param priority Priority of the sequence being played
*/
void PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority)
bool PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority)
{
// alert and alarms are repeated if condition persists. bacground notification instead are set once, so try to prevent loosing any update
// alert and alarms are repeated if condition persists. background notification instead are set once, so try to prevent loosing any update
if (newNotification && priority != NOTIFY_PRIORITY_BACKGROUND) {
// prevent overwriting higher priority or background notifications
if (extLedNotification.priority == NOTIFY_PRIORITY_BACKGROUND || extLedNotification.priority > priority) {
return;
if (extLedNotification.priority == NOTIFY_PRIORITY_BACKGROUND || extLedNotification.priority >= priority) {
return false;
}
}
extLedNotification.priority = priority;
extLedNotification.sequence = *sequence;
newNotification = true;
return true;
}

View File

@ -84,8 +84,9 @@ pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear);
* are repeated only once if repeat = -1
* @param sequence Sequence to be played
* @param priority Priority of the sequence being played
* @return true if sequence is enqueued, false otherwise
*/
void PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority);
bool PIOS_NOTIFICATION_Default_Ext_Led_Play(const LedSequence_t *sequence, pios_notify_priority priority);
/*
* Play a sequence on an external rgb led. Sequences with priority higher than NOTIFY_PRIORITY_LOW