diff --git a/flight/modules/Notify/notify.c b/flight/modules/Notify/notify.c index ef6aee552..ed3f7ded2 100644 --- a/flight/modules/Notify/notify.c +++ b/flight/modules/Notify/notify.c @@ -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( ¬ifications[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; diff --git a/flight/pios/common/pios_notify.c b/flight/pios/common/pios_notify.c index 9b0a1fc67..1cf86a00d 100644 --- a/flight/pios/common/pios_notify.c +++ b/flight/pios/common/pios_notify.c @@ -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; } diff --git a/flight/pios/inc/pios_notify.h b/flight/pios/inc/pios_notify.h index 12daefdc2..3ee6a3dec 100644 --- a/flight/pios/inc/pios_notify.h +++ b/flight/pios/inc/pios_notify.h @@ -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