1
0
mirror of https://bitbucket.org/librepilot/librepilot.git synced 2025-01-19 04:52:12 +01:00

Merged in alessiomorale/librepilot/LP-361_notification_improvements (pull request #283)

Lp 361_notification_improvements
This commit is contained in:
Lalanne Laurent 2016-07-21 20:05:54 +02:00
commit 2de896818e
5 changed files with 77 additions and 62 deletions

View File

@ -50,15 +50,18 @@ extern const Color_t Color_White;
#define COLOR_BLACK { .R = 0x00, .G = 0x00, .B = 0x00 } #define COLOR_BLACK { .R = 0x00, .G = 0x00, .B = 0x00 }
#define COLOR_OFF COLOR_BLACK #define COLOR_OFF COLOR_BLACK
#define COLOR_RED { .R = 0xFF, .G = 0x00, .B = 0x00 } #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_LIME { .R = 0x00, .G = 0xFF, .B = 0x00 }
#define COLOR_BLUE { .R = 0x00, .G = 0x00, .B = 0xFF } #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_CIAN { .R = 0x00, .G = 0xFF, .B = 0xFF }
#define COLOR_MAGENTA { .R = 0xFF, .G = 0x00, .B = 0xFF } #define COLOR_MAGENTA { .R = 0xFF, .G = 0x00, .B = 0xFF }
#define COLOR_NAVY { .R = 0x00, .G = 0x00, .B = 0x80 } #define COLOR_NAVY { .R = 0x00, .G = 0x00, .B = 0x80 }
#define COLOR_GREEN { .R = 0x00, .G = 0x80, .B = 0x00 } #define COLOR_GREEN { .R = 0x00, .G = 0x80, .B = 0x00 }
#define COLOR_PURPLE { .R = 0x80, .G = 0x00, .B = 0x80 } #define COLOR_PURPLE { .R = 0x80, .G = 0x00, .B = 0x80 }
#define COLOR_TEAL { .R = 0x00, .G = 0x80, .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 } #define COLOR_WHITE { .R = 0xAA, .G = 0xAA, .B = 0xAA }
#endif /* UTIL_H */ #endif /* UTIL_H */

View File

@ -35,25 +35,26 @@
// This represent the list of basic light sequences, defined later // This represent the list of basic light sequences, defined later
typedef enum { typedef enum {
NOTIFY_SEQUENCE_ARMED_FM_MANUAL = 0, NOTIFY_SEQUENCE_ARMED_FM_MANUAL = 0,
NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1 = 1, NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1,
NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2 = 2, NOTIFY_SEQUENCE_ARMED_FM_STABILIZED2,
NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3 = 3, NOTIFY_SEQUENCE_ARMED_FM_STABILIZED3,
NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4 = 4, NOTIFY_SEQUENCE_ARMED_FM_STABILIZED4,
NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5 = 5, NOTIFY_SEQUENCE_ARMED_FM_STABILIZED5,
NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6 = 6, NOTIFY_SEQUENCE_ARMED_FM_STABILIZED6,
NOTIFY_SEQUENCE_ARMED_FM_GPS = 8, NOTIFY_SEQUENCE_ARMED_FM_GPS,
NOTIFY_SEQUENCE_ARMED_FM_RTH = 9, NOTIFY_SEQUENCE_ARMED_FM_RTH,
NOTIFY_SEQUENCE_ARMED_FM_LAND = 10, NOTIFY_SEQUENCE_ARMED_FM_LAND,
NOTIFY_SEQUENCE_ARMED_FM_AUTO = 11, NOTIFY_SEQUENCE_ARMED_FM_AUTO,
NOTIFY_SEQUENCE_ALM_WARN_GPS = 12, NOTIFY_SEQUENCE_ALM_WARN_GPS,
NOTIFY_SEQUENCE_ALM_ERROR_GPS = 13, NOTIFY_SEQUENCE_ALM_ERROR_GPS,
NOTIFY_SEQUENCE_ALM_WARN_BATTERY = 14, NOTIFY_SEQUENCE_ALM_WARN_BATTERY,
NOTIFY_SEQUENCE_ALM_ERROR_BATTERY = 15, NOTIFY_SEQUENCE_ALM_ERROR_BATTERY,
NOTIFY_SEQUENCE_ALM_MAG = 16, NOTIFY_SEQUENCE_ALM_WARN_MAG,
NOTIFY_SEQUENCE_ALM_CONFIG = 17, NOTIFY_SEQUENCE_ALM_ERROR_MAG,
NOTIFY_SEQUENCE_ALM_RECEIVER = 18, NOTIFY_SEQUENCE_ALM_CONFIG,
NOTIFY_SEQUENCE_DISARMED = 19, NOTIFY_SEQUENCE_ALM_RECEIVER,
NOTIFY_SEQUENCE_ALM_ATTITUDE = 20, NOTIFY_SEQUENCE_DISARMED,
NOTIFY_SEQUENCE_ALM_ATTITUDE,
NOTIFY_SEQUENCE_NULL = 255, // skips any signalling for this condition NOTIFY_SEQUENCE_NULL = 255, // skips any signalling for this condition
} NotifySequences; } 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) uint8_t errorNotification; // index of the sequence to be used when alarm is in error status(pick one from NotifySequences enum)
} AlarmDefinition_t; } 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 // This is the list of defined light sequences
/* how each sequence is defined /* how each sequence is defined
@ -90,10 +106,12 @@ typedef struct {
*/ */
const LedSequence_t notifications[] = { const LedSequence_t notifications[] = {
[NOTIFY_SEQUENCE_DISARMED] = { .repeats = -1, .steps = { [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 = { [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 = { [NOTIFY_SEQUENCE_ARMED_FM_STABILIZED1] = { .repeats = -1, .steps = {
{ .time_off = 900, .time_on = 100, .color = COLOR_BLUE, .repeats = 1, }, { .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 = 100, .time_on = 200, .color = COLOR_GREEN, .repeats = 2, },
{ .time_off = 500, .time_on = 200, .color = COLOR_GREEN, .repeats = 1, }, { .time_off = 500, .time_on = 200, .color = COLOR_GREEN, .repeats = 1, },
}, }, }, },
[NOTIFY_SEQUENCE_ALM_WARN_GPS] = STANDARD_WARN_SEQUENCE(COLOR_GREEN, 1),
[NOTIFY_SEQUENCE_ALM_WARN_GPS] = { .repeats = 2, .steps = { [NOTIFY_SEQUENCE_ALM_ERROR_GPS] = STANDARD_ERROR_SEQUENCE(COLOR_GREEN, 1),
{ .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_BATTERY] = { .repeats = 1, .steps = { [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 = { [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 = { [NOTIFY_SEQUENCE_ALM_ERROR_MAG] = STANDARD_ERROR_SEQUENCE(COLOR_PURPLE, 1),
{ .time_off = 300, .time_on = 300, .color = COLOR_RED, .repeats = 2, }, [NOTIFY_SEQUENCE_ALM_WARN_MAG] = STANDARD_WARN_SEQUENCE(COLOR_PURPLE, 1),
{ .time_off = 300, .time_on = 300, .color = COLOR_PURPLE, .repeats = 1, }, [NOTIFY_SEQUENCE_ALM_CONFIG] = STANDARD_ERROR_SEQUENCE(COLOR_RED, 2),
}, }, [NOTIFY_SEQUENCE_ALM_RECEIVER] = STANDARD_ERROR_SEQUENCE(COLOR_YELLOW, 1),
[NOTIFY_SEQUENCE_ALM_CONFIG] = { .repeats = 1, .steps = { [NOTIFY_SEQUENCE_ALM_ATTITUDE] = { .repeats = 10, .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 = {
{ .time_off = 0, .time_on = 50, .color = COLOR_RED, .repeats = 1, }, { .time_off = 0, .time_on = 50, .color = COLOR_RED, .repeats = 1, },
{ .time_off = 0, .time_on = 50, .color = COLOR_BLUE, .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 // List of alarms to show with attached sequences for each status
const AlarmDefinition_t alarmsMap[] = { const AlarmDefinition_t alarmsMap[] = {
{ {
.timeBetweenNotifications = 10000, .timeBetweenNotifications = 5000,
.alarmIndex = SYSTEMALARMS_ALARM_GPS, .alarmIndex = SYSTEMALARMS_ALARM_GPS,
.warnNotification = NOTIFY_SEQUENCE_ALM_WARN_GPS, .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_GPS,
.criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_GPS, .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_GPS,
@ -202,9 +205,9 @@ const AlarmDefinition_t alarmsMap[] = {
{ {
.timeBetweenNotifications = 5000, .timeBetweenNotifications = 5000,
.alarmIndex = SYSTEMALARMS_ALARM_MAGNETOMETER, .alarmIndex = SYSTEMALARMS_ALARM_MAGNETOMETER,
.warnNotification = NOTIFY_SEQUENCE_NULL, .warnNotification = NOTIFY_SEQUENCE_ALM_WARN_MAG,
.criticalNotification = NOTIFY_SEQUENCE_ALM_MAG, .criticalNotification = NOTIFY_SEQUENCE_ALM_ERROR_MAG,
.errorNotification = NOTIFY_SEQUENCE_ALM_MAG, .errorNotification = NOTIFY_SEQUENCE_ALM_ERROR_MAG,
}, },
{ {
.timeBetweenNotifications = 15000, .timeBetweenNotifications = 15000,
@ -221,7 +224,7 @@ const AlarmDefinition_t alarmsMap[] = {
.errorNotification = NOTIFY_SEQUENCE_ALM_CONFIG, .errorNotification = NOTIFY_SEQUENCE_ALM_CONFIG,
}, },
{ {
.timeBetweenNotifications = 2000, .timeBetweenNotifications = 5000,
.alarmIndex = SYSTEMALARMS_ALARM_RECEIVER, .alarmIndex = SYSTEMALARMS_ALARM_RECEIVER,
.warnNotification = NOTIFY_SEQUENCE_ALM_RECEIVER, .warnNotification = NOTIFY_SEQUENCE_ALM_RECEIVER,
.criticalNotification = NOTIFY_SEQUENCE_ALM_RECEIVER, .criticalNotification = NOTIFY_SEQUENCE_ALM_RECEIVER,

View File

@ -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,16 +121,23 @@ 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(
&notifications[sequence], &notifications[sequence],
alarm == SYSTEMALARMS_ALARM_WARNING ? NOTIFY_PRIORITY_REGULAR : NOTIFY_PRIORITY_CRITICAL); alarm == SYSTEMALARMS_ALARM_WARNING ? NOTIFY_PRIORITY_REGULAR : NOTIFY_PRIORITY_CRITICAL);
} }
*last_alarm = alarm; if (updated) {
*last_alm_time = current_time; *last_alarm = alarm;
*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;

View File

@ -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;
} }

View File

@ -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