mirror of
https://bitbucket.org/librepilot/librepilot.git
synced 2025-01-19 04:52:12 +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:
parent
715400dd69
commit
fa041ecf05
@ -106,7 +106,7 @@ void onTimerCb(__attribute__((unused)) UAVObjEvent *ev)
|
|||||||
|
|
||||||
SystemAlarmsAlarmGet(&alarms);
|
SystemAlarmsAlarmGet(&alarms);
|
||||||
for (uint8_t i = 0; i < alarmsMapSize; i++) {
|
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,
|
checkAlarm(alarm,
|
||||||
&alarmStatus[i].lastAlarm,
|
&alarmStatus[i].lastAlarm,
|
||||||
&alarmStatus[i].lastAlarmTime,
|
&alarmStatus[i].lastAlarmTime,
|
||||||
@ -121,17 +121,24 @@ void checkAlarm(uint8_t alarm, uint8_t *last_alarm, uint32_t *last_alm_time, uin
|
|||||||
{
|
{
|
||||||
if (alarm > SYSTEMALARMS_ALARM_OK) {
|
if (alarm > SYSTEMALARMS_ALARM_OK) {
|
||||||
uint32_t current_time = PIOS_DELAY_GetuS();
|
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 :
|
uint8_t sequence = (alarm == SYSTEMALARMS_ALARM_WARNING) ? warn_sequence :
|
||||||
((alarm == SYSTEMALARMS_ALARM_CRITICAL) ? critical_sequence : error_sequence);
|
((alarm == SYSTEMALARMS_ALARM_CRITICAL) ? critical_sequence : error_sequence);
|
||||||
|
bool updated = true;
|
||||||
if (sequence != NOTIFY_SEQUENCE_NULL) {
|
if (sequence != NOTIFY_SEQUENCE_NULL) {
|
||||||
PIOS_NOTIFICATION_Default_Ext_Led_Play(
|
updated = PIOS_NOTIFICATION_Default_Ext_Led_Play(
|
||||||
¬ifications[sequence],
|
¬ifications[sequence],
|
||||||
alarm == SYSTEMALARMS_ALARM_WARNING ? NOTIFY_PRIORITY_REGULAR : NOTIFY_PRIORITY_CRITICAL);
|
alarm == SYSTEMALARMS_ALARM_WARNING ? NOTIFY_PRIORITY_REGULAR : NOTIFY_PRIORITY_CRITICAL);
|
||||||
}
|
}
|
||||||
|
if (updated) {
|
||||||
*last_alarm = alarm;
|
*last_alarm = alarm;
|
||||||
*last_alm_time = current_time;
|
*last_alm_time = current_time;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
// workaround timer overflow
|
||||||
|
if (*last_alm_time > current_time) {
|
||||||
|
*last_alm_time = 0;
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
*last_alarm = SYSTEMALARMS_ALARM_OK;
|
*last_alarm = SYSTEMALARMS_ALARM_OK;
|
||||||
}
|
}
|
||||||
|
@ -56,18 +56,19 @@ pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear)
|
|||||||
* @param sequence Sequence to be played
|
* @param sequence Sequence to be played
|
||||||
* @param priority Priority of the sequence being 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) {
|
if (newNotification && priority != NOTIFY_PRIORITY_BACKGROUND) {
|
||||||
// prevent overwriting higher priority or background notifications
|
// prevent overwriting higher priority or background notifications
|
||||||
if (extLedNotification.priority == NOTIFY_PRIORITY_BACKGROUND || extLedNotification.priority > priority) {
|
if (extLedNotification.priority == NOTIFY_PRIORITY_BACKGROUND || extLedNotification.priority >= priority) {
|
||||||
return;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
extLedNotification.priority = priority;
|
extLedNotification.priority = priority;
|
||||||
extLedNotification.sequence = *sequence;
|
extLedNotification.sequence = *sequence;
|
||||||
newNotification = true;
|
newNotification = true;
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -84,8 +84,9 @@ pios_notify_notification PIOS_NOTIFY_GetActiveNotification(bool clear);
|
|||||||
* are repeated only once if repeat = -1
|
* are repeated only once if repeat = -1
|
||||||
* @param sequence Sequence to be played
|
* @param sequence Sequence to be played
|
||||||
* @param priority Priority of the sequence being 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
|
* Play a sequence on an external rgb led. Sequences with priority higher than NOTIFY_PRIORITY_LOW
|
||||||
|
Loading…
x
Reference in New Issue
Block a user