From fa041ecf05b925d7ed4902a9f6657bf94848ce48 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 17 Jul 2016 17:13:09 +0200 Subject: [PATCH 1/2] LP-361 - Don't lose notifications when more than an alarm is active , fix time between notifications condition, cleanup --- flight/modules/Notify/notify.c | 17 ++++++++++++----- flight/pios/common/pios_notify.c | 9 +++++---- flight/pios/inc/pios_notify.h | 3 ++- 3 files changed, 19 insertions(+), 10 deletions(-) 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 From 02d04ddf43d8ba6ad6ae19e8742047f9de68bea9 Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Sun, 17 Jul 2016 17:19:34 +0200 Subject: [PATCH 2/2] LP-361 - Cleanup sequences to make alarms easier to understand Error sequence: pause, RED, x 2, pause; warn sequence: pause, ORANGE, , pause; ITEM COLOR: - GPS = GREEN; - MAG = PURPLE; - CONFIG = RED; - RECEIVER = YELLOW. BATTERY ALARM: - warning 5x ORANGE blinks - critical 5x RED blinks DISARMED: short white blinks --- flight/libraries/inc/optypes.h | 7 +- flight/modules/Notify/inc/sequences.h | 103 +++++++++++++------------- 2 files changed, 58 insertions(+), 52 deletions(-) diff --git a/flight/libraries/inc/optypes.h b/flight/libraries/inc/optypes.h index 6b9080db7..677e8bf61 100644 --- a/flight/libraries/inc/optypes.h +++ b/flight/libraries/inc/optypes.h @@ -50,15 +50,18 @@ extern const Color_t Color_White; #define COLOR_BLACK { .R = 0x00, .G = 0x00, .B = 0x00 } #define COLOR_OFF COLOR_BLACK #define COLOR_RED { .R = 0xFF, .G = 0x00, .B = 0x00 } +#define COLOR_DARKRED { .R = 0x80, .G = 0x00, .B = 0x00 } #define COLOR_LIME { .R = 0x00, .G = 0xFF, .B = 0x00 } #define COLOR_BLUE { .R = 0x00, .G = 0x00, .B = 0xFF } -#define COLOR_YELLOW { .R = 0xFF, .G = 0xFF, .B = 0x00 } +#define COLOR_YELLOW { .R = 0xCC, .G = 0xCC, .B = 0x00 } #define COLOR_CIAN { .R = 0x00, .G = 0xFF, .B = 0xFF } #define COLOR_MAGENTA { .R = 0xFF, .G = 0x00, .B = 0xFF } #define COLOR_NAVY { .R = 0x00, .G = 0x00, .B = 0x80 } #define COLOR_GREEN { .R = 0x00, .G = 0x80, .B = 0x00 } #define COLOR_PURPLE { .R = 0x80, .G = 0x00, .B = 0x80 } #define COLOR_TEAL { .R = 0x00, .G = 0x80, .B = 0x80 } -#define COLOR_ORANGE { .R = 0xFF, .G = 0xA5, .B = 0x00 } +#define COLOR_ORANGE { .R = 0xAA, .G = 0x44, .B = 0x00 } #define COLOR_WHITE { .R = 0xAA, .G = 0xAA, .B = 0xAA } + + #endif /* UTIL_H */ diff --git a/flight/modules/Notify/inc/sequences.h b/flight/modules/Notify/inc/sequences.h index 3298d5ff0..72e99203a 100644 --- a/flight/modules/Notify/inc/sequences.h +++ b/flight/modules/Notify/inc/sequences.h @@ -35,25 +35,26 @@ // This represent the list of basic light sequences, defined later typedef enum { NOTIFY_SEQUENCE_ARMED_FM_MANUAL = 0, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1 = 1, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2 = 2, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3 = 3, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4 = 4, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5 = 5, - NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6 = 6, - NOTIFY_SEQUENCE_ARMED_FM_GPS = 8, - NOTIFY_SEQUENCE_ARMED_FM_RTH = 9, - NOTIFY_SEQUENCE_ARMED_FM_LAND = 10, - NOTIFY_SEQUENCE_ARMED_FM_AUTO = 11, - NOTIFY_SEQUENCE_ALM_WARN_GPS = 12, - NOTIFY_SEQUENCE_ALM_ERROR_GPS = 13, - NOTIFY_SEQUENCE_ALM_WARN_BATTERY = 14, - NOTIFY_SEQUENCE_ALM_ERROR_BATTERY = 15, - NOTIFY_SEQUENCE_ALM_MAG = 16, - NOTIFY_SEQUENCE_ALM_CONFIG = 17, - NOTIFY_SEQUENCE_ALM_RECEIVER = 18, - NOTIFY_SEQUENCE_DISARMED = 19, - NOTIFY_SEQUENCE_ALM_ATTITUDE = 20, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5, + NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6, + NOTIFY_SEQUENCE_ARMED_FM_GPS, + NOTIFY_SEQUENCE_ARMED_FM_RTH, + NOTIFY_SEQUENCE_ARMED_FM_LAND, + NOTIFY_SEQUENCE_ARMED_FM_AUTO, + NOTIFY_SEQUENCE_ALM_WARN_GPS, + NOTIFY_SEQUENCE_ALM_ERROR_GPS, + NOTIFY_SEQUENCE_ALM_WARN_BATTERY, + NOTIFY_SEQUENCE_ALM_ERROR_BATTERY, + NOTIFY_SEQUENCE_ALM_WARN_MAG, + NOTIFY_SEQUENCE_ALM_ERROR_MAG, + NOTIFY_SEQUENCE_ALM_CONFIG, + NOTIFY_SEQUENCE_ALM_RECEIVER, + NOTIFY_SEQUENCE_DISARMED, + NOTIFY_SEQUENCE_ALM_ATTITUDE, NOTIFY_SEQUENCE_NULL = 255, // skips any signalling for this condition } NotifySequences; @@ -66,6 +67,21 @@ typedef struct { uint8_t errorNotification; // index of the sequence to be used when alarm is in error status(pick one from NotifySequences enum) } AlarmDefinition_t; +#define STANDARD_ERROR_SEQUENCE(alarm_color, alarm_repeats) \ + { .repeats = alarm_repeats, .steps = { \ + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \ + { .time_off = 100, .time_on = 300, .color = COLOR_DARKRED, .repeats = 1, }, \ + { .time_off = 100, .time_on = 300, .color = alarm_color, .repeats = 2, }, \ + { .time_off = 100, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \ + }, } + +#define STANDARD_WARN_SEQUENCE(alarm_color, alarm_repeats) \ + { .repeats = alarm_repeats, .steps = { \ + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \ + { .time_off = 100, .time_on = 300, .color = COLOR_ORANGE, .repeats = 1, }, \ + { .time_off = 100, .time_on = 300, .color = alarm_color, .repeats = 1, }, \ + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, \ + }, } // This is the list of defined light sequences /* how each sequence is defined @@ -90,10 +106,12 @@ typedef struct { */ const LedSequence_t notifications[] = { [NOTIFY_SEQUENCE_DISARMED] = { .repeats = -1, .steps = { - { .time_off = 500, .time_on = 500, .color = COLOR_TEAL, .repeats = 1, }, + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, + { .time_off = 100, .time_on = 100, .color = COLOR_WHITE, .repeats = 1, }, + { .time_off = 200, .time_on = 10, .color = COLOR_BLACK, .repeats = 1, }, }, }, [NOTIFY_SEQUENCE_ARMED_FM_MANUAL] = { .repeats = -1, .steps = { - { .time_off = 900, .time_on = 100, .color = COLOR_YELLOW, .repeats = 1, }, + { .time_off = 900, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, }, }, }, [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1] = { .repeats = -1, .steps = { { .time_off = 900, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, }, @@ -132,34 +150,19 @@ const LedSequence_t notifications[] = { { .time_off = 100, .time_on = 200, .color = COLOR_GREEN, .repeats = 2, }, { .time_off = 500, .time_on = 200, .color = COLOR_GREEN, .repeats = 1, }, }, }, - - [NOTIFY_SEQUENCE_ALM_WARN_GPS] = { .repeats = 2, .steps = { - { .time_off = 300, .time_on = 300, .color = COLOR_ORANGE, .repeats = 2, }, - { .time_off = 300, .time_on = 300, .color = COLOR_GREEN, .repeats = 1, }, - }, }, - [NOTIFY_SEQUENCE_ALM_ERROR_GPS] = { .repeats = 2, .steps = { - { .time_off = 300, .time_on = 300, .color = COLOR_RED, .repeats = 2, }, - { .time_off = 300, .time_on = 300, .color = COLOR_GREEN, .repeats = 1, }, - }, }, + [NOTIFY_SEQUENCE_ALM_WARN_GPS] = STANDARD_WARN_SEQUENCE(COLOR_GREEN, 1), + [NOTIFY_SEQUENCE_ALM_ERROR_GPS] = STANDARD_ERROR_SEQUENCE(COLOR_GREEN, 1), [NOTIFY_SEQUENCE_ALM_WARN_BATTERY] = { .repeats = 1, .steps = { - { .time_off = 100, .time_on = 100, .color = COLOR_ORANGE, .repeats = 10, }, + { .time_off = 100, .time_on = 100, .color = COLOR_ORANGE, .repeats = 5, }, }, }, [NOTIFY_SEQUENCE_ALM_ERROR_BATTERY] = { .repeats = 1, .steps = { - { .time_off = 100, .time_on = 100, .color = COLOR_RED, .repeats = 10, }, + { .time_off = 100, .time_on = 100, .color = COLOR_RED, .repeats = 5, }, }, }, - [NOTIFY_SEQUENCE_ALM_MAG] = { .repeats = 1, .steps = { - { .time_off = 300, .time_on = 300, .color = COLOR_RED, .repeats = 2, }, - { .time_off = 300, .time_on = 300, .color = COLOR_PURPLE, .repeats = 1, }, - }, }, - [NOTIFY_SEQUENCE_ALM_CONFIG] = { .repeats = 1, .steps = { - { .time_off = 50, .time_on = 50, .color = COLOR_RED, .repeats = 9, }, - { .time_off = 500, .time_on = 50, .color = COLOR_RED, .repeats = 1, }, - }, }, - [NOTIFY_SEQUENCE_ALM_RECEIVER] = { .repeats = 1, .steps = { - { .time_off = 50, .time_on = 50, .color = COLOR_ORANGE, .repeats = 9, }, - { .time_off = 500, .time_on = 50, .color = COLOR_ORANGE, .repeats = 1, }, - }, }, - [NOTIFY_SEQUENCE_ALM_ATTITUDE] = { .repeats = 10, .steps = { + [NOTIFY_SEQUENCE_ALM_ERROR_MAG] = STANDARD_ERROR_SEQUENCE(COLOR_PURPLE, 1), + [NOTIFY_SEQUENCE_ALM_WARN_MAG] = STANDARD_WARN_SEQUENCE(COLOR_PURPLE, 1), + [NOTIFY_SEQUENCE_ALM_CONFIG] = STANDARD_ERROR_SEQUENCE(COLOR_RED, 2), + [NOTIFY_SEQUENCE_ALM_RECEIVER] = STANDARD_ERROR_SEQUENCE(COLOR_YELLOW, 1), + [NOTIFY_SEQUENCE_ALM_ATTITUDE] = { .repeats = 10, .steps = { { .time_off = 0, .time_on = 50, .color = COLOR_RED, .repeats = 1, }, { .time_off = 0, .time_on = 50, .color = COLOR_BLUE, .repeats = 1, }, }, }, @@ -193,7 +196,7 @@ const LedSequence_t *flightModeMap[] = { // List of alarms to show with attached sequences for each status const AlarmDefinition_t alarmsMap[] = { { - .timeBetweenNotifications = 10000, + .timeBetweenNotifications = 5000, .alarmIndex = SYSTEMALARMS_ALARM_GPS, .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_GPS, .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_GPS, @@ -202,9 +205,9 @@ const AlarmDefinition_t alarmsMap[] = { { .timeBetweenNotifications = 5000, .alarmIndex = SYSTEMALARMS_ALARM_MAGNETOMETER, - .warnNotification = NOTIFY_SEQUENCE_NULL, - .criticalNotification = NOTIFY_SEQUENCE_ALM_MAG, - .errorNotification = NOTIFY_SEQUENCE_ALM_MAG, + .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_MAG, + .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_MAG, + .errorNotification = NOTIFY_SEQUENCE_ALM_ERROR_MAG, }, { .timeBetweenNotifications = 15000, @@ -221,7 +224,7 @@ const AlarmDefinition_t alarmsMap[] = { .errorNotification = NOTIFY_SEQUENCE_ALM_CONFIG, }, { - .timeBetweenNotifications = 2000, + .timeBetweenNotifications = 5000, .alarmIndex = SYSTEMALARMS_ALARM_RECEIVER, .warnNotification = NOTIFY_SEQUENCE_ALM_RECEIVER, .criticalNotification = NOTIFY_SEQUENCE_ALM_RECEIVER,